DroneInvaders partially done, and corrected some variables and method names to lower_snake.

This commit is contained in:
ben 2022-07-21 16:36:45 -05:00
parent 5b169d4dbe
commit 6b6cd55c5b
9 changed files with 57 additions and 46 deletions

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

View file

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8 (venv)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View file

@ -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):

View file

@ -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):

View file

@ -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

View file

@ -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)

View file

@ -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):

20
main.py
View file

@ -1,16 +1,4 @@
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
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/
print('This is my notes')
print('This includes markdown files, and lots of python programs')
print('And remember:\n')
import this