Commit 38d880b7 authored by captnfab's avatar captnfab 🦃
Browse files

fire using keyboard

parent 3fcf43d0
......@@ -1290,8 +1290,15 @@ class GuiBattleShips:
self.prev_cpu_miss = []
self.debug = False
self.draw_enemy_ships = False
self.aiming = 4,4
def update(self, rnd, params):
if rnd.state.options.get('x', None) is None:
rnd.state.options['x'] = self.aiming[0]
if rnd.state.options.get('y', None) is None:
rnd.state.options['y'] = self.aiming[1]
self.aiming = (rnd.state.options['x'], rnd.state.options['y'])
self.draw_enemy_ships = params['ai'] == AI.CHEAT
for (old, new, topleft) in [
(self.prev_player_hits, rnd.player.hits, self.ocean_player_rect.topleft),
......@@ -1348,6 +1355,14 @@ class GuiBattleShips:
s.blit(self.bg, (0, 0))
update_rects.append(s.get_rect())
x,y = self.aiming
pygame.draw.polygon(s, ORANGE, [
self.coords_to_pos((x, y), self.ocean_cpu_rect.topleft),
self.coords_to_pos((x+1, y), self.ocean_cpu_rect.topleft),
self.coords_to_pos((x+1, y+1), self.ocean_cpu_rect.topleft),
self.coords_to_pos((x, y+1), self.ocean_cpu_rect.topleft),
], 3)
self._draw_board_objects(s, self.ocean_player_rect.topleft, player)
self._draw_board_objects(s, self.ocean_cpu_rect.topleft, cpu, draw_ships=self.draw_enemy_ships)
......@@ -1376,6 +1391,8 @@ class GuiBattleShips:
if x>= 0 and y >= 0 and x < rnd.width and y < rnd.width:
rnd.state.options['x'] = x
rnd.state.options['y'] = y
rnd.state.options['needs_redraw'] = True
# keyboard command and position
elif event.type == pygame.KEYDOWN and event.key in [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT, pygame.K_RETURN, pygame.K_SPACE] and not self.debug:
if event.key == pygame.K_RETURN:
......@@ -1389,7 +1406,6 @@ class GuiBattleShips:
x, y = rnd.state.options['x'], rnd.state.options['y']
if event.key == pygame.K_UP and rnd.state.options['y'] > 0:
rnd.state.options['y'] -= 1
rnd.state.options['y'] = self.tmp_ship.y
elif event.key == pygame.K_DOWN and rnd.state.options['y'] < rnd.width - 1:
rnd.state.options['y'] += 1
elif event.key == pygame.K_LEFT and rnd.state.options['x'] > 0:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment