From 6a906bb7a07c397863d8c2766a5e2dd26c169823 Mon Sep 17 00:00:00 2001 From: Gabriel Eirea Date: Thu, 13 Jan 2011 17:23:00 +0000 Subject: Improved talk_range graphics --- diff --git a/AnimatedSprite.py b/AnimatedSprite.py index 48a5236..76960c8 100644 --- a/AnimatedSprite.py +++ b/AnimatedSprite.py @@ -35,6 +35,7 @@ class AnimatedSprite(pygame.sprite.Sprite): self.move = 0 self.image = self._images[self._frames[self._frame]] + (self.width, self.height) = self.image.get_size() # assuming same size 4 all # self.update(pygame.time.get_ticks()) @@ -51,7 +52,10 @@ class AnimatedSprite(pygame.sprite.Sprite): screen.blit(self.image, (self.x, self.y)) def do_move(self, grid): - pass + # by default, update according to sequence, override for more complex stuff + self.x += self._dxs[self._frame] + self.y += self._dys[self._frame] + self._frame = self._next_frames[self._frame] def update_frame(self, fr): self._frame = fr @@ -60,11 +64,17 @@ class AnimatedSprite(pygame.sprite.Sprite): self.move = move def upper_left_tile(self): - return ( (self.x+34)/50, (self.y+16)/50 ) + return ( self.x/50, self.y/50 ) def draw_rect(self, screen): - pygame.draw.rect(screen,(0,0,0),(self.x+15, self.y+38, 38, 38),1) + pygame.draw.rect(screen,(0,0,0),self.collision_rect(),1) + def collision_rect(self): + # by default use the same as image, override for more accurate collisions + return self.rect() + + def rect(self): + return (self.x, self.y, self.width, self.height) if __name__ == "__main__": diff --git a/AnimatedSprite.pyc b/AnimatedSprite.pyc index df3ae63..85c3645 100644 --- a/AnimatedSprite.pyc +++ b/AnimatedSprite.pyc Binary files differ diff --git a/DerechosSprites.py b/DerechosSprites.py index 92e0341..1d383ec 100644 --- a/DerechosSprites.py +++ b/DerechosSprites.py @@ -78,6 +78,9 @@ class MainSprite(AnimatedSprite): elif self.move == TALKING: pass + def collision_rect(self): + return (self.x+15, self.y+38, 38, 38) + class BoySprite(AnimatedSprite): """ @@ -192,18 +195,14 @@ class BoySprite(AnimatedSprite): elif self.move == RIGHT: self._frame = 24 - def draw_talking_range(self, screen): - pygame.draw.arc(screen, (200, 0, 0), (self.x+9, self.y, 48, 48), - -math.pi/4, math.pi/4, 2) - pygame.draw.arc(screen, (200, 0, 0), (self.x+9, self.y, 48, 48), - math.pi/4*3, math.pi/4*5, 2) - def draw_talking(self, screen): pygame.draw.arc(screen, (0, 0, 200), (self.x+9, self.y, 48, 48), -math.pi/4, math.pi/4, 2) pygame.draw.arc(screen, (0, 0, 200), (self.x+9, self.y, 48, 48), math.pi/4*3, math.pi/4*5, 2) + def collision_rect(self): + return (self.x+15, self.y+38, 38, 38) def draw_grid(grid,screen): @@ -226,16 +225,13 @@ if __name__ == "__main__": w = int(master_width/4) h = int(master_height/4) for i in xrange(4): - images.append(master_image.subsurface((i*w,0,w,h))) + images.append(master_image.subsurface((i*w, 0, w, h))) for i in xrange(4): - images.append(master_image.subsurface((i*w,h,w,h))) + images.append(master_image.subsurface((i*w, h, w, h))) for i in xrange(4): - images.append(master_image.subsurface((i*w,2*h,w,h))) + images.append(master_image.subsurface((i*w, 2*h, w, h))) for i in xrange(4): - images.append(master_image.subsurface((i*w,3*h,w,h))) - - bg_image = pygame.image.load(os.path.join('images', - 'derechos-plaza-fondo.jpg')).convert_alpha() + images.append(master_image.subsurface((i*w, 3*h, w, h))) fms = [0, 1, 0, 2, 0, 1, 0, 3, # up 4, 5, 4, 6, 4, 5, 4, 7, # down @@ -257,6 +253,27 @@ if __name__ == "__main__": sp = MainSprite(images, fms, nf, dxs, dys, 30, 370, 10) sp2 = BoySprite(images, fms, nf, dxs, dys, 150, 470, 10) + images = [] + master_image = pygame.image.load(os.path.join('images', + 'spacebar.png')).convert_alpha() + master_width, master_height = master_image.get_size() + w = int(master_width) + h = int(master_height/2) + images.append(master_image.subsurface((0, 0, w, h))) + images.append(master_image.subsurface((0, h, w, h))) + fms = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1] + nf = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 0] + dxs = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0] + dys = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0] + sb = AnimatedSprite(images, fms, nf, dxs, dys, 0, 0, 10) + + bg_image = pygame.image.load(os.path.join('images', + 'derechos-plaza-fondo.jpg')).convert_alpha() + grid = [[0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], [0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], [0,0,1,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0], @@ -310,6 +327,8 @@ if __name__ == "__main__": sp.update_move(STOP) sp2.update_move(STOP) print("Not talking...") + elif event.key == pygame.K_ESCAPE: + playing = False elif event.type == pygame.KEYUP: keys_pressed = pygame.key.get_pressed() if event.key == pygame.K_UP and not talking: @@ -379,6 +398,8 @@ if __name__ == "__main__": if ulx-ulx2 >= -1 and ulx-ulx2 <=1 \ and uly-uly2 >= -1 and uly-uly2<=1: talking_range = True + sb.x = sp2.x + 12 + sb.y = sp2.y - 10 else: talking_range = False @@ -390,9 +411,12 @@ if __name__ == "__main__": sp.render(screen) if talking_range and not talking: - sp2.draw_talking_range(screen) + sb.update(time_passed,grid) + sb.render(screen) elif talking: sp2.draw_talking(screen) + +# sp.draw_rect(screen) pygame.display.flip() diff --git a/images/spacebar.png b/images/spacebar.png new file mode 100644 index 0000000..cfc1121 --- /dev/null +++ b/images/spacebar.png Binary files differ diff --git a/images/spacebar.svg b/images/spacebar.svg new file mode 100644 index 0000000..e8c9e8c --- /dev/null +++ b/images/spacebar.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + -- cgit v0.9.1