def loop(self): """ And here is our main game loop! In case you are new to game programming this is what is called every frame. This is where we will handle the display and stuff. """ # clock.tick is used for keeping track of time and limiting the frame # rate. self.clock.tick() self.window.dispatch_events() # And this is where that mysterious "time" comes in. This way rabbyt # knows how much time has passed and can do the awesome animations. rabbyt.set_time(self.time) # If you are new to this sort of thing rabbyt.clear clears the screen # (erases what was drawn last loop). We pass white as the color that we # want to clear it with. rabbyt.clear((1,1,1,1)) # And now we draw our blocks and smile face. for b in self.blocks.values(): b.draw() if self.game.gameover == True: if self.game.won == False: self.dead_face.render() else: self.won_face.render() else: self.smile_face.render() # This draws the buffer onto the screen. Without this we would be # staring at a blank screen. self.window.flip()
def run(queue): running = True game = Game(1240, 780) while running: clock.tick(40) for event in pygame.event.get(): running &= game.handle_event(event) try: item = queue.get(False) update = simplejson.loads(item) for (key, value) in update.iteritems(): print Piece._items[update['id']], key, value current = getattr(Piece._items[update['id']], key) setattr(Piece._items[update['id']], key, rabbyt.lerp(current, value, dt=200)) except Empty: pass #game.render() rabbyt.set_time(pygame.time.get_ticks()) rabbyt.clear() rabbyt.render_unsorted(game.boards) rabbyt.render_unsorted(game.pieces) rabbyt.scheduler.pump() pygame.display.flip()
def continue_level(self): """continues""" if self.game.get_ticks() - self.game.fps > 1000: print "FPS: ", self.game.clock.get_fps() self.game.fps = self.game.get_ticks() self.handle_user_events() if self.saving: self.handle_save() #Timing rabbyt.set_time(self.get_ticks()/1000.0) rabbyt.scheduler.pump() rabbyt.clear() #Update self.update_UI() self.update_game_objects() self.handle_collisions_between(self.ship, self.enemies) self.handle_collisions_between(self.ship, self.enemy_bullets) self.handle_collisions_between(self.bullets, self.enemies) self.handle_collisions_between(self.past_selves, self.enemies) self.handle_collisions_between(self.past_selves, self.enemy_bullets) self.handle_item_pickups_between(self.ship, self.items) #Render self.render_game_objects() self.game.clock.tick(40) pygame.display.flip()
def on_draw(self): rabbyt.set_time(self.time) self.clear() glPushMatrix() glTranslatef(self.width // 2, self.height // 2, 0) scale = min(self.width, self.height) / self.scale glScalef(scale, scale, scale) rabbyt.render_unsorted(self.sprites) glPopMatrix()
def run(self, game, state_stack): """Makes the Cutscene run""" game.set_state_time() scene = rabbyt.Sprite("1cutscene.png") scene.scale = 0.95 scene.y = -60 scene.alpha = rabbyt.lerp(0.0, 0.8, startt=1, endt=8) scene.x = rabbyt.lerp(-20, 60, startt=1, endt=6) scene2 = rabbyt.Sprite("1cutscene2.png") scene2.alpha = rabbyt.lerp(0.8, 0.0, startt=6, endt=13) scene2.scale = 0.95 scene2.xy = (60, -60) words = FontSprite(game.font, "Scientist: I'll be back soon.") words.xy = (-195, -250) #set music pygame.mixer.music.stop() pygame.mixer.music.load('scene1.wav') pygame.mixer.music.play() game.done = False while not game.done: rabbyt.clear() rabbyt.set_time(game.get_ticks()/1000.0) ticks = game.get_ticks()/1000.0 if ticks < 6: scene.render() if ticks >= 6: scene2.render() if ticks >= 14: game.done = True state_stack.append(states.name.Name()) words.render() for event in pygame.event.get(): if event.type == QUIT: game.done = True fdata = open("RabbitHighScores", 'w') for i in range(5): fdata.write(game.high_score_names[i] + " " \ + str(game.high_scores[i]) + "\n") if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_RETURN: game.done = True state_stack.append(states.name.Name()) elif event.type == pygame.JOYBUTTONDOWN and game.joystick.get_button(game.controls.settings["Escape"]): game.done = True state_stack.append(states.name.Name()) pygame.display.flip()
def loop(self): dt = clock.tick() self.time += dt self.window.dispatch_events() rabbyt.set_time(self.time) rabbyt.clear() self.gui.render() self.bg_overlay.render() self.selection_marker.render() self.window.flip() return True
def draw(self, width, height): glColor3f(1., 1., 1.) self.stars_texture.blit_tiled(0, 0, 0, width, height) glPushMatrix() glTranslatef(float(width // 2), float(height // 2), 0.) scale = float(min(width, height)) / self.camera.scale glScalef(scale, scale, scale) rabbyt.set_time(self.time) self.sprites.sort(key=attrgetter('z')) rabbyt.render_unsorted(self.sprites) if self.debug: glColor3f(0., 1., 0.) glDisable(GL_TEXTURE_2D) debug_draw(self.world) glPopMatrix()
def run(): running = True game = Game(1240, 780) while running: clock.tick(40) for event in pygame.event.get(): running &= game.handle_event(event) #game.render() rabbyt.set_time(pygame.time.get_ticks()) rabbyt.clear() rabbyt.render_unsorted(game.boards) rabbyt.render_unsorted(game.pieces) rabbyt.scheduler.pump() pygame.display.flip()
def TitleScreen(self, state_stack): """ Title Screen""" self.frame = 0 self.done = False """rabbit_screen = rabbyt.Sprite ('8jumping_rabbit.png', (-321,184.5,321,-184.5)) rabbit_tex_shapes = settings.get_tex_shapes(rabbit_screen.tex_shape, 8)""" while not self.done: self.clock.tick(40) if pygame.time.get_ticks() - self.fps > 1000: print "FPS: ", self.clock.get_fps() self.fps = pygame.time.get_ticks() for event in pygame.event.get(): if event.type == QUIT: self.done = True fdata = open("RabbitHighScores", 'w') for i in range(5): fdata.write(self.highScoreNames[i] + \ " " + str(self.highScores[i]) + "\n") elif event.type == KEYDOWN: if event.key == K_ESCAPE: self.done = True fdata = open("RabbitHighScores", 'w') for i in range(5): fdata.write(self.highScoreNames[i] + \ " " + str(self.highScores[i]) + "\n") ## Some sample reaction to events. elif event.key == K_SPACE: ## This screen will end and go to another screen. self.done = True state_stack.append("Menu Screen") rabbyt.set_time(pygame.time.get_ticks()/1000.0) rabbyt.scheduler.pump() rabbyt.clear() #self.animate(rabbit_screen, rabbit_tex_shapes) #rabbit_screen.render() pygame.display.flip()
def run(self, game, state_stack): """runs the game""" rabbyt.set_time(self.get_ticks()/1000.0) self.done = False self.game = game #rabbyt.scheduler.add((game.get_ticks() + \ #self.background.row_update_time)/1000, self.update_tiles_loop) self.background.initialize() while not self.done: self.continue_level() all_enemies_defeated = (self.wave_builder.all_waves_called() and \ len(self.enemies) == 0) if all_enemies_defeated or self.boss_dead: self.victory_end() if self.ship.health <= 0: self.failure_end()
def update(self): set_time(self.model.time) self.window.clear() if self.model.player.sleep: self.sleep() else: if self.blackout.alpha >= 1: self.sunRise() elif self.blackout.alpha <= 0: self.sunSet() self.model.room.background.render() for weapon in self.model.player.weapons: for projectile in weapon.projectiles: projectile.render() for sprite in self.model.spritesOnScreen: if sprite.viewable: sprite.render() for actor in self.model.actorsOnScreen: for projectile in actor.projectiles: projectile.render() self.model.inventoryButton.render() for label in self.model.inventoryButton.labels: label.draw() self.model.Health_Bar.render() self.model.notificationSystem.render() self.model.DayCounter.render() self.model.WeaponGui.render() if self.model.contextMenu: self.model.contextMenu.render() if self.model.inventoryMenu: if self.model.inventoryMenu.viewable: self.model.inventoryMenu.render() self.blackout.render()
for event in pygame.event.get(): if event.type == pygame.QUIT: import sys; sys.exit(0) elif event.type == pygame.KEYDOWN: if event.key in (pygame.K_ESCAPE, pygame.K_q): import sys sys.exit(0) elif event.key == pygame.K_SPACE: car1.boost() pressed = pygame.key.get_pressed() car1.accelerating = pressed[pygame.K_UP] car1.turning_right = pressed[pygame.K_RIGHT] car1.turning_left = pressed[pygame.K_LEFT] rabbyt.set_time(pygame.time.get_ticks()/1000.0) for c in cars: c.update() rabbyt.scheduler.pump() rabbyt.clear((.56, .3, 0, 1)) for c in cars: c.render() rabbyt.render_unsorted(Car.dust_particles) rabbyt.render_unsorted(Car.boost_particles)
def on_draw(self): """ Draw method to be called on every frame. """ rabbyt.set_time(self.time) # Handle player movement due to keyboard/mouse input. if self.keyboard[KEYBOARD_CONTROLS["UP"]]: self.player.mup(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["DOWN"]]: self.player.mdown(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["RIGHT"]]: self.player.mright(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["LEFT"]]: self.player.mleft(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["FORWARD"]] or \ self.mouse & MOUSE_CONTROLS["MOUSEMOVE"] == MOUSE_CONTROLS["MOUSEMOVE"]: self.player.forward(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["BACKWARD"]]: self.player.backward(PLAYER_SPEED_BACKWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["STRAFE_RIGHT"]]: self.player.strafe_right(PLAYER_SPEED_STRAFE * self.dt) if self.keyboard[KEYBOARD_CONTROLS["STRAFE_LEFT"]]: self.player.strafe_left(PLAYER_SPEED_STRAFE * self.dt) if self.keyboard[KEYBOARD_CONTROLS["TURN_RIGHT"]]: self.player.turn_right(PLAYER_TURN_SPEED * self.dt) if self.keyboard[KEYBOARD_CONTROLS["TURN_LEFT"]]: self.player.turn_left(PLAYER_TURN_SPEED * self.dt) # Turn the player to face the mouse if we need to. if (self.mouse & MOUSE_CONTROLS["FACE"] or PLAYER_ALWAYS_FACE_MOUSE) and \ self.mousex is not None and self.mousey is not None: # Calculate the x, y coordinates of the click based on the given # screen coordinates. self.player.face( self.mousex + self.player.x - self.window.get_size()[0] / 2, self.mousey + self.player.y - self.window.get_size()[1] / 2) # Update the sprite used based on the player's facing direction and movement. self.player.updatedir() # Update the player's x, y coordinates. self.player.updatepos() # Keep the player inside the map. self.player.clamp(0, MAP_HEIGHT * MAP_TILE_SIZE, MAP_WIDTH * MAP_TILE_SIZE, 0) # Reset the screen to a blank state. rabbyt.clear((0, 0, 0, 1)) # Center the viewable area around the player. self.view(self.player.x - self.window.get_size()[0] / 2, self.player.y - self.window.get_size()[1] / 2) # Do the drawing. # Determine which tile the player is on. tilex = int(self.player.x / MAP_TILE_SIZE) tiley = int(self.player.y / MAP_TILE_SIZE) # Determine how many tiles need to be drawn on the screen on each side # of the player (the center). tilecountx = int(self.window.get_size()[0] / (MAP_TILE_SIZE * 2)) + 2 tilecounty = int(self.window.get_size()[1] / (MAP_TILE_SIZE * 2)) + 2 startx = max(0, tilex - tilecountx) endx = min(MAP_WIDTH, tilex + tilecountx) starty = max(0, tiley - tilecounty) endy = min(MAP_HEIGHT, tiley + tilecounty) # Draw the background terrain. terrain = self.terrain for x in range(startx, endx): for y in range(starty, endy): terrain[x][y].left = x * MAP_TILE_SIZE terrain[x][y].bottom = y * MAP_TILE_SIZE terrain[x][y].render() # Draw the player. self.player.render() # Set the render mode to HUD mode. self.hud() # Draw the FPS. This is a Pyglet sprite and not a Rabbyt sprite, so we # use .draw() instead of .render(). self.fps_display.draw()
def runGame(): """Initialize new game.""" pygame.display.set_caption('Escape from Wikipedia - Loading') fpsclock = pygame.time.Clock() camx = 0 camy = 0 section = 0 player = Player(PLAYER_START) loading = Word("LOADING", (camx - 205, camy - 55), attr=BOLD, size=2, color=PURPLE) rabbyt.clear(WHITE) loading.render() # Loading screen pygame.display.flip() # Short, simple page #page = Page("http://en.wikipedia.org/wiki/Solariellidae") # Longest page in Wikipedia #page = Page("http://en.wikipedia.org/wiki/Character_mask") # Random page page = Page("http://en.wikipedia.org/wiki/Special:Random") pygame.display.set_caption('Escape from... ' + page.title) # xkcd #page = Page("http://en.wikipedia.org/wiki/Xkcd") #print len(page.words) # Main loop while True: for event in pygame.event.get(): if event.type == QUIT: terminate() elif event.type == KEYDOWN: if event.key in QUIT_KEYS: terminate() elif event.key in RESTART_KEYS: glutils.scroll(-camx, -camy) # Reset glMatrix return elif event.key in LEFT_KEYS: player.goingleft = True player.goingright = False player.image.tex_shape = (1, 1, 0, 0) elif event.key in RIGHT_KEYS: player.goingright = True player.goingleft = False player.image.tex_shape = (0, 1, 1, 0) elif event.key in UP_KEYS: player.jump() elif event.key in DOWN_KEYS and player.plat is not None: # Enter hyperlink if not player.plat.hyperlink == "": pygame.display.set_caption( 'Escape from Wikipedia - Loading') loading = Word("LOADING", (camx - 205, camy - 55), attr=BOLD, size=2, color=PURPLE) rabbyt.clear(WHITE) loading.render() # Display load screen pygame.display.flip() page = Page(player.plat.hyperlink) pygame.display.set_caption(page.title) pygame.display.set_caption('Escape from... ' + page.title) #print len(page.words) player.reset(page) elif event.type == KEYUP: if event.key in LEFT_KEYS: player.goingleft = False elif event.key in RIGHT_KEYS: player.goingright = False elif event.key in UP_KEYS and player.velocity[1] > 0: player.velocity[1] *= 0.5 # Control jump height # Update position player.update() # Check for player-platform collisions collisions = rabbyt.collisions.aabb_collide_single(player, page.visible_words) # Player forced out of platforms by most direct route, more or less; for plat in collisions: if (player.right / 3 + 2 * player.left / 3 < plat.left and player.velocity[0] > 0): player.right = plat.left - 1 elif (player.left / 3 + 2 * player.right / 3 > plat.right and player.velocity[0] < 0): player.left = plat.right + 1 # More sensitive about the top, to compensate for high fall veloc elif player.top > plat.top and player.velocity[1] < 0: player.bottom = plat.top + 1 player.plat = plat player.velocity[1] = 0 # Stop falling player.jumps = 0 # Reset jumps if plat.hyperlink != "": player.hl_landed(TIMEOUT) elif (2 * player.top / 3 + player.bottom / 3 < plat.bottom and player.velocity[1] > 0): player.top = plat.bottom - 1 player.velocity[1] = 0 # Jump stops prev_section = section prev_y = camy # adjust camera if beyond the "camera slack" if camx - player.x > CAMERASLACK: glutils.scroll(player.x + CAMERASLACK - camx, 0) camx = player.x + CAMERASLACK elif player.x - camx > CAMERASLACK: glutils.scroll(player.x - CAMERASLACK - camx, 0) camx = player.x - CAMERASLACK if camy - player.y > CAMERASLACK: glutils.scroll(0, player.y + CAMERASLACK - camy) camy = player.y + CAMERASLACK elif player.y - camy > CAMERASLACK: glutils.scroll(0, player.y - CAMERASLACK - camy) camy = player.y - CAMERASLACK # Keep track of viewing section section += int(prev_y / WINHEIGHT) - int(camy / WINHEIGHT) if not section == prev_section: if section > len(page.sections) + 1: glutils.scroll(-camx, -camy) # Reset glMatrix return page.visible_words = page.words[ page.sections[min(len(page.sections) - 1, max(0, section - 1))]: page.sections[max(0, min(len(page.sections) - 1, section + 1))]] # Slow to FPS fpsclock.tick(FPS) # Need to tell Rabbyt what time it is every frame rabbyt.set_time(pygame.time.get_ticks() / TIME_FACTOR) # Draw screen rabbyt.clear(WHITE) rabbyt.render_unsorted(page.visible_words) rabbyt.render_unsorted(page.lines) player.render() pygame.display.flip()
def run(self, game, state_stack): #set music pygame.mixer.music.stop() pygame.mixer.music.load('scene2.wav') """Starts the cutscene""" clock = pygame.time.Clock() self.game = game game.set_state_time() scene = rabbyt.Sprite("1space.png") scene.scale = 2.0 scene.x = 400 rabbit = rabbyt.Sprite("1rabbit.png") self.state_stack = state_stack #scene.alpha = rabbyt.lerp(0.0, 0.8, startt=1, endt=30) #scene.x = rabbyt.lerp(-20, 60, startt=1, endt=6) rabbit.alpha = rabbyt.lerp(0.0, 1.0, startt=3, endt=5) rabbit.scale = 0.5 #rabbit.xy = (60,-60) words = FontSprite(game.font, "Dimensional Rabbit: ZzZzz ...") words.alpha = rabbyt.lerp(0.0, 1.0, startt=3, endt=5) words.y = -250 words.x = -180 self.music_started = False game.done = False while not game.done: clock.tick(40) rabbyt.clear() scene.render() rabbyt.set_time(game.get_ticks()/1000.0) ticks = game.get_ticks()/1000.0 if ticks >= 3: if not self.music_started: pygame.mixer.music.play() self.music_started = True words.render() rabbit.render() if ticks >= 5 and ticks < 7: words.x = -200 words.text = "Dimensional Rabbit: ZZzzZ ZZzz ..." elif ticks >= 7 and ticks < 9: words.text = "Dimensional Rabbit: Oh!" words.x = -160 elif ticks >= 9 and ticks < 11: words.text = "Dimensional Rabbit: I didn't think ..." words.x = -240 elif ticks >= 11 and ticks < 13: words.text = "Dimensional Rabbit: ..." + \ " anybody would make it this far" words.x = -330 elif ticks >= 13 and ticks < 17: words.text = "Dimensional Rabbit: Pardon me, you look lost." words.x = -270 elif ticks >= 17 and ticks < 21: words.text = "Scientist: I know exactly where I'm going." words.x = -250 elif ticks >= 21 and ticks < 25: words.text = "Dimensional Rabbit: Then you won't be " + \ "needing help from me." words.x = -385 elif ticks >= 25 and ticks < 29: words.text = "Dimensional Rabbit: Tata!" words.x = -160 rabbit.alpha = rabbyt.lerp(1.0, 0.0, startt=25, endt=29) elif ticks >= 29: words.text = "Scientist: ..." words.x = -100 scene.alpha = rabbyt.lerp(1.0, 0.0, startt=29, endt=33) if ticks >= 33: game.done = True self.set_next_state() for event in pygame.event.get(): if event.type == QUIT: game.done = True fdata = open("RabbitHighScores", 'w') for i in range(5): fdata.write(game.high_score_names[i] + \ " " + str(game.high_scores[i]) + "\n") if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_RETURN: game.done = True self.set_next_state() elif event.type == pygame.JOYBUTTONDOWN and game.joystick.get_button(game.controls.settings["Escape"]): game.done = True self.set_next_state() pygame.display.flip()
def on_draw(self): """ Draw method to be called on every frame. """ rabbyt.set_time(self.time) # Handle player movement due to keyboard/mouse input. if self.keyboard[KEYBOARD_CONTROLS["UP"]]: self.player.mup(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["DOWN"]]: self.player.mdown(PLAYER_SPEED_FORWARD* self.dt) if self.keyboard[KEYBOARD_CONTROLS["RIGHT"]]: self.player.mright(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["LEFT"]]: self.player.mleft(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["FORWARD"]] or \ self.mouse & MOUSE_CONTROLS["MOUSEMOVE"] == MOUSE_CONTROLS["MOUSEMOVE"]: self.player.forward(PLAYER_SPEED_FORWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["BACKWARD"]]: self.player.backward(PLAYER_SPEED_BACKWARD * self.dt) if self.keyboard[KEYBOARD_CONTROLS["STRAFE_RIGHT"]]: self.player.strafe_right(PLAYER_SPEED_STRAFE * self.dt) if self.keyboard[KEYBOARD_CONTROLS["STRAFE_LEFT"]]: self.player.strafe_left(PLAYER_SPEED_STRAFE * self.dt) if self.keyboard[KEYBOARD_CONTROLS["TURN_RIGHT"]]: self.player.turn_right(PLAYER_TURN_SPEED * self.dt) if self.keyboard[KEYBOARD_CONTROLS["TURN_LEFT"]]: self.player.turn_left(PLAYER_TURN_SPEED * self.dt) # Turn the player to face the mouse if we need to. if (self.mouse & MOUSE_CONTROLS["FACE"] or PLAYER_ALWAYS_FACE_MOUSE) and \ self.mousex is not None and self.mousey is not None: # Calculate the x, y coordinates of the click based on the given # screen coordinates. self.player.face(self.mousex + self.player.x - self.window.get_size()[0]/2, self.mousey + self.player.y - self.window.get_size()[1]/2) # Update the sprite used based on the player's facing direction and movement. self.player.updatedir() # Update the player's x, y coordinates. self.player.updatepos() # Keep the player inside the map. self.player.clamp(0, MAP_HEIGHT*MAP_TILE_SIZE, MAP_WIDTH*MAP_TILE_SIZE, 0) # Reset the screen to a blank state. rabbyt.clear((0, 0, 0, 1)) # Center the viewable area around the player. self.view(self.player.x - self.window.get_size()[0]/2, self.player.y - self.window.get_size()[1]/2) # Do the drawing. # Determine which tile the player is on. tilex = int(self.player.x / MAP_TILE_SIZE) tiley = int(self.player.y / MAP_TILE_SIZE) # Determine how many tiles need to be drawn on the screen on each side # of the player (the center). tilecountx = int(self.window.get_size()[0] / (MAP_TILE_SIZE*2)) + 2 tilecounty = int(self.window.get_size()[1] / (MAP_TILE_SIZE*2)) + 2 startx = max(0, tilex - tilecountx) endx = min(MAP_WIDTH, tilex + tilecountx) starty = max(0, tiley - tilecounty) endy = min(MAP_HEIGHT, tiley + tilecounty) # Draw the background terrain. terrain = self.terrain for x in range(startx, endx): for y in range(starty, endy): terrain[x][y].left = x * MAP_TILE_SIZE terrain[x][y].bottom = y * MAP_TILE_SIZE terrain[x][y].render() # Draw the player. self.player.render() # Set the render mode to HUD mode. self.hud(); # Draw the FPS. This is a Pyglet sprite and not a Rabbyt sprite, so we # use .draw() instead of .render(). self.fps_display.draw()
def step(self, dt): self.time += dt rabbyt.set_time(self.time)
def run(self, game, state_stack): """Starts the cutscene""" clock = pygame.time.Clock() self.game = game game.set_state_time() scene = rabbyt.Sprite("1space.png") scene.scale = 2.0 scene.x = 400 rabbit = rabbyt.Sprite("1rabbit.png") self.state_stack = state_stack # scene.alpha = rabbyt.lerp(0.0, 0.8, startt=1, endt=30) # scene.x = rabbyt.lerp(-20, 60, startt=1, endt=6) rabbit.alpha = rabbyt.lerp(0.0, 1.0, startt=3, endt=5) rabbit.scale = 0.5 # rabbit.xy = (60,-60) words = FontSprite(game.font, "Dimensional Rabbit: Oh ...") words.alpha = rabbyt.lerp(0.0, 1.0, startt=3, endt=5) words.y = -250 words.x = -180 # set music pygame.mixer.music.stop() pygame.mixer.music.load("scene4.wav") self.music_started = False game.done = False while not game.done: clock.tick(40) rabbyt.clear() scene.render() rabbyt.set_time(game.get_ticks() / 1000.0) ticks = game.get_ticks() / 1000.0 if ticks >= 3: if not self.music_started: pygame.mixer.music.play() self.music_started = True words.render() rabbit.render() if ticks >= 5 and ticks < 7: words.x = -200 words.text = "Dimensional Rabbit: It's you again ..." elif ticks >= 7 and ticks < 11: words.text = "Scientist: THAT WAS THE WRONG TIME" words.x = -240 elif ticks >= 11 and ticks < 15: words.text = "Scientist: WHY'D you lead me to WW2?!" words.x = -250 elif ticks >= 15 and ticks < 19: words.text = "Dimensional Rabbit: So I was off" + " by like 500 years." words.x = -315 elif ticks >= 19 and ticks < 23: words.text = "Dimensional Rabbit: Do you know how many " + "portals there are" words.x = -380 elif ticks >= 23 and ticks < 27: words.text = "Dimensional Rabbit: in this place?" words.x = -200 elif ticks >= 27 and ticks < 31: words.text = "Scientist: Well can you tell me where now?" words.x = -250 elif ticks >= 31 and ticks < 35: words.text = "Dimensional Rabbit: Yeah it's this one " + "for sure." words.x = -305 elif ticks >= 35 and ticks < 39: words.text = "Dimensional Rabbit: Sorry about the mix up. Good luck!" words.x = -350 rabbit.alpha = rabbyt.lerp(1.0, 0.0, startt=25, endt=29) elif ticks >= 40: words.text = "Scientist: I hope you're right this time!" words.x = -200 scene.alpha = rabbyt.lerp(1.0, 0.0, startt=29, endt=33) if ticks >= 37: game.done = True self.set_next_state() for event in pygame.event.get(): if event.type == QUIT: game.done = True fdata = open("RabbitHighScores", "w") for i in range(5): fdata.write(game.high_score_names[i] + " " + str(game.high_scores[i]) + "\n") if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_RETURN: game.done = True self.set_next_state() elif event.type == pygame.JOYBUTTONDOWN and game.joystick.get_button(game.controls.settings["Escape"]): game.done = True self.set_next_state() pygame.display.flip()
for y in range(-200, 400, 15): shape, sprite = create_cube(space, xy=(x + random.random() * 10, y)) shapes.append(shape) sprites.append(sprite) clock = pygame.time.Clock() running = True while running: clock.tick(40) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False rabbyt.set_time(pygame.time.get_ticks()) rabbyt.scheduler.pump() dt = 1 / 60 / 2 # This is the only call in the loop with ctypes overhead :) cp.cpSpaceStep(space, dt) cp.cpSpaceStep(space, dt) rabbyt.clear() rabbyt.render_unsorted(sprites) pygame.display.flip()
brender.init () bmusic.init () # START LOGIC trender = brender.async_render () tevents = bsprites.async_catch_events () tlogic = glogic.async_logic () fps_clock = pygame.time.Clock () try : # MAIN LOOP time = 0 time_step = 1.0 / float ( BCONF.fps ) while working ( tlogic ) : time += time_step rabbyt.set_time ( time ) btasks.run () if not bevents.handle () : break fps_clock.tick ( BCONF.fps if BCONF.keepfps else 0 ) finally : stop ( tlogic ) stop ( trender ) stop ( tevents ) bevents.done () brender.done () bmusic.done () bprofile.stats ()
for y in range(-200, 400, 15): shape, sprite = create_cube(space, xy = (x+random.random()*10,y)) shapes.append(shape) sprites.append(sprite) clock = pygame.time.Clock() running = True while running: clock.tick(40) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False rabbyt.set_time(pygame.time.get_ticks()) rabbyt.scheduler.pump() dt = 1/60/2 # This is the only call in the loop with ctypes overhead :) cp.cpSpaceStep(space, dt) cp.cpSpaceStep(space, dt) rabbyt.clear() rabbyt.render_unsorted(sprites) pygame.display.flip()
def run(self, game, state_stack): """Starts the cutscene""" clock = pygame.time.Clock() self.game = game game.set_state_time() scene = rabbyt.Sprite("1space.png") scene.scale = 2.0 scene.x = 400 rabbit = rabbyt.Sprite("1rabbit.png") self.state_stack = state_stack #scene.alpha = rabbyt.lerp(0.0, 0.8, startt=1, endt=30) #scene.x = rabbyt.lerp(-20, 60, startt=1, endt=6) rabbit.alpha = rabbyt.lerp(0.0, 1.0, startt=3, endt=5) rabbit.scale = 0.5 #rabbit.xy = (60,-60) words = FontSprite(game.font, "Dimensional Rabbit: ZzZzz ...") words.alpha = rabbyt.lerp(0.0, 1.0, startt=3, endt=5) words.y = -250 words.x = -180 #set music pygame.mixer.music.stop() pygame.mixer.music.load('scene3.wav') self.music_started = False game.done = False while not game.done: clock.tick(40) rabbyt.clear() scene.render() rabbyt.set_time(game.get_ticks()/1000.0) ticks = game.get_ticks()/1000.0 if ticks >= 3: if not self.music_started: self.music_started = True pygame.mixer.music.play() words.render() rabbit.render() if ticks >= 5 and ticks < 7: words.x = -200 words.text = "Dimensional Rabbit: Hello Again!" elif ticks >= 7 and ticks < 9: words.text = "Dimensional Rabbit: How are you doing?" words.x = -220 elif ticks >= 9 and ticks < 11: words.text = "Dimensional Rabbit: Do you need help" words.x = -220 elif ticks >= 11 and ticks < 13: words.text = "Dimensional Rabbit: ..." + \ " Navigating this place?" words.x = -260 elif ticks >= 13 and ticks < 17: words.text = "Scientist: Well... do you know where" words.x = -220 elif ticks >= 17 and ticks < 21: words.text = "Scientist: The year 2444 is?." words.x = -175 elif ticks >= 21 and ticks < 25: words.text = "Dimensional Rabbit: Oh it's right around " + \ "here I think..." words.x = -350 elif ticks >= 25 and ticks < 29: words.text = "Scientist: Really? That doesn't look..." words.x = -210 rabbit.alpha = rabbyt.lerp(1.0, 0.0, startt=25, endt=29) elif ticks >= 29: words.text = "Scientist: WHOA!!" words.x = -110 scene.alpha = rabbyt.lerp(1.0, 0.0, startt=29, endt=33) if ticks >= 33: game.done = True self.set_next_state() for event in pygame.event.get(): if event.type == QUIT: game.done = True fdata = open("RabbitHighScores", 'w') for i in range(5): fdata.write(game.high_score_names[i] + \ " " + str(game.high_scores[i]) + "\n") if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_RETURN: game.done = True self.set_next_state() elif event.type == pygame.JOYBUTTONDOWN and game.joystick.get_button(game.controls.settings["Escape"]): game.done = True self.set_next_state() pygame.display.flip()
def run(self, game, state_stack): """Makes the Cutscene run""" pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096) pygame.mixer.music.stop() pygame.mixer.music.load('scene5.wav') pygame.mixer.music.play(-1, 0.0) game.set_state_time() scene = rabbyt.Sprite("1cutscene.png") scene.scale = 0.95 scene.y = -60 scene.alpha = rabbyt.lerp(0.0, 0.8, startt=1, endt=10) scene.x = rabbyt.lerp(-20, 60, startt=1, endt=10) scene2 = rabbyt.Sprite("1cutscene2.png") scene2.alpha = rabbyt.lerp(0.8, 0.0, startt=10, endt=22) scene2.scale = 0.95 scene2.xy = (60, -60) words = FontSprite(game.font, "Girlfriend: You're Back!") words.xy = (-150, -250) game.done = False while not game.done: rabbyt.clear() rabbyt.set_time(game.get_ticks()/1000.0) ticks = game.get_ticks()/1000.0 if ticks < 10: scene.render() else: scene2.render() if ticks >= 6 and ticks < 10: words = FontSprite(game.font, "Scientist: I'm back!") words.xy = (-150, -250) elif ticks >= 10 and ticks < 14: words = FontSprite(game.font, "Scientist: And I brought flowers!") words.xy = (-200, -250) elif ticks >= 14 and ticks <18: words = FontSprite(game.font, "Girlfriend: And you brought flowers!") words.xy = (-220, -250) elif ticks >= 18 and ticks <22: words = FontSprite(game.font, "Scientist: Do you want to go back for more?") words.xy = (-270, -250) if ticks >= 22: game.done = True state_stack.append(states.highscore.High()) words.render() for event in pygame.event.get(): if event.type == QUIT: game.done = True fdata = open("RabbitHighScores", 'w') for i in range(5): fdata.write(game.high_score_names[i] + " " \ + str(game.high_scores[i]) + "\n") if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_RETURN: game.done = True state_stack.append(states.highscore.High()) elif event.type == pygame.JOYBUTTONDOWN and game.joystick.get_button(game.controls.settings["Escape"]): game.done = True state_stack.append(states.highscore.High()) pygame.display.flip()
def run(self, game, state_stack): backg = rabbyt.Sprite('1Menu_Screen1.png') arrows = rabbyt.Sprite('1arrows.png') tilt = rabbyt.Sprite('1zx.png') time = rabbyt.Sprite('1c.png') space = rabbyt.Sprite('1sp.png') dash = rabbyt.Sprite('1d.png') arrows.xy = (-295, 80) tilt.xy = (-295, -36) time.xy = (-295, -109) space.xy = (-295, -183) dash.xy = (-295, -257) game.done = False while not game.done: rabbyt.set_time(game.get_ticks()/1000.0) rabbyt.scheduler.pump() rabbyt.clear() for event in pygame.event.get(): if event.type == pygame.QUIT: game.done = True fdata = open("RabbitHighScores", 'w') for i in range(5): fdata.write(game.high_score_names[i] + " " + \ str(game.high_scores[i]) + "\n") elif event.type == pygame.KEYDOWN: self.joystick = 0 if event.key == pygame.K_ESCAPE: game.done = True state_stack.append(states.menu.Menu()) elif event.type == pygame.JOYBUTTONDOWN: self.joystick = 1 if game.joystick.get_button(game.controls.settings["Escape"]): game.done = True state_stack.append(states.menu.Menu()) backg.render() arrows.render() tilt.render() time.render() space.render() dash.render() rabbyt.render_unsorted(self.bullets) if self.joystick: user_actions = self.joystick_to_actions(game) self.ship.handle_actions(user_actions, self) else: pressed = pygame.key.get_pressed() user_actions = self.keyboard_to_actions(pressed) self.ship.handle_actions(user_actions, self) for bullet in self.bullets: if bullet.isOffMap(): self.bullets.remove(bullet) self.ship.update() self.ship.render() game.clock.tick(40) pygame.display.flip()