예제 #1
0
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
예제 #2
0
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
예제 #3
0
파일: engine.py 프로젝트: rodrigocam/simian
 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()
예제 #4
0
class Player(GameObject):
    def __init__(self, x, y):
        super().__init__(x, y)
        self.sprite = Sprite("engineer.jpg")
        self.keyboard = Keyboard()

    def update(self, time_elapsed):
        if (self.keyboard.is_key_pressed(Keyboard.RIGHT)):
            self.velocity = Vec2(100, 0)

        if (self.keyboard.is_key_pressed(Keyboard.LEFT)):
            self.velocity = Vec2(-100, 0)

        if (self.keyboard.is_key_pressed(Keyboard.DOWN)):
            self.velocity = Vec2(0, 100)

        if (self.keyboard.is_key_pressed(Keyboard.UP)):
            self.velocity = Vec2(0, -100)

    def draw(self, graphics):
        self.sprite.set_x(self.position.x)
        self.sprite.set_y(self.position.y)
        graphics.add(self.sprite)
예제 #5
0
    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
예제 #6
0
class Ball(RigidBody):
    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 update(self, time_elapsed):
        if (self.keyboard.is_key_pressed(Keyboard.RETURN)):
            self.velocity = Vec2(-70, 70)
            self.moving = True

        self.position += self.velocity * time_elapsed

    def draw(self, graphics):
        self.sprite.x = self.position.x
        self.sprite.y = self.position.y
        graphics.add(self.sprite)
예제 #7
0
    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)
예제 #8
0
 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
예제 #9
0
 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
예제 #10
0
 def load(self):
     self.keyboard = Keyboard()
     self.player = Player(50, 50)
     self.game_objects = [self.player]
예제 #11
0
 def __init__(self, x, y):
     super().__init__(x, y)
     self.sprite = Sprite("engineer.jpg")
     self.keyboard = Keyboard()
예제 #12
0
 def __init__(self, position):
     super().__init__(position, 0, BoxCollider(position, (296, 71)), 5)
     self.sprite = Sprite(conf.ASSETS + 'bar2.jpg')
     self.keyboard = Keyboard()