def update(event, screen): for grid_cols in grids: for grid in grid_cols: grid.update(event) grid.render(screen) for city in corners: city.update(event) city.render(screen) for player in players: player.update(event) player.render(screen)
def test_render_standard(self): """ It is possible to use standard renderers as asset var """ text = player.render( self.request, 'player:tests/dir1/view.pt') self.assertEqual(text, '<h1>Test</h1>')
def add_message(request, msg, type='info'): """ Add status message Predefined message types * info * success * warning * error """ if ':' not in type: type = 'message:%s'%type request.session.flash(render(request, type, msg), 'status')
def test_render(self): text = player.render(self.request, "test:view").strip() self.assertEqual(text, "<h1>Test</h1>")
def render(self): """ render form """ return render(self.request, self.tmpl_view, self, actions = self.actions, widgets = self.widgets)
def render_widget(self): """ render field widget """ tmpl = self.tmpl_widget or 'form:widget' return render(self.request, tmpl, self, view=self, value=self.form_value)
def render(self): """ render field """ return render(self.request, self.tmpl_input, self, view=self, value=self.form_value)
moveX, moveY = 0, 0 gameLoop = True while gameLoop: for event in pygame.event.get(): if (event.type == pygame.KEYDOWN): if (event.key == pygame.K_d): moveX = 5 elif (event.key == pygame.K_a): moveX = -5 elif (event.key == pygame.K_w): player.jump() if (event.type == pygame.KEYUP): if (event.key == pygame.K_d): moveX = 0 elif (event.key == pygame.K_a): moveX = 0 window.fill((0, 0, 150)) for block in blockList: block.render(window) player.x += moveX player.update(gravity, blockList) player.render(window) clock.tick(60) pygame.display.flip()
def test_render_standard(self): """ It is possible to use standard renderers as asset var """ text = player.render(self.request, 'player:tests/dir1/view.jinja2') self.assertEqual(text, '<h1>Test</h1>')
def test_render(self): text = player.render(self.request, 'test:view').strip() self.assertEqual(text, '<h1>Test</h1>')
def __game_cycle(self): p = self.player l = self.level p.travel(l.track_length(), self.window) base_segment = l.find_segment(p.position) player_segment = l.find_segment(p.position + s.PLAYER_Z) p.accelerate() p.steer(player_segment) p.climb(base_segment) p.detect_collisions(player_segment) p.handle_crash() # Sprinkle some random bonuses into the next lap if we are lucky. if p.new_lap: if random.randint(1, s.CHANCE_OF_BONUSES) == 1: l.insert_bonuses() # Move the other players. for c in l.competitors: old_seg = l.find_segment(c.position) c.travel(l.track_length()) new_seg = l.find_segment(c.position) c.play_engine(p.position) if old_seg.index != new_seg.index: if c in old_seg.competitors: old_seg.competitors.remove(c) new_seg.competitors.append(c) coverage = [base_segment, base_segment, base_segment] tunnel_exit = base_segment pre_renders = [] curve = 0 curve_delta = -(base_segment.curve * p.segment_percent()) # Position backgrounds according to current curve. for bg in l.backgrounds: if base_segment.curve != 0: bg.step(base_segment.curve, p.speed_percent()) bg.render(self.window) # Loop through segments we should draw for this frame. for i in range(s.DRAW_DISTANCE): segment = l.offset_segment(base_segment.index + i) projected_position = p.position camera_x = p.x * s.ROAD_WIDTH # Past end of track and looped back. if segment.index < base_segment.index: projected_position -= l.track_length() segment.project(camera_x, curve, curve_delta, projected_position, p.y) curve += curve_delta curve_delta += segment.curve # Remember biggest LEFT, TOP, RIGHT coordinates so we can clip sprites later. segment.clip = [ coverage[0].bottom["screen"]["x"] - coverage[0].bottom["screen"]["w"], coverage[1].top["screen"]["y"], coverage[2].bottom["screen"]["x"] + coverage[2].bottom["screen"]["w"]] if len(segment.pre_polygons) > 0: pre_renders.append(segment) if segment.tunnel_end: tunnel_exit = segment if segment.should_ignore(coverage[1]): continue segment.render_grass(self.window) segment.render_road(self.window) if (segment.top["screen"]["y"] > coverage[1].top["screen"]["y"]): coverage[1] = segment # Remember where we should draw the left and right tunnel walls. if segment.in_tunnel: s_top = segment.top["screen"] tl_top = coverage[0].top["screen"] tr_top = coverage[2].top["screen"] if (s_top["x"] - s_top["w"]) > (tl_top["x"] - tl_top["w"]): coverage[0] = segment if (s_top["x"] + s_top["w"]) < (tr_top["x"] + tr_top["w"]): coverage[2] = segment # Draw tunnel roof and walls. if base_segment.in_tunnel: self.player.in_tunnel = True tunnel_exit.render_tunnel_roof(self.window, coverage[1].top["screen"]["y"]) coverage[0].render_left_tunnel(self.window) coverage[2].render_right_tunnel(self.window) else: self.player.in_tunnel = False # Let backgrounds know how much height they need to cover on the next paint. for bg in l.backgrounds: bg.visible_height = s.DIMENSIONS[1] - coverage[1].top["screen"]["y"] # Draw sprites in from back to front (painters algorithm). for segment in reversed(pre_renders): segment.render_polygons(self.window, coverage) for i in reversed(range(1, s.DRAW_DISTANCE)): segment = l.offset_segment(base_segment.index + i) segment.render_world_objects(self.window) p.render(self.window, base_segment) p.render_hud(self.window) if p.blood_alpha > 0: p.render_blood(self.window) for e in pygame.event.get(): u.try_quit(e) if e.type == pygame.KEYDOWN and e.key == pygame.K_RETURN: pygame.mixer.music.pause() self.paused = True # Steering, acceleration. keys = pygame.key.get_pressed() p.set_acceleration(keys) p.set_direction(keys)
bullets.append(player.shoot(scroll,display,sounds['shoot'])) if move > 0: player.translate([player.speed*dt*1.5,0]) elif move < 0: player.translate([-player.speed*dt,0]) player.update(dt,sounds['jump'],boulders) for blt in bullets: blt.update(dt,boulders,tiles,sounds['hit']) for bder in boulders: bder.set_tiles(tiles) bder.update(dt) #---------------------------------------rendering--------------------------------------- bg.render(display,scroll) #render_map(game_map_bg,display,bg_tileset,scroll,[],16) core.render(display,scroll) tiles = render_map(game_map,display,tileset,scroll,['1','2']) for bder in boulders: bder.render(display,scroll) for bullet in bullets: bullet.render(display,scroll) player.set_tiles(tiles) player.render(display,scroll) text = font1.render("Score :",True,(255,255,255)) text2 = font2.render(str(score),True,(255,255,255)) screen.blit(pygame.transform.scale(display,WINDOW_SIZE),(0,0)) screen.blit(text,(screen.get_width()/2 - 40,0)) screen.blit(text2,(screen.get_width()/2 + 50,0)) pygame.display.update() clock.tick(60)
def __game_cycle(self): p = self.player l = self.level p.travel(l.track_length(), self.window) base_segment = l.find_segment(p.position) player_segment = l.find_segment(p.position + s.PLAYER_Z) p.accelerate() p.steer(player_segment) p.climb(base_segment) p.detect_collisions(player_segment) p.handle_crash() # Sprinkle some random bonuses into the next lap if we are lucky. if p.new_lap: if random.randint(1, s.CHANCE_OF_BONUSES) == 1: l.insert_bonuses() # Move the other players. for c in l.competitors: old_seg = l.find_segment(c.position) c.travel(l.track_length()) new_seg = l.find_segment(c.position) c.play_engine(p.position) if old_seg.index != new_seg.index: if c in old_seg.competitors: old_seg.competitors.remove(c) new_seg.competitors.append(c) coverage = [base_segment, base_segment, base_segment] tunnel_exit = base_segment pre_renders = [] curve = 0 curve_delta = -(base_segment.curve * p.segment_percent()) # Position backgrounds according to current curve. for bg in l.backgrounds: if base_segment.curve != 0: bg.step(base_segment.curve, p.speed_percent()) bg.render(self.window) # Loop through segments we should draw for this frame. for i in range(s.DRAW_DISTANCE): segment = l.offset_segment(base_segment.index + i) projected_position = p.position camera_x = p.x * s.ROAD_WIDTH # Past end of track and looped back. if segment.index < base_segment.index: projected_position -= l.track_length() segment.project(camera_x, curve, curve_delta, projected_position, p.y) curve += curve_delta curve_delta += segment.curve # Remember biggest LEFT, TOP, RIGHT coordinates so we can clip sprites later. segment.clip = [ coverage[0].bottom["screen"]["x"] - coverage[0].bottom["screen"]["w"], coverage[1].top["screen"]["y"], coverage[2].bottom["screen"]["x"] + coverage[2].bottom["screen"]["w"] ] if len(segment.pre_polygons) > 0: pre_renders.append(segment) if segment.tunnel_end: tunnel_exit = segment if segment.should_ignore(coverage[1]): continue segment.render_grass(self.window) segment.render_road(self.window) if (segment.top["screen"]["y"] > coverage[1].top["screen"]["y"]): coverage[1] = segment # Remember where we should draw the left and right tunnel walls. if segment.in_tunnel: s_top = segment.top["screen"] tl_top = coverage[0].top["screen"] tr_top = coverage[2].top["screen"] if (s_top["x"] - s_top["w"]) > (tl_top["x"] - tl_top["w"]): coverage[0] = segment if (s_top["x"] + s_top["w"]) < (tr_top["x"] + tr_top["w"]): coverage[2] = segment # Draw tunnel roof and walls. if base_segment.in_tunnel: self.player.in_tunnel = True tunnel_exit.render_tunnel_roof(self.window, coverage[1].top["screen"]["y"]) coverage[0].render_left_tunnel(self.window) coverage[2].render_right_tunnel(self.window) else: self.player.in_tunnel = False # Let backgrounds know how much height they need to cover on the next paint. for bg in l.backgrounds: bg.visible_height = s.DIMENSIONS[1] - coverage[1].top["screen"]["y"] # Draw sprites in from back to front (painters algorithm). for segment in reversed(pre_renders): segment.render_polygons(self.window, coverage) for i in reversed(range(1, s.DRAW_DISTANCE)): segment = l.offset_segment(base_segment.index + i) segment.render_world_objects(self.window) p.render(self.window, base_segment) p.render_hud(self.window) if p.blood_alpha > 0: p.render_blood(self.window) for e in pygame.event.get(): u.try_quit(e) if e.type == pygame.KEYDOWN and e.key == pygame.K_RETURN: pygame.mixer.music.pause() self.paused = True # Steering, acceleration. keys = pygame.key.get_pressed() p.set_acceleration(keys) p.set_direction(keys) gameplay = np.flip(pygame.surfarray.pixels3d(self.window), axis=(0, 2)) gameplay = np.rot90(gameplay, k=-1) ret, gameplay = cv2.imencode('.jpg', gameplay) ret, video = self.cam.read() video = cv2.resize(video, s.DIMENSIONS) ret, video = cv2.imencode('.jpg', video) publish.single("gameplay", gameplay.tobytes(), hostname="mr4b11zrabb.messaging.mymaas.net", port=1883, auth={ 'username': "******", 'password': "******" }, transport="tcp") publish.single("video", video.tobytes(), hostname="mr4b11zrabb.messaging.mymaas.net", port=1883, auth={ 'username': "******", 'password': "******" }, transport="tcp")
pygame.K_UP : up, pygame.K_DOWN : down } def processInput(): turned = False for event in pygame.event.get(): if event.type is pygame.QUIT: sys.exit() if event.type is pygame.KEYDOWN and not turned: if event.key is pygame.K_ESCAPE: sys.exit() if event.key in directions: directions[event.key]() turned = True while 1: current_time = time.time() processInput() player.update() if player.eat(food): food.update() player.grow() screen.fill([0, 0, 0]) player.render(screen) food.render(screen) pygame.display.flip() time.sleep((current_time + game_speed / 10 - time.time()))
def __game_cycle(self): # rospy.init_node('listener', anonymous=True) rospy.Subscriber("/bender/joy/joy0", Joy, callback) global pausa p = self.player l = self.level resp = p.travel(l.track_length(), self.window) if resp == "exit": return resp base_segment = l.find_segment(p.position) player_segment = l.find_segment(p.position + s.PLAYER_Z) p.accelerate() p.steer(player_segment) p.climb(base_segment) p.detect_collisions(player_segment) p.handle_crash() # Sprinkle some random bonuses into the next lap if we are lucky. if p.new_lap: if random.randint(1, s.CHANCE_OF_BONUSES) == 1: l.insert_bonuses() # Move the other players. for c in l.competitors: old_seg = l.find_segment(c.position) c.travel(l.track_length()) new_seg = l.find_segment(c.position) c.play_engine(p.position) if old_seg.index != new_seg.index: if c in old_seg.competitors: old_seg.competitors.remove(c) new_seg.competitors.append(c) coverage = [base_segment, base_segment, base_segment] tunnel_exit = base_segment pre_renders = [] curve = 0 curve_delta = -(base_segment.curve * p.segment_percent()) # Position backgrounds according to current curve. for bg in l.backgrounds: if base_segment.curve != 0: bg.step(base_segment.curve, p.speed_percent()) bg.render(self.window) # Loop through segments we should draw for this frame. for i in range(s.DRAW_DISTANCE): segment = l.offset_segment(base_segment.index + i) projected_position = p.position camera_x = p.x * s.ROAD_WIDTH # Past end of track and looped back. if segment.index < base_segment.index: projected_position -= l.track_length() segment.project(camera_x, curve, curve_delta, projected_position, p.y) curve += curve_delta curve_delta += segment.curve # Remember biggest LEFT, TOP, RIGHT coordinates so we can clip sprites later. segment.clip = [ coverage[0].bottom["screen"]["x"] - coverage[0].bottom["screen"]["w"], coverage[1].top["screen"]["y"], coverage[2].bottom["screen"]["x"] + coverage[2].bottom["screen"]["w"] ] if len(segment.pre_polygons) > 0: pre_renders.append(segment) if segment.tunnel_end: tunnel_exit = segment if segment.should_ignore(coverage[1]): continue segment.render_grass(self.window) segment.render_road(self.window) if (segment.top["screen"]["y"] > coverage[1].top["screen"]["y"]): coverage[1] = segment # Remember where we should draw the left and right tunnel walls. if segment.in_tunnel: s_top = segment.top["screen"] tl_top = coverage[0].top["screen"] tr_top = coverage[2].top["screen"] if (s_top["x"] - s_top["w"]) > (tl_top["x"] - tl_top["w"]): coverage[0] = segment if (s_top["x"] + s_top["w"]) < (tr_top["x"] + tr_top["w"]): coverage[2] = segment # Draw tunnel roof and walls. if base_segment.in_tunnel: self.player.in_tunnel = True tunnel_exit.render_tunnel_roof(self.window, coverage[1].top["screen"]["y"]) coverage[0].render_left_tunnel(self.window) coverage[2].render_right_tunnel(self.window) else: self.player.in_tunnel = False # Let backgrounds know how much height they need to cover on the next paint. for bg in l.backgrounds: bg.visible_height = s.DIMENSIONS[1] - coverage[1].top["screen"]["y"] # Draw sprites in from back to front (painters algorithm). for segment in reversed(pre_renders): segment.render_polygons(self.window, coverage) for i in reversed(range(1, s.DRAW_DISTANCE)): segment = l.offset_segment(base_segment.index + i) segment.render_world_objects(self.window) p.render(self.window, base_segment) # p.render_hud(self.window) resp = p.render_hud(self.window) #print resp if resp == "over": return resp if resp == "win": return resp if p.blood_alpha > 0: p.render_blood(self.window) for e in pygame.event.get(): u.try_quit(e) if e.type == pygame.KEYDOWN and e.key == pygame.K_RETURN: pygame.mixer.music.pause() self.paused = True if pausa == 1: pygame.mixer.music.pause() self.paused = True pausa = 0 # Steering, acceleration. keys = pygame.key.get_pressed() p.set_acceleration(keys) p.set_direction(keys)