-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
68 lines (60 loc) · 2.42 KB
/
player.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
__author__ = 'tim'
def set_player_bitmap(player):
if player['race'] == 'HUMAN':
if player['class'] == 'WARRIOR':
player['bitmap'] = 'HUMAN_FIGHTER'
return player
def init_player(name, race, profession):
from constants import PROFESSIONS, RACES
from levels import gen_random_map
from random import randint
player = {}
player['name'] = name
player['race'] = race
player['class'] = profession
player['level'] = 1
player['currentmaplevel'] = 0
player['xp'] = 0
player['str'] = RACES[player['race']]['str'] + PROFESSIONS[player['class']]['strmod']
player['int'] = RACES[player['race']]['int'] + PROFESSIONS[player['class']]['intmod']
player['dex'] = RACES[player['race']]['dex'] + PROFESSIONS[player['class']]['dexmod']
player['hp'] = 1 + randint(PROFESSIONS[player['class']]['hpmod'] // 2, PROFESSIONS[player['class']]['hpmod'] )
player['levels'] = []
player['levels'].append(gen_random_map())
player['locationx'] = player['levels'][0]['playerstartx']
player['locationy'] = player['levels'][0]['playerstarty']
player['vision_radius'] = RACES[player['race']]['vision_radius']
player = set_player_bitmap(player)
return player
def move_player(player, direction):
from utils import check_adjacent_tile_passable
# check for passable
if direction == 'N':
if check_adjacent_tile_passable(player, 0, -1):
player['locationy'] -= 1
if direction == 'NW':
if check_adjacent_tile_passable(player, -1, -1):
player['locationy'] -= 1
player['locationx'] -= 1
if direction == 'NE':
if check_adjacent_tile_passable(player, 1, -1):
player['locationy'] -= 1
player['locationx'] += 1
if direction == 'SW':
if check_adjacent_tile_passable(player, -1, 1):
player['locationy'] += 1
player['locationx'] -= 1
if direction == 'SE':
if check_adjacent_tile_passable(player, +1, +1):
player['locationy'] += 1
player['locationx'] += 1
elif direction == 'S':
if check_adjacent_tile_passable(player, 0, +1):
player['locationy'] += 1
elif direction == 'W':
if check_adjacent_tile_passable(player, -1, 0):
player['locationx'] -= 1
elif direction == 'E':
if check_adjacent_tile_passable(player, +1, 0):
player['locationx'] += 1
return player