-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.py
83 lines (76 loc) · 4.47 KB
/
hero.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
from enum import Enum
import pygame as pg
class HeroState(Enum):
idle = 0
left = 1
right = 2
jump = 3
class Hero:
def __init__(self, height, width):
self.state = HeroState.idle
self.right_image_array = [
pg.transform.scale(pg.image.load('images/Run (1).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Run (2).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Run (3).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Run (4).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Run (5).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Run (6).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Run (7).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Run (8).png'), (height, width))
]
self.left_image_array = [
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (1).png'), (height, width)), True, False),
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (2).png'), (height, width)), True, False),
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (3).png'), (height, width)), True, False),
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (4).png'), (height, width)), True, False),
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (5).png'), (height, width)), True, False),
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (6).png'), (height, width)), True, False),
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (7).png'), (height, width)), True, False),
pg.transform.flip(pg.transform.scale(pg.image.load('images/Run (8).png'), (height, width)), True, False)
]
self.idle_image_array = [
pg.transform.scale(pg.image.load('images/Idle (1).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Idle (2).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Idle (3).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Idle (4).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Idle (5).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Idle (6).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Idle (7).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Idle (8).png'), (height, width))
]
self.jump_image_array = [
pg.transform.scale(pg.image.load('images/Slide (1).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Slide (2).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Slide (3).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Slide (4).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Slide (5).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Slide (6).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Slide (7).png'), (height, width)),
pg.transform.scale(pg.image.load('images/Slide (8).png'), (height, width))
]
self.animation_index = 0
self.rect = pg.transform.scale(pg.image.load('images/Idle (1).png'), (height, width)).get_rect(x=0, y=0)
def update(self, state):
self.state = state
if self.animation_index + 1 > 49:
self.animation_index = 0
else:
self.animation_index += 1
def draw(self, window, x, y):
index_ = self.animation_index // 7
if self.state == HeroState.right:
image__ = self.right_image_array[index_]
self.rect = image__.get_rect(x=x, y=y)
window.blit(image__, (x, y))
elif self.state == HeroState.left:
image__ = self.left_image_array[index_]
self.rect = image__.get_rect(x=x, y=y)
window.blit(image__, (x, y))
elif self.state == HeroState.idle:
image__ = self.idle_image_array[index_]
self.rect = image__.get_rect(x=x, y=y)
window.blit(image__, (x, y))
elif self.state == HeroState.jump:
image__ = self.jump_image_array[index_]
self.rect = image__.get_rect(x=x, y=y)
window.blit(image__, (x, y))