Advertisement
Guest User

paddle.py

a guest
Nov 21st, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import pygame
  2. import pymunk
  3. import colors
  4. import const
  5.  
  6. from pygame.locals import *
  7. from pymunk import Vec2d
  8. from entity import Entity
  9.  
  10. class Paddle(Entity):
  11.  
  12.     DIMENSIONS = (20, 80)
  13.  
  14.     def __init__(self, space, pos):
  15.         image = self._get_base_image()
  16.  
  17.         super(Paddle, self).__init__(image=image, space=space, mass=500,
  18.                                      inertia=pymunk.inf, x=pos[0], y=pos[1])
  19.  
  20.         self.shape = pymunk.Poly.create_box(self.body, Paddle.DIMENSIONS)
  21.         self.shape.elasticity = 1.
  22.         self.space.add(self.body, self.shape)
  23.  
  24.     def _get_base_image(self):
  25.         surf = pygame.Surface(Paddle.DIMENSIONS)
  26.         surf.fill(colors.BLUE)
  27.         return surf
  28.  
  29.     def update(self, dt=0):
  30.         super(Paddle, self).update(dt)
  31.         self.body.velocity = self._handle_input()
  32.  
  33.     def _handle_input(self):
  34.         keys = pygame.key.get_pressed()
  35.         if keys[K_UP]: return Vec2d(0, 200)
  36.         elif keys[K_DOWN]: return Vec2d(0, -200)
  37.         else: return Vec2d(0, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement