-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.py
More file actions
67 lines (50 loc) · 1.43 KB
/
Copy pathtutorial.py
File metadata and controls
67 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pygame
from pygame.locals import *
import sys # 외장 모듈
import math
# 초기화
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("PyGame")
clock = pygame.time.Clock()
class Character:
def __init__(self, x, y, radius, speed):
self.x = x
self.y = y
self.radius = radius
self.speed = speed
def draw(self):
pygame.draw.circle(screen, (255, 255, 255), (self.x, self.y), self.radius, 0)
def move(self, x, y):
self.x += x
self.y += y
def move_to(self, x, y):
self.x = x
self.y = y
class Goal:
def __init__(self, x, y, radius):
self.x = x
self.y = y
self.radius = radius
def draw(self):
pygame.draw.circle(screen, (255, 0, 0), (self.x, self.y), self.radius, 0)
def collide_check(character, goal):
distance = math.sqrt((character.x - goal.x) ** 2 + (character.y - goal.y) ** 2)
if distance < character.radius + goal.radius:
return True
else:
return False
me = Character(400, 300, 20, 5)
goal = Goal(400, 100, 20)
while True:
clock.tick(60)
screen.fill((0, 0, 0))
me.draw()
goal.draw()
me.move_to(pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])
print(collide_check(me, goal))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()