def FireEmblem(screen): inGame = True nbSave = 0 state = ["Title", "Scene1", 1] characters = [] while inGame: if state[0] == "Dialogue": state = DialogueScene.Dialogue(screen, state[1], state[2]) elif state[0] == "Battle": infosBattle = utils.loadBattle(state[1], nbSave) endBattle = Battle.battle(screen, infosBattle[0], infosBattle[1], infosBattle[2], infosBattle[3]) state = endBattle[0] characters = endBattle[1] if state[0] not in ["Quit", "Title"]: utils.save("auto", state[0], state[1], state[2], pygame.Surface((600, 600)), characters) elif state[0] == "Title": state = TitleScreen.TitleScreen(screen) elif state[0] == "Load": state = LoadMenu.loadMenu(screen) elif state[0] == "Save": state = SaveMenu.SaveMenu(screen, state[1], state[2], state[3], state[4], characters) elif state[0] == "Options": state = Options.Options(screen) elif state[0] == "Quit": inGame = False
def RunningTheLoop(Loop): NextLocation = False if Loop == 'Ocean': NextLocation = OceanOverworld.OceanOverworldFunc(True) return NextLocation if Loop == 'Island': NextLocation = ExploreIsland.IslandExploration(True) return NextLocation if Loop == 'Title': NextLocation = TitleScreen.TitleScreen(True) return NextLocation if Loop == 'EXIT': pygame.quit() exit()
def main(): # Array of scenes that shall be passed to the director scenes = [] # The "Director" of the game. It takes in the array of scenes and holds most of the "background" data for the game dire = Director(scenes) # The Scenes of the game. They all take the director object as an argument titlescr = TitleScreen(dire) onep = EdiblesOnePlayer(dire) twop = EdiblesTwoPlayer(dire) config = Config(dire) # Here the scenes are being appended to the end of the array scenes.append(titlescr) scenes.append(onep) scenes.append(twop) scenes.append((config)) # Changes/Sets the first scene of the game to be the Title Screen. dire.change_scene(titlescr) # Starts the game loop dire.loop()
def create_title_screen(self): title_screen = TitleScreen.TitleScreen() title_stage = Stage(self.game_engine) title_stage.add_object(title_screen) self.game_engine.add_stage(title_stage) self.game_engine.set_active_stage(title_stage)
import math import pygame import sys import Stage1 import TitleScreen import gameOver pygame.init() clock=pygame.time.Clock() clock.tick() window=pygame.display.set_mode([640,480]) pygame.display.set_caption("Team JhaneMarVhiel") font=pygame.font.Font("freesansbold.ttf",32) #font=pygame.font.Font("HARNGTON.TTF",60) TitleScreen=TitleScreen.cTitleScreen() Stage1=Stage1.cStage1() gameOver=gameOver.cGameOver() #CurrentScreen=gameOver CurrentScreen=TitleScreen while True: newScreen=CurrentScreen.update(clock) if (newScreen=="Stage1"): CurrentScreen=Stage1 CurrentScreen.draw(window) events=pygame.event.get() for event in events: if ((event.type==pygame.QUIT)or (newScreen=="QUIT")or (event.type==pygame.KEYDOWN and event.key==pygame.K_ESCAPE)):
def __init__(self): pygame.init() #start up pygame self.window = pygame.display.set_mode( (640, 790)) #set window size to 512, 512 pygame.display.set_caption("Search") #title window pygame.key.set_repeat(1, 80) import objects self.all_sprites = pygame.sprite.Group() self.all_tiles = pygame.sprite.Group() self.active_tiles = pygame.sprite.Group() self.inventoryWindow = pygame.sprite.Group( ) #create a sprite group for the inventory window self.doors = pygame.sprite.Group() self.active_doors = pygame.sprite.Group( ) #make sprite group for this room's doors that Horace can walk through self.inactive_doors = pygame.sprite.Group( ) #make sprite group for this room's doors that are closed so that they will change appearance but still be drawn (removing them #from self.active_doors won't actually cause them to disappear) self.status_bar = pygame.sprite.Group() self.entities = pygame.sprite.Group() self.props = pygame.sprite.Group() self.active_props = pygame.sprite.Group() self.active_message_boxes = pygame.sprite.Group( ) #sprite group to hold active message boxes self.active_option_boxes = pygame.sprite.Group() self.active_enemies = pygame.sprite.Group() self.title_screen = pygame.sprite.Group() self.minimap_group = pygame.sprite.Group() self.active_ground_items = pygame.sprite.Group() self.message_box_active = False #check if there are active message boxes self.active_battle = pygame.sprite.Group() self.active_enemy_status_bar = pygame.sprite.Group() #for prop in objects.cave_plants: # self.props.add(prop) self.clock = pygame.time.Clock() apple = item( self, 91, 91, "img/items/misc/apple_2.png", 'Apple', 2, 'Here is an unnecessarily long description of an apple. It is entirely to test the function of the textWrapper class', True, 'common', 1) apple2 = item(self, 64, 64, "img/items/misc/apple_2.png", 'Apple', 2, 'Another apple', True, 'common', 1) apple3 = item(self, 64, 64, "img/items/misc/apple_2.png", 'Apple', 2, 'A third apple', True, 'common', 1) broken_gauntlets_statreq = {"STR": 1, "DEX": 0, "AGL": 0, "INT": 0} broken_cuirass_statreq = {"STR": 2, "DEX": 0, "AGL": 0, "INT": 0} broken_gauntlets_elembonus = { "LIGHT": 12, "DARK": 0, "FIRE": 0, "ICE": 0 } broken_cuirass_elembonus = {"LIGHT": 2, "DARK": 3, "FIRE": 0, "ICE": 0} broken_greaves_statreq = {"STR": 0, "DEX": 0, "AGL": 0, "INT": 0} broken_greaves_elembonus = {"LIGHT": 0, "DARK": 0, "FIRE": 0, "ICE": 0} cracked_helmet_elembonus = { "LIGHT": 12, "DARK": 0, "FIRE": 0, "ICE": 0 } cracked_helmet_statreq = {"STR": 0, "DEX": 0, "AGL": 0, "INT": 0} self.broken_gauntlets = Armor(self, "Broken gauntlets", 64, 64, 2, "Plate", broken_gauntlets_elembonus, broken_gauntlets_statreq, "arms", "broken", "gauntlets", 10, "A pair of broken gauntlets") self.broken_cuirass = Armor(self, "Broken cuirass", 64, 64, 3, "Plate", broken_cuirass_elembonus, broken_cuirass_statreq, "torso", "broken", "cuirass", 6, "A broken cuirass.") self.broken_greaves = Armor(self, "Broken greaves", 64, 64, 2, "Plate", broken_greaves_elembonus, broken_greaves_statreq, "legs", "broken", "greaves", 8, "A pair of broken greaves.") self.cracked_helmet = Armor(self, "Cracked helmet", 64, 64, 3, "Plate", cracked_helmet_elembonus, cracked_helmet_statreq, "head", "broken", "helmet", 8, "A cracked helmet.") broken_sword_statreq = {"STR": 2, "DEX": 0, "AGL": 0, "INT": 0} broken_sword_elembonus = {"LIGHT": 5} self.broken_sword = Weapon( self, "Broken sword", 64, 64, "Straight sword", "right", "medium", "piercing", 8, 8, broken_sword_elembonus, broken_sword_statreq, None, None, "broken_sword", 15, "Horace's guardsman's sword. Mostly ornamental, its blade is now broken in two by falling rubble." ) inventory = [ apple, apple2, apple3, self.broken_gauntlets, self.broken_cuirass, self.broken_greaves, self.cracked_helmet, self.broken_sword ] #create very basic inventory array self.player = Player(self, 64, 64, inventory, 50, 50, 20, 20, 3, 5, 5, 3, 5, None, None, None, None, None, None) goblin_targetable_areas = [ "Target: head", "Target: arms", "Target: legs", "Target: torso" ] self.goblin = Enemy(self, self.player, 384, 384, 2, "Goblin", 20, 20, 3, None, None, None, None, "Beast", "goblin", goblin_targetable_areas) self.goblin_2 = Enemy(self, self.player, 256, 384, 2, "Goblin", 20, 20, 3, None, None, None, None, "Beast", "goblin", goblin_targetable_areas) room_1_enemies = [self.goblin, self.goblin_2] self.rightDoor = Door( self, 9, 4, "right", True, "img/tile/chasm/chasm_door_right.png", "img/tile/chasm/chasm_wall_right.png" ) #initialize doors. There will be only four doors, each representing a cardinal direction. A room can have 1-4 doors. self.leftDoor = Door(self, 0, 4, "left", True, "img/tile/chasm/chasm_door_left.png", "img/tile/chasm/chasm_wall_left.png") self.forwardDoor = Door(self, 4, 0, "forward", True, "img/tile/chasm/chasm_door_top.png", "img/tile/chasm/chasm_wall_top.png") self.backwardDoor = Door(self, 4, 9, "backward", True, "img/tile/chasm/chasm_door_bottom.png", "img/tile/chasm/chasm_wall_top.png") self.display_inventory = False #flag to check whether the inventory window is open or not self.z1r1 = Room( self, "base", [self.backwardDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r1, room_1_enemies ) #initialize some basic rooms, each with a different background image to tell them apart. #enter a list of doors to represent the doors of the room. self.z2r2 = Room(self, "base", [self.backwardDoor, self.forwardDoor, self.rightDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r2, []) self.z3r3 = Room(self, "base", [self.forwardDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r3, []) self.z4r4 = Room(self, "base", [self.leftDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r4, []) self.ZONE1 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, self.z1r1, 0, 0, 0, 0], [0, self.z2r2, self.z4r4, 0, 0, 0], [0, self.z3r3, 0, 0, 0, 0]] self.battle = False self.titlescreen = TitleScreen(self, 0, 0) self.clock_group = pygame.sprite.Group() #create a 2D array of rooms to represent this zone. #self.currentLocation = #self.z1r1 = Room(self, "base", "door", "img/tile/chasm/chasm_01.png") #create a new Room object (see assets.py) #for x in range(0, 8): # for y in range(0, 8): # self.active_tiles.add(self.z1r1.tiles[x][y]) #fill the active_tiles sprite group with the tiles from the room object #create some random items #messages = ["Yes", "No", None, None] #dialogBox = optionBox(self, 64, 512, self.player, messages, "Will you accept the blessing?") #dialogBox.add(self.active_option_boxes) pygame.font.init() self.clock = pygame.time.Clock() self.prevKey = None self.minimap = Minimap(self, 500, 500, "minimap", self.player)
class Game(object): def __init__(self): pygame.init() #start up pygame self.window = pygame.display.set_mode( (640, 790)) #set window size to 512, 512 pygame.display.set_caption("Search") #title window pygame.key.set_repeat(1, 80) import objects self.all_sprites = pygame.sprite.Group() self.all_tiles = pygame.sprite.Group() self.active_tiles = pygame.sprite.Group() self.inventoryWindow = pygame.sprite.Group( ) #create a sprite group for the inventory window self.doors = pygame.sprite.Group() self.active_doors = pygame.sprite.Group( ) #make sprite group for this room's doors that Horace can walk through self.inactive_doors = pygame.sprite.Group( ) #make sprite group for this room's doors that are closed so that they will change appearance but still be drawn (removing them #from self.active_doors won't actually cause them to disappear) self.status_bar = pygame.sprite.Group() self.entities = pygame.sprite.Group() self.props = pygame.sprite.Group() self.active_props = pygame.sprite.Group() self.active_message_boxes = pygame.sprite.Group( ) #sprite group to hold active message boxes self.active_option_boxes = pygame.sprite.Group() self.active_enemies = pygame.sprite.Group() self.title_screen = pygame.sprite.Group() self.minimap_group = pygame.sprite.Group() self.active_ground_items = pygame.sprite.Group() self.message_box_active = False #check if there are active message boxes self.active_battle = pygame.sprite.Group() self.active_enemy_status_bar = pygame.sprite.Group() #for prop in objects.cave_plants: # self.props.add(prop) self.clock = pygame.time.Clock() apple = item( self, 91, 91, "img/items/misc/apple_2.png", 'Apple', 2, 'Here is an unnecessarily long description of an apple. It is entirely to test the function of the textWrapper class', True, 'common', 1) apple2 = item(self, 64, 64, "img/items/misc/apple_2.png", 'Apple', 2, 'Another apple', True, 'common', 1) apple3 = item(self, 64, 64, "img/items/misc/apple_2.png", 'Apple', 2, 'A third apple', True, 'common', 1) broken_gauntlets_statreq = {"STR": 1, "DEX": 0, "AGL": 0, "INT": 0} broken_cuirass_statreq = {"STR": 2, "DEX": 0, "AGL": 0, "INT": 0} broken_gauntlets_elembonus = { "LIGHT": 12, "DARK": 0, "FIRE": 0, "ICE": 0 } broken_cuirass_elembonus = {"LIGHT": 2, "DARK": 3, "FIRE": 0, "ICE": 0} broken_greaves_statreq = {"STR": 0, "DEX": 0, "AGL": 0, "INT": 0} broken_greaves_elembonus = {"LIGHT": 0, "DARK": 0, "FIRE": 0, "ICE": 0} cracked_helmet_elembonus = { "LIGHT": 12, "DARK": 0, "FIRE": 0, "ICE": 0 } cracked_helmet_statreq = {"STR": 0, "DEX": 0, "AGL": 0, "INT": 0} self.broken_gauntlets = Armor(self, "Broken gauntlets", 64, 64, 2, "Plate", broken_gauntlets_elembonus, broken_gauntlets_statreq, "arms", "broken", "gauntlets", 10, "A pair of broken gauntlets") self.broken_cuirass = Armor(self, "Broken cuirass", 64, 64, 3, "Plate", broken_cuirass_elembonus, broken_cuirass_statreq, "torso", "broken", "cuirass", 6, "A broken cuirass.") self.broken_greaves = Armor(self, "Broken greaves", 64, 64, 2, "Plate", broken_greaves_elembonus, broken_greaves_statreq, "legs", "broken", "greaves", 8, "A pair of broken greaves.") self.cracked_helmet = Armor(self, "Cracked helmet", 64, 64, 3, "Plate", cracked_helmet_elembonus, cracked_helmet_statreq, "head", "broken", "helmet", 8, "A cracked helmet.") broken_sword_statreq = {"STR": 2, "DEX": 0, "AGL": 0, "INT": 0} broken_sword_elembonus = {"LIGHT": 5} self.broken_sword = Weapon( self, "Broken sword", 64, 64, "Straight sword", "right", "medium", "piercing", 8, 8, broken_sword_elembonus, broken_sword_statreq, None, None, "broken_sword", 15, "Horace's guardsman's sword. Mostly ornamental, its blade is now broken in two by falling rubble." ) inventory = [ apple, apple2, apple3, self.broken_gauntlets, self.broken_cuirass, self.broken_greaves, self.cracked_helmet, self.broken_sword ] #create very basic inventory array self.player = Player(self, 64, 64, inventory, 50, 50, 20, 20, 3, 5, 5, 3, 5, None, None, None, None, None, None) goblin_targetable_areas = [ "Target: head", "Target: arms", "Target: legs", "Target: torso" ] self.goblin = Enemy(self, self.player, 384, 384, 2, "Goblin", 20, 20, 3, None, None, None, None, "Beast", "goblin", goblin_targetable_areas) self.goblin_2 = Enemy(self, self.player, 256, 384, 2, "Goblin", 20, 20, 3, None, None, None, None, "Beast", "goblin", goblin_targetable_areas) room_1_enemies = [self.goblin, self.goblin_2] self.rightDoor = Door( self, 9, 4, "right", True, "img/tile/chasm/chasm_door_right.png", "img/tile/chasm/chasm_wall_right.png" ) #initialize doors. There will be only four doors, each representing a cardinal direction. A room can have 1-4 doors. self.leftDoor = Door(self, 0, 4, "left", True, "img/tile/chasm/chasm_door_left.png", "img/tile/chasm/chasm_wall_left.png") self.forwardDoor = Door(self, 4, 0, "forward", True, "img/tile/chasm/chasm_door_top.png", "img/tile/chasm/chasm_wall_top.png") self.backwardDoor = Door(self, 4, 9, "backward", True, "img/tile/chasm/chasm_door_bottom.png", "img/tile/chasm/chasm_wall_top.png") self.display_inventory = False #flag to check whether the inventory window is open or not self.z1r1 = Room( self, "base", [self.backwardDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r1, room_1_enemies ) #initialize some basic rooms, each with a different background image to tell them apart. #enter a list of doors to represent the doors of the room. self.z2r2 = Room(self, "base", [self.backwardDoor, self.forwardDoor, self.rightDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r2, []) self.z3r3 = Room(self, "base", [self.forwardDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r3, []) self.z4r4 = Room(self, "base", [self.leftDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r4, []) self.ZONE1 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, self.z1r1, 0, 0, 0, 0], [0, self.z2r2, self.z4r4, 0, 0, 0], [0, self.z3r3, 0, 0, 0, 0]] self.battle = False self.titlescreen = TitleScreen(self, 0, 0) self.clock_group = pygame.sprite.Group() #create a 2D array of rooms to represent this zone. #self.currentLocation = #self.z1r1 = Room(self, "base", "door", "img/tile/chasm/chasm_01.png") #create a new Room object (see assets.py) #for x in range(0, 8): # for y in range(0, 8): # self.active_tiles.add(self.z1r1.tiles[x][y]) #fill the active_tiles sprite group with the tiles from the room object #create some random items #messages = ["Yes", "No", None, None] #dialogBox = optionBox(self, 64, 512, self.player, messages, "Will you accept the blessing?") #dialogBox.add(self.active_option_boxes) pygame.font.init() self.clock = pygame.time.Clock() self.prevKey = None self.minimap = Minimap(self, 500, 500, "minimap", self.player) def new(self): self.leftwall = pygame.image.load( "img/tile/chasm/chasm_wall_left.png").convert() self.rightwall = pygame.image.load( "img/tile/chasm/chasm_wall_right.png").convert() self.topwall = pygame.image.load( "img/tile/chasm/chasm_wall_top.png").convert() self.bottomwall = pygame.image.load( "img/tile/chasm/chasm_wall_bottom.png").convert() self.window.blit(self.rightwall, (576, 0)) self.window.blit(self.topwall, (0, 0)) self.window.blit(self.bottomwall, (0, 576)) self.window.blit(self.leftwall, (0, 0)) self.statusbar = statusBar(self, self.player, 0, 640) self.statusbar.updateBonuses() self.startingRoom = self.ZONE1[self.player.roomLocation[0]][ self.player.roomLocation[ 1]] #access the 2D array "ZONE1" above and get the room that the player starts in self.activeRoom = 0 #initialize the active room to 0 (will later be a room object) #self.z1r1 = Room(self, "base", "door", "img/tile/chasm/chasm_01.png") #create a new Room object (see assets.py) for x in range(0, 8): for y in range(0, 8): self.active_tiles.add(self.startingRoom.tiles[x][y]) #fill the active_tiles sprite group with the tiles from the room object for door in self.startingRoom.doors: self.active_doors.add(door) self.inventory = inventoryGUI( self, self.player, 64, 128) #initialize new inventoryGUI object (see assets.py) def titleScreen(self): self.title = True pygame.mixer.music.load( 'music/Defending-the-Princess-Haunted_v002.mp3') pygame.mixer.music.play(0) while self.title == True: self.titleScreenEvents() self.titleScreenDraw() self.titleScreenUpdate() def titleScreenDraw(self): self.title_screen.draw(self.window) def titleScreenUpdate(self): self.title_screen.update() def run(self): #method to run the game self.playing = True #initialize "self.playing" to true while self.playing == True: #pygame.time.delay(100) #while self.playing == true, delay + run self.events() if self.battle == False: self.events() #call the events method below else: self.battleEvents() if self.battle == False: self.move_enemies() self.draw() #call the draw method below #if self.battle == True: # self.battleEvent.add(self.active_battle) self.update() self.clock.tick(25) def titleScreenEvents(self): for event in pygame.event.get(): if event.type == pygame.QUIT: self.quit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: self.title = False if event.type == pygame.MOUSEMOTION: mousePos = pygame.mouse.get_pos() self.titlescreen.buttonMouseOver(mousePos) if event.type == pygame.MOUSEBUTTONDOWN: mousePos = pygame.mouse.get_pos() if self.titlescreen.clickButton(mousePos) == 4: self.quit() elif self.titlescreen.clickButton(mousePos) == 1: self.title = False WALK_SOUND = pygame.USEREVENT + 2 pygame.time.set_timer(WALK_SOUND, 5000) pygame.display.flip() def events(self): WALK_SOUND = pygame.USEREVENT + 2 for event in pygame.event.get(): #loop through events of pygame if event.type == pygame.QUIT: self.quit() #if the event is "quit" run the method self.quit() if event.type == WALK_SOUND: if self.player.footstepSound == False: self.player.footstep1.play() self.player.footstepSound = True elif self.player.footstepSound == True: self.player.footstep2.play() self.player.footstepSound = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.quit() if event.key == pygame.K_LEFT and self.player.x > 64 and self.checkPropCollisions( "left") == False: self.player.move(-10, 0) self.prevKey = "l" self.player.footstepSound = True if event.key == pygame.K_RIGHT and self.player.x < 512 and self.checkPropCollisions( "right") == False: self.player.move(10, 0) self.prevKey = "r" self.player.footstepSound = True if event.key == pygame.K_UP and self.player.y > 64 and self.checkPropCollisions( "up") == False: self.player.move(0, -10) self.prevKey = "u" self.player.footstepSound = True if event.key == pygame.K_DOWN and self.player.y < 512 and self.checkPropCollisions( "down") == False: self.player.move(0, 10) self.prevKey = "d" self.player.footstepSound = True if event.key == pygame.K_e: if self.display_inventory == True: self.display_inventory = False self.toggleInventoryVisibility() elif self.display_inventory == False: self.display_inventory = True self.toggleInventoryVisibility() if event.key == pygame.K_d: self.player.takeDamage(1) self.statusbar.decreaseHealth(1) if event.key == pygame.K_h: self.player.heal(1) self.statusbar.increaseHealth(1) if event.type == pygame.KEYUP: if self.prevKey == "l" or self.prevKey == "r" or self.prevKey == "u" or self.prevKey == "d": self.player.idle() if self.player.footstepSound == False or self.player.footstepSound == True: self.player.footstepSound = None if event.type == pygame.MOUSEBUTTONDOWN: mousePos = pygame.mouse.get_pos( ) #get position of mouse on the screen #print(self.display_inventory) #print(self.inventory.dropButton.rect) if ( self.display_inventory == True ): #only process this loop if the inventory is visible on the screen headRect = pygame.Rect(470, 146, 64, 64) torsoRect = pygame.Rect(470, 228, 64, 64) armsRect = pygame.Rect(470, 310, 64, 64) legsRect = pygame.Rect(470, 392, 64, 64) lWeaponRect = pygame.Rect(382, 228, 64, 64) rWeaponRect = pygame.Rect(383, 310, 64, 64) if self.inventory.dropButton.rect.collidepoint( mousePos) == True: #check if drop button clicked self.inventory.drop() print("Drop button clicked!") elif self.inventory.equipButton.rect.collidepoint( mousePos) == True: #check if equip button clicked print("Equip button clicked!") if (self.inventory.currentEquipmentSelection == None): self.inventory.equip() else: self.inventory.unequip() elif self.inventory.inspectButton.rect.collidepoint( mousePos ) == True: #check if inspect button clicked self.inventory.inspect( ) #run inventoryGUI's inspect() function elif self.inventory.sellButton.rect.collidepoint( mousePos) == True: #check if sell button clicked print("Sell button clicked!") elif headRect.collidepoint(mousePos) == True: self.inventory.selectEquipment("head") elif torsoRect.collidepoint(mousePos) == True: self.inventory.selectEquipment("torso") elif armsRect.collidepoint(mousePos) == True: self.inventory.selectEquipment("arms") elif legsRect.collidepoint(mousePos) == True: self.inventory.selectEquipment("legs") elif lWeaponRect.collidepoint(mousePos) == True: self.inventory.selectEquipment("lweapon") elif rWeaponRect.collidepoint(mousePos) == True: self.inventory.selectEquipment("rweapon") for item in self.player.inventory: offsetRect = pygame.Rect((item.x + 64, item.y + 128), (item.rect.x, item.rect.y)) #for each item in the player's inventory, create an offset rectangle (because the inventory window's #top left point is not at the game window's (0,0) if offsetRect.collidepoint( mousePos ) == True: #check if an item was clicked print("wtf?") self.inventory.select( item ) #run method defined in inventoryGUI class body (see assets.py) if self.message_box_active == True: mousePos = pygame.mouse.get_pos() for sprite in self.active_message_boxes.sprites(): if sprite.okButton.rect.collidepoint(mousePos) == True: sprite.remove(self.active_message_boxes) for optionBox in self.active_option_boxes: print(optionBox.checkClicked(mousePos[0], mousePos[1])) self.checkCollisions() self.checkItemCollisions() self.checkEnemyCollisions() pygame.display.flip() def battleEvents(self): CLOCK_TICK = pygame.USEREVENT + 2 #pygame.time.set_timer(CLOCK_TICK, 1000) ANIMATE_KEYSTROKES = pygame.USEREVENT + 1 ANIMATE_ENEMY = pygame.USEREVENT + 3 ANIMATE_ENEMY_ATTACK = pygame.USEREVENT + 4 for event in pygame.event.get(): if event.type == pygame.QUIT: self.quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_t: pygame.time.set_timer( CLOCK_TICK, 1000) #tick every second (1000 milliseconds) else: self.battleEvent.game_clock.tick() time_elapsed = self.battleEvent.game_clock.get_time() if event.key == pygame.K_UP: key_up = ("UP", time_elapsed) self.battleEvent.keyInputHandler(key_up) elif event.key == pygame.K_DOWN: key_down = ("DOWN", time_elapsed) self.battleEvent.keyInputHandler(key_down) elif event.key == pygame.K_LEFT: key_left = ("LEFT", time_elapsed) self.battleEvent.keyInputHandler(key_left) elif event.key == pygame.K_RIGHT: key_right = ("RIGHT", time_elapsed) self.battleEvent.keyInputHandler(key_right) if event.type == CLOCK_TICK: print("Clock ticked!") self.battleEvent.turn_determiner() if event.type == ANIMATE_ENEMY_ATTACK: self.battleEvent.enemy_attacking_animation() if event.type == ANIMATE_KEYSTROKES: for keystroke in self.battleEvent.displayed_keystrokes: keystroke.animate() if event.type == ANIMATE_ENEMY: self.battleEvent.enemyAnimation() def quit(self): pygame.quit() #quit pygame sys.exit() #close (IDLE is kind of weird with this) def draw_grid(self): for x in range(0, 512, 64): #every 64 pixels from 0 to 512 (window border): pygame.draw.line(self.window, (100, 100, 100), (x, 0), (x, 512)) #draw a light grey line on the window from each x to the bottom of the screen for y in range(0, 512, 64): #every 64 pixels from 0 to 512 (window border): pygame.draw.line(self.window, (100, 100, 100), (0, y), (512, y)) #draw a light grey line on the window from each y to the right of the screen. def move_enemies(self): for enemy in self.active_enemies.sprites(): enemy.move() def droppedItems(self, item): print("method run!") print(self.player.x) print(self.player.y) item.x = self.player.x - 20 item.y = self.player.y + 30 item.rect.x = item.x item.rect.y = item.y print(item.x) print(item.y) item.add(self.active_ground_items) def draw(self): self.draw_grid() #call the draw_grid method self.status_bar.draw(self.window) self.active_tiles.draw( self.window) #draw all tiles in the active_tiles group self.active_doors.draw(self.window) self.inactive_doors.draw(self.window) #group to the screen self.active_props.draw(self.window) #draw all of the current room's props to the screen self.entities.draw(self.window) #draw all entities self.active_enemies.draw(self.window) self.active_ground_items.draw(self.window) self.active_option_boxes.draw(self.window) self.inventoryWindow.draw(self.window) self.minimap_group.draw(self.window) self.active_message_boxes.draw(self.window) self.active_battle.draw(self.window) self.active_enemy_status_bar.draw(self.window) self.clock_group.draw(self.window) pygame.display.flip() #update the surfaces def callUpdateStatusBar(self, healthChange, bar): if bar == 1: self.statusbar.updateBonuses() if healthChange < 0: self.statusbar.decreaseHealth() elif healthChange > 0: self.statusbar.increaseHealth() elif bar == 2: for enemy_status_bar in self.active_enemy_status_bar: if healthChange < 0: enemy_status_bar.decreaseHealth() elif healthChange > 0: enemy_status_bar.increaseHealth() def checkPropCollisions(self, direction): #collides = False #for prop in self.active_props.sprites(): # if pygame.sprite.collide_rect(self.player, prop) == True: # collides = True #return collides collides = False for prop in self.active_props.sprites( ): #this code works for some reason. I have no idea why. It just does. if pygame.sprite.collide_rect(self.player, prop) == True: if direction == "left": if prop.x < self.player.x: collides = True elif direction == "right": if prop.x > self.player.x: collides = True elif direction == "up": if prop.y < self.player.y: collides = True elif direction == "down": if prop.y > self.player.y: collides = True return collides def checkItemCollisions(self): hasCollided = False itemName = None for item in self.active_ground_items.sprites(): if pygame.sprite.collide_rect(self.player, item) == True: itemName = item.name hasCollided = True if hasCollided == True: messages = ["Pick up", "Leave", None, None] mainMessage = "Pick up " + itemName + "?" if len(self.active_option_boxes.sprites()) < 1: pickUpItem = optionBox(self, 64, 448, self.player, messages, mainMessage) else: self.active_option_boxes.empty() def checkEnemyCollisions(self): for enemy in self.active_enemies.sprites(): if pygame.sprite.collide_rect(self.player, enemy) == True: self.battle = True self.battleEvent = Battle(self, self.player, enemy, 0, 150) self.battleEvent.add(self.active_battle) ANIMATE_KEYSTROKES = pygame.USEREVENT + 1 pygame.time.set_timer(ANIMATE_KEYSTROKES, 125) ANIMATE_ENEMY = pygame.USEREVENT + 3 pygame.time.set_timer(ANIMATE_ENEMY, 125) #ANIMATE_ENEMY_ATTACK = pygame.USEREVENT + 4 #pygame.time.set_timer(ANIMATE_ENEMY_ATTACK, 125) def toggleInventoryVisibility(self): if self.display_inventory == True: self.inventoryWindow.add(self.inventory) else: self.inventoryWindow.remove(self.inventory) def update(self): self.all_sprites.update() #self.active_battle.update #pygame.display.flip() def checkCollisions(self): #for some clarification, the player's roomLocation variable is an array of the format [x, y] that is used to determine what room of the 2D array "ZONE1" # (or zone in general) the player is currently in. So if the player enters a door to the right of the room, we would increase y by one if pygame.sprite.collide_rect( self.player, self.rightDoor ) == True and self.rightDoor.status == True: #check if the player entered a door on the right side of a room self.player.roomLocation[1] = self.player.roomLocation[ 1] + 1 #modify the player's roomLocation variable one space to the right print(self.player.roomLocation) self.switchRooms("right") #call switchRooms function below elif pygame.sprite.collide_rect( self.player, self.leftDoor ) == True and self.leftDoor.status == True: #check if the player entered a door on the left side of a room self.player.roomLocation[1] = self.player.roomLocation[ 1] - 1 #modify the player's roomLocation variable one space to the left print(self.player.roomLocation) self.switchRooms("left") #call switchRooms function below elif pygame.sprite.collide_rect( self.player, self.forwardDoor ) == True and self.forwardDoor.status == True: #check if the player entered a door that goes into a room beyond the room the player is currently in self.player.roomLocation[0] = self.player.roomLocation[ 0] - 1 #modify the player's roomLocation variable one space "up" print(self.player.roomLocation) self.switchRooms("forward") #call switchRooms function below elif pygame.sprite.collide_rect( self.player, self.backwardDoor ) == True and self.backwardDoor.status == True: #check if the player entered a door that goes into a room behind the room the player is currently in self.player.roomLocation[0] = self.player.roomLocation[0] + 1 print(self.player.roomLocation) self.switchRooms("backward") #call switchRooms function below elif pygame.sprite.collide_rect( self.player, self.rightDoor) == True and self.rightDoor.status == False: print("Error message") #for sprite in self.all_tiles.sprites(): # sprite.remove(self.all_tiles) #print(self.all_tiles.sprites()) #for x in range(0, 8): # for y in range(0, 8): # self.active_tiles.add(self.z2r2.tiles[x][y]) #print(self.active_tiles.sprites()) def switchRooms(self, direction): self.activeRoom = self.ZONE1[self.player.roomLocation[0]][ self.player.roomLocation[ 1]] #since the player's roomLocation was modified in checkCollisions(), update the activeRoom #variable to be the room the player has just moved to for sprite in self.active_tiles.sprites(): sprite.remove( self.active_tiles ) #remove all tiles currently in the active_tiles sprite group for prop in self.active_props.sprites( ): #remove all of the previous room's props as well prop.remove(self.active_props) for enemy in self.active_enemies.sprites(): enemy.remove(self.active_enemies) for x in range(0, 8): for y in range(0, 8): self.active_tiles.add( self.activeRoom.tiles[x][y] ) #fill the now empty active_tiles sprite group with tiles from the new room the player has just moved to #these will be drawn almost instantly #print(self.active_tiles.sprites()) if direction == "right": self.player.x = 70 #make sure that if the player enters a door to the right, they come out on the left side of the next room self.player.y = 256 elif direction == "left": self.player.x = 506 #make sure that if the player enters a door to the left, they come out on the right side of the next room self.player.y = 256 elif direction == "forward": self.player.x = 256 #make sure that if the player enters a door ahead of them, they come out at the "back" (relatively speaking) of the next room self.player.y = 506 elif direction == "backward": self.player.x = 256 #make sure that if the player enters a door that's behind them, they come out at the "front" (relatively speaking) of the next room self.player.y = 70 for door in self.active_doors: door.closeDoor() door.status = False door.add( self.inactive_doors ) #remove the previous room's doors from the door sprite group so that they will (theoretically) no longer be drawn for door in self.activeRoom.doors: door.add( self.active_doors ) #add the next room's doors to the active_doors sprite group to be drawn door.status = True door.openDoor() for prop in self.activeRoom.props: prop.add(self.active_props) for enemy in self.activeRoom.enemies: enemy.add(self.active_enemies) self.player.background = self.activeRoom.full_background_image self.minimap.updateLocation()
def __init__(self): # 284 may be where hit boxes lie # get pygame up and running pygame.init() pygame.display.init() # Create main window self.window = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) # Clock for ticking, variable for time between frame draws, self.clock = pygame.time.Clock() self.time_passed = 0 # Set main window Caption pygame.display.set_caption("Ghosts in a Gymnasium") # Create background same size as window self.background = pygame.image.load("data/sprites/background/bbcourt.png").convert_alpha() # Draw background in window self.window.blit(self.background, (0,0)) # display new background pygame.display.flip() # Creates title screen title_on = True title_screen = TitleScreen(self.window) # checks to see if player advanced past title screen while title_on: title_on = title_screen.display_title() # clear events, clear screen pygame.event.pump() self.window.blit(self.background, (0,0)) pygame.display.flip() # Let pygame know we want to listen to just three events pygame.event.set_allowed([QUIT,KEYDOWN,KEYUP,MOUSEBUTTONDOWN]) # list of key presses by player self.player_key_list = [] # Allow for repeats, 2 ms apart pygame.key.set_repeat(1,2) ####### Code for Sandbox stage ####### in_sandbox = True self.sandbox_stage = Sandbox.Sandbox(self.window,self.clock) while in_sandbox: in_sandbox = self.sandbox_stage.play() # list of all chairs player placed self.chair_list = self.sandbox_stage.chair_sprites # Group containing all sprites self.sprites = pygame.sprite.OrderedUpdates() # Group containing just mice self.mice_group = pygame.sprite.RenderUpdates() # Group containing just Ghosts self.ghost_group = pygame.sprite.RenderUpdates() self.mouse1 = Mouse("Mickey", (815,305)) self.sprites.add(self.mouse1) self.mice_group.add(self.mouse1) self.mouse2 = Mouse("Mike", (400,305)) self.sprites.add(self.mouse2) self.mice_group.add(self.mouse2) self.ghostman_a = Ghostman("Melchoir",(75,650)) self.sprites.add(self.ghostman_a) self.ghost_group.add(self.ghostman_a) self.ghostman_b = Ghostman("Casper",(250,305)) self.sprites.add(self.ghostman_b) self.ghost_group.add(self.ghostman_b) for c in self.chair_list: self.sprites.add(c) # blit orginal background and show self.window.blit(self.background, (0,0)) pygame.display.flip() # Sprite setup and construction, boolean for if we did change # a frame of animation self.updated_animation = False self.eating_time = 0 # setup player,ghosts, and mice self.player = Player("Anthony",(1000,625)) self.sprites.add(self.player) self.mice_array = [self.mouse1,self.mouse2] self.score_board = Scoreboard((600,120)) self.sprites.add(self.score_board) self.did_not_feed = DidNotFeed((575,150), self.ghostman_a,self.ghostman_b) self.sprites.add(self.did_not_feed) self.micea_dead = False self.miceb_dead = False for sprite in self.sprites: if sprite.image == False: continue self.window.blit(sprite.image,sprite.rect.topleft)
def main(): Game = True titleScreen = True while Game:# While Loop For Game Title = TitleScreen()# Set Up Title Screens and Windows plus Music WindowWidth = 790 WindowHeight = 450 windowSurface = pygame.display.set_mode((WindowWidth, WindowHeight), 0, 32) mainClock = pygame.time.Clock() pygame.display.set_caption('Jurastic Measures') soundTitle = pygame.mixer.Sound('Music/JurassicPark.wav') soundGame = pygame.mixer.Sound('Music/Doomsday.wav') endScreenSound = pygame.mixer.Sound('Music/BIB.wav') soundTitle.play(-1) while titleScreen:# Shows Title Screen until Player Presses Space then the Game Starts Title.drawTitle(windowSurface) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key == K_SPACE: soundTitle.stop() titleScreen = False # Set Up Variables TrexX = 100 TrexY = 260 TricX = 600 TricY = 260 ground = 260 gravity = 1 Trex = TRexAnimate() Tric = TriceratopsAnimate() WinScreen = EndScreen() # Set Up BackGround Images ForeGround6 = pygame.image.load('LevelBackground/Foreground6.png') ForeGround5 = pygame.image.load('LevelBackground/Foreground5.png') ForeGround4 = pygame.image.load('LevelBackground/Foreground4.png') ForeGround3 = pygame.image.load('LevelBackground/Foreground3.png') ForeGround2 = pygame.image.load('LevelBackground/Foreground2.png') ForeGround1 = pygame.image.load('LevelBackground/Foreground.png') Background = pygame.image.load('LevelBackground/BorderBars.png') bgXSize, bgYSize = ForeGround1.get_size() bgX, bgY = int(-bgXSize // 4.5), 119 bbX, bbY = 0, 0 leftRockEdge = 55 rightRockEdge = 65 rightEdgePlusRockMax = 75 bgXRightMax = -1*(bgXSize - WindowWidth) bgXLeftMax = 0 bgXMove = 0 TRANSP = (0, 0, 0, 0) decreasingHitBoxSizeXSize = 19 # Set up for invisiable sprite for Trex Sprite1 = 'TrexImages/T-Rex.png' SPR1 = pygame.image.load(Sprite1).convert_alpha() spr1XSize, spr1YSize = SPR1.get_size() spr1XSizeBox = spr1XSize spr1XSizeBox -= decreasingHitBoxSizeXSize TrexSurface = pygame.Surface((spr1XSize, spr1YSize), flags=SRCALPHA, depth=32) TrexSurface.fill(TRANSP) # Set up for invisiable sprite for Triceratops Sprite2 = 'TriceratopsImages/Triceratops.png' SPR2 = pygame.image.load(Sprite2).convert_alpha() spr2XSize, spr2YSize = SPR2.get_size() spr2XSizeBox = spr2XSize spr2XSizeBox -= decreasingHitBoxSizeXSize TricSurface = pygame.Surface((spr2XSize, spr2YSize), flags=SRCALPHA, depth=32) TricSurface.fill(TRANSP) # Set Up for animation LEFT = 'left' RIGHT = 'right' # Rate of movement and attack TrexWALKRATE = 5 TrexSPRINTRATE = int(TrexWALKRATE * 1.6) TrexJumpRate = 9 TrexJumpRateReSet = 9 TrexHealth = 100 TrexHealthDamageRate = 8.75 TricWALKRATE = 3 TricSPRINTRATE = int(TricWALKRATE * 1.6) TricJumpRate = 7 TricJumpRateReSet = 7 TricHealth = 100 TricHealthDamageRate = 6.25 bgXMoveRate = 2 # Set Up For Health Bars TrexHealthBarX = 175 TricHealthBarX = 525 # Setting animation variables TrexDirection, TricDirection = RIGHT, LEFT Bite, Horn = 0, 0 ForeGroundRightMax = ForeGroundLeftMax = touching = TrexWall = TricWall = TricRock = TrexRock = False TrexMoveLeft = TrexMoveRight = TrexWalking = BiteAttack = TrexJump = TrexRunning = TrexBlock = TrexDead = False TricMoveLeft = TricMoveRight = TricWalking = HornAttack = TricJump = TricRunning = TricBlock = TricDead = False TimeForFrame = 30 TrexDeadCounter = TricDeadCounter = 0 PlayGame = True TricWin = TrexWin = False soundGame.play(-1) while PlayGame: #Blits Background and Health Bars windowSurface.blit(ForeGround6, (bgX, bgY)) windowSurface.blit(ForeGround5, (bgX, bgY)) windowSurface.blit(ForeGround4, (bgX, bgY)) windowSurface.blit(ForeGround3, (bgX, bgY)) windowSurface.blit(ForeGround2, (bgX, bgY)) windowSurface.blit(ForeGround1, (bgX, bgY)) windowSurface.blit(Background,(bbX, bbY)) HealthBars = HealthBar(TrexHealth, TricHealth, TrexHealthBarX, TricHealthBarX, windowSurface) HealthBars.DrawHB() # Sets up Health Bars for damage if TricHealth <= 0: HealthBars.DrawHB() if TricDeadCounter >= 60: print(1) pygame.time.delay(200) TrexWin = True PlayGame = False if TrexHealth <= 0: HealthBars.DrawHB() if TrexDeadCounter >= 60: pygame.time.delay(200) TricWin = True PlayGame = False for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() # Trex Movement if not TrexJump and not TrexBlock and not TrexDead: if event.key == K_a: TrexMoveLeft = True TrexMoveRight = False TrexDirection = LEFT TrexWalking = True bgXMove = bgXMoveRate touching = False if not TrexJump and not TrexBlock and not TrexDead: if event.key == K_d: TrexMoveLeft = False TrexMoveRight = True TrexDirection = RIGHT TrexWalking = True bgXMove = -bgXMoveRate if not TrexRunning and not TrexBlock and not TrexJump and not TrexDead: TrexAttack = pygame.key.get_pressed() if TrexAttack[K_e]: if Bite == 0: BiteAttack = True Bite = TimeForFrame if not TrexDead: if event.key == K_f: BiteAttack = False TrexRunning = True if TrexMoveLeft: TrexDirection = LEFT if TrexMoveRight: TrexDirection = RIGHT if not TrexBlock and not TrexDead: TRexJump = pygame.key.get_pressed() if TRexJump[K_w]: TrexJump = True BiteAttack = False if not TrexJump and not TrexDead: if event.key == K_s: TrexBlock = True TrexMoveLeft = False TrexMoveRight = False BiteAttack = False TrexRunning = False TrexJump = False # Triceratops Movement if not TricJump and not TricBlock and not TricDead: if event.key == K_LEFT: TricMoveLeft = True TricMoveRight = False TricDirection = LEFT TricWalking = True bgXMove = bgXMoveRate if not TricJump and not TricBlock and not TricDead: if event.key == K_RIGHT: TricMoveLeft = False TricMoveRight = True TricDirection = RIGHT TricWalking = True bgXMove = -bgXMoveRate touching = False if not TricRunning and not TricBlock and not TricJump and not TricDead: TRicAttack = pygame.key.get_pressed() if TRicAttack[K_RCTRL]: if Horn == 0: HornAttack = True Horn = TimeForFrame if not TricDead: if event.key == K_KP0: HornAttack = False TricRunning = True if TricMoveLeft: TricDirection = LEFT if TricMoveRight: TricDirection = RIGHT if not TricBlock and not TricDead: TRicJump = pygame.key.get_pressed() if TRicJump[K_UP]: TricJump = True HornAttack = False if not TricJump and not TricDead: if event.key == K_DOWN: TricBlock = True TricMoveLeft = False TricMoveRight = False HornAttack = False TricRunning = False TricJump = False elif event.type == KEYUP: # Trex Stop Movement if not TrexMoveRight: if event.key == K_a: TrexMoveLeft = False TrexDirection = LEFT TrexWalking = False bgXMove = 0 if not TrexMoveLeft: if event.key == K_d: TrexMoveRight = False TrexDirection = RIGHT TrexWalking = False bgXMove = 0 if event.key == K_f: TrexRunning = False if TrexMoveLeft: TrexDirection = LEFT if TrexMoveRight: TrexDirection = RIGHT if event.key == K_s: TrexBlock = False # Triceratops Stop Movement if not TricMoveRight: if event.key == K_LEFT: TricMoveLeft = False TricDirection = LEFT TricWalking = False bgXMove = 0 if not TricMoveLeft: if event.key == K_RIGHT: TricMoveRight = False TricDirection = RIGHT TricWalking = False bgXMove = 0 if event.key == K_KP0: TricRunning = False if TricMoveLeft: TricDirection = LEFT if TricMoveRight: TricDirection = RIGHT if event.key == K_DOWN: TricBlock = False # Trex Animation Trex.playAnimation() # Trex Animation if TrexHealth <= 0: TrexDead = True TrexMoveLeft = False TrexMoveRight = False TrexWalking = False TrexRunning = False TrexBlock = False BiteAttack = False TrexJump = False if TrexMoveRight or TrexMoveLeft or BiteAttack or TrexJump or TrexBlock or TrexDead: if TrexWalking and(TrexMoveRight or TrexMoveLeft) and not BiteAttack and not TrexRunning and not TrexJump: if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, True, False, False, False, False, False, False) elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, True, False, False, False, False, False, False) TrexRate = TrexWALKRATE if BiteAttack and not TrexWalking: if bgX == bgXRightMax or bgX == bgXLeftMax: TrexRate = 0 elif touching: TrexRate = 0 bgXMove = 0 else: TrexRate = bgXMove TrexX += TrexRate if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, False, True, False, False, False, False, False) if Bite <= TimeForFrame: Bite -= 1 if Bite == (TimeForFrame - TimeForFrame): BiteAttack = False elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, False, True, False, False, False, False, False) if Bite <= TimeForFrame: Bite -= 1 if Bite == (TimeForFrame - TimeForFrame): BiteAttack = False if TrexWalking and BiteAttack and(TrexMoveRight or TrexMoveLeft) and not TrexRunning: if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, True, True, False, False, False, False, False) if Bite <= TimeForFrame: Bite -= 1 if Bite == (TimeForFrame - TimeForFrame): BiteAttack = False elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, True, True, False, False, False, False, False) if Bite <= TimeForFrame: Bite -= 1 if Bite == (TimeForFrame - TimeForFrame): BiteAttack = False TrexRate = TrexWALKRATE if TrexRunning and(TrexMoveRight or TrexMoveLeft) and not TrexJump: Bite = 0 if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, False, False, True, False, False, False, False) elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, False, False, True, False, False, False, False) TrexRate = TrexSPRINTRATE if TrexJump: Bite = 0 if bgX == bgXRightMax or bgX == bgXLeftMax: TrexRate = 0 elif touching: TrexRate = 0 bgXMove = 0 else: TrexRate = bgXMove TrexX += TrexRate if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, False, False, False, True, False, False, False) elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, False, False, False, True, False, False, False) if TrexMoveLeft or TrexMoveRight: if not touching: if TrexRunning: TrexRate = int(TrexSPRINTRATE//1.75) else: TrexRate = int(TrexWALKRATE//1.5) if TrexBlock: Bite = 0 if bgX == bgXRightMax or bgX == bgXLeftMax: TrexRate = 0 elif touching: TrexRate = 0 bgXMove = 0 else: TrexRate = bgXMove TrexX += TrexRate if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, False, False, False, False, True, False, False) elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, False, False, False, False, True, False, False) if TrexDead: if bgX == bgXRightMax or bgX == bgXLeftMax: TrexRate = 0 elif touching: TrexRate = 0 bgXMove = 0 else: TrexRate = bgXMove TrexX += TrexRate if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, False, False, False, False, False, False, True) elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, False, False, False, False, False, False, True) TrexDeadCounter += 1 if TrexMoveLeft: TrexX -= TrexRate if TrexMoveRight: TrexX += TrexRate if TrexJump: if TrexY <= ground: TrexY = TrexY - TrexJumpRate TrexJumpRate = TrexJumpRate - gravity if TrexY == ground: TrexJump = False TrexJumpRate = TrexJumpRateReSet else: # Trex Standing if bgX == bgXRightMax or bgX == bgXLeftMax: TrexRate = 0 elif touching: TrexRate = 0 bgXMove = 0 else: TrexRate = bgXMove TrexX += TrexRate if TrexDirection == LEFT: Trex.Animation(windowSurface, TrexX, TrexY, LEFT, False, False, False, False, False, True, False) elif TrexDirection == RIGHT: Trex.Animation(windowSurface, TrexX, TrexY, RIGHT, False, False, False, False, False, True, False) # Triceratops Animation Tric.playAnimation() if TricHealth <= 0: TricDead = True TricMoveLeft = False TricMoveRight = False TricWalking = False TricRunning = False TricBlock = False HornAttack = False TricJump = False if TricMoveRight or TricMoveLeft or HornAttack or TricJump or TricBlock or TricDead: if TricWalking and(TricMoveRight or TricMoveLeft) and not HornAttack and not TricRunning and not TricJump: if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, True, False, False, False, False, False, False) elif TricDirection == RIGHT: Tric.Animation(windowSurface, TricX, TricY, RIGHT, True, False, False, False, False, False, False) TricRate = TricWALKRATE if HornAttack and not TricWalking: if bgX == bgXRightMax or bgX == bgXLeftMax: TricRate = 0 elif touching: TricRate = 0 bgXMove = 0 else: TricRate = bgXMove TricX += TricRate if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, False, True, False, False, False, False, False) if Horn <= TimeForFrame: Horn -= 1 if Horn == (TimeForFrame - TimeForFrame): HornAttack = False elif TricDirection == RIGHT: TricX += TricRate Tric.Animation(windowSurface, TricX, TricY, RIGHT, False, True, False, False, False, False, False) if Horn <= TimeForFrame: Horn -= 1 if Horn == (TimeForFrame - TimeForFrame): HornAttack = False if HornAttack and TricWalking and (TricMoveRight or TricMoveLeft) and not TricRunning: if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, True, True, False, False, False, False, False) if Horn <= TimeForFrame: Horn -= 1 if Horn == (TimeForFrame - TimeForFrame): HornAttack = False elif TricDirection == RIGHT: Tric.Animation(windowSurface, TricX, TricY, RIGHT, True, True, False, False, False, False, False) if Horn <= TimeForFrame: Horn -= 1 if Horn == (TimeForFrame - TimeForFrame): HornAttack = False if TricRunning and(TricMoveRight or TricMoveLeft) and not TricJump: Horn = 0 if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, False, False, True, False, False, False, False) elif TricDirection == RIGHT: Tric.Animation(windowSurface, TricX, TricY, RIGHT, False, False, True, False, False, False, False) TricRate = TricSPRINTRATE if TricJump: Horn = 0 if bgX == bgXRightMax or bgX == bgXLeftMax: TricRate = 0 elif touching: TricRate = 0 bgXMove = 0 else: TricRate = bgXMove TricX += TricRate if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, False, False, False, True, False, False, False) elif TricDirection == RIGHT: Tric.Animation(windowSurface, TricX, TricY, RIGHT, False, False, False, True, False, False, False) if TricMoveLeft or TricMoveRight: if not touching: if TricRunning: TricRate = int(TricSPRINTRATE//1.75) else: TricRate = int(TricWALKRATE//1.5) if TricBlock: Horn = 0 if bgX == bgXRightMax or bgX == bgXLeftMax: TricRate = 0 elif touching: TricRate = 0 bgXMove = 0 else: TricRate = bgXMove TricX += TricRate if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, False, False, False, False, True, False, False) elif TricDirection == RIGHT: Tric.Animation(windowSurface, TricX, TricY, RIGHT, False, False, False, False, True, False, False) if TricDead: if bgX == bgXRightMax or bgX == bgXLeftMax: TricRate = 0 elif touching: TricRate = 0 bgXMove = 0 else: TricRate = bgXMove TricX += TricRate if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, False, False, False, False, False, False, True) elif TricDirection == RIGHT: Tric.Animation(windowSurface, TricX, TricY, RIGHT, False, False, False, False, False, False, True) TricDeadCounter += 1 else: if bgX == bgXRightMax or bgX == bgXLeftMax: TricRate = 0 elif touching: TricRate = 0 bgXMove = 0 else: TricRate = bgXMove TricX += TricRate if TricDirection == LEFT: Tric.Animation(windowSurface, TricX, TricY, LEFT, False, False, False, False, False, True, False) elif TricDirection == RIGHT: Tric.Animation(windowSurface, TricX, TricY, RIGHT, False, False, False, False, False, True, False) if TricMoveLeft: TricX -= TricRate if TricMoveRight: TricX += TricRate if TricJump: if TricY <= ground: TricY = TricY - TricJumpRate TricJumpRate = TricJumpRate - gravity if TricY == ground: TricJump = False TricJumpRate = TricJumpRateReSet # Trex Sprite Stuff spr1XPos, spr1YPos = TrexX, TrexY TrexSurface.blit(windowSurface, (spr1XPos, spr1YPos)) # Tric Sprite Stuff spr2XPos, spr2YPos = TricX, TricY TrexSurface.blit(windowSurface, (spr2XPos, spr2YPos)) # BackGroundLimits if TricMoveRight and TrexMoveLeft: if TrexWall and TricWall: bgXMove = 0 if TrexJump ^ TricJump: bgXMove = 0 bgX = bgX + bgXMove if bgX <= bgXRightMax: bgX = bgXRightMax elif bgX <= bgXRightMax + rightEdgePlusRockMax: ForeGroundRightMax = True elif bgX >= bgXRightMax + rightEdgePlusRockMax: ForeGroundRightMax = False if bgX > bgXLeftMax: bgX = bgXLeftMax elif bgX > -leftRockEdge: ForeGroundLeftMax = True elif bgX < -leftRockEdge: ForeGroundLeftMax = False # Trex Limits if not ForeGroundLeftMax: if spr1XPos <= 0: TrexX = 0 TrexWall = True else: TrexWall = False elif TrexDirection == LEFT and TrexMoveLeft and TrexWall: if spr1XPos <= leftRockEdge: TrexX = leftRockEdge + bgX TrexRock = True elif TrexDirection == RIGHT: TrexRock = False elif TrexDirection == LEFT and TrexMoveLeft and TrexRock: if spr1XPos <= leftRockEdge + bgX: TrexX = leftRockEdge + bgX elif TrexDirection == LEFT and TrexMoveLeft and not TrexRock: if spr1XPos <= leftRockEdge + bgX: TrexX = leftRockEdge + bgX else: TrexWall = False # Tric Limits if not ForeGroundRightMax: if spr2XPos >= WindowWidth - spr2XSizeBox: TricX = WindowWidth - spr2XSizeBox TricWall = True else: TricWall = False elif TricDirection == RIGHT and TricMoveRight and TricWall: if spr2XPos >= WindowWidth - spr2XSize - rightRockEdge: TricX = WindowWidth - spr2XSize - rightRockEdge + (-bgXRightMax + bgX) TricRock = True elif TricDirection == LEFT: TricRock = False elif TricDirection == RIGHT and TricMoveRight and TricRock: if spr2XPos >= WindowWidth - spr2XSize - rightRockEdge: TricX = WindowWidth - spr2XSize - rightRockEdge + (-bgXRightMax + bgX) elif TricDirection == RIGHT and TricMoveRight and not TricRock: if spr2XPos >= WindowWidth - spr2XSize - rightRockEdge + (-bgXRightMax + bgX): TricX = WindowWidth - spr2XSize - rightRockEdge + (-bgXRightMax + bgX) else: TricWall = False # Hit Boxes Set Up if spr1XPos + spr1XSizeBox >= spr2XPos: touching = True if spr2XPos >= spr1XPos + spr1XSizeBox and TricMoveRight: touching = False if touching: TrexX = TrexX - TrexRate TricX = TricX + TricRate bgX = bgX - bgXMove if touching and BiteAttack and TrexDirection == RIGHT: if Bite == int(TimeForFrame//1.75): if TricBlock: TricHealth -= int(TricHealthDamageRate//4) elif TricJump: if TricY <= 235: TricHealth -= 0 else: TricHealth -= TricHealthDamageRate else: TricHealth -= TricHealthDamageRate if touching and HornAttack and TricDirection == LEFT: if Horn == int(TimeForFrame//1.75): if TrexBlock: TrexHealth -= int(TrexHealthDamageRate//3) elif TrexJump: if TrexY <= 225: TrexHealth -= 0 else: TrexHealth -= TrexHealthDamageRate else: TrexHealth -= TrexHealthDamageRate pygame.display.update() mainClock.tick(TimeForFrame) # Set up for Win Screens if TrexWin or TricWin: soundGame.stop() endScreenSound.play(-1) while TrexWin: WinScreen.TrexWin(windowSurface, True) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key == K_SPACE: titleScreen = True endScreenSound.stop() TrexWin = False while TricWin: WinScreen.TricWin(windowSurface, True) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key == K_SPACE: titleScreen = True endScreenSound.stop() TricWin = False
def main(): spyral.director.push(TitleScreen.Title())
import math import pygame import sys import Stage1 import TitleScreen import gameOver pygame.init() clock = pygame.time.Clock() clock.tick() window = pygame.display.set_mode([640, 480]) pygame.display.set_caption("Team JhaneMarVhiel") font = pygame.font.Font("freesansbold.ttf", 32) #font=pygame.font.Font("HARNGTON.TTF",60) TitleScreen = TitleScreen.cTitleScreen() Stage1 = Stage1.cStage1() gameOver = gameOver.cGameOver() #CurrentScreen=gameOver CurrentScreen = TitleScreen while True: newScreen = CurrentScreen.update(clock) if (newScreen == "Stage1"): CurrentScreen = Stage1 CurrentScreen.draw(window) events = pygame.event.get() for event in events: if ((event.type == pygame.QUIT) or (newScreen == "QUIT") or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)): pygame.quit() sys.exit() clock.tick(30)
import TitleScreen as titlescreen if __name__ == "__main__": t = titlescreen.TitleScreen()