The beginnings of my Air Traffic Control game.

Also, I included my game plan.
This commit is contained in:
Danielle Tear
2024-03-05 17:51:19 -05:00
parent 43c0cf70e7
commit eac94f2980
12 changed files with 914 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

7
agents/airport_agent.py Normal file
View File

@@ -0,0 +1,7 @@
class Airport:
def __init__(self, char, color, pos):
self.color = color
self.character = char
self.position = pos
self.z = 2

11
agents/path_agent.py Normal file
View File

@@ -0,0 +1,11 @@
class Path:
def __init__(self, direction_char, color, pos, plane):
self.character = direction_char
self.color = color
self.position = pos
self.plane = plane
def play_turn(self, game):
if self.plane.position == self.position:
game.remove_agent(self)

157
agents/plane_agent.py Normal file
View File

@@ -0,0 +1,157 @@
from retro.game import Game
from random import randint
from agents.path_agent import Path
from agents.airport_agent import Airport
class Plane:
def __init__(self, char, Color, pos, direction, spawner):
self.character = char
self.saved_color = Color
self.color = Color
self.selected = False
self.position = pos
self.future_positions = []
self.paths = []
self.direction = direction
self.spawner = spawner
self.z = 1
def handle_keystroke(self, keystroke, game):
if self.selected == False:
if keystroke == self.character:
self.selected = True
self.color = "white"
elif self.selected == True:
if keystroke.name == "KEY_LEFT":
if len(self.future_positions) == 0:
self.direction = 2
new_position = (self.position[0] - 1, self.position[1])
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path("<", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
else:
self.direction = 2
new_position = (self.future_positions[-1][0]- 1, self.future_positions[-1][1])
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path("<", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
elif keystroke.name == "KEY_RIGHT":
if len(self.future_positions) == 0:
self.direction = 1
new_position = (self.position[0] + 1, self.position[1])
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path(">", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
else:
self.direction = 1
new_position = (self.future_positions[-1][0] + 1, self.future_positions[-1][1])
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path(">", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
elif keystroke.name == "KEY_UP":
if len(self.future_positions) == 0:
self.direction = 4
new_position = (self.position[0], self.position[1] - 1)
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path("^", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
else:
self.direction = 4
new_position = (self.future_positions[-1][0], self.future_positions[-1][1] - 1)
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path("^", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
elif keystroke.name == "KEY_DOWN":
if len(self.future_positions) == 0:
self.direction = 3
new_position = (self.position[0], self.position[1] + 1)
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path("v", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
else:
self.direction = 3
new_position = (self.future_positions[-1][0], self.future_positions[-1][1] + 1)
if game.on_board(new_position):
self.future_positions.append(new_position)
path = Path("v", self.saved_color, new_position, self)
self.paths.append(path)
game.add_agent(path)
elif keystroke == self.character:
self.selected = False
self.color = self.saved_color
elif keystroke.name == "KEY_BACKSPACE":
self.future_positions = []
for path in self.paths:
game.remove_agent(path)
self.paths = []
else:
self.selected = False
self.color = self.saved_color
def play_turn(self, game):
if game.turn_number % 12 == 0:
x,y = self.position
if len(self.future_positions) == 0:
if self.direction == 1:
self.position = (x + 1, y)
if self.direction == 2:
self.position = (x - 1, y)
if self.direction == 3:
self.position = (x, y + 1)
if self.direction == 4:
self.position = (x, y - 1)
else:
new_position = self.future_positions.pop(0)
self.position = new_position
new_x,new_y = self.position
agents = game.get_agents_by_position()
agents_at_pos = agents.get((new_x, new_y))
for agent in agents_at_pos:
if type(agent) == Path and agent.plane == self:
self.paths.remove(agent)
if type(agent) == Plane and agent != self:
agent.character = "*"
agent.color = "red"
self.character = "*"
self.color = "red"
for path in agent.paths:
game.remove_agent(path)
for path in self.paths:
game.remove_agent(path)
game.end()
elif type(agent) == Airport:
if agent.color == self.saved_color:
game.remove_agent(self)
game.state["Planes Landed"] += 1
self.spawner.characters.append(self.character)
for path in self.paths:
game.remove_agent(path)
else:
agent.character = "*"
agent.color = "red"
game.end()
if new_x == -1 or new_x == 64:
self.character = "*"
self.color = "red"
game.end()
if new_y == -1 or new_y == 32:
self.character = "*"
self.color = "red"
game.end()

45
agents/plane_spawner.py Normal file
View File

@@ -0,0 +1,45 @@
from agents.plane_agent import Plane
from random import randint
class AirplaneSpawner:
def __init__(self):
self.display = False
self.characters = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
self.colors = ["cyan", "magenta", "green"]
def play_turn(self, game):
if self.should_spawn_plane(game.state["Planes Landed"]):
if len(self.characters) != 0:
char_index = randint(0, len(self.characters) - 1)
color_index = randint(0, len(self.colors) - 1)
character = self.characters.pop(char_index)
color = self.colors[color_index]
side = randint(1,4)
x = randint(8,55)
y = randint(7, 20)
if side == 1:
plane = Plane(character, color, (1, y), side, self)
if side == 2:
plane = Plane(character, color, (63, y), side, self)
if side == 3:
plane = Plane(character, color, (x, 1), side, self)
if side == 4:
plane = Plane(character, color, (x, 31), side, self)
game.add_agent(plane)
def should_spawn_plane(self, score):
if len(self.characters) == 10:
return True
if score < 5:
return randint(0,10000) > 9980
elif score < 10:
return randint(0,10000) > 9960
elif score < 20:
return randint(0,10000) > 9900
elif score < 30:
return randint(0,10000) > 9850
elif score < 40:
return randint(0,10000) > 9800
else:
return randint(0,10000) > 9700