This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
blue_player_pilot.py
75 lines (61 loc) · 2.3 KB
/
blue_player_pilot.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
import pygame
from agent import Agent
from bot import Bot
from bullet import *
RECTANGLE_STARTING_X = 64
RECTANGLE_STARTING_Y = 64
BLUE = (0, 0, 255)
class BluePlayerPilot(Agent):
"""the blue rectangle agent whose decisions are determined by the user"""
def __init__(self, environment=None):
super(BluePlayerPilot, self).__init__("blue_player_pilot", environment)
self.bot = Bot()
self.bot.image.fill(BLUE)
self.bot.rect.x = RECTANGLE_STARTING_X
self.bot.rect.y = RECTANGLE_STARTING_Y
self.rect = self.bot.rect
self.blue_coordinate = (self.rect.x, self.rect.y)
self.dx = 0
self.dy = 0
self.angle = 0
def check_input_for_actions(self):
"""checks user input in order to make decisions"""
# self.make_movements()
# self.rotate()
self.shoot()
self.update_position()
def make_movements(self):
"""checks for any movements keys being pressed and moves accordingly"""
self.dx = 0
self.dy = 0
key = pygame.key.get_pressed()
if key[pygame.K_LEFT]:
self.dx = -2
if key[pygame.K_RIGHT]:
self.dx = 2
if key[pygame.K_UP]:
self.dy = -2
if key[pygame.K_DOWN]:
self.dy = 2
self.bot.move(self.dx, self.dy)
def shoot(self):
"""adds bullets to the game"""
# first determine if we can shoot
if self.bot.reloaded():
# get the bullet list from the environment
bullet_list = self.environment.get_object("bullet_list")
key = pygame.key.get_pressed()
if key[pygame.K_a]:
bullet_list.add(self.bot.shoot_left())
elif key[pygame.K_d]:
bullet_list.add(self.bot.shoot_right())
elif key[pygame.K_w]:
bullet_list.add(self.bot.shoot_up())
elif key[pygame.K_s]:
bullet_list.add(self.bot.shoot_down())
def setup_bot_map(self):
"""sets the bot wall_list so that wall collision can be detected"""
self.bot.wall_list = self.environment.get_object("wall_list")
def update_position(self):
"""updates the player's coordinates for reference by other agents"""
self.blue_coordinate = (self.rect.x, self.rect.y)