diff options
author | Gabriel Eirea <geirea@gmail.com> | 2011-01-13 17:23:00 (GMT) |
---|---|---|
committer | Gabriel Eirea <geirea@gmail.com> | 2011-01-13 17:23:00 (GMT) |
commit | 6a906bb7a07c397863d8c2766a5e2dd26c169823 (patch) | |
tree | f57aee56fba9b5b697d33385c56d88cbacd212dd | |
parent | 59fdf0ab04401e43090b64a4086544a5d5ffce17 (diff) |
Improved talk_range graphics
-rw-r--r-- | AnimatedSprite.py | 16 | ||||
-rw-r--r-- | AnimatedSprite.pyc | bin | 3013 -> 3483 bytes | |||
-rw-r--r-- | DerechosSprites.py | 52 | ||||
-rw-r--r-- | images/spacebar.png | bin | 0 -> 568 bytes | |||
-rw-r--r-- | images/spacebar.svg | 113 |
5 files changed, 164 insertions, 17 deletions
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 Binary files differindex df3ae63..85c3645 100644 --- a/AnimatedSprite.pyc +++ b/AnimatedSprite.pyc 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 Binary files differnew file mode 100644 index 0000000..cfc1121 --- /dev/null +++ b/images/spacebar.png 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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="210mm" + height="297mm" + id="svg2" + version="1.1" + inkscape:version="0.47 r22583" + sodipodi:docname="Nuevo documento 1"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + <inkscape:perspective + id="perspective2828" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3622" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="0.7" + inkscape:cx="146.42857" + inkscape:cy="522.96958" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1278" + inkscape:window-height="780" + inkscape:window-x="0" + inkscape:window-y="18" + inkscape:window-maximized="0" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Capa 1" + inkscape:groupmode="layer" + id="layer1"> + <rect + style="fill:#333333;fill-opacity:1;stroke:#707070;stroke-width:0.20591851;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect2816-4" + width="391.42856" + height="75.718628" + x="312.65515" + y="420.47079" + ry="18.172468" + transform="matrix(1,0,-0.33182143,0.94334222,0,0)" /> + <rect + style="fill:#00d200;fill-opacity:1;stroke:#707070;stroke-width:0.20591851;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect2816" + width="391.42856" + height="75.718628" + x="301.19818" + y="385.94321" + ry="18.172468" + transform="matrix(1,0,-0.33182143,0.94334222,0,0)" /> + <rect + style="fill:#333333;fill-opacity:1;stroke:#707070;stroke-width:0.20591851;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect2816-4-7" + width="391.42856" + height="75.718628" + x="357.57892" + y="555.85571" + ry="18.172468" + transform="matrix(1,0,-0.33182143,0.94334222,0,0)" /> + <rect + style="fill:#00d200;fill-opacity:1;stroke:#707070;stroke-width:0.20591851;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect2816-44" + width="391.42856" + height="75.718628" + x="351.74991" + y="538.28906" + ry="18.172468" + transform="matrix(1,0,-0.33182143,0.94334222,0,0)" /> + </g> +</svg> |