def __init__(self): SceneBase.__init__(self) self.returnbutton = Button("Return to Menu", (900, 425), self.GoBack, size=(300, 60), font_size=20, bg=(109, 177, 255))
def __init__(self): SceneBase.__init__(self) self.continuebutton = Button("Continue", (900, 500), self.Continue, size=(160, 60), font_size=20, bg=(109, 177, 255))
def __init__(self): SceneBase.__init__(self) self.economybutton = Button("+5 MoonCrystals Economy", (300, 200), self.Economy, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.defensebutton = Button("+500 Mothership HP", (300, 300), self.Defense, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.continuebutton = Button("Make the Game Great Again", (900, 500), self.Continue, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.damagebutton = Button("Unit Damage +10", (300, 400), self.Damage, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.healthbutton = Button("Unit Health +20", (300, 500), self.Health, size=(240, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() if not b.MusicStatus(): b.PlayMusic("menumusic")
def __init__(self): SceneBase.__init__(self) self.hardcoremode = ToggleBox((600, 225), self.HardcoreMode, size=(30, 30), bg=(0, 170, 28)) self.hardcoretext = Text(225, 500, "Hardcore Mode", bold=True, font="Arial", fontSize=18) self.backbutton = Button("Back", (50, 625), self.GoBack, size=(60, 30), bg=(109, 177, 255)) self.text1 = Text(100, 600, "Options Menu", bold=True, color=(255, 255, 255), font="Arial", fontSize=35)
class Instructions(SceneBase): def __init__(self): SceneBase.__init__(self) self.returnbutton = Button("Return to Menu", (900, 425), self.GoBack, size=(300, 60), font_size=20, bg=(109, 177, 255)) def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: if self.returnbutton.IsClicked(mousepos): self.returnbutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/Instructions.jpg"), (0, 0)) self.returnbutton.Draw(screen) def GoBack(self): print("REturning to menu") self.SwitchToScene("Scenes.MenuScene.MenuScene")
class Level1Defeat(SceneBase): def __init__(self): SceneBase.__init__(self) self.continuebutton = Button("Menu", (900, 500), self.Continue, size=(120, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() b.PlayMusic("leveldefeatmusic") def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: if self.continuebutton.IsClicked(mousepos): self.continuebutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/level1defeat.jpg"), (0, 0)) self.continuebutton.Draw(screen) def Continue(self): print("returning to menu scene cuz youre shit at games") self.SwitchToScene("Scenes.MenuScene.MenuScene")
class Level6Opening(SceneBase): def __init__(self): SceneBase.__init__(self) self.continuebutton = Button("Continue", (900, 500), self.Continue, size=(160, 60), font_size=20, bg=(109, 177, 255)) def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: if self.continuebutton.IsClicked(mousepos): self.continuebutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/level6opening.jpg"), (0, 0)) self.continuebutton.Draw(screen) def Continue(self): print("going to final level") self.SwitchToScene(NeptuneGameScene())
class Level1Victory(SceneBase): def __init__(self): SceneBase.__init__(self) self.continuebutton = Button("Continue...", (900, 500), self.Continue, size=(160, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() b.PlayMusic("levelvictorymusic") def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: if self.continuebutton.IsClicked(mousepos): self.continuebutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/level1victory.jpg"), (0, 0)) self.continuebutton.Draw(screen) def Continue(self): print("going to upgrades") self.SwitchToScene(MoonUpgrade())
def __init__(self): SceneBase.__init__(self) self.continuebutton = Button("Continue", (900,500), self.Continue, size=(120,60), font_size=20, bg=(109,177,255)) b = Boombox() b.PlayMusic("levelvictorymusic")
def __init__(self): SceneBase.__init__(self) self.text = Text(228, 600, "Special Thanks: Connor Daniel", bold=True, color=(109, 177, 255), fontSize=45) self.returnbutton = Button("Return to Menu", (900, 425), self.GoBack, size=(300, 60), font_size=20, bg=(109, 177, 255))
def __init__(self): SceneBase.__init__(self) self.continuebutton = Button("Continue", (900, 525), self.Continue, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.backbutton = Button("Back", (900, 605), self.GoBack, size=(120, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() b.PlayMusic("loremusic")
def __init__(self): SceneBase.__init__(self) self.backbutton = Button("Back", (900, 605), self.GoBack, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.returnbutton = Button("Menu", (900, 525), self.Return, size=(120, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() if not b.MusicStatus(): b.PlayMusic("loremusic")
class MenuScene(SceneBase): def __init__(self): SceneBase.__init__(self) self.menubutton = Button("BUTTON", (60,30), self.function) def ProcessInput(self, events, pressed_keys): for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: mousepos = pygame.mouse.get_pos() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/background.jpg"), (0,0)) self.menubutton.Draw(screen) def function(self): print ("WHOOOOOOOOOO")
class SpaceMongolianLoreKraymer(SceneBase): def __init__(self): SceneBase.__init__(self) self.backbutton = Button("Back", (900, 605), self.GoBack, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.returnbutton = Button("Menu", (900, 525), self.Return, size=(120, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() if not b.MusicStatus(): b.PlayMusic("loremusic") def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: # Check if the buttons has been pressed if self.backbutton.IsClicked(mousepos): self.backbutton.call_back_() if self.returnbutton.IsClicked(mousepos): self.returnbutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/Lore/kramerlore.jpg"), (0, 0)) self.backbutton.Draw(screen) self.returnbutton.Draw(screen) def GoBack(self): print("Returning to addisonlore...") self.SwitchToScene( "Scenes.Lore.SpaceMongolianLoreAddison.SpaceMongolianLoreAddison") def Return(self): print("REturning to menu scene...") self.SwitchToScene("Scenes.MenuScene.MenuScene")
def __init__(self): # Set window width and height self.display_width = 702 self.display_height = 754 # Set number of cells to use in game self.cell_x = 100 self.cell_y = 100 # Initialize a grid to keep track of the statuses of all cells self.grid = Grid(self.cell_x, self.cell_y) # Set some properties on for the window self.game_display = pygame.display.set_mode( (self.display_width, self.display_height)) pygame.display.set_caption('Conway\'s Game of Life') self.clock = pygame.time.Clock() # Create a bool to determine whenever to loop the update grid function self.loop = False # Create a variable to terminate the game self.game_exit = False self.controls = pygame.sprite.Group() self.cells = pygame.sprite.Group() self.stop = pygame.sprite.Group() self.step_button = Button(100, 702, 100, 50, self.update_cells, "Step 1") self.loop_button = Button(500, 702, 100, 50, self.set_loop, "Loop") self.stop_button = Button(500, 702, 100, 50, self.set_loop, "Stop") self.clear_button = Button(202, 702, 100, 50, self.clear_grid, "Clear") # Draw all the cells and add them to the cells sprite group x = 2 for i in range(self.cell_x): y = 2 for j in range(self.cell_y): new_cell = Cell(x, y, i, j, self.grid) self.cells.add(new_cell) y += 7 x += 7 # Add in the step, loop and clear the buttons to the controls sprite group self.controls.add(self.step_button) self.controls.add(self.loop_button) self.controls.add(self.clear_button) # Add the stop button to the stop sprite group self.stop.add(self.stop_button)
class SpaceMongolianLoreTohnborjin(SceneBase): def __init__(self): SceneBase.__init__(self) self.continuebutton = Button("Continue", (900, 525), self.Continue, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.backbutton = Button("Back", (900, 605), self.GoBack, size=(120, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() b.PlayMusic("loremusic") def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: # Check if the buttons has been pressed if self.continuebutton.IsClicked(mousepos): self.continuebutton.call_back_() if self.backbutton.IsClicked(mousepos): self.backbutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/Lore/tohnlore.jpg"), (0, 0)) self.continuebutton.Draw(screen) self.backbutton.Draw(screen) def Continue(self): print("Next Lore") self.SwitchToScene(SpaceMongolianLoreAndrew()) def GoBack(self): self.SwitchToScene("Scenes.MenuScene.MenuScene")
def main_menu_loop(self): start_game = False # Create buttons with the static callback functions new_game_img = self.ui_cache.get_image("new_game_but") new_game_img_hov = self.ui_cache.get_image("new_game_but_hover") new_game_button = Button(self.get_half_width(), self.get_half_height() - 50, new_game_img, new_game_img_hov, 200, 50, start_game_cb) quit_img = self.ui_cache.get_image("quit_but") quit_img_hover = self.ui_cache.get_image("quit_but_hover") quit_button = Button(self.get_half_width(), self.get_half_height() + 10, quit_img, quit_img_hover, 200, 50, quit_game) # Define sprite group for buttons to easily draw button_entities = pygame.sprite.Group() button_entities.add((new_game_button, quit_button)) # Retrieve other UI images from cache bg_img = self.ui_cache.get_image("menu_bg") credits_img = self.ui_cache.get_image("credits") # Only draw background and other static images once to screen self.screen.blit(bg_img, (0, 0)) self.screen.blit(credits_img, (20, self.window_height - 50)) # Set the screen title pygame.display.set_caption("The Forming") while not start_game: self.clock.tick(self.fps) mouse_clicked = False # Loop through all events for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.MOUSEBUTTONDOWN: mouse_clicked = True if event.type == pygame.KEYDOWN: pass # Update the buttons. Start game will return True if clicked, exiting the menu loop start_game = new_game_button.update(pygame.mouse.get_pos(), mouse_clicked) quit_button.update(pygame.mouse.get_pos(), mouse_clicked) button_entities.draw(self.screen) pygame.display.flip() self.main_game_loop()
def spawnMenu(self, gridPos, screenPos, actions): if not self.menuSpawned: self.menuPosition = gridPos self.buttonContainer.position = screenPos self.buttonContainer.buttons.clear() x = 10 y = 10 for action in actions: self.buttonContainer.addButton(Button(Rect(x, y, 80, 20), (255, 0, 0), action.getName(), lambda: self.taskList.enqueueTask(action.getTask()))) y += 30 self.menuSpawned = True else: if (self.buttonContainer.position.x + self.buttonContainer.size.x > screenPos.x > self.buttonContainer.position.x and self.buttonContainer.position.y + self.buttonContainer.size.y > screenPos.y > self.buttonContainer.position.y): if self.buttonContainer.getButtonPressed(screenPos): self.menuSpawned = False else: self.menuSpawned = False
def __init__(self): SceneBase.__init__(self) self.text = Text(228, 600, "Level Select", bold=True, color=(109, 177, 255), fontSize=45) self.marsbutton = Button("2. Mars", (690, 325), self.Mars, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.moonbutton = Button("1. Moon", (510, 325), self.Moon, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.saturnbutton = Button("3. Saturn", (510, 425), self.Saturn, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.mercurybutton = Button("4. Mercury", (690, 425), self.Mercury, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.uranusbutton = Button("5. Uranus", (510, 525), self.Uranus, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.neptunebutton = Button("6. Neptune", (690, 525), self.Neptune, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.continuebutton = Button("Back", (50, 625), self.Continue, size=(60, 30), bg=(109, 177, 255)) # Start music b = Boombox() if not b.MusicStatus(): b.PlayMusic("menumusic")
class Game: def __init__(self): # Set window width and height self.display_width = 702 self.display_height = 754 # Set number of cells to use in game self.cell_x = 100 self.cell_y = 100 # Initialize a grid to keep track of the statuses of all cells self.grid = Grid(self.cell_x, self.cell_y) # Set some properties on for the window self.game_display = pygame.display.set_mode( (self.display_width, self.display_height)) pygame.display.set_caption('Conway\'s Game of Life') self.clock = pygame.time.Clock() # Create a bool to determine whenever to loop the update grid function self.loop = False # Create a variable to terminate the game self.game_exit = False self.controls = pygame.sprite.Group() self.cells = pygame.sprite.Group() self.stop = pygame.sprite.Group() self.step_button = Button(100, 702, 100, 50, self.update_cells, "Step 1") self.loop_button = Button(500, 702, 100, 50, self.set_loop, "Loop") self.stop_button = Button(500, 702, 100, 50, self.set_loop, "Stop") self.clear_button = Button(202, 702, 100, 50, self.clear_grid, "Clear") # Draw all the cells and add them to the cells sprite group x = 2 for i in range(self.cell_x): y = 2 for j in range(self.cell_y): new_cell = Cell(x, y, i, j, self.grid) self.cells.add(new_cell) y += 7 x += 7 # Add in the step, loop and clear the buttons to the controls sprite group self.controls.add(self.step_button) self.controls.add(self.loop_button) self.controls.add(self.clear_button) # Add the stop button to the stop sprite group self.stop.add(self.stop_button) def event_loop(self): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if not self.loop: for button in self.controls: button.handle_event(event) for cell in self.cells: cell.handle_event(event) else: self.stop_button.handle_event(event) def draw(self): self.game_display.fill((200, 200, 200)) if not self.loop: self.controls.draw(self.game_display) else: self.stop.draw(self.game_display) self.cells.draw(self.game_display) pygame.display.update() def run(self): while not self.game_exit: if self.loop: self.update_cells() time.sleep(0.05) self.event_loop() self.draw() self.clock.tick(60) def quit(self): self.game_exit = True def update_cells(self): self.grid.update() for cell in self.cells: cell.check_status() def set_loop(self): self.loop = not self.loop def clear_grid(self): self.grid.clear() for cell in self.cells: cell.check_status()
class OptionsScene(SceneBase): def __init__(self): SceneBase.__init__(self) self.hardcoremode = ToggleBox((600, 225), self.HardcoreMode, size=(30, 30), bg=(0, 170, 28)) self.hardcoretext = Text(225, 500, "Hardcore Mode", bold=True, font="Arial", fontSize=18) self.backbutton = Button("Back", (50, 625), self.GoBack, size=(60, 30), bg=(109, 177, 255)) self.text1 = Text(100, 600, "Options Menu", bold=True, color=(255, 255, 255), font="Arial", fontSize=35) def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: # Check if the buttons have been pressed if self.hardcoremode.IsClicked(mousepos): self.hardcoremode.ToggleBox() self.hardcoremode.call_back() if self.backbutton.IsClicked(mousepos): self.backbutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/MoonBG1.jpg"), (0, 0)) self.text1.Draw(screen) self.hardcoretext.Draw(screen) self.backbutton.Draw(screen) if Options.hardcoremode == True: self.hardcoremode.SetToggle(True) self.hardcoremode.Draw(screen) # Button functions def HardcoreMode(self): Options.SetHardcoreMode(self.hardcoremode.IsToggled()) def GoBack(self): self.SwitchToScene("Scenes.MenuScene.MenuScene")
class MenuScene(SceneBase): def __init__(self): SceneBase.__init__(self) self.startbutton = Button("New Game", (510, 325), self.StartGame, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.Instructionsbutton = Button("Instructions", (690, 325), self.Instructions, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.Lorebutton = Button("Read Lore", (510, 425), self.Lore, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.exitbutton = Button("Exit Game", (690, 425), self.ExitGame, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.optionsbutton = Button("Options", (1150, 625), self.Options, size=(90, 40), bg=(109, 177, 255)) self.creditsbutton = Button("Credits", (600, 525), self.Credits, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.text = Text( 228, 600, "Mongolian Space Stick Wars XD Special Day One Edition", bold=True, color=(109, 177, 255), fontSize=45) self.text1 = Text( 224, 600, "Mongolian Space Stick Wars XD Special Day One Edition", bold=True, color=(255, 255, 255), font="Arial", fontSize=45) # Start music b = Boombox() b.PlayMusic("menumusic") def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: # Check if the buttons has been pressed if self.startbutton.IsClicked(mousepos): self.startbutton.call_back_() if self.exitbutton.IsClicked(mousepos): self.exitbutton.call_back_() if self.Lorebutton.IsClicked(mousepos): self.Lorebutton.call_back_() if self.optionsbutton.IsClicked(mousepos): self.optionsbutton.call_back_() if self.Instructionsbutton.IsClicked(mousepos): self.Instructionsbutton.call_back_() if self.creditsbutton.IsClicked(mousepos): self.creditsbutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/MoonBG1.jpg"), (0, 0)) self.text.DrawCenter(screen) self.text1.DrawCenter(screen) self.startbutton.Draw(screen) self.exitbutton.Draw(screen) self.Lorebutton.Draw(screen) self.optionsbutton.Draw(screen) self.Instructionsbutton.Draw(screen) self.creditsbutton.Draw(screen) # Button functions def ExitGame(self): print("Exiting Game...") self.next = None def StartGame(self): print("Starting New Game...") if DLCCheck.CheckDLC(): self.SwitchToScene(LevelSelect()) else: print("[ERROR] DLC key not found") def Lore(self): print("Going to Lore...") self.SwitchToScene(SpaceMongolianLoreTohnborjin()) def Options(self): print("Going to Options...") self.SwitchToScene(OptionsScene()) def Instructions(self): print("Going to Instructions...") self.SwitchToScene(Instructions()) def Credits(self): print("going to credits...") self.SwitchToScene(Credits())
def __init__(self): SceneBase.__init__(self) self.menubutton = Button("BUTTON", (60,30), self.function)
def __init__(self): SceneBase.__init__(self) self.startbutton = Button("New Game", (510, 325), self.StartGame, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.Instructionsbutton = Button("Instructions", (690, 325), self.Instructions, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.Lorebutton = Button("Read Lore", (510, 425), self.Lore, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.exitbutton = Button("Exit Game", (690, 425), self.ExitGame, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.optionsbutton = Button("Options", (1150, 625), self.Options, size=(90, 40), bg=(109, 177, 255)) self.creditsbutton = Button("Credits", (600, 525), self.Credits, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.text = Text( 228, 600, "Mongolian Space Stick Wars XD Special Day One Edition", bold=True, color=(109, 177, 255), fontSize=45) self.text1 = Text( 224, 600, "Mongolian Space Stick Wars XD Special Day One Edition", bold=True, color=(255, 255, 255), font="Arial", fontSize=45) # Start music b = Boombox() b.PlayMusic("menumusic")
class NeptuneGameScene(SceneBase): def __init__(self): SceneBase.__init__(self) UnitLoader.__init__() self.counter = 0 self.Economy = False self.MoneyCounter = 0 self.AttackRate = 0 self.EAttackRate = 0 self.Health = 1000 if UpgradeData.defense: self.EHealth = 1500 elif not UpgradeData.defense: self.EHealth = 1000 print(self.Health) self.offset = 0 self.movecamera = 0 self.scrollfactor = 25 self.UnitMovement = UnitMovement() if Options.hardcoremode: self.AI = BaseAI(6) else: self.AI = BaseAI(3) self.defendbutton = Button("Defend", (60, 635), self.Attack, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.holdbutton = Button("Hold", (185, 635), self.HoldPosition, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.attackbutton = Button("Attack", (310, 635), self.DefendPosition, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.openmenu = Button("Build List", (1130, 600), self.Menu, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.resourcebar = Bar("Moon Crystals: 100", (1080, 15), size=(240, 30), font_size=20, bg=(176, 185, 186)) self.supplybar = Bar("Units: 0/40", (1080, 45), size=(240, 30), font_size=20, bg=(176, 185, 186)) self.buildmenu = ToggleMenu((1140, 350), size=(160, 400), bg=(176, 185, 186), shown=False) self.buildrifleblaster = Button("RifleBlaster 100", (1130, 275), self.BRB, size=(120, 60), font_size=15, bg=(109, 177, 255)) self.buildhorserifleblaster = Button("HorseRifleBlaster 200", (1130, 435), self.BHRB, size=(120, 60), font_size=12, bg=(109, 177, 255)) self.buildspaceraider = Button("SpaceRaider 50", (1130, 195), self.BSR, size=(120, 60), font_size=15, bg=(109, 177, 255)) self.buildtank = Button("Tank 300", (1130, 355), self.BTANK, size=(120, 60), font_size=15, bg=(109, 177, 255)) self.buildmenutoggle = False self.buildqueue = StatBar(" ", (1090, 635), size=(200, 20), bg=(176, 185, 186), fg=(109, 177, 255)) self.basehealth = StatBar(" ", (80, 45), size=(150, 20), bg=(176, 185, 186), fg=(219, 40, 0)) self.ebasehealth = StatBar(" ", (80, 15), size=(150, 20), bg=(176, 185, 186), fg=(109, 177, 255)) self.text = Text(15, 80, "Base Health", bold=True, fontSize=18) self.etext = Text(45, 80, "Enemy Base Health", bold=True, fontSize=18) self.buildmenu.AddButton(self.buildhorserifleblaster) self.buildmenu.AddButton(self.buildrifleblaster) self.buildmenu.AddButton(self.buildspaceraider) self.buildmenu.AddButton(self.buildtank) b = Boombox() b.PlayMusic("level6playmusic") def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: # Keydown events if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.key == pygame.K_ESCAPE: print("removed") elif event.key == pygame.K_a: self.buildqueue.SetFillPercentage(10, 100) elif event.key == pygame.K_b: self.buildmenutoggle = not self.buildmenutoggle self.buildmenu.ToggleMenu(self.buildmenutoggle) elif event.key == pygame.K_RIGHT: if self.movecamera >= 0: self.movecamera += self.scrollfactor elif event.key == pygame.K_LEFT: if self.movecamera <= 3600: self.movecamera -= self.scrollfactor elif event.key == pygame.K_m: print("removed") elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: if self.movecamera >= 0: self.movecamera -= self.scrollfactor elif event.key == pygame.K_LEFT: if self.movecamera <= 3600: self.movecamera += self.scrollfactor # Mouse click events elif event.type == pygame.MOUSEBUTTONDOWN: if self.attackbutton.IsClicked(mousepos): self.attackbutton.call_back_() elif self.defendbutton.IsClicked(mousepos): self.defendbutton.call_back_() elif self.holdbutton.IsClicked(mousepos): self.holdbutton.call_back_() elif self.buildhorserifleblaster.IsClicked(mousepos): self.buildhorserifleblaster.call_back_() elif self.buildspaceraider.IsClicked(mousepos): self.buildspaceraider.call_back_() elif self.buildtank.IsClicked(mousepos): self.buildtank.call_back_() elif self.buildrifleblaster.IsClicked(mousepos): self.buildrifleblaster.call_back_() elif self.openmenu.IsClicked(mousepos): self.buildmenutoggle = not self.buildmenutoggle self.buildmenu.ToggleMenu(self.buildmenutoggle) def Update(self): if self.movecamera != 0: if Camera.CheckCameraOffsets(self.offset, self.movecamera): self.offset += self.movecamera Camera.SetCameraOffset(self.offset, 0) self.cu = UnitLoader.GetCreatedUnits() self.ce = UnitSpawner.GetCreatedUnits() self.basehealth.SetFillPercentage(self.Health, 1000) self.ebasehealth.SetFillPercentage(self.EHealth, 1000) #Generate Money if (len(self.cu) > 0): self.Economy = True if (self.Economy == True): if (self.MoneyCounter == 60): self.MoneyCounter = 0 if UpgradeData.economy: CurrencyManagement.AddMoonCrystals(15) elif not UpgradeData.economy: CurrencyManagement.AddMoonCrystals(10) else: self.MoneyCounter += 1 if (len(self.cu) < 1): if (len(self.ce) < 1): if (self.Economy == True): self.Economy = False if (CurrencyManagement.GetMoonCrystals() < 100): CurrencyManagement.AddMoonCrystals( 100 - CurrencyManagement.GetMoonCrystals()) # Move all the units based on the current movement mode self.UnitMovement.MoveUnits() self.UnitMovement.MoveEnemyUnits() UnitLoader.BuildUnitsInQueue(self.buildqueue) # Call the AI self.AI.AIUpdate() # Move all spawned enemy units self.UnitMovement.MoveEnemyUnits() UnitSpawner.BuildUnitsInQueue() #You attack AttackDefend.UnitsAttack(self.cu, self.ce, self.AttackRate, self.EAttackRate) if (self.AttackRate > 50): self.AttackRate = 0 else: self.AttackRate += 1 if (self.EAttackRate > 50): self.EAttackRate = 0 else: self.EAttackRate += 1 #Attack Base if (self.Health != 1000): if (self.Health != 1500): if (len(self.cu) > 0): self.Health = WinCon.ReachedPlayer(self.cu, 0, self.Health) if (self.Health == 1500): if (len(self.cu) > 0): self.Health = WinCon.ReachedPlayer(self.cu, 0, self.Health) if (self.Health == 1000): if (len(self.cu) > 0): self.Health = WinCon.ReachedPlayer(self.cu, 0) if (self.Health <= 0): print "Congrats you have won" self.SwitchToScene("Scenes.Levels.Level6Victory.Level6Victory") #Enemies Attack Base if (self.EHealth != 1000): if (self.EHealth != 1500): if (len(self.ce) > 0): self.EHealth = WinCon.ReachedEPlayer( self.ce, 1, self.EHealth) if (self.EHealth == 1000): if (len(self.ce) > 0): self.EHealth = WinCon.ReachedEPlayer(self.ce, 1) if (self.EHealth == 1500): if (len(self.ce) > 0): self.EHealth = WinCon.ReachedEPlayer(self.ce, 1, self.EHealth) if (self.EHealth <= 0): print "YOU LOST YOU F*****G SUCK YOU LITTLE DUMBASS" self.SwitchToScene("Scenes.Levels.Level6Defeat.Level6Defeat") #self.EHealth = WinCon.ReachedPlayer(self.ce, 1, self.EHealth) def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("Images/Neptune.jpg"), (0 - Camera.GetXOffset(), 0)) # Draw your units on screen for unit in self.cu: topLeft = (unit.xpos - Camera.GetXOffset(), unit.ypos, unit.width, unit.hight) bottomRight = (unit.animate.frame, 0, unit.width, unit.hight) if (self.UnitMovement.movementmode == "A"): unit.animate.nextFrame() screen.blit(GetImage(unit.imagepath + "walk.png"), topLeft, bottomRight) else: unit.animate.prevFrame() screen.blit( pygame.transform.flip( GetImage(unit.imagepath + "walk.png"), True, False), topLeft, bottomRight) # Draw enemy units on screen for unit in self.ce: unit.animate.prevFrame() topLeft = (unit.xpos - Camera.GetXOffset(), unit.ypos, unit.width, unit.hight) bottomRight = (unit.animate.frame, 0, unit.width, unit.hight) screen.blit( pygame.transform.flip(GetImage(unit.imagepath + "walk.png"), True, False), topLeft, bottomRight) # Draw the GUI self.attackbutton.Draw(screen) self.holdbutton.Draw(screen) self.defendbutton.Draw(screen) # Make sure not to update the text unless it has changed if "Moon Crystals: " + str( CurrencyManagement.GetMoonCrystals()) != self.resourcebar.txt: self.resourcebar.SetText("Moon Crystals: " + str(CurrencyManagement.GetMoonCrystals())) if "Units: " + str( UnitLoader.GetUsedSupply()) + "/40" != self.supplybar.txt: self.supplybar.SetText("Units: " + str(UnitLoader.GetUsedSupply()) + "/40") self.resourcebar.Draw(screen) self.supplybar.Draw(screen) self.buildqueue.Draw(screen) self.buildmenu.Draw(screen) self.openmenu.Draw(screen) self.basehealth.Draw(screen) self.ebasehealth.Draw(screen) self.text.Draw(screen) self.etext.Draw(screen) # Cleanup function def Terminate(self): UnitLoader.createdUnits = [] UnitLoader.queuedUnits = [] UnitLoader.buildCount = 0 UnitLoader.lane = 0 UnitLoader.currentUnit = None CurrencyManagement.mooncrystals = 100 UnitSpawner.createdUnits = [] UnitSpawner.queuedUnits = [] UnitSpawner.buildCount = 0 UnitSpawner.lane = 0 UnitSpawner.currentUnit = None Camera.SetCameraOffset(0, 0) # Button functions def DefendPosition(self): self.UnitMovement.SetMovementMode("A") def Menu(self): self.buildmenutoggle = not self.buildmenutoggle self.buildmenu.ToggleMenu(self.buildmenutoggle) def HoldPosition(self): self.UnitMovement.SetMovementMode("H") def Attack(self): self.UnitMovement.SetMovementMode("D") def BRB(self): unit = Unit(UnitLoader.units["RifleBlaster"]) UnitLoader.EnqueueUnit(unit) def BHRB(self): unit = Unit(UnitLoader.units["HorseRifleBlaster"]) UnitLoader.EnqueueUnit(unit) def BSR(self): unit = Unit(UnitLoader.units["SpaceRaider"]) UnitLoader.EnqueueUnit(unit) def BTANK(self): unit = Unit(UnitLoader.units["Tank"]) UnitLoader.EnqueueUnit(unit)
class UranusUpgrade(SceneBase): def __init__(self): SceneBase.__init__(self) self.economybutton = Button("+5 MoonCrystals Economy", (300, 200), self.Economy, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.defensebutton = Button("+500 Mothership HP", (300, 300), self.Defense, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.continuebutton = Button("Make the Game Great Again", (900, 500), self.Continue, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.damagebutton = Button("Unit Damage +10", (300, 400), self.Damage, size=(240, 60), font_size=20, bg=(109, 177, 255)) self.healthbutton = Button("Unit Health +20", (300, 500), self.Health, size=(240, 60), font_size=20, bg=(109, 177, 255)) b = Boombox() if not b.MusicStatus(): b.PlayMusic("menumusic") def ProcessInput(self, events, pressed_keys): global x mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: self.SwitchToScene(None) elif event.type == pygame.MOUSEBUTTONDOWN: # Check if the buttons has been pressed if self.economybutton.IsClicked( mousepos) and not UpgradeData.economy: self.economybutton.call_back_() if self.defensebutton.IsClicked( mousepos) and not UpgradeData.defense: self.defensebutton.call_back_() if self.damagebutton.IsClicked( mousepos) and not UpgradeData.damage: self.damagebutton.call_back_() if self.healthbutton.IsClicked( mousepos) and not UpgradeData.health: self.healthbutton.call_back_() if self.continuebutton.IsClicked(mousepos): self.continuebutton.call_back_() def Update(self): pass def Render(self, screen): global x screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/background.jpg"), (0, 0)) if not UpgradeData.economy: self.economybutton.Draw(screen) if not UpgradeData.defense: self.defensebutton.Draw(screen) if not UpgradeData.damage: self.damagebutton.Draw(screen) if not UpgradeData.health: self.healthbutton.Draw(screen) self.continuebutton.Draw(screen) def Continue(self): self.SwitchToScene("Scenes.Levels.Level6Opening.Level6Opening") def Economy(self): UpgradeData.EconomyUpgrade(True) print("Economy upgraded") print(UpgradeData.economy) self.SwitchToScene("Scenes.Levels.Level6Opening.Level6Opening") def Defense(self): UpgradeData.DefenseUpgrade(True) print("Defense upgraded") print(UpgradeData.defense) self.SwitchToScene("Scenes.Levels.Level6Opening.Level6Opening") def Damage(self): UpgradeData.DamageUpgrade(True) print("unit damageu upgraded") self.SwitchToScene("Scenes.Levels.Level6Opening.Level6Opening") def Health(self): UpgradeData.HealthUpgrade(True) print("health damage upgraded") self.SwitchToScene("Scenes.Levels.Level6Opening.Level6Opening")
def __init__(self): SceneBase.__init__(self) UnitLoader.__init__() self.counter = 0 self.Economy = False self.MoneyCounter = 0 self.AttackRate = 0 self.EAttackRate = 0 self.Health = 1000 if UpgradeData.defense: self.EHealth = 1500 elif not UpgradeData.defense: self.EHealth = 1000 print(self.Health) self.offset = 0 self.movecamera = 0 self.scrollfactor = 25 self.UnitMovement = UnitMovement() if Options.hardcoremode: self.AI = BaseAI(6) else: self.AI = BaseAI(3) self.defendbutton = Button("Defend", (60, 635), self.Attack, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.holdbutton = Button("Hold", (185, 635), self.HoldPosition, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.attackbutton = Button("Attack", (310, 635), self.DefendPosition, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.openmenu = Button("Build List", (1130, 600), self.Menu, size=(120, 30), font_size=20, bg=(109, 177, 255)) self.resourcebar = Bar("Moon Crystals: 100", (1080, 15), size=(240, 30), font_size=20, bg=(176, 185, 186)) self.supplybar = Bar("Units: 0/40", (1080, 45), size=(240, 30), font_size=20, bg=(176, 185, 186)) self.buildmenu = ToggleMenu((1140, 350), size=(160, 400), bg=(176, 185, 186), shown=False) self.buildrifleblaster = Button("RifleBlaster 100", (1130, 275), self.BRB, size=(120, 60), font_size=15, bg=(109, 177, 255)) self.buildhorserifleblaster = Button("HorseRifleBlaster 200", (1130, 435), self.BHRB, size=(120, 60), font_size=12, bg=(109, 177, 255)) self.buildspaceraider = Button("SpaceRaider 50", (1130, 195), self.BSR, size=(120, 60), font_size=15, bg=(109, 177, 255)) self.buildtank = Button("Tank 300", (1130, 355), self.BTANK, size=(120, 60), font_size=15, bg=(109, 177, 255)) self.buildmenutoggle = False self.buildqueue = StatBar(" ", (1090, 635), size=(200, 20), bg=(176, 185, 186), fg=(109, 177, 255)) self.basehealth = StatBar(" ", (80, 45), size=(150, 20), bg=(176, 185, 186), fg=(219, 40, 0)) self.ebasehealth = StatBar(" ", (80, 15), size=(150, 20), bg=(176, 185, 186), fg=(109, 177, 255)) self.text = Text(15, 80, "Base Health", bold=True, fontSize=18) self.etext = Text(45, 80, "Enemy Base Health", bold=True, fontSize=18) self.buildmenu.AddButton(self.buildhorserifleblaster) self.buildmenu.AddButton(self.buildrifleblaster) self.buildmenu.AddButton(self.buildspaceraider) self.buildmenu.AddButton(self.buildtank) b = Boombox() b.PlayMusic("level6playmusic")
class LevelSelect(SceneBase): def __init__(self): SceneBase.__init__(self) self.text = Text(228, 600, "Level Select", bold=True, color=(109, 177, 255), fontSize=45) self.marsbutton = Button("2. Mars", (690, 325), self.Mars, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.moonbutton = Button("1. Moon", (510, 325), self.Moon, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.saturnbutton = Button("3. Saturn", (510, 425), self.Saturn, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.mercurybutton = Button("4. Mercury", (690, 425), self.Mercury, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.uranusbutton = Button("5. Uranus", (510, 525), self.Uranus, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.neptunebutton = Button("6. Neptune", (690, 525), self.Neptune, size=(120, 60), font_size=20, bg=(109, 177, 255)) self.continuebutton = Button("Back", (50, 625), self.Continue, size=(60, 30), bg=(109, 177, 255)) # Start music b = Boombox() if not b.MusicStatus(): b.PlayMusic("menumusic") def ProcessInput(self, events, pressed_keys): mousepos = pygame.mouse.get_pos() for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN: self.SwitchToScene(None) elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: self.SwitchToScene("Scenes.MenuScene.MenuScene") elif event.type == pygame.MOUSEBUTTONDOWN: # Check if the buttons has been pressed if self.marsbutton.IsClicked(mousepos) and LevelData.mars: self.marsbutton.call_back_() if self.mercurybutton.IsClicked( mousepos) and LevelData.mercury: self.mercurybutton.call_back_() if self.saturnbutton.IsClicked(mousepos) and LevelData.saturn: self.saturnbutton.call_back_() if self.moonbutton.IsClicked(mousepos): self.moonbutton.call_back_() if self.uranusbutton.IsClicked(mousepos) and LevelData.uranus: self.uranusbutton.call_back_() if self.continuebutton.IsClicked(mousepos): self.continuebutton.call_back_() if self.neptunebutton.IsClicked( mousepos) and LevelData.neptune: self.neptunebutton.call_back_() def Update(self): pass def Render(self, screen): screen.fill((0, 0, 0)) screen.blit(GetImage("./Images/MoonBG1.jpg"), (0, 0)) self.text.Draw(screen) if LevelData.mars: self.marsbutton.Draw(screen) if LevelData.mercury: self.mercurybutton.Draw(screen) if LevelData.saturn: self.saturnbutton.Draw(screen) self.moonbutton.Draw(screen) if LevelData.uranus: self.uranusbutton.Draw(screen) self.continuebutton.Draw(screen) if LevelData.neptune: self.neptunebutton.Draw(screen) # Button functions def Mercury(self): print("Starting New Game : Mercury...") self.SwitchToScene("Scenes.Levels.Level4Opening.Level4Opening") def Mars(self): print("Starting New Game : Mars...") self.SwitchToScene("Scenes.Levels.Level2Opening.Level2Opening") def Saturn(self): print("Starting New Game : Saturn...") self.SwitchToScene("Scenes.Levels.Level3Opening.Level3Opening") def Moon(self): print("Starting New Game : Moon...") self.SwitchToScene("Scenes.Levels.Level1Opening.Level1Opening") def Uranus(self): print("Starting New Game : Ur ANUS...") self.SwitchToScene("Scenes.Levels.Level5Opening.Level5Opening") def Neptune(self): print("Starting New Game : Neptune...") self.SwitchToScene("Scenes.Levels.Level6Opening.Level6Opening") def Continue(self): print("returning to menu") self.SwitchToScene("Scenes.MenuScene.MenuScene")