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
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (venv)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
|
@ -1,8 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.8 (venv)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -4,7 +4,7 @@ from drone import Drone
|
||||||
from pygame import mixer
|
from pygame import mixer
|
||||||
|
|
||||||
class Bomb(BoundedTurtle):
|
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
|
pass
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
|
|
|
@ -2,15 +2,15 @@ from abc import abstractmethod
|
||||||
from turtle import Turtle
|
from turtle import Turtle
|
||||||
|
|
||||||
class BoundedTurtle(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__()
|
super().__init__()
|
||||||
self.__xMin = xMin
|
self.__x_min = x_min
|
||||||
self.__xMax = xMax
|
self.__x_max = x_max
|
||||||
self.__yMin = yMin
|
self.__y_min = y_min
|
||||||
self.__yMax = yMax
|
self.__y_max = y_max
|
||||||
self.__speed = speed
|
self.__speed = speed
|
||||||
|
|
||||||
def outOfBounds(self):
|
def out_of_bounds(self):
|
||||||
xPos, yPos = self.position()
|
xPos, yPos = self.position()
|
||||||
out = False
|
out = False
|
||||||
if xPos < self.__xMin or xPos > self.__xMax:
|
if xPos < self.__xMin or xPos > self.__xMax:
|
||||||
|
@ -19,17 +19,17 @@ class BoundedTurtle(Turtle):
|
||||||
out = True
|
out = True
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def belowBottomBound(self):
|
def below_bottom_bound(self):
|
||||||
x_pos, y_pos = self.position()
|
x_pos, y_pos = self.position()
|
||||||
out = False
|
out = False
|
||||||
if y_pos < self.__yMin:
|
if y_pos < self.__yMin:
|
||||||
out = True
|
out = True
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def getSpeed(self):
|
def get_speed(self):
|
||||||
return self.__speed
|
return self.__speed
|
||||||
|
|
||||||
def getXMin(self):
|
def get_x_min(self):
|
||||||
return self.__xMin
|
return self.__xMin
|
||||||
|
|
||||||
def getXMax(self):
|
def getXMax(self):
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
from boundedturtle import BoundedTurtle
|
from boundedturtle import BoundedTurtle
|
||||||
import random
|
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
|
@staticmethod
|
||||||
def getDrones():
|
def get_drones():
|
||||||
return [x for x in Drone.droneList if x.__alive]
|
return [x for x in Drone.droneList if x.__alive]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -15,9 +18,6 @@ class Drone(BoundedTurtle):
|
||||||
drone.remove()
|
drone.remove()
|
||||||
Drone.droneList = []
|
Drone.droneList = []
|
||||||
|
|
||||||
def __init__(self, speed, xMin, xMax, yMin, yMax):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,39 @@ from lasercannon import LaserCannon
|
||||||
from scoreboard import Scoreboard
|
from scoreboard import Scoreboard
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
class DroneInvaders:
|
class DroneInvaders:
|
||||||
def __init__(self, xMin, xMax, yMin, yMax):
|
def __init__(self, x_min, x_max, y_min, y_max):
|
||||||
pass
|
"""
|
||||||
|
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):
|
def play(self):
|
||||||
pass
|
self.screen.exitonclick()
|
||||||
|
|
||||||
|
def add_drone(self):
|
||||||
def addDrone(self):
|
if len(Drone.get_drones()) < 7:
|
||||||
pass
|
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):
|
def quit(self):
|
||||||
pass
|
self.screen.bye()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from bomb import Bomb
|
||||||
from pygame import mixer
|
from pygame import mixer
|
||||||
|
|
||||||
class LaserCannon(Turtle):
|
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
|
pass
|
||||||
|
|
||||||
def aim(self, x, y):
|
def aim(self, x, y):
|
||||||
|
|
20
main.py
20
main.py
|
@ -1,16 +1,4 @@
|
||||||
# This is a sample Python script.
|
print('This is my notes')
|
||||||
|
print('This includes markdown files, and lots of python programs')
|
||||||
# Press Shift+F10 to execute it or replace it with your code.
|
print('And remember:\n')
|
||||||
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
import this
|
||||||
|
|
||||||
|
|
||||||
def print_hi(name):
|
|
||||||
# Use a breakpoint in the code line below to debug your script.
|
|
||||||
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
|
||||||
|
|
||||||
|
|
||||||
# Press the green button in the gutter to run the script.
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print_hi('beans 5 5')
|
|
||||||
|
|
||||||
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
|
Loading…
Reference in a new issue