Python pygame.K_UP Examples
The following are 30
code examples of pygame.K_UP().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: sprites.py From pygame_tutorials with MIT License | 8 votes |
def get_keys(self): self.rot_speed = 0 self.vel = vec(0, 0) keys = pg.key.get_pressed() if keys[pg.K_LEFT] or keys[pg.K_a]: self.rot_speed = PLAYER_ROT_SPEED if keys[pg.K_RIGHT] or keys[pg.K_d]: self.rot_speed = -PLAYER_ROT_SPEED if keys[pg.K_UP] or keys[pg.K_w]: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) if keys[pg.K_DOWN] or keys[pg.K_s]: self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) if keys[pg.K_SPACE]: now = pg.time.get_ticks() if now - self.last_shot > BULLET_RATE: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) Bullet(self.game, pos, dir) self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
Example #2
Source File: gamestart.py From Games with MIT License | 8 votes |
def GameStartInterface(screen, sounds, cfg): dino = Dinosaur(cfg.IMAGE_PATHS['dino']) ground = pygame.image.load(cfg.IMAGE_PATHS['ground']).subsurface((0, 0), (83, 19)) rect = ground.get_rect() rect.left, rect.bottom = cfg.SCREENSIZE[0]/20, cfg.SCREENSIZE[1] clock = pygame.time.Clock() press_flag = False while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: press_flag = True dino.jump(sounds) dino.update() screen.fill(cfg.BACKGROUND_COLOR) screen.blit(ground, rect) dino.draw(screen) pygame.display.update() clock.tick(cfg.FPS) if (not dino.is_jumping) and press_flag: return True
Example #3
Source File: movement.py From pygame_tutorials with MIT License | 6 votes |
def update(self): self.vx, self.vy = 0, 0 keystate = pg.key.get_pressed() if keystate[pg.K_UP]: self.vy = -5 if keystate[pg.K_DOWN]: self.vy = 5 if keystate[pg.K_LEFT]: self.vx = -2 if keystate[pg.K_RIGHT]: self.vx = 1 if self.vx != 0 and self.vy != 0: self.vx /= 1.414 self.vy /= 1.414 self.rect.x += self.vx self.rect.y += self.vy
Example #4
Source File: graphics.py From highway-env with MIT License | 6 votes |
def handle_continuous_action_event(cls, action_type: ContinuousAction, event: pygame.event.EventType) -> None: action = action_type.last_action.copy() steering_index = action_type.space().shape[0] - 1 if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT and action_type.lateral: action[steering_index] = 0.7 if event.key == pygame.K_LEFT and action_type.lateral: action[steering_index] = -0.7 if event.key == pygame.K_DOWN and action_type.longitudinal: action[0] = -0.7 if event.key == pygame.K_UP and action_type.longitudinal: action[0] = 0.7 elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT and action_type.lateral: action[steering_index] = 0 if event.key == pygame.K_LEFT and action_type.lateral: action[steering_index] = 0 if event.key == pygame.K_DOWN and action_type.longitudinal: action[0] = 0 if event.key == pygame.K_UP and action_type.longitudinal: action[0] = 0 action_type.act(action)
Example #5
Source File: manual-control-pygame.py From DJITelloPy with MIT License | 6 votes |
def keydown(self, key): """ Update velocities based on key pressed Arguments: key: pygame key """ if key == pygame.K_UP: # set forward velocity self.for_back_velocity = S elif key == pygame.K_DOWN: # set backward velocity self.for_back_velocity = -S elif key == pygame.K_LEFT: # set left velocity self.left_right_velocity = -S elif key == pygame.K_RIGHT: # set right velocity self.left_right_velocity = S elif key == pygame.K_w: # set up velocity self.up_down_velocity = S elif key == pygame.K_s: # set down velocity self.up_down_velocity = -S elif key == pygame.K_a: # set yaw counter clockwise velocity self.yaw_velocity = -S elif key == pygame.K_d: # set yaw clockwise velocity self.yaw_velocity = S
Example #6
Source File: manual-control-pygame.py From DJITelloPy with MIT License | 6 votes |
def keyup(self, key): """ Update velocities based on key released Arguments: key: pygame key """ if key == pygame.K_UP or key == pygame.K_DOWN: # set zero forward/backward velocity self.for_back_velocity = 0 elif key == pygame.K_LEFT or key == pygame.K_RIGHT: # set zero left/right velocity self.left_right_velocity = 0 elif key == pygame.K_w or key == pygame.K_s: # set zero up/down velocity self.up_down_velocity = 0 elif key == pygame.K_a or key == pygame.K_d: # set zero yaw velocity self.yaw_velocity = 0 elif key == pygame.K_t: # takeoff self.tello.takeoff() self.send_rc_control = True elif key == pygame.K_l: # land not self.tello.land() self.send_rc_control = False
Example #7
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def get_keys(self): self.rot_speed = 0 self.vel = vec(0, 0) keys = pg.key.get_pressed() if keys[pg.K_LEFT] or keys[pg.K_a]: self.rot_speed = PLAYER_ROT_SPEED if keys[pg.K_RIGHT] or keys[pg.K_d]: self.rot_speed = -PLAYER_ROT_SPEED if keys[pg.K_UP] or keys[pg.K_w]: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) if keys[pg.K_DOWN] or keys[pg.K_s]: self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) if keys[pg.K_SPACE]: now = pg.time.get_ticks() if now - self.last_shot > BULLET_RATE: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) Bullet(self.game, pos, dir) self.vel = vec(-KICKBACK, 0).rotate(-self.rot) MuzzleFlash(self.game, pos)
Example #8
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def get_keys(self): self.rot_speed = 0 self.vel = vec(0, 0) keys = pg.key.get_pressed() if keys[pg.K_LEFT] or keys[pg.K_a]: self.rot_speed = PLAYER_ROT_SPEED if keys[pg.K_RIGHT] or keys[pg.K_d]: self.rot_speed = -PLAYER_ROT_SPEED if keys[pg.K_UP] or keys[pg.K_w]: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) if keys[pg.K_DOWN] or keys[pg.K_s]: self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) if keys[pg.K_SPACE]: now = pg.time.get_ticks() if now - self.last_shot > BULLET_RATE: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) Bullet(self.game, pos, dir) self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
Example #9
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def get_keys(self): self.rot_speed = 0 self.vel = vec(0, 0) keys = pg.key.get_pressed() if keys[pg.K_LEFT] or keys[pg.K_a]: self.rot_speed = PLAYER_ROT_SPEED if keys[pg.K_RIGHT] or keys[pg.K_d]: self.rot_speed = -PLAYER_ROT_SPEED if keys[pg.K_UP] or keys[pg.K_w]: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) if keys[pg.K_DOWN] or keys[pg.K_s]: self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) if keys[pg.K_SPACE]: now = pg.time.get_ticks() if now - self.last_shot > BULLET_RATE: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) Bullet(self.game, pos, dir) self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
Example #10
Source File: player.py From Tutoriales_juegos_Python with GNU General Public License v3.0 | 6 votes |
def handle_event(self, event): if event.type == pygame.QUIT: game_over = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.update('left') if event.key == pygame.K_RIGHT: self.update('right') if event.key == pygame.K_UP: self.update('up') if event.key == pygame.K_DOWN: self.update('down') if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: self.update('stand_left') if event.key == pygame.K_RIGHT: self.update('stand_right') if event.key == pygame.K_UP: self.update('stand_up') if event.key == pygame.K_DOWN: self.update('stand_down')
Example #11
Source File: tilemap_demo2.py From pygame_tutorials with MIT License | 6 votes |
def update(self): pg.display.set_caption(str((self.rect.x, self.rect.y))) self.vx, self.vy = 0, 0 keys = pg.key.get_pressed() if keys[pg.K_UP]: self.vy = -5 if keys[pg.K_DOWN]: self.vy = 5 if keys[pg.K_LEFT]: self.vx = -5 if keys[pg.K_RIGHT]: self.vx = 5 # if self.vx != 0 and self.vy != 0: # self.vx *= 0.7071 # self.vy *= 0.7071 self.rect.x += self.vx if pg.sprite.spritecollide(self, walls, False, pg.sprite.collide_mask): self.rect.x -= self.vx self.rect.y += self.vy if pg.sprite.spritecollide(self, walls, False, pg.sprite.collide_mask): self.rect.y -= self.vy
Example #12
Source File: engine.py From Fruit-API with GNU General Public License v3.0 | 6 votes |
def __human_control(self, key): if self.human_control: robot = self.robots[self.human_control_robot] if key == pygame.K_LEFT: robot.move(GlobalConstants.LEFT_ACTION, self.sprites) if key == pygame.K_RIGHT: robot.move(GlobalConstants.RIGHT_ACTION, self.sprites) if key == pygame.K_UP: robot.move(GlobalConstants.UP_ACTION, self.sprites) if key == pygame.K_DOWN: robot.move(GlobalConstants.DOWN_ACTION, self.sprites) if key == pygame.K_a: reward = robot.move(GlobalConstants.FIRE_ACTION, self.sprites) if reward > 0: self.rewards[self.human_control_robot].append(reward) self.total_score[self.human_control_robot] += reward
Example #13
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def get_keys(self): self.rot_speed = 0 self.vel = vec(0, 0) keys = pg.key.get_pressed() if keys[pg.K_LEFT] or keys[pg.K_a]: self.rot_speed = PLAYER_ROT_SPEED if keys[pg.K_RIGHT] or keys[pg.K_d]: self.rot_speed = -PLAYER_ROT_SPEED if keys[pg.K_UP] or keys[pg.K_w]: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) if keys[pg.K_DOWN] or keys[pg.K_s]: self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) if keys[pg.K_SPACE]: now = pg.time.get_ticks() if now - self.last_shot > BULLET_RATE: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) Bullet(self.game, pos, dir) self.vel = vec(-KICKBACK, 0).rotate(-self.rot) MuzzleFlash(self.game, pos)
Example #14
Source File: gamestart.py From AIGames with MIT License | 6 votes |
def GameStartInterface(screen, sounds, cfg): dino = Dinosaur(cfg.IMAGE_PATHS['dino']) ground = pygame.image.load(cfg.IMAGE_PATHS['ground']).subsurface((0, 0), (83, 19)) rect = ground.get_rect() rect.left, rect.bottom = cfg.SCREENSIZE[0]/20, cfg.SCREENSIZE[1] clock = pygame.time.Clock() press_flag = False while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: press_flag = True dino.jump(sounds) dino.update() screen.fill(cfg.BACKGROUND_COLOR) screen.blit(ground, rect) dino.draw(screen) pygame.display.update() clock.tick(cfg.FPS) if (not dino.is_jumping) and press_flag: return True
Example #15
Source File: viewer.py From generals-bot with MIT License | 6 votes |
def _handleKeypress(self, key): if self._clicked == None or self._moveEvent == None: return False column = self._clicked[0] row = self._clicked[1] target = None if key == pygame.K_LEFT: if column > 0: target = (column-1, row) elif key == pygame.K_RIGHT: if column < self._map.cols - 1: target = (column+1, row) elif key == pygame.K_UP: if row > 0: target = (column, row-1) elif key == pygame.K_DOWN: if row < self._map.rows - 1: target = (column, row+1) if target != None: self._moveEvent(self._clicked, target) self._clicked = target
Example #16
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def get_keys(self): self.rot_speed = 0 self.vel = vec(0, 0) keys = pg.key.get_pressed() if keys[pg.K_LEFT] or keys[pg.K_a]: self.rot_speed = PLAYER_ROT_SPEED if keys[pg.K_RIGHT] or keys[pg.K_d]: self.rot_speed = -PLAYER_ROT_SPEED if keys[pg.K_UP] or keys[pg.K_w]: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) if keys[pg.K_DOWN] or keys[pg.K_s]: self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) if keys[pg.K_SPACE]: now = pg.time.get_ticks() if now - self.last_shot > BULLET_RATE: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) Bullet(self.game, pos, dir) self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
Example #17
Source File: endGame.py From AIGames with MIT License | 6 votes |
def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg, mode): if mode == 'train': return sounds['die'].play() clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return boundary_values = [0, base_pos[-1]] bird.update(boundary_values) screen.blit(backgroud_image, (0, 0)) pipe_sprites.draw(screen) screen.blit(other_images['base'], base_pos) showScore(screen, score, number_images) bird.draw(screen) pygame.display.update() clock.tick(cfg.FPS)
Example #18
Source File: sprites.py From pygame_tutorials with MIT License | 6 votes |
def get_keys(self): self.rot_speed = 0 self.vel = vec(0, 0) keys = pg.key.get_pressed() if keys[pg.K_LEFT] or keys[pg.K_a]: self.rot_speed = PLAYER_ROT_SPEED if keys[pg.K_RIGHT] or keys[pg.K_d]: self.rot_speed = -PLAYER_ROT_SPEED if keys[pg.K_UP] or keys[pg.K_w]: self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) if keys[pg.K_DOWN] or keys[pg.K_s]: self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) if keys[pg.K_SPACE]: now = pg.time.get_ticks() if now - self.last_shot > BULLET_RATE: self.last_shot = now dir = vec(1, 0).rotate(-self.rot) pos = self.pos + BARREL_OFFSET.rotate(-self.rot) Bullet(self.game, pos, dir) self.vel = vec(-KICKBACK, 0).rotate(-self.rot)
Example #19
Source File: endGame.py From Games with MIT License | 6 votes |
def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg): sounds['die'].play() clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return boundary_values = [0, base_pos[-1]] bird.update(boundary_values, float(clock.tick(cfg.FPS))/1000.) screen.blit(backgroud_image, (0, 0)) pipe_sprites.draw(screen) screen.blit(other_images['base'], base_pos) showScore(screen, score, number_images) bird.draw(screen) pygame.display.update() clock.tick(cfg.FPS)
Example #20
Source File: endGame.py From AIGames with MIT License | 6 votes |
def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg, mode): if mode == 'train': return sounds['die'].play() clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return boundary_values = [0, base_pos[-1]] bird.update(boundary_values) screen.blit(backgroud_image, (0, 0)) pipe_sprites.draw(screen) screen.blit(other_images['base'], base_pos) showScore(screen, score, number_images) bird.draw(screen) pygame.display.update() clock.tick(cfg.FPS)
Example #21
Source File: motion_demo.py From pygame_tutorials with MIT License | 6 votes |
def update(self): self.acc = vec(0, 0) keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.acc.x = -0.2 if keys[pygame.K_RIGHT]: self.acc.x = 0.2 if keys[pygame.K_UP]: self.acc.y = -0.2 if keys[pygame.K_DOWN]: self.acc.y = 0.2 self.vel += self.acc self.pos += self.vel + 0.5 * self.acc if self.pos.x > WIDTH: self.pos.x = 0 if self.pos.x < 0: self.pos.x = WIDTH if self.pos.y > HEIGHT: self.pos.y = 0 if self.pos.y < 0: self.pos.y = HEIGHT self.rect.center = self.pos
Example #22
Source File: creature.py From Hermit with MIT License | 5 votes |
def keyupdowncontrol(self,event,horse): if event.type == pygame.KEYDOWN: if event.key==pygame.K_DOWN: if self.status[1] == "": self.drink() if event.key==pygame.K_UP: if self.status[0] == "" : if abs((self.yo-10) - horse.yo)<10*self.s: self.mount(horse) else: settings.msg= ["CANNOT MOUNT ON SLOPE.",settings.msgt] elif self.status[0] == "mounted": self.dismount(horse) if event.type == pygame.KEYDOWN: if self.eventdelay <= 0: if event.key==pygame.K_LEFT: if not "bow" in self.status[1] and not "drinking" in self.status[1]: self.status[1] = "bow prepares" self.eventdelay=80 if event.type == pygame.KEYUP: if event.key==pygame.K_LEFT: if "bow" in self.status[1]: self.releasebow()
Example #23
Source File: startGame.py From AIGames with MIT License | 5 votes |
def startGame(screen, sounds, bird_images, other_images, backgroud_image, cfg, mode): base_pos = [0, cfg.SCREENHEIGHT*0.79] base_diff_bg = other_images['base'].get_width() - backgroud_image.get_width() msg_pos = [(cfg.SCREENWIDTH-other_images['message'].get_width())/2, cfg.SCREENHEIGHT*0.12] bird_idx = 0 bird_idx_change_count = 0 bird_idx_cycle = itertools.cycle([0, 1, 2, 1]) bird_pos = [cfg.SCREENWIDTH*0.2, (cfg.SCREENHEIGHT-list(bird_images.values())[0].get_height())/2] bird_y_shift_count = 0 bird_y_shift_max = 9 shift = 1 clock = pygame.time.Clock() if mode == 'train': return {'bird_pos': bird_pos, 'base_pos': base_pos, 'bird_idx': bird_idx} while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return {'bird_pos': bird_pos, 'base_pos': base_pos, 'bird_idx': bird_idx} sounds['wing'].play() bird_idx_change_count += 1 if bird_idx_change_count % 5 == 0: bird_idx = next(bird_idx_cycle) bird_idx_change_count = 0 base_pos[0] = -((-base_pos[0] + 4) % base_diff_bg) bird_y_shift_count += 1 if bird_y_shift_count == bird_y_shift_max: bird_y_shift_max = 16 shift = -1 * shift bird_y_shift_count = 0 bird_pos[-1] = bird_pos[-1] + shift screen.blit(backgroud_image, (0, 0)) screen.blit(list(bird_images.values())[bird_idx], bird_pos) screen.blit(other_images['message'], msg_pos) screen.blit(other_images['base'], base_pos) pygame.display.update() clock.tick(cfg.FPS)
Example #24
Source File: startGame.py From AIGames with MIT License | 5 votes |
def startGame(screen, sounds, bird_images, other_images, backgroud_image, cfg, mode): base_pos = [0, cfg.SCREENHEIGHT*0.79] base_diff_bg = other_images['base'].get_width() - backgroud_image.get_width() msg_pos = [(cfg.SCREENWIDTH-other_images['message'].get_width())/2, cfg.SCREENHEIGHT*0.12] bird_idx = 0 bird_idx_change_count = 0 bird_idx_cycle = itertools.cycle([0, 1, 2, 1]) bird_pos = [cfg.SCREENWIDTH*0.2, (cfg.SCREENHEIGHT-list(bird_images.values())[0].get_height())/2] bird_y_shift_count = 0 bird_y_shift_max = 9 shift = 1 clock = pygame.time.Clock() if mode == 'train': return {'bird_pos': bird_pos, 'base_pos': base_pos, 'bird_idx': bird_idx} while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return {'bird_pos': bird_pos, 'base_pos': base_pos, 'bird_idx': bird_idx} sounds['wing'].play() bird_idx_change_count += 1 if bird_idx_change_count % 5 == 0: bird_idx = next(bird_idx_cycle) bird_idx_change_count = 0 base_pos[0] = -((-base_pos[0] + 4) % base_diff_bg) bird_y_shift_count += 1 if bird_y_shift_count == bird_y_shift_max: bird_y_shift_max = 16 shift = -1 * shift bird_y_shift_count = 0 bird_pos[-1] = bird_pos[-1] + shift screen.blit(backgroud_image, (0, 0)) screen.blit(list(bird_images.values())[bird_idx], bird_pos) screen.blit(other_images['message'], msg_pos) screen.blit(other_images['base'], base_pos) pygame.display.update() clock.tick(cfg.FPS)
Example #25
Source File: gameend.py From AIGames with MIT License | 5 votes |
def GameEndInterface(screen, cfg): replay_image = pygame.image.load(cfg.IMAGE_PATHS['replay']) replay_image = pygame.transform.scale(replay_image, (35, 31)) replay_image_rect = replay_image.get_rect() replay_image_rect.centerx = cfg.SCREENSIZE[0] / 2 replay_image_rect.top = cfg.SCREENSIZE[1] * 0.52 gameover_image = pygame.image.load(cfg.IMAGE_PATHS['gameover']) gameover_image = pygame.transform.scale(gameover_image, (190, 11)) gameover_image_rect = gameover_image.get_rect() gameover_image_rect.centerx = cfg.SCREENSIZE[0] / 2 gameover_image_rect.centery = cfg.SCREENSIZE[1] * 0.35 clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return True elif event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = pygame.mouse.get_pos() if replay_image_rect.collidepoint(mouse_pos): return True screen.blit(replay_image, replay_image_rect) screen.blit(gameover_image, gameover_image_rect) pygame.display.update() clock.tick(cfg.FPS)
Example #26
Source File: pyespcar_sdk.py From 1ZLAB_PyEspCar with GNU General Public License v3.0 | 5 votes |
def __init__(self, mqtt_client, is_debug=False): # 是否开启调试模式 self.is_debug = is_debug # MQTT的客户端 self.mqtt_client = mqtt_client # 设置小车的默认速度 self.speed = self.DEFAULT_CAR_SPEED # 设置默认的舵机云台角度变换值 self.cp_delta_angle = self.DEFAULT_CP_DELTA_ANGLE # 记录当前底部舵机的角度 self.bottom_servo_angle = self.BOTTOM_SERVO_DEFAULT_ANGLE # 记录顶部舵机的角度 self.top_servo_angle = self.TOP_SERVO_DEFAULT_ANGLE # 键盘事件映射字典 self.KEY_FUNC_MAP = { pygame.K_LEFT: self.turn_left, pygame.K_RIGHT: self.turn_right, pygame.K_UP: self.go_forward, pygame.K_DOWN: self.go_backward, pygame.K_a: self.cp_left, pygame.K_d: self.cp_right, pygame.K_w: self.cp_up, pygame.K_s: self.cp_down, pygame.K_r: self.cp_reset } # 小车停止 self.stop() # 舵机复位 self.cp_reset()
Example #27
Source File: graphics.py From highway-env with MIT License | 5 votes |
def handle_discrete_action_event(cls, action_type: DiscreteMetaAction, event: pygame.event.EventType) -> None: if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT and action_type.longitudinal: action_type.act(action_type.actions_indexes["FASTER"]) if event.key == pygame.K_LEFT and action_type.longitudinal: action_type.act(action_type.actions_indexes["SLOWER"]) if event.key == pygame.K_DOWN and action_type.lateral: action_type.act(action_type.actions_indexes["LANE_RIGHT"]) if event.key == pygame.K_UP: action_type.act(action_type.actions_indexes["LANE_LEFT"])
Example #28
Source File: engine.py From Fruit-API with GNU General Public License v3.0 | 5 votes |
def __human_control(self, key): action = -1 if key == pygame.K_LEFT: action = DeepSeaTreasureConstants.LEFT_ACTION if key == pygame.K_RIGHT: action = DeepSeaTreasureConstants.RIGHT_ACTION if key == pygame.K_UP: action = DeepSeaTreasureConstants.UP_ACTION if key == pygame.K_DOWN: action = DeepSeaTreasureConstants.DOWN_ACTION return action
Example #29
Source File: engine.py From Fruit-API with GNU General Public License v3.0 | 5 votes |
def __human_control(self, key): action = -1 if key == pygame.K_LEFT: self.move(MountainCarConstants.LEFT_ACTION) action = MountainCarConstants.LEFT_ACTION if key == pygame.K_RIGHT: self.move(MountainCarConstants.RIGHT_ACTION) action = MountainCarConstants.RIGHT_ACTION if key == pygame.K_UP: self.move(MountainCarConstants.UP_ACTION) action = MountainCarConstants.UP_ACTION return action
Example #30
Source File: engine.py From Fruit-API with GNU General Public License v3.0 | 5 votes |
def __human_control(self, key): if self.human_control: if key == pygame.K_LEFT: self.player1.move(GlobalConstants.LEFT_ACTION, self.sprites) if key == pygame.K_RIGHT: self.player1.move(GlobalConstants.RIGHT_ACTION, self.sprites) if key == pygame.K_UP: self.player1.move(GlobalConstants.UP_ACTION, self.sprites) if key == pygame.K_DOWN: self.player1.move(GlobalConstants.DOWN_ACTION, self.sprites) if key == pygame.K_a: self.__eat() if key == pygame.K_s: self.__pick()