From dcd41228d70087af8748d70db29f25b83a524134 Mon Sep 17 00:00:00 2001 From: Alan Aguiar Date: Tue, 29 Oct 2013 01:21:21 +0000 Subject: bigger horse in each eat time --- diff --git a/horse.py b/horse.py index e1e588a..692d909 100755 --- a/horse.py +++ b/horse.py @@ -46,7 +46,8 @@ class Game(): # images / (type pygame Surface) self.background = None self.grass_image = None - self.horse_image = None + self.horse_image_o = None + self.horse_image_r = None self.horse_image_l = None self.moving_left = False self.apple_image = None @@ -71,11 +72,12 @@ class Game(): self.grass_image = pygame.image.load('images/grass.png','grass') 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(self.screen) - self.horse_size = self.horse_image.get_size() + self.horse_image_o = pygame.image.load('images/horse.png','horse') + self.horse_image_o.convert(self.screen) + self.horse_size = self.horse_image_o.get_size() # Make a copy for the left-facing image - self.horse_image_l=pygame.transform.flip(self.horse_image,True,False) + self.horse_image_r = self.horse_image_o.copy() + self.horse_image_l = pygame.transform.flip(self.horse_image_r, True, False) # Make the edibles self.apple_size = (10,10) self.apple_image = pygame.Surface(self.apple_size, 0, self.screen) @@ -106,25 +108,40 @@ class Game(): self.drawObject(o) if self.moving_left: - self.drawObject((self.horse_image_l, self.horse_loc)) + self.drawObject((self.horse_image_l, self.horse_loc, 'hh')) else: - self.drawObject((self.horse_image, self.horse_loc)) + self.drawObject((self.horse_image_r, self.horse_loc, 'hh')) # flip display buffer pygame.display.flip() + + def bigger_horse(self, t): + x, y = self.horse_image_r.get_size() + if t == 'a': + x = x + 2 + y = y + 2 + elif t == 'c': + x = x + 4 + y = y + 4 + elif t == 'h': + x = x + 8 + y = y + 8 + self.horse_image_r = pygame.transform.scale(self.horse_image_o, (x, y)) + self.horse_image_l = pygame.transform.flip(self.horse_image_r, True, False) + self.horse_size = self.horse_image_r.get_size() def drawObject(self, o): # unpack the object - (image, loc) = o + (image, loc, t) = 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) self.screen.blit(image, adj_loc) - def placeObject(self, image, location): + def placeObject(self, image, location, t): #adj_loc = self.adjust_loc(location, image.get_size()) #adj_loc = location - self.objects.append((image, location)) + self.objects.append((image, location, t)) 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""" @@ -138,14 +155,14 @@ class Game(): #if event.key in (27,113): # esc or q=quit # self.game_running = False if event.key == 97: # a=apple - self.placeObject(self.apple_image, self.mouse_pos) + self.placeObject(self.apple_image, self.mouse_pos, 'a') elif event.key == 99: # c=carrot - self.placeObject(self.carrot_image, self.mouse_pos) + self.placeObject(self.carrot_image, self.mouse_pos, 'c') elif event.key == 104: # h=hay - self.placeObject(self.hay_image, self.mouse_pos) + self.placeObject(self.hay_image, self.mouse_pos, 'h') elif event.type == pygame.MOUSEBUTTONDOWN: # place apples - self.placeObject(self.apple_image, self.mouse_pos) + self.placeObject(self.apple_image, self.mouse_pos, 'a') elif event.type == pygame.MOUSEMOTION: # Remember mouse location, because we need it in KEYDOWN events self.mouse_pos = event.pos @@ -155,7 +172,7 @@ class Game(): # millis is ignored if len(self.objects)>0: # move the horse toward the first object in the queue, at full speed - (target_image,target_loc) = self.objects[0] + (target_image, target_loc, t) = self.objects[0] horse_speed = self.horse_speed else: # the horse might feel inclined to wander slowly toward a random target @@ -178,7 +195,8 @@ class Game(): # TODO: perhaps colision detection would be better here if dist < self.horse_speed*2: if len(self.objects)>0: - self.objects.pop(0) + t = self.objects.pop(0) + self.bigger_horse(t[2]) else: self.target_loc = None # dont move the horse (causes bounce) -- cgit v0.9.1