Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import sys, os, time, random, pygame, math, socket
  2. from pygame.locals import *
  3. from load_image import load_image
  4.  
  5. pygame.init()
  6.  
  7. # This is to replace the gmk "all" and also to update everything.
  8. global globalGameObjectList
  9. globalGameObjectList = []
  10.  
  11.  
  12. # All drawing should be done on the globalSurface object
  13. global globalWindow, globalScreen
  14.  
  15. globalWindow = pygame.display.set_mode((1280, 1024))
  16. globalSurface = pygame.display.get_surface()
  17.  
  18.  
  19. global globalXview, globalYview, globalWview, globalHview
  20.  
  21. globalXview, globalYview = 0, 0
  22. globalWview = 800
  23. globalHview = 600
  24.  
  25.  
  26. class GameObject(pygame.sprite.Sprite):
  27.  
  28. def __init__(self, xpos, ypos):
  29.  
  30. pygame.sprite.Sprite.__init__(self)
  31.  
  32. self.x = xpos
  33. self.y = ypos
  34.  
  35. self.hspeed = 0
  36. self.vspeed = 0
  37.  
  38. self.sprite = 0
  39.  
  40. globalGameObjectList.append(self)
  41.  
  42.  
  43. def BeginStep(self):
  44.  
  45. pass
  46.  
  47.  
  48. def Step(self):
  49.  
  50. pass
  51.  
  52.  
  53. def EndStep(self):
  54.  
  55. self.x += self.hspeed
  56. self.y += self.vspeed
  57.  
  58. def Draw(self):
  59.  
  60. globalSurface.blit(self.sprite, (self.rect.topleft[0]-globalXview, self.rect.topleft[1]-globalYview))
  61.  
  62.  
  63.  
  64. class MapObject(GameObject):
  65.  
  66. def __init__(self):
  67.  
  68. GameObject.__init__(self, 0, 0)
  69.  
  70. self.sprite, self.rect = load_image('Sprites/Maps/MapTesting2.png')
  71.  
  72.  
  73.  
  74. class Character(GameObject):
  75.  
  76. def __init__(self):
  77.  
  78. GameObject.__init__(self, 200, 200)
  79.  
  80. self.sprite, self.rect = load_image('Sprites/Characters/Scout/Red/ScoutRedS_fr1.png')
  81.  
  82. self.rect.center = (self.x, self.y)
  83.  
  84.  
  85. def Step(self):
  86.  
  87. self.y += 2
  88. self.rect.center = (self.x, self.y)
  89.  
  90.  
  91.  
  92. gameMap = MapObject()
  93.  
  94. global globalMyself
  95. globalMyself = Character()
  96.  
  97. while True:
  98.  
  99. print globalXview
  100.  
  101. for a in range(len(globalGameObjectList)):
  102.  
  103. globalGameObjectList[a].BeginStep()
  104.  
  105. for a in range(len(globalGameObjectList)):
  106.  
  107. globalGameObjectList[a].Step()
  108.  
  109. for a in range(len(globalGameObjectList)):
  110.  
  111. globalGameObjectList[a].EndStep()
  112.  
  113. globalXview = globalMyself.x-globalWview/2
  114. globalYview = globalMyself.y-globalHview/2
  115.  
  116. globalSurface.fill((255, 255, 255))
  117.  
  118. for a in range(len(globalGameObjectList)):
  119.  
  120. globalGameObjectList[a].Draw()
  121.  
  122. pygame.display.flip()
Add Comment
Please, Sign In to add comment