Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- DISPLAY_WIDTH = 700
- DISPLAY_HEIGHT = 600
- screen = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
- TICK_COUNT = 60 # per second
- class Player(object):
- def __init__(self, color, x, y, vx = 0, vy = 0):
- self._x = x
- self._y = y
- self._vx = vx #/ float(TICK_COUNT)
- self._vy = vy #/ float(TICK_COUNT)
- self.color = color
- def show(self):
- pass
- def updateState(self):
- #print "UPDATe STATE BEGIN", self._x, self._y
- self._x += self._vx / (float(TICK_COUNT)/60)
- self._y += self._vy / (float(TICK_COUNT)/60)
- #print "UPDATe STATE END", self._x, self._y
- def handle(event_key):
- pass
- class Quad(Player):
- def __init__(self, color, x, y, width, height, vx = 0, vy = 0):
- self._width = width
- self._height = height
- Player.__init__(self, color, x, y, vx, vy)
- def show(self):
- pygame.draw.rect(screen, self.color, pygame.Rect(self._x, self._y, self._width, self._height))
- def getV(self):
- return self._vx, self._vy
- def setV(self, vx, vy):
- self._vx = vx
- self._vy = vy
- def getPos(self):
- return self._x, self._y
- def setPos(self, x, y):
- self._x = x
- self._y = y
- def handle_keydown(self, event_key):
- if event_key == pygame.K_s:
- self._vy += 2
- elif event_key == pygame.K_w:
- self._vy -= 2
- elif event_key == pygame.K_d:
- self._vx += 2
- elif event_key == pygame.K_a:
- self._vx -= 2
- elif event_key == pygame.K_e:
- self._width *= 2
- self._height *= 2
- elif event_key == pygame.K_q:
- self._width /= 2
- self._height /= 2
- def handle_keyup(self, event_key):
- if event_key == pygame.K_s:
- self._vy -= 2
- elif event_key == pygame.K_w:
- self._vy += 2
- elif event_key == pygame.K_d:
- self._vx -= 2
- elif event_key == pygame.K_a:
- self._vx += 2
- def updateState(self):
- #print "UPDATe STATE BEGIN", self._x, self._y
- self._x += self._vx / (float(TICK_COUNT)/60)
- if self._x <= 0 :
- self._x=0
- if self._x>=DISPLAY_WIDTH - self._width:
- self._x=DISPLAY_WIDTH - self._width
- self._y += self._vy / (float(TICK_COUNT)/60)
- if self._y <= 0 :
- self._y=0
- if self._y >= DISPLAY_HEIGHT-self._height:
- self._y=DISPLAY_HEIGHT-self._height
- self._vy = 0.0
- else:
- self._vy += 0.02
- #self._y += self._vy / (float(TICK_COUNT)/60)
- self._vy += 0.05
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement