Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4.  
  5. DISPLAY_WIDTH = 700
  6. DISPLAY_HEIGHT = 600
  7.  
  8. screen = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
  9. TICK_COUNT = 60 # per second
  10.  
  11. class Player(object):
  12. def __init__(self, color, x, y, vx = 0, vy = 0):
  13. self._x = x
  14. self._y = y
  15. self._vx = vx #/ float(TICK_COUNT)
  16. self._vy = vy #/ float(TICK_COUNT)
  17. self.color = color
  18. def show(self):
  19. pass
  20. def updateState(self):
  21. #print "UPDATe STATE BEGIN", self._x, self._y
  22. self._x += self._vx / (float(TICK_COUNT)/60)
  23. self._y += self._vy / (float(TICK_COUNT)/60)
  24. #print "UPDATe STATE END", self._x, self._y
  25. def handle(event_key):
  26. pass
  27.  
  28. class Quad(Player):
  29. def __init__(self, color, x, y, width, height, vx = 0, vy = 0):
  30. self._width = width
  31. self._height = height
  32. Player.__init__(self, color, x, y, vx, vy)
  33. def show(self):
  34. pygame.draw.rect(screen, self.color, pygame.Rect(self._x, self._y, self._width, self._height))
  35. def getV(self):
  36. return self._vx, self._vy
  37. def setV(self, vx, vy):
  38. self._vx = vx
  39. self._vy = vy
  40. def getPos(self):
  41. return self._x, self._y
  42. def setPos(self, x, y):
  43. self._x = x
  44. self._y = y
  45.  
  46. def handle_keydown(self, event_key):
  47. if event_key == pygame.K_s:
  48. self._vy += 2
  49. elif event_key == pygame.K_w:
  50. self._vy -= 2
  51. elif event_key == pygame.K_d:
  52. self._vx += 2
  53. elif event_key == pygame.K_a:
  54. self._vx -= 2
  55. elif event_key == pygame.K_e:
  56. self._width *= 2
  57. self._height *= 2
  58. elif event_key == pygame.K_q:
  59. self._width /= 2
  60. self._height /= 2
  61.  
  62. def handle_keyup(self, event_key):
  63. if event_key == pygame.K_s:
  64. self._vy -= 2
  65. elif event_key == pygame.K_w:
  66. self._vy += 2
  67. elif event_key == pygame.K_d:
  68. self._vx -= 2
  69. elif event_key == pygame.K_a:
  70. self._vx += 2
  71.  
  72. def updateState(self):
  73. #print "UPDATe STATE BEGIN", self._x, self._y
  74. self._x += self._vx / (float(TICK_COUNT)/60)
  75. if self._x <= 0 :
  76. self._x=0
  77. if self._x>=DISPLAY_WIDTH - self._width:
  78. self._x=DISPLAY_WIDTH - self._width
  79.  
  80.  
  81. self._y += self._vy / (float(TICK_COUNT)/60)
  82. if self._y <= 0 :
  83. self._y=0
  84. if self._y >= DISPLAY_HEIGHT-self._height:
  85. self._y=DISPLAY_HEIGHT-self._height
  86. self._vy = 0.0
  87. else:
  88. self._vy += 0.02
  89.  
  90. #self._y += self._vy / (float(TICK_COUNT)/60)
  91.  
  92. self._vy += 0.05
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement