Advertisement
Guest User

Untitled

a guest
May 14th, 2010
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.70 KB | None | 0 0
  1. from pygame import Color
  2. import sys
  3. import pygame
  4. import random
  5.  
  6. class DrawGroup(pygame.sprite.Group):
  7.         def draw(self):
  8.                 sprites = self.sprites()
  9.  
  10.                 for sprite in sprites:
  11.                         sprite.draw()
  12.  
  13. class CelestialObject(pygame.sprite.Sprite):
  14.         def __init__(self, screen, color,xloc, yloc, radius, mass, orbit_rect):
  15.                 pygame.sprite.Sprite.__init__(self)
  16.                 self.screen = screen
  17.                 self.color=color
  18.                 self.xloc = xloc
  19.                 self.yloc = yloc
  20.                 self.radius = radius
  21.                 self.mass = mass
  22.                 self.orbit_rect = orbit_rect
  23.                 self.target = None
  24.                 self.toggle_show_orbit_path = False
  25.  
  26.         def setTarget(self, orbitable):
  27.                 self.target = orbitable
  28.  
  29.         def showOrbitPath(self):
  30.                 self.toggle_show_orbit_path = True
  31.        
  32.         def hideOrbitPath(self):
  33.                 self.toggle_show_orbit_path = False
  34.  
  35.         def update(self, time_passed):
  36.                 if self.target != None:
  37.                         pass
  38.  
  39.         def draw(self):
  40.                 pygame.draw.circle(self.screen, self.color, (self.xloc,self.yloc), self.radius, 0)
  41.  
  42.                 if self.toggle_show_orbit_path == True:
  43.                         #pygame.draw.rect(self.screen, self.color, self.orbit_rect, 1)
  44.                         pygame.draw.ellipse(self.screen, self.color, self.orbit_rect, 1)
  45.  
  46. if __name__ == "__main__":
  47.         SCREEN_AREA = (700, 500)
  48.  
  49.         pygame.init()
  50.         screen = pygame.display.set_mode(SCREEN_AREA, pygame.HWSURFACE) #pygame.FULLSCREEN pygame.HWSURFACE
  51.         pygame.display.set_caption('Running CelestialObject Example, escape to close')
  52.  
  53.         earth = CelestialObject(screen=screen, color=Color('blue'),xloc=300, yloc=200, radius=63, mass=59, orbit_rect = pygame.Rect(-200,-200,1000,400))
  54.         moon = CelestialObject(screen=screen, color=Color('gray'),xloc=500, yloc=200, radius=17, mass=1.1, orbit_rect = pygame.Rect(155,100,355,290))
  55.  
  56.         moon.setTarget(earth)
  57.         moon.showOrbitPath()
  58.  
  59.         celestial_group = DrawGroup((earth,moon))
  60.  
  61.         clock = pygame.time.Clock()
  62.         while 1:
  63.                 time_passed = clock.tick(22)
  64.  
  65.                 for event in pygame.event.get():
  66.                         if event.type == pygame.QUIT:
  67.                                 sys.exit(0)
  68.                         elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
  69.                                 sys.exit(0)
  70.  
  71.                 celestial_group.update(time_passed)
  72.                 celestial_group.draw()
  73.  
  74.                 pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement