def update(self, tiles): self.frame += 1 imgframe = 0 moving = False if button.is_held(LEFT): self.facing = -1 moving = True self.move(-2, 0, tiles) if button.is_held(RIGHT): self.facing = 1 moving = True self.move(2, 0, tiles) if button.is_pressed(A_BUTTON): if not self.jumping: play_sound("sfx/jump.ogg") self.jump_speed = -5 self.jumping = True if self.jumping: if button.is_pressed(A_BUTTON) and self.jump_speed >= -2 and self.jump_speed <= 5: if button.is_held(A_BUTTON): self.flying = True if not button.is_held(A_BUTTON): self.flying = False else: self.flying = False if self.facing < 0: self.images = self.left_images else: self.images = self.right_images if moving: imgframe = self.frame/3%2 if self.jumping: imgframe = 1 if self.flying: imgframe = 2+(self.frame/2%2) self.image = self.images[imgframe] if not self.flying: if button.is_held(A_BUTTON) and not self.flying: self.jump_speed += 0.4 else: self.jump_speed += 0.8 else: if self.fuel <= 0: self.fuel = 0 self.flying = False else: play_sound("sfx/burn.ogg", 0.2) self.jump_speed = -1 if self.jump_speed > 5: self.jump_speed = 5 self.move(0, self.jump_speed, tiles) if self.jump_speed > 3: self.jumping = True
def controls(self): if button.is_pressed(A_BUTTON): self.jump() if button.is_pressed(B_BUTTON): self.shoot() self.control_walk() self.aim_shot() self.choose_images()
def run_menu(): timer = 0 play_music("data/title.ogg") game = Game() set_global_sound_volume(0.75) while True: clock.tick() button.handle_input() # If we pressed start, begin the game if button.is_pressed(START): play_music("data/algar-orka.xm", -1) # Creates text box whitefont = font.Font(GAMEBOY_FONT, GB_SCREEN_COLOR) box = dialog.DialogBox((152, 46), (50, 50, 50), GB_SCREEN_COLOR, whitefont) box.set_dialog([ "Spin to \ win.", "- Garen 2008" ]) # Updates box when Z is pressed box.set_scrolldelay(2) while not box.over(): clock.tick() button.handle_input() if button.is_pressed(A_BUTTON): box.progress() screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(game.background, (0, 0)) box.draw(screen, (4, 4)) display.update() game.won = True #game.level = 1 game.lives = 3 game.score = 0 #Play each level for lvl in LEVELS: game.startLevel(lvl) #game.level += 1 game.loop() #if not game.player.alive(): # break screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(load_image("data/bg.png"), (0, 0)) ren = game.font.render("Press Start") timer += 1 timer = timer % 30 if timer < 15: screen.blit(ren, (80-ren.get_width()/2, 104-ren.get_height()/2)) display.update()
def update(self, tiles): self.frame += 1 imgframe = 0 if self.punch_time > 0: self.punch_time -= 1 moving = False if button.is_held(LEFT) and self.punch_time <= 0: self.facing = -1 moving = True self.move(-2, 0, tiles) if button.is_held(RIGHT) and self.punch_time <= 0: self.facing = 1 moving = True self.move(2, 0, tiles) if button.is_pressed(A_BUTTON) and self.punch_time <= 0: if not self.jumping: play_sound("data/jump.ogg") self.jump_speed = -5 self.jumping = True if button.is_pressed(B_BUTTON): self.punch() if self.facing < 0: self.images = self.left_images else: self.images = self.right_images if moving: imgframe = self.frame / 3 % 2 if self.jumping: imgframe = 1 if self.punch_time > 0: imgframe = 3 if self.punch_time == 3: Punch(self) play_sound("data/swoosh.ogg") if self.punch_time > 3: imgframe = 2 self.image = self.images[imgframe] if button.is_held(A_BUTTON): self.jump_speed += 0.4 else: self.jump_speed += 0.8 if self.jump_speed > 5: self.jump_speed = 5 if self.punch_time <= 0: self.move(0, self.jump_speed, tiles) if self.jump_speed > 3: self.jumping = True
def update(self, tiles): self.frame += 1 imgframe = 0 if self.punch_time > 0: self.punch_time -= 1 moving = False if button.is_held(LEFT) and self.punch_time <= 0: self.facing = -1 moving = True self.move(-2, 0, tiles) if button.is_held(RIGHT) and self.punch_time <= 0: self.facing = 1 moving = True self.move(2, 0, tiles) if button.is_pressed(A_BUTTON) and self.punch_time <= 0: if not self.jumping: play_sound("data/jump.ogg") self.jump_speed = -5 self.jumping = True if button.is_pressed(B_BUTTON): self.punch() if self.facing < 0: self.images = self.left_images else: self.images = self.right_images if moving: imgframe = self.frame/3%2 if self.jumping: imgframe = 1 if self.punch_time > 0: imgframe = 3 if self.punch_time == 3: Punch(self) play_sound("data/swoosh.ogg") if self.punch_time > 3: imgframe = 2 self.image = self.images[imgframe] if button.is_held(A_BUTTON): self.jump_speed += 0.4 else: self.jump_speed += 0.8 if self.jump_speed > 5: self.jump_speed = 5 if self.punch_time <= 0: self.move(0, self.jump_speed, tiles) if self.jump_speed > 3: self.jumping = True
def pause(self): pygame.mixer.music.pause() button.handle_input() play_sound("data/pause.ogg") while not button.is_pressed(START): button.handle_input() ren = self.font.render("PAUSED") screen = display.get_surface() screen.blit(ren, (80 - ren.get_width() / 2, 74 - ren.get_height() / 2)) display.update() play_sound("data/pause.ogg") pygame.mixer.music.unpause()
def update(self, tiles): self.frame += 1 imgframe = 0 moving = False if button.is_held(LEFT): self.facing = -1 moving = True self.move(-2, 0, tiles) if button.is_held(RIGHT): self.facing = 1 moving = True self.move(2, 0, tiles) if button.is_held(B_BUTTON): pass if button.is_pressed(A_BUTTON): if not self.jumping: play_sound("data/jump.ogg") self.jump_speed = -5 self.jumping = True if self.facing < 0: self.images = self.left_images else: self.images = self.right_images if moving: imgframe = self.frame/3 % 2 if self.jumping: imgframe = 1 self.image = self.images[imgframe] if button.is_held(A_BUTTON): self.jump_speed += 0.4 else: self.jump_speed += 0.8 if self.jump_speed > 5: self.jump_speed = 5 self.move(0, self.jump_speed, tiles) if self.jump_speed > 3: self.jumping = True
def update(self, tiles): self.frame += 1 imgframe = 0 moving = False if button.is_held(LEFT): self.facing = -9 moving = True self.move(-0, 0, tiles) if button.is_held(RIGHT): self.facing = 1 moving = True self.move(5, 0, tiles) if button.is_pressed(A_BUTTON): if not self.jumping: play_sound("data/jump.ogg") self.jump_speed = -6 self.jumping = True if self.facing < 0: self.images = self.left_images else: self.images = self.right_images if moving: imgframe = self.frame / 3 % 2 if self.jumping: imgframe = 1 self.image = self.images[imgframe] if button.is_held(A_BUTTON): self.jump_speed += 0.4 else: self.jump_speed += 0.8 if self.jump_speed > 5: self.jump_speed = 5 self.move(0, self.jump_speed, tiles) if self.jump_speed > 3: self.jumping = True
def handle_input(self): button.handle_input() if button.is_pressed(START): self.pause() if button.is_pressed(A_BUTTON) and button.is_held(SELECT): self.playing = False
def run_menu(): play_music("sfx/title_screen.ogg") timer = 0 game = Game() set_global_sound_volume(0.75) while True: clock.tick() button.handle_input() if button.is_pressed(START): play_music("sfx/ChibiNinja.ogg", -1) whitefont = font.Font(GAMEBOY_FONT, GB_SCREEN_COLOR) box = dialog.DialogBox((152, 46), (50, 50, 50), GB_SCREEN_COLOR, whitefont) box.set_dialog([ "GET THEM DARN ALIENS!" ]) box.set_scrolldelay(2) while not box.over(): clock.tick() button.handle_input() if button.is_pressed(A_BUTTON): box.progress() screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(game.background, (0, 0)) box.draw(screen, (4, 4)) display.update() game.won = True game.level = 1 game.lives = 5 game.score = 0 # Play each level for lvl in LEVELS: game.start_level(lvl) game.level += 1 game.loop() if not game.player.alive(): break # If we got to the end of the game, display credits if game.won: pos = 144 credits = [ "Credits", "", "", "Programming by", "Tommy Brunn", "pymike", "saluk", "", "", "Art by", "Tommy Brunn", "", "", "Sound Mixing", "Tommy Brunn", "", "", "Music", "Eric Skiff", "thechad1138", "", "", "Special Thanks To", "SFXR by DrPetter", "pymike", "saluk", "", "", "", "", "", "", "", "", "", "", "", "", "", " Thanks for playing!"] while pos > -144-(len(credits)*7): button.handle_input() if button.is_pressed(START): break screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(game.background, (0, 0)) clock.tick() pos -= 0.5 y = 0 for c in credits: ren = game.font.render(c) screen.blit(ren, (80-ren.get_width()/2, pos+y)) y += 10 display.update() play_music("sfx/title_screen.ogg") #Draw main menu screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) #screen.blit(load_image("gfx/menu.png"), (0, 0)) ren = game.font.render("Press Start") timer += 1 timer = timer % 30 if timer < 15: screen.blit(ren, (80-ren.get_width()/2, 104-ren.get_height()/2)) display.update()
def run_menu(): timer = 0 play_music("data/title.ogg") game = Game() set_global_sound_volume(0.75) while 1: clock.tick() button.handle_input() # If we pressed start, begin the game if button.is_pressed(START): play_music("data/algar-orka.xm", -1) whitefont = font.Font(GAMEBOY_FONT, GB_SCREEN_COLOR) box = dialog.DialogBox((152, 46), (50, 50, 50), GB_SCREEN_COLOR, whitefont) box.set_dialog([ "bubbman was on his way to oliland,", "when his car broke down in the dododu mountains!", "can bubbman cross the monster-infested mountain range?" ]) box.set_scrolldelay(2) while not box.over(): clock.tick() button.handle_input() if button.is_pressed(A_BUTTON): box.progress() screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(game.background, (0, 0)) box.draw(screen, (4, 4)) display.update() game.won = True game.level = 1 game.lives = 5 game.score = 0 # Play each level for lvl in LEVELS: game.start_level(lvl) game.level += 1 game.loop() if not game.player.alive(): break # If we got to the end of the game, display credits if game.won: pos = 144 credits = [ "Credits", "", "", "Programmers", "pymike", "saluk", "", "", "Sound Mixing", "pymike", "", "", "Music", "ModArchive.org", "DrPetter", "", "", "Special Thanks To", "SFXR by DrPetter", "The Gimp 2", "Geany", "", "", "", "", "", "", "", "", "", "", "", "", "", " Thanks for playing!!" ] while pos > -144 - (len(credits) * 7): button.handle_input() if button.is_pressed(START): break screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(game.background, (0, 0)) clock.tick() pos -= 0.5 y = 0 for c in credits: ren = game.font.render(c) screen.blit(ren, (80 - ren.get_width() / 2, pos + y)) y += 10 display.update() play_music("data/title.ogg") # Draw the main menu screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(load_image("data/bubbman-menu.png"), (0, 0)) ren = game.font.render("Press Start") timer += 1 timer = timer % 30 if timer < 15: screen.blit(ren, (80 - ren.get_width() / 2, 104 - ren.get_height() / 2)) display.update()
def update(self): clock.tick() for object in self.objects: if (object.rect.right >= self.camera.left and \ object.rect.left <= self.camera.right) or \ object.always_update == True: object.update(self.engine.tiles) object.always_update = True self.camera.centerx = self.player.rect.centerx if self.camera.left < 0: self.camera.left = 0 if self.camera.right > len(self.engine.tiles[0])*16: self.camera.right = len(self.engine.tiles[0])*16 # Make sure we don't move off the far left of the level if self.player.rect.left < 0: self.player.rect.left = 0 if self.player.rect.bottom > 144: self.player.rect.bottom = 144 # Get rich quick! if button.is_pressed(B_BUTTON): self.player.falling = True (x, y) = (self.player.rect.left, self.player.rect.top) (newX, newY) = self.engine.rotateLeftTile((x, y), 144) self.player.rect.left = newX self.player.rect.top = newY for obj in self.objects: if not obj == self.player: obj.kill() self.matrix = self.engine.rotateLeft() self.engine.parseMatrix(self.matrix) if button.is_pressed(A_BUTTON): self.player.falling = True (x, y) = (self.player.rect.left, self.player.rect.top) (newX, newY) = self.engine.rotateLeftTile((x, y), 144) self.player.rect.left = newX self.player.rect.top = newY for obj in self.objects: if not obj == self.player: obj.kill() self.matrix = self.engine.rotateRight() self.engine.parseMatrix(self.matrix) for c in self.coins: if self.player.rect.colliderect(c.rect): c.kill() c.looted = True self.score += 25 play_sound("data/coin.ogg") for s in self.solids: if self.player.rect.colliderect(s.rect): cX = s.rect.centerx cY = s.rect.centery pX = self.player.rect.centerx pY = self.player.rect.centery if (pX-cX) == 0: self.player.rect.bottom = s.rect.top else: slope = (pY-cY)/(pX-cX) if slope == 0: if pX>cX: self.player.rect.left = s.rect.right else: self.player.rect.right = s.rect.left elif slope > 0 and slope <= 16.0/11: #slu4ai I self.player.rect.left = s.rect.right elif slope < 0 and slope >= -16.0/11: #slu4ai III self.player.rect.right = s.rect.left else: #slu4ai II self.player.rect.bottom = s.rect.top for s in self.dropBs: if self.player.rect.colliderect(s.rect): cX = s.rect.centerx cY = s.rect.centery pX = self.player.rect.centerx pY = self.player.rect.centery if (pX-cX) == 0: self.player.rect.bottom = s.rect.top else: slope = (pY-cY)/(pX-cX) if slope == 0: if pX>cX: self.player.rect.left = s.rect.right else: self.player.rect.right = s.rect.left elif slope > 0 and slope <= 16.0/11: #slu4ai I self.player.rect.left = s.rect.right elif slope < 0 and slope >= -16.0/11: #slu4ai III self.player.rect.right = s.rect.left else: #slu4ai II self.player.rect.bottom = s.rect.top for db in self.dropBs: print "tile", self.matrix[db.x][db.y], db.x, db.y if(db.y + 1 < len(self.matrix)): if self.matrix[db.x][db.y + 1] == '.' or self.matrix[db.x][db.y + 1] == 'C': temp = self.matrix[db.x][db.y + 1] self.matrix[db.x][db.y+1] = 'D' self.matrix[db.x][db.y] = temp db.y = db.y + 1 for g in self.gates: if self.player.rect.colliderect(g.rect): self.levelCompleted = True '''
"This is a dialog box! Press the a button to go to the next page.", "Press it again and this box will close."]) menu = dialog.Menu(nesfont, ["Close", "Pause", "Exit"]) #dialogbox.close() while 1: # Tick, tock, at 30 frames per second clock.tick() # Handle button and key input button.handle_input() # If displaying dialog, do events for dialog! if not dialogbox.over(): if button.is_pressed(A_BUTTON): dialogbox.progress() # Otherwise, play the "game" else: # Move if LEFT or RIGHT is being pressed. if button.is_held(LEFT): player.pos[0] -= 3 if button.is_held(RIGHT): player.pos[0] += 3 # Move the menu cursor if you press up or down if button.is_pressed(UP): menu.move_cursor(-1) if button.is_pressed(DOWN):
"Press it again and this box will close." ]) menu = dialog.Menu(nesfont, ["Close", "Pause", "Exit"]) # dialogbox.close() while 1: # Tick, tock, at 30 frames per second clock.tick() # Handle button and key input button.handle_input() # If displaying dialog, do events for dialog! if not dialogbox.over(): if button.is_pressed(A_BUTTON): dialogbox.progress() # Otherwise, play the "game" else: # Move if LEFT or RIGHT is being pressed. if button.is_held(LEFT): player.pos[0] -= 3 if button.is_held(RIGHT): player.pos[0] += 3 # Move the menu cursor if you press up or down if button.is_pressed(UP): menu.move_cursor(-1) if button.is_pressed(DOWN):
def run_menu(): timer = 0 play_music("data/title.ogg") game = Game() set_global_sound_volume(0.75) while 1: clock.tick() button.handle_input() # If we pressed start, begin the game if button.is_pressed(START): play_music("data/algar-orka.xm", -1) whitefont = font.Font(GAMEBOY_FONT, GB_SCREEN_COLOR) box = dialog.DialogBox((152, 46), (50, 50, 50), GB_SCREEN_COLOR, whitefont) box.set_dialog([ "johnny the adventurer discovered a huge tower,", "and, being the manly man he is, must explore it!", "can you help him climb the perilous tower??" ]) box.set_scrolldelay(2) while not box.over(): clock.tick() button.handle_input() if button.is_pressed(A_BUTTON): box.progress() screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(game.background, (0, 0)) box.draw(screen, (4, 4)) display.update() game.won = True game.level = 1 game.lives = 5 game.score = 0 # Play each level for lvl in LEVELS: game.start_level(lvl) game.level += 1 game.loop() if not game.player.alive(): break # If we got to the end of the game, display credits if game.won: pos = 144 credits = [ "Credits", "", "", "Programmers", "pymike", "saluk", "", "", "Sound Mixing", "pymike", "", "", "Music", "ModArchive.org", "DrPetter", "", "", "Special Thanks To", "SFXR by DrPetter", "The Gimp 2", "Geany", "", "", "", "", "", "", "", "", "", "", "", "", "", " Thanks for playing!!"] while pos > -144-(len(credits)*7): button.handle_input() if button.is_pressed(START): break screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(game.background, (0, 0)) clock.tick() pos -= 0.5 y = 0 for c in credits: ren = game.font.render(c) screen.blit(ren, (80-ren.get_width()/2, pos+y)) y += 10 display.update() play_music("data/title.ogg") # Draw the main menu screen = display.get_surface() screen.fill(GB_SCREEN_COLOR) screen.blit(load_image("data/bubbman-menu.png"), (0, 0)) ren = game.font.render("Press Start") timer += 1 timer = timer % 30 if timer < 15: screen.blit(ren, (80-ren.get_width()/2, 104-ren.get_height()/2)) display.update()