def update(self): """ function to be run every tick to keep the object up to date """ pos = mouse.get_pos() mp_sz = get_map_size() x = int(pos[0] / TILE_W) y = int(pos[1] / TILE_H) btns = mouse.get_pressed() if btns[0] and pos[0] < mp_sz[0] and pos[1] < mp_sz[1] \ and self.state == Tower.PLACEMENT: self.state = Tower.CHECKING screen_cover_up(self.location, (self.width, self.height)) if btns[2] and self.state == Tower.PLACEMENT: util.enums.SPRITES[0].pop() util.enums.MONEY += self.cost return elif btns[0] and (self.state == Tower.IDLE or self.state == Tower.ATTACKING): self.click() if self.state == Tower.PLACEMENT: self.location = pos elif self.state == Tower.CHECKING: if pos[0] < mp_sz[0] and pos[1] < mp_sz[1]: if self.check_under(x, y): self.location = (x * TILE_W, y * TILE_H) self.add_to_bg() self.state = Tower.IDLE self.select() else: self.state = Tower.PLACEMENT elif self.state == Tower.IDLE: if self.frame != 0: self.frame = 0 elif self.state == Tower.ATTACKING: map_cover_up(self.location, (self.width, self.height)) self.animate(10) self.srf = self.frames[self.frame] self.draw(util.enums.SCREEN)
def move_right(self): moved = self.calc_movement() map_cover_up(self.location, (self.width, self.height)) self.location[0] += int(moved[0]) self.draw(util.enums.SCREEN)