diff --git a/ship.py b/drone.py similarity index 75% rename from ship.py rename to drone.py index 5b4c37e..2eb1b37 100644 --- a/ship.py +++ b/drone.py @@ -4,6 +4,8 @@ import math import random from spritesheet import SquareSpriteSheet +from route import Route +from stop import Stop class DroneStatus(Enum): GROUNDED = 0 @@ -13,7 +15,7 @@ class DroneStatus(Enum): LANDING = 4 class Drone: - def __init__(self, screen, pos = (0, 0)) -> None: + def __init__(self, screen, pos = (0, 0), route=[]) -> None: # image self.screen = screen @@ -32,15 +34,17 @@ class Drone: self.prev_index = 0 self.next_index = 1 - self.route = [(400,400),(0,400),(400,0),(0,0),(400,0)] - + self.route = route + # status - self.status = DroneStatus.TAKINGOFF + self.status = DroneStatus.GROUNDED self.animate = False self.last_departure = 0 self.rate = 100/1000 #(units per second) + self.status_message = "" + def update(self): current_time = pygame.time.get_ticks() @@ -52,20 +56,25 @@ class Drone: self.scale = .25 self.animate = False + self.status_message = "On The Ground" elif(self.status == DroneStatus.TAKINGOFF): - self.scale += .001 + if(len(self.route.stops) >= 2): + self.scale += .001 - if(self.scale >= 1): - self.scale = 1 - self.status = DroneStatus.TURNING + if(self.scale >= 1): + self.scale = 1 + self.status = DroneStatus.TURNING + print(self.status, self.scale) - self.animate = True + self.animate = True + else: + self.status_message = "Cannot take off. No Route." elif(self.status == DroneStatus.TURNING): - x1 = self.route[self.prev_index][0] - y1 = self.route[self.prev_index][1] + x1 = self.route.stops[self.prev_index].pos[0] + y1 = self.route.stops[self.prev_index].pos[1] - x2 = self.route[self.next_index][0] - y2 = self.route[self.next_index][1] + x2 = self.route.stops[self.next_index].pos[0] + y2 = self.route.stops[self.next_index].pos[1] #https://replit.com/@Rabbid76/PyGame-RotateWithMouse#main.py @@ -91,13 +100,15 @@ class Drone: self.animate = True + self.status_message = "Turning." + elif(self.status == DroneStatus.INTHEAIR): - x1 = self.route[self.prev_index][0] - y1 = self.route[self.prev_index][1] + x1 = self.route.stops[self.prev_index].pos[0] + y1 = self.route.stops[self.prev_index].pos[1] - x2 = self.route[self.next_index][0] - y2 = self.route[self.next_index][1] + x2 = self.route.stops[self.next_index].pos[0] + y2 = self.route.stops[self.next_index].pos[1] going_north = y2 >= y1 going_east = x2 >= x1 @@ -116,7 +127,7 @@ class Drone: # if traveled the distance, ground the drone and update stops if(distance_traveled >= total_distance): # force position - self.pos = self.route[self.next_index] + self.pos = self.route.stops[self.next_index].pos self.status = DroneStatus.LANDING else: @@ -151,6 +162,8 @@ class Drone: self.scale = 1 self.animate = True + self.status_message = "In The Air." + elif(self.status == DroneStatus.LANDING): self.scale -= .001 @@ -158,10 +171,11 @@ class Drone: self.scale = .25 self.status = DroneStatus.TAKINGOFF self.prev_index = self.next_index - self.next_index = self.prev_index + 1 if self.prev_index + 1 < len(self.route) else 0 + self.next_index = self.prev_index + 1 if self.prev_index + 1 < len(self.route.stops) else 0 self.animate = True + self.status_message = "Landing." if(self.animate): if current_time - self.last_update >= self.animation_cooldown: self.frame += 1 @@ -169,4 +183,5 @@ class Drone: self.last_update = current_time current_image = self.sheet.get_image_by_frame(self.frame, self.scale, self.angle) - self.screen.blit(current_image, (self.pos)) \ No newline at end of file + self.screen.blit(current_image, (self.pos)) + diff --git a/game.py b/game.py index 180d8fe..942d383 100644 --- a/game.py +++ b/game.py @@ -2,7 +2,9 @@ import pygame from settings import Settings from spritesheet import SquareSpriteSheet -from ship import Drone +from drone import Drone, DroneStatus +from route import Route +from stop import Stop settings = Settings() @@ -11,7 +13,12 @@ pygame.display.set_caption(settings.caption) pygame.init() -ship = Drone(screen, (0, 0)) +route = Route("Drone Route.", []) +route.add_stop(Stop("",(100,100))) +route.add_stop(Stop("",(200,200))) + +drone = Drone(screen, (100, 100), route) +drone.status = DroneStatus.TAKINGOFF run = True @@ -19,10 +26,13 @@ while run: #update background screen.fill(settings.background_color) - ship.update() + drone.update() #event handler for event in pygame.event.get(): + if event.type == pygame.MOUSEBUTTONDOWN: + pass + if event.type == pygame.QUIT: run = False diff --git a/route.py b/route.py new file mode 100644 index 0000000..c746ad7 --- /dev/null +++ b/route.py @@ -0,0 +1,8 @@ +import pygame + +class Route: + def __init__(self, name, stops) -> None: + self.name = name + self.stops = stops + def add_stop(self, stop): + self.stops.append(stop) \ No newline at end of file diff --git a/stop.py b/stop.py new file mode 100644 index 0000000..e86d893 --- /dev/null +++ b/stop.py @@ -0,0 +1,8 @@ +import pygame + +class Stop: + def __init__(self, name, pos) -> None: + self.name = name + self.pos = pos + def __str__(self) -> str: + return f"{self.pos[0]}, {self.pos[1]}" \ No newline at end of file