san560

Untitled

Dec 11th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. This is my entire sprites file.
  2.  
  3. import pygame as pg
  4. from settings import *
  5. vec = pg.math.Vector2
  6.  
  7. class Player(pg.sprite.Sprite):
  8. #sprite for the PLAYER
  9. def __init__(self):
  10. pg.sprite.Sprite.__init__(self)
  11. self.image = pg.Surface((30,40))
  12. self.image.fill(YELLOW)
  13. self.rect = self.image.get_rect()
  14. self.rect.center = (WIDTH / 2, HEIGHT - 30)
  15. self.pos = vec(WIDTH / 2, HEIGHT / 2)
  16. self.vel = vec(0,0)
  17. self.acc = vec(0,0)
  18.  
  19. def jump(self):
  20. # jump only if standing on platform
  21. self.vel.y = -10
  22.  
  23.  
  24. def update(self):
  25. self.acc = vec(0, 0.5)
  26. keys = pg.key.get_pressed()
  27. if keys[pg.K_LEFT]:
  28. self.acc.x = -PLAYER_ACC
  29. if keys[pg.K_RIGHT]:
  30. self.acc.x = PLAYER_ACC
  31.  
  32. # apply friction
  33. self.acc.x += self.vel.x * PLAYER_FRICTION
  34.  
  35.  
  36. # equations of motion
  37. self.vel += self.acc
  38. self.pos += self.vel + 0.5 * self.acc
  39. # wrap around the sides of the screen
  40. if self.pos.x > WIDTH:
  41. self.pos.x = 0
  42. if self.pos.x < 0:
  43. self.pos.x = WIDTH
  44.  
  45.  
  46. self.rect.midbottom = self.pos
  47.  
  48. class Platform(pg.sprite.Sprite):
  49. def __init__(self, x, y, w, h):
  50. pg.sprite.Sprite.__init__(self)
  51. self.image = pg.Surface((w, h))
  52. self.image.fill(GREEN)
  53. self.rect = self.image.get_rect()
  54. self.rect.x = x
  55. self.rect.y = y
Advertisement
Add Comment
Please, Sign In to add comment