Browse code
attacking
edwlan authored on 29/07/2013 05:17:08
Showing 4 changed files
Showing 4 changed files
... | ... |
@@ -99,7 +99,7 @@ class Adventurer(object): |
99 | 99 |
dieroll = dice.DieRoll() |
100 | 100 |
dieroll.add_adjustment(-damage) |
101 | 101 |
|
102 |
- result, damage = self.skills.check('toughness', dieroll) |
|
102 |
+ result, __ = self.skills.check('toughness', dieroll) |
|
103 | 103 |
|
104 | 104 |
if not result: |
105 | 105 |
if damage > 0: |
... | ... |
@@ -15,6 +15,8 @@ class Overlay(object): |
15 | 15 |
self.x = x |
16 | 16 |
self.y = y |
17 | 17 |
self.map = map |
18 |
+ def draw(self): |
|
19 |
+ self.map.add(self) |
|
18 | 20 |
|
19 | 21 |
|
20 | 22 |
class Actor(Overlay): |
... | ... |
@@ -34,17 +36,18 @@ class Actor(Overlay): |
34 | 36 |
adventurer = combat.Adventurer.randomize() |
35 | 37 |
self.adventurer = adventurer |
36 | 38 |
|
37 |
- def draw(self): |
|
38 |
- self.map.add(self) |
|
39 |
- |
|
40 | 39 |
def move(self, dx, dy): |
41 | 40 |
dx, dy = self.map.move(self, dx,dy) |
42 | 41 |
self.x += dx |
43 | 42 |
self.y += dy |
44 | 43 |
|
45 | 44 |
def tick(self): |
46 |
- pass |
|
47 |
- |
|
45 |
+ result = True |
|
46 |
+ if self.adventurer.state >= 2: |
|
47 |
+ result = False |
|
48 |
+ self.char = ord('%') |
|
49 |
+ self.blocks = False |
|
50 |
+ return result |
|
48 | 51 |
|
49 | 52 |
def ishostile(self, other): |
50 | 53 |
return True #TODO: implement factions |
... | ... |
@@ -57,9 +60,7 @@ class Actor(Overlay): |
57 | 60 |
other.bumped_by(self) |
58 | 61 |
|
59 | 62 |
def attacked_by(self, other): |
60 |
- if self.adventurer.state >= 2: |
|
61 |
- self.char = '%' |
|
62 |
- elif self.adventurer.skills.check('agility'): |
|
63 |
+ if self.adventurer.skills.check('agility'): |
|
63 | 64 |
self.adventurer.attack(other.adventurer) |
64 | 65 |
|
65 | 66 |
def bumped_by(self, other): |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
import libs.patch_random |
2 | 2 |
import random |
3 |
-random.seed(2) |
|
3 |
+#random.seed(2) |
|
4 | 4 |
|
5 | 5 |
import libtcodpy as tc |
6 | 6 |
import numpy as np |
... | ... |
@@ -13,6 +13,7 @@ from src import console |
13 | 13 |
from src import map |
14 | 14 |
|
15 | 15 |
import random |
16 |
+import bisect |
|
16 | 17 |
|
17 | 18 |
|
18 | 19 |
class Application(object): |
... | ... |
@@ -35,15 +36,25 @@ class Application(object): |
35 | 36 |
|
36 | 37 |
tc.sys_set_fps(60) |
37 | 38 |
|
39 |
+ def update_actors(self): |
|
40 |
+ to_pop = [] |
|
41 |
+ for idx,actor in enumerate(self.actors): |
|
42 |
+ if not actor.tick(): |
|
43 |
+ bisect.insort(to_pop, idx) |
|
44 |
+ for pop in reversed(to_pop): |
|
45 |
+ self.actors.pop(pop) |
|
46 |
+ |
|
38 | 47 |
def init(self): |
39 | 48 |
self.screen.init("test") |
40 | 49 |
self.player.draw() |
41 |
- for actor in self.actors: |
|
42 |
- actor.draw() |
|
50 |
+ self.update_actors() |
|
51 |
+ for overlay in self.actors + self.objects: |
|
52 |
+ overlay.draw() |
|
43 | 53 |
|
44 | 54 |
def run(self): |
45 | 55 |
while not tc.console_is_window_closed(): |
46 | 56 |
self.events.tick() |
57 |
+ self.update_actors() |
|
47 | 58 |
self.map.draw(self.screen) |
48 | 59 |
tc.console_print(0, 0,1, '%d' % tc.sys_get_fps()) |
49 | 60 |
tc.console_flush() |
... | ... |
@@ -8,6 +8,7 @@ class Player(libs.overlay.Actor): |
8 | 8 |
light_radius = 10 |
9 | 9 |
def __init__(self, x,y, map, adventurer): |
10 | 10 |
libs.overlay.Actor.__init__(self, x,y, map, adventurer) |
11 |
+ print 'Player\'s name is %s' % self.adventurer.name |
|
11 | 12 |
self.map.set_pov((self.pos, self.light_radius)) |
12 | 13 |
def move(self, dx, dy): |
13 | 14 |
libs.overlay.Actor.move(self, dx,dy) |