From 36ba6422ba301aeaa3d1a5a42a821fcf17c3500c Mon Sep 17 00:00:00 2001 From: Alan Aguiar Date: Fri, 25 May 2012 21:25:38 +0000 Subject: some cleans in horse.py --- diff --git a/horse.py b/horse.py index 5808351..74c5b8c 100644 --- a/horse.py +++ b/horse.py @@ -57,29 +57,29 @@ class Game(): self.horse_reach = 20 # pixels from cener of horse where he can reach self.target_loc = None - def setup(self,screen): - self.screen_size = screen.get_size() # tuple + def setup(self): + self.screen_size = self.screen.get_size() # tuple # load the images and convert to screen format self.grass_image = pygame.image.load('images/grass.png','grass') - self.grass_image.convert(screen) + self.grass_image.convert(self.screen) self.grass_size = self.grass_image.get_size() self.horse_image = pygame.image.load('images/horse.png','horse') - self.horse_image.convert(screen) + self.horse_image.convert(self.screen) self.horse_size = self.horse_image.get_size() # Make a copy for the left-facing image self.horse_image_l=pygame.transform.flip(self.horse_image,True,False) # Make the edibles self.apple_size = (10,10) - self.apple_image = pygame.Surface(self.apple_size,0,screen) + self.apple_image = pygame.Surface(self.apple_size, 0, self.screen) self.apple_image.fill((0xff,0,0)) self.carrot_size = (7,20) - self.carrot_image = pygame.Surface(self.carrot_size,0,screen) + self.carrot_image = pygame.Surface(self.carrot_size, 0, self.screen) self.carrot_image.fill((0xff,0x99,0)) self.hay_size = (20,20) - self.hay_image = pygame.Surface(self.hay_size,0,screen) + self.hay_image = pygame.Surface(self.hay_size, 0, self.screen) self.hay_image.fill((0x99,0x66,0x33)) - self.background = pygame.Surface((self.screen_size[0], self.screen_size[1]), 0, screen) + self.background = pygame.Surface((self.screen_size[0], self.screen_size[1]), 0, self.screen) tilex=int(math.ceil(self.screen_size[0]/float(self.grass_size[0]))) tiley=int(math.ceil(self.screen_size[1]/float(self.grass_size[1]))) @@ -87,33 +87,36 @@ class Game(): for y in range(0,tiley): self.background.blit(self.grass_image,(x*self.grass_size[0],y*self.grass_size[1])) - self.update(screen) + self.update() - def update(self,screen): + def update(self): """updates the screen image""" - screen.blit(self.background, (0,0)) - if self.moving_left: - self.drawObject(screen,(self.horse_image_l, self.horse_loc)) - else: - self.drawObject(screen,(self.horse_image, self.horse_loc)) + self.screen.blit(self.background, (0,0)) + # draw apples and other objects for o in self.objects: - self.drawObject(screen, o) + self.drawObject(o) + + if self.moving_left: + self.drawObject((self.horse_image_l, self.horse_loc)) + else: + self.drawObject((self.horse_image, self.horse_loc)) + # flip display buffer pygame.display.flip() - def drawObject(self, screen, o): + def drawObject(self, o): # unpack the object (image, loc) = o object_size = image.get_size() # adjust the upper left corner so that the center of object is at the recorded location adj_loc = (loc[0]-object_size[0]/2,loc[1]-object_size[1]/2) - screen.blit(image, adj_loc) + self.screen.blit(image, adj_loc) def placeObject(self, image, location): #adj_loc = self.adjust_loc(location, image.get_size()) - adj_loc = location - self.objects.append((image, adj_loc)) + #adj_loc = location + self.objects.append((image, location)) def adjust_loc(self,loc,object_size): """adjust the given location by half the object size. Thus the center of the object will be at loc""" @@ -190,36 +193,22 @@ class Game(): self.moving_left = True else: self.moving_left = False - - def isRunning(self): - return self.game_running - def run(self): - #size = (1200,900) - #size = (16*75,11*75) - #if olpcgames.ACTIVITY: - # size = olpcgames.ACTIVITY.game_size - #screen = pygame.display.set_mode(size) - screen = pygame.display.get_surface() + self.screen = pygame.display.get_surface() clock = pygame.time.Clock() - #g = Game() - self.setup(screen) - self.mouse_pos = pygame.mouse.get_pos() + self.setup() - while self.isRunning(): + while self.game_running: #GTK events while gtk.events_pending(): gtk.main_iteration() # tick with wait 1/25th of a second - milliseconds = clock.tick(25) # maximum number of frames per second + milliseconds = clock.tick(25) self.tick(milliseconds) - self.update(screen) - - # Event processing loop - # not sure i want the pausescreen behavior - #events = pausescreen.get_events() + self.update() + events = pygame.event.get() for event in events: self.handleEvent(event) -- cgit v0.9.1