def control_p2(): keyboard = Keyboard() position = Vec2(0, 0) if keyboard.is_key_pressed(Keyboard.K_s): position = Vec2(0, 200) if keyboard.is_key_pressed(Keyboard.K_w): position = Vec2(0, -200) return position
def load(self, game_name, window_size): """ Initialize the main canvas, the screen_manager and the keyboard. """ self.game_canvas = GameCanvas(game_name, window_size) self.scene_manager = SceneManager() self.keyboard = Keyboard()
def control_p1(): keyboard = Keyboard() position = Vec2(0, 0) if keyboard.is_key_pressed(Keyboard.DOWN): position = Vec2(0, 200) if keyboard.is_key_pressed(Keyboard.UP): position = Vec2(0, -200) return position
def update(self, time_elapsed): self.collision_manager.manage_collision() for g in self.game_objects: g.update(time_elapsed) if self.ball.position.x > 800: self.game_end = True self.game_text = Text("Player 1 Wins", 24) elif self.ball.position.x < 0: self.game_end = True self.game_text = Text("Player 2 Wins", 24) if (self.game_end): if (Keyboard().is_key_pressed(Keyboard.RETURN)): GameEngine().set_next_scene("Stage 1") self.state = State.FINISHED
def load(self): self.keyboard = Keyboard() self.ball = ObjectPool().get(Ball, 350, 100) self.game_end = False self.game_start = True self.game_text2 = Text("Pressione enter para começar", 24) self.game_objects = GameObjectList( self.ball, ObjectPool().get(Ground, 148, 634.5), ObjectPool().get(Ground, 444, 634.5), ObjectPool().get(Ground, 740, 634.5), ObjectPool().get(Ground, 148, -33.5), ObjectPool().get(Ground, 444, -33.5), ObjectPool().get(Ground, 740, -33.5), PongBar((50, 300), control_p2), PongBar((750, 300), control_p1), ) self.collision_manager = CollisionManager() self.collision_manager.attach(self.game_objects)
def __init__(self, position): super().__init__(position, 1, BoxCollider(position, (27, 26)), 1.2) self.keyboard = Keyboard() self.sprite = Sprite(conf.ASSETS + 'ball.png') self.moving = False
def __init__(self, position, control): super().__init__(position, 0, BoxCollider(position, (71, 296)), 5) self.sprite = Sprite(conf.ASSETS + 'bar.jpg') self.keyboard = Keyboard() self.control = control
def load(self): self.keyboard = Keyboard() self.player = Player(50, 50) self.game_objects = [self.player]
def __init__(self, x, y): super().__init__(x, y) self.sprite = Sprite("engineer.jpg") self.keyboard = Keyboard()
def __init__(self, position): super().__init__(position, 0, BoxCollider(position, (296, 71)), 5) self.sprite = Sprite(conf.ASSETS + 'bar2.jpg') self.keyboard = Keyboard()