diff options
-rw-r--r-- | gui.py | 9 | ||||
-rw-r--r-- | reversing_game_mechanics/game_mechanics.txt (renamed from game_mechanics.txt) | 0 | ||||
-rw-r--r-- | subscriber.py | 44 |
3 files changed, 52 insertions, 1 deletions
@@ -319,8 +319,12 @@ def draw_markers(): def draw_debug(): for cell in c.world.cells.values(): parent = None + shoot_vec = None + settled = None try: parent = cell.parent + shoot_vec = cell.shoot_vec + settled = cell.calmed_down except AttributeError: pass @@ -329,6 +333,11 @@ def draw_debug(): draw_circle(parent.pos,3,(255,0,0),True) + if shoot_vec != None and settled != True: + shoot_vec = 400 * shoot_vec / shoot_vec.len() + draw_line(cell.pos, cell.pos+shoot_vec, (0,255,255)) + + def draw_frame(): global screen, movement, zoom, screensize, input, bot_input, marker, marker_updated, running diff --git a/game_mechanics.txt b/reversing_game_mechanics/game_mechanics.txt index 9c64805..9c64805 100644 --- a/game_mechanics.txt +++ b/reversing_game_mechanics/game_mechanics.txt diff --git a/subscriber.py b/subscriber.py index 483ae04..4327e04 100644 --- a/subscriber.py +++ b/subscriber.py @@ -82,14 +82,37 @@ class EnhancingSubscriber(DummySubscriber): self.c = None self.history = {} self.time = 0 + self.victims = {} def set_client(self,c): self.c = c + + def cleanup_victims(self): + delete = [] + + for eater in self.victims: + self.victims[eater] = list(filter(lambda v : v[1] < self.time - 100, self.victims[eater])) + if len(self.victims[eater]) == 0: + delete += [eater] + + for eater in delete: + del self.victims[eater] + def on_cell_eaten(self, eater_id, eaten_id): + if self.c.world.cells[eater_id].is_virus: + print("virus ate something!") + if eater_id not in self.victims: + self.victims[eater_id] = [] + + self.victims[eater_id] += [(self.c.world.cells[eaten_id], self.time)] + def on_world_update_post(self): self.c.world.time = self.time self.time += 1 + if self.time % 100 == 0: + self.cleanup_victims() + # create and purge poslog history, movement and movement_angle for cid in self.history: self.history[cid].stale = True @@ -183,7 +206,26 @@ class EnhancingSubscriber(DummySubscriber): if is_split: cell.parent = min(cell.player.cells, key=lambda c : (c.pos - cell.poslog[0]).len() if c != cell else float('inf')) - cell.shoot_vec = None # TODO FIXME: use direction of the last ejected blob feed into the mother virus + try: + last_feed = self.victims[cell.parent.cid][-1][0] + if not last_feed.is_ejected_mass: + print("wtf, last virus feed was not ejected mass?!") + raise KeyError + else: + cell.shoot_vec = cell.parent.pos - last_feed.poslog[0] + cell.shoot_vec2 = last_feed.poslog[0] - last_feed.poslog[-1] + try: + pos_when_shot = last_feed.parent.poslog[len(last_feed.poslog)] + cell.shoot_vec3 = cell.parent.pos - pos_when_shot + except: + print("MOAAAHH") + cell.shoot_vec3 = None + except KeyError: + print("wtf, no last virus feed?!") + cell.shoot_vec = None + cell.shoot_vec2 = None + cell.shoot_vec3 = None + cell.calmed_down = False elif cell.is_ejected_mass: |