DroneInvaders partially done, and corrected some variables and method names to lower_snake.
This commit is contained in:
parent
5b169d4dbe
commit
6b6cd55c5b
9 changed files with 57 additions and 46 deletions
|
@ -4,7 +4,7 @@ from drone import Drone
|
|||
from pygame import mixer
|
||||
|
||||
class Bomb(BoundedTurtle):
|
||||
def __init__(self, initHeading, speed, xMin, xMax, yMin, yMax, scoreboard):
|
||||
def __init__(self, initHeading, speed, x_min, xMax, yMin, yMax, scoreboard):
|
||||
pass
|
||||
|
||||
def move(self):
|
||||
|
|
|
@ -2,15 +2,15 @@ from abc import abstractmethod
|
|||
from turtle import Turtle
|
||||
|
||||
class BoundedTurtle(Turtle):
|
||||
def __init__(self, speed, xMin, xMax, yMin, yMax):
|
||||
def __init__(self, speed, x_min, x_max, y_min, y_max):
|
||||
super().__init__()
|
||||
self.__xMin = xMin
|
||||
self.__xMax = xMax
|
||||
self.__yMin = yMin
|
||||
self.__yMax = yMax
|
||||
self.__x_min = x_min
|
||||
self.__x_max = x_max
|
||||
self.__y_min = y_min
|
||||
self.__y_max = y_max
|
||||
self.__speed = speed
|
||||
|
||||
def outOfBounds(self):
|
||||
def out_of_bounds(self):
|
||||
xPos, yPos = self.position()
|
||||
out = False
|
||||
if xPos < self.__xMin or xPos > self.__xMax:
|
||||
|
@ -19,17 +19,17 @@ class BoundedTurtle(Turtle):
|
|||
out = True
|
||||
return out
|
||||
|
||||
def belowBottomBound(self):
|
||||
def below_bottom_bound(self):
|
||||
x_pos, y_pos = self.position()
|
||||
out = False
|
||||
if y_pos < self.__yMin:
|
||||
out = True
|
||||
return out
|
||||
|
||||
def getSpeed(self):
|
||||
def get_speed(self):
|
||||
return self.__speed
|
||||
|
||||
def getXMin(self):
|
||||
def get_x_min(self):
|
||||
return self.__xMin
|
||||
|
||||
def getXMax(self):
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
from boundedturtle import BoundedTurtle
|
||||
import random
|
||||
|
||||
class Drone(BoundedTurtle):
|
||||
|
||||
droneList = [] #static variable
|
||||
class Drone(BoundedTurtle):
|
||||
droneList = [] # static variable
|
||||
|
||||
def __init__(self, speed, x_min, x_max, y_min, y_max):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def getDrones():
|
||||
def get_drones():
|
||||
return [x for x in Drone.droneList if x.__alive]
|
||||
|
||||
@staticmethod
|
||||
|
@ -15,9 +18,6 @@ class Drone(BoundedTurtle):
|
|||
drone.remove()
|
||||
Drone.droneList = []
|
||||
|
||||
def __init__(self, speed, xMin, xMax, yMin, yMax):
|
||||
pass
|
||||
|
||||
def move(self):
|
||||
pass
|
||||
|
||||
|
@ -26,4 +26,4 @@ class Drone(BoundedTurtle):
|
|||
pass
|
||||
|
||||
def remove(self):
|
||||
pass
|
||||
pass
|
||||
|
|
|
@ -4,18 +4,39 @@ from lasercannon import LaserCannon
|
|||
from scoreboard import Scoreboard
|
||||
import time
|
||||
|
||||
|
||||
class DroneInvaders:
|
||||
def __init__(self, xMin, xMax, yMin, yMax):
|
||||
pass
|
||||
def __init__(self, x_min, x_max, y_min, y_max):
|
||||
"""
|
||||
Initializes DroneInvaders
|
||||
:param x_min: minimum x value for things on screen
|
||||
:param x_max: maximum x value for things on screen
|
||||
:param y_min: minimum y value for things on screen
|
||||
:param y_max: maximum y value from things on screen
|
||||
"""
|
||||
self.x_min = x_min
|
||||
self.x_max = x_max
|
||||
self.y_min = y_min
|
||||
self.y_max = y_max
|
||||
self.screen = Screen()
|
||||
self.screen.title('Drone Invaders - A totally original game')
|
||||
self.screen.setworldcoordinates(x_min, y_min, x_max, y_max)
|
||||
self.scoreboard = Scoreboard(x_min + 0.1, y_max - 0.2)
|
||||
self.delay = 0.1
|
||||
self.game_states = {'Intro': 1, 'Playing': 2, 'InterLevel': 3, 'GameOver': 4, 'Pause': 5}
|
||||
self.game_state = self.game_states['Intro']
|
||||
self.screen.bgcolor('light green')
|
||||
self.laser_cannon = LaserCannon(x_min, x_max, y_min, y_max, self.screen, self.scoreboard)
|
||||
|
||||
def play(self):
|
||||
pass
|
||||
self.screen.exitonclick()
|
||||
|
||||
|
||||
def addDrone(self):
|
||||
pass
|
||||
def add_drone(self):
|
||||
if len(Drone.get_drones()) < 7:
|
||||
Drone(0.01, self.x_min, self.x_max, self.y_min, self.y_max)
|
||||
if not self.done:
|
||||
self.screen.ontimer(fun=self.addDrone, t=1000)
|
||||
|
||||
def quit(self):
|
||||
pass
|
||||
|
||||
|
||||
self.screen.bye()
|
||||
exit(0)
|
||||
|
|
|
@ -3,7 +3,7 @@ from bomb import Bomb
|
|||
from pygame import mixer
|
||||
|
||||
class LaserCannon(Turtle):
|
||||
def __init__(self, xMin, xMax, yMin, yMax, screen, scoreboard):
|
||||
def __init__(self, x_min, x_max, y_min, y_max, screen, scoreboard):
|
||||
pass
|
||||
|
||||
def aim(self, x, y):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue