-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprite.py
86 lines (41 loc) · 1.44 KB
/
Sprite.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#Sprite Class
class Sprite:
def __init__(this, image, start_pos = (0,0)):
this.image = image
this.pos = start_pos
this.gravity = False
this.gravity_speed = 5
def set_image(this, new_imgage):
this.image = new_imgage
def set_pos(this, new_pos):
this.pos = new_pos
def set_gravity(this, value, speed):
this.gravity = True
this.gravity_speed = speed
def render(this, screen, gravity_active = False):
x, y = this.pos
screen.blit(this.image, this.pos)
if (this.gravity and gravity_active):
y += this.gravity_speed
this.pos = (x, y)
def get_image(this):
return this.image
def get_pos(this):
return this.pos
def get_width(this):
return this.image.get_width()
def get_height(this):
return this.image.get_height()
def move(this, speed, left = False, up = False):
x, y = this.pos
if (left):
x -= speed
elif (up):
y -= speed
this.pos = (x, y)
def get_collision(this, other):
x1, y1 = this.pos
x2, y2 = other.get_pos()
if (x1 + this.get_width() >= x2 and x1 + this.get_width() < x2 + other.get_width()):
if (y1 > y2 and y1 < y2 + other.get_height()) or (y1+this.get_height() < y2 + other.get_height() and y1+this.get_height() > y2):
return True