-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter.py
More file actions
70 lines (58 loc) · 1.67 KB
/
character.py
File metadata and controls
70 lines (58 loc) · 1.67 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
68
69
70
import pyglet
import sys
import random
import math
from drawable import Drawable
from pyglet.window import key
from entity import Entity
class Character(Entity):
DOWN = 4
UP = 5
RIGHT = 6
LEFT = 7
def __init__(self, game, tx, ty, group):
super().__init__(game, tx, ty, group)
self.particle_hitbox = (0,0,7,18)
self.speed = 1.5
self.level = 1
self.xp = 0
self.health_dt = 0
self.direction = self.DOWN
for i in range(4, 8):
self.init_sprite('character_p_'+str(i)+'.png', group)
self.hitbox = (0,0,7,3)
def update(self, dt):
super().update(dt)
vel_x = 0
vel_y = 0
if self.health < 8:
self.health_dt += dt
if self.health_dt > 20:
self.health += 1
self.health_dt = random.random() * 5
if self.game.world.progression != self.game.world.TITLE and self.game.world.progression != self.game.world.TITLE_COMPLETE:
if self.game.keys[key.D]:
vel_x = self.speed
self.direction = self.RIGHT
elif self.game.keys[key.A]:
vel_x = -self.speed
self.direction = self.LEFT
if self.game.keys[key.W]:
vel_y = self.speed
self.direction = self.UP
elif self.game.keys[key.S]:
vel_y = -self.speed
self.direction = self.DOWN
if vel_x != 0 or vel_y != 0:
angle = math.atan2(vel_y, vel_x)
self.vx = math.cos(angle) * self.speed
self.vy = math.sin(angle) * self.speed
else:
self.vx = 0
self.vy = 0
self.set_visible_sprite(self.direction-4)
sprite = self.get_visible_sprite()
sprite.group = self.game.world.group_for(self.ty-1)
if self.xp > 100:
self.level += 1
self.xp = 0