-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.py
More file actions
51 lines (38 loc) · 1.18 KB
/
enemy.py
File metadata and controls
51 lines (38 loc) · 1.18 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
import pygame
import sys
from pygame.locals import *
class Enemy:
def __init__(self, manager):
self.image = pygame.image.load('res/sprite/enemy.png')
self.x = 0
self.y = 0
self.manager = manager
def set_x(self, x):
self.x = x
def get_width(self):
return self.image.get_width()
def get_height(self):
return self.image.get_height()
def is_reached(self, canvas) -> bool:
if self.manager.left_to_right:
return canvas.get_width() < self.x + self.get_width()
else:
return self.x < 0
def update(self, canvas):
# 끝에 닿았는가? -> 함수로 만들어 보자
if self.is_reached(canvas):
# 매니저에게 알리기
self.manager.reserve_to_change_direction()
# 정해진 방향으로 이동
if self.manager.left_to_right:
self.x += 3
else:
self.x -= 3
if self.manager.move_down:
self.move_down()
def move_down(self):
self.y += self.get_height()
def render(self, canvas):
canvas.blit(self.image, (self.x, self.y))
def onKilled(self):
pass