/
ent.py
118 lines (108 loc) · 4.27 KB
/
ent.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
import libtcodpy as tcod
import core
import enum
import game
import map
import gui
import ai
import item
import hit
''' living actors, entities '''
class Entity(core.Object):
pass
######################### LIVING STUFF ###################
class Player(Entity):
def __init__(self, x, y):
_ai = ai.AiPlayer()
_at = hit.Attacker(3)
_de = hit.DestructiblePlayer(10, 1)
_co = item.Container(15)
self.name = 'you'
self.char = '@'
self.speed = 10
Entity.__init__(self, x, y, name=self.name, char=self.char, speed=self.speed,
attacker=_at, ai=_ai, destructible=_de, container=_co)
self.sense_objects = False #outside fov
self.sense_entities = False #outside fov
self.sense_map = False #this means you can't see smoke!
self.blind = False #can see characters of the things
def update(self):#override this
pass
def take_turn(self): #for this!
if self.ai:
self.ai.update()
class Zombie(Entity):
def __init__(self, x, y):
_ai = ai.AiZombie()
_de = hit.DestructibleMonster(7, 1, corpse_name="zombie body")
_at = hit.Attacker(2)
self.speed = tcod.random_get_int(0, 4, 6)
bod = enum.body.human
Entity.__init__(self, x, y, name='zombie', char='Z', speed=self.speed,
attacker=_at, ai=_ai, destructible=_de, body=bod)
######################### GAME OBJECTS ###################
# tools #
class Shovel(Entity):
def __init__(self, x, y):
_pi = item.Digger(10)
Entity.__init__(self, x, y, name='shovel', char='/', blocks=False, pickable=_pi)
class Slingshot(Entity):
def __init__(self, x, y):
_pi = item.SlingshotThrow(3, 5)
Entity.__init__(self, x, y, name='slingshot', char='/', blocks=False, pickable=_pi)
# equip #
class DaggerSmall(Entity):
def __init__(self, x, y):
_eq = item.Equip('right hand', po=1)
Entity.__init__(self, x, y, name='tiny dagger', char='/', blocks=False, equipment=_eq)
class HelmetCopper(Entity):
def __init__(self, x, y):
_eq = item.Equip('head', de=2)
Entity.__init__(self, x, y, name='copper helmet', char='[', blocks=False, equipment=_eq)
class ShieldWood(Entity):
def __init__(self, x, y):
_eq = item.Equip('left hand', de=1)
Entity.__init__(self, x, y, name='small shield', material=enum.mat.WOOD, char='[',
blocks=False, equipment=_eq)
# consumables #
class MossRed(Entity):
def __init__(self, x, y):
_pi = item.Healer(10)
Entity.__init__(self, x, y, name='red moss', char='+', blocks=False, pickable=_pi)
class GrenadeSmoke(Entity):
def __init__(self, x, y):
_pi = item.SmokeThrow(5, 1, 5)
Entity.__init__(self, x, y, name='smoke grenade', char='!', blocks=False, pickable=_pi)
class Grenade(Entity):
def __init__(self, x, y):
_pi = item.ExplosiveThrow(3,10,5)
Entity.__init__(self, x, y, name='grenade', char='!', blocks=False, pickable=_pi)
# random junk and stuff #
class Smoke(Entity):
def __init__(self, x, y, life, was_visible=True):
self.life = life
self.was_visible = was_visible
Entity.__init__(self, x, y, name='smoke', char=chr(tcod.CHAR_BLOCK2), blocks=False)
if not map.is_wall(self.x, self.y):
map.fov_set(self.x, self.y, visible=False, blocked=map.is_wall(self.x, self.y))
def update(self):
Entity.update(self)
self.life -= 1
if self.life <= 0:
self.remove = True
map.fov_set(self.x, self.y, visible=self.was_visible, blocked=False)
#map.fov_init()
class Projectile(Entity):
def __init__(self, x, y, power, wearer=None, name=None, self_remove=False):
_at = hit.Attacker(power)
nam = 'projectile'
if name: nam = name
Entity.__init__(self, x, y, name=nam, char='*', blocks=False, attacker=_at)
t = self.attacker.attack_tile(x, y)
if t:
game.log('the', self.name, 'hits the',t.init_name+'!')
if t.destructible.is_dead() and wearer:
game.log(wearer.name, 'killed the', t.init_name+'!')
self.attacker = None
self.remove = self_remove