-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.py
76 lines (59 loc) · 2.88 KB
/
character.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
import os
import pygame
from color import mix_colors, white
from map import Map
up = complex(0,-1)
down = complex(0,1)
right = complex(1,0)
left = complex(-1,0)
#model_up = pygame.image.load(os.path.join("Art","player_up.png"))
#model_down = pygame.image.load(os.path.join("Art","player_down.png"))
#model_right= pygame.image.load(os.path.join("Art","player_right.png"))
#model_left = pygame.image.load(os.path.join("Art","player_left.png"))
#models = {up:model_up, down:model_down, right:model_right, left:model_left}
#models_up = [pygame.image.load(os.path.join("Art","player_u_" + str(i) + ".png")) for i in range(12) + [-1] ]
#models_down = [pygame.image.load(os.path.join("Art","player_d_" + str(i) + ".png")) for i in range(12) + [-1] ]
#models_left = [pygame.image.load(os.path.join("Art","player_l_" + str(i) + ".png")) for i in range(12) + [-1] ]
#models_right = [pygame.image.load(os.path.join("Art","player_r_" + str(i) + ".png")) for i in range(12) + [-1] ]
#models = {up:models_up, down:models_down, right:models_right, left:models_left}
models_down = [pygame.image.load(os.path.join("Art","player","player_d_" + str(i) + ".png")) for i in range(0,12,2) + [-1] ]
models_up = [pygame.image.load(os.path.join("Art","player","player_u_" + str(i) + ".png")) for i in range(0,12,2) + [-1] ]
models_left = [pygame.image.load(os.path.join("Art","player","player_r_" + str(i) + ".png")) for i in range(0,12,2) + [-1] ]
models_right = [pygame.transform.flip(pygame.image.load( os.path.join("Art","player","player_r_" + str(i) + ".png")), True, False) for i in range(0,12,2) + [-1] ]
models = {up:models_up, down:models_down, right:models_right, left:models_left}
class Character(object):
def __init__( self, world, x, y ):
self.world = world
self.position = complex( x, y )
self.color = white
#self.model = model_down
self.model = models_down[-1]
def draw( self, screen ):
screen.blit( self.model, (self.position.real*40, self.position.imag*40) )
def move( self, direction ):
self.model = models[direction][self.color/2]
#self.model = models[direction]
new_position = self.position + direction
if self.world.walkable( int(new_position.real), int(new_position.imag), self.color ):
self.position = new_position
def attack( self, direction ):
attack_position = self.position + direction
self.color = mix_colors( self.color, self.world.hit( int(attack_position.real), int(attack_position.imag) ) )
self.model = models[direction][self.color/2]
#self.model = models[direction]
def move_up( self ):
self.move( up )
def move_down( self ):
self.move( down )
def move_left( self ):
self.move( left )
def move_right( self ):
self.move( right )
def attack_up( self ):
self.attack( up )
def attack_down( self ):
self.attack( down )
def attack_left( self ):
self.attack( left )
def attack_right( self ):
self.attack( right )