generated from mwc/project_game
add asteroids
This project has sparked a interest in seeing what else i can creatate using coding
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,14 +1,16 @@
|
|||||||
from retro.game import Game
|
from retro.game import Game
|
||||||
from spaceship import Spaceship
|
from spaceship import Spaceship
|
||||||
# from asteroid_spawner import AsteroidSpawner
|
from asteroid_spawner import AsteroidSpawner
|
||||||
from targets import Alien
|
from targets import Alien
|
||||||
from shooter import Shooter
|
from shooter import Shooter
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
board_size = (100, 25)
|
board_size = (100, 25)
|
||||||
width, height = board_size
|
width, height = board_size
|
||||||
ship = Spaceship(board_size)
|
ship = Spaceship(board_size)
|
||||||
shooter = Shooter()
|
shooter = Shooter()
|
||||||
spawner = Alien((random.randint(0, width-1), random.randint(0, height-1)))
|
asteroid_spawner = AsteroidSpawner()
|
||||||
game = Game([ship, spawner, shooter], {"score": 0}, board_size=board_size, color="white_on_blue")
|
alien = Alien((random.randint(0, width - 1), random.randint(0, height - 1)))
|
||||||
game.play()
|
game = Game([ship, shooter, asteroid_spawner, alien],{"score": 0},board_size=board_size,color="black_on_red")
|
||||||
|
game.play()
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ class Shooter:
|
|||||||
self.position = (0, 0)
|
self.position = (0, 0)
|
||||||
|
|
||||||
def handle_keystroke(self, keystroke, game):
|
def handle_keystroke(self, keystroke, game):
|
||||||
|
|
||||||
if keystroke == ' ' and not self.display:
|
if keystroke == ' ' and not self.display:
|
||||||
ship = game.get_agent_by_name('ship')
|
ship = game.get_agent_by_name('ship')
|
||||||
if ship is None:
|
if ship is None:
|
||||||
@@ -23,9 +22,7 @@ class Shooter:
|
|||||||
self.display = True
|
self.display = True
|
||||||
|
|
||||||
def play_turn(self, game):
|
def play_turn(self, game):
|
||||||
|
|
||||||
if not self.display:
|
if not self.display:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
x, y = self.position
|
x, y = self.position
|
||||||
|
|||||||
@@ -8,20 +8,18 @@ class Alien:
|
|||||||
self.position = position
|
self.position = position
|
||||||
|
|
||||||
def play_turn(self, game):
|
def play_turn(self, game):
|
||||||
|
|
||||||
width, height = game.board_size
|
width, height = game.board_size
|
||||||
|
|
||||||
x, y = self.position
|
x, y = self.position
|
||||||
|
|
||||||
directions = [
|
directions = [
|
||||||
(-1, 0), # left
|
(-2, 0), # left
|
||||||
(1, 0), # right
|
(2, 0), # right
|
||||||
(0, -1), # up
|
(0, -2), # up
|
||||||
(0, 1), # down
|
(0, 2), # down
|
||||||
(-1, -1), # up-left
|
(-2, -2), # up-left
|
||||||
(-1, 1), # down-left
|
(-2, 2), # down-left
|
||||||
(1, -1), # up-right
|
(2, -2), # up-right
|
||||||
(1, 1) # down-right
|
(2, 2) # down-right
|
||||||
]
|
]
|
||||||
|
|
||||||
possible_positions = []
|
possible_positions = []
|
||||||
|
|||||||
Reference in New Issue
Block a user