From d09d6fe3fbf6dd1342bda889827e0eaef333183f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mart=C3=ADnez=20Mart=C3=AD?= Date: Mon, 2 Jun 2008 23:31:56 +0200 Subject: [PATCH] Agregado disparo para Tajundra --- qwesprites.py | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sprites.py | 137 --------------------------- stage.py | 27 ++++++ stage.pyc | Bin 3859 -> 4426 bytes stage1.st | 28 +++--- stage2.st | 27 ++++++ stage3.st | 27 ++++++ taju.py | 41 +++++---- 8 files changed, 410 insertions(+), 167 deletions(-) create mode 100644 qwesprites.py delete mode 100644 sprites.py create mode 100644 stage2.st create mode 100644 stage3.st diff --git a/qwesprites.py b/qwesprites.py new file mode 100644 index 0000000..957828d --- /dev/null +++ b/qwesprites.py @@ -0,0 +1,290 @@ +# Quick W Engine +# encoding: UTF-8 +import pygame + + +class qweSprite(pygame.sprite.Sprite): + dx=dy=x=y=0 + w=h=32 + alive=True + in_ground=False + FRICTION_AIR=(0.2,0.2) + FRICTION_FLOOR=(8,8) + FRICTION_CEIL=(1,4) + GRAVITY=5 + BOUNCE=0 + + + def __init__(self, stage): + pygame.sprite.Sprite.__init__(self) + + def move(self,x,y): + self.x+=x + self.y+=y + + self.rect=self.x,self.y,self.w,self.h + + def selectImage(self): + return self.image + + def draw(self,screen): + screen.blit(self.selectImage(), self.rect) + + def tickms(self, ms, stage): + rect1=pygame.Rect(self.rect) + + self.checkpos(stage,ms) + self.move(self.dx*ms/1000.0,self.dy*ms/1000.0) + self.dx/=1+self.FRICTION_AIR[0]*ms/1000.0 + self.dy/=1+self.FRICTION_AIR[1]*ms/1000.0 + + rect2=self.rect + + return [rect1.union(rect2)] + + + def checkcell(self,stage,px,py): + sx,sy=stage.BlockSize + x,y,w,h=self.rect + Pantalla=stage.StageData + + if px>0: x0=x+px + elif px<0: x0=x+w+px + else: x0=x+w/2 + + if py>0: y0=y+py + elif py<0: y0=y+h+py + else: y0=y+h/2 + + + x0=int(x0)/sx + y0=int(y0)/sy + if y0<0 and x0>=0 and x0=0 and y0=0 and x0=0) or + (self.checkcell(stage,-9,12)!=' ' and self.dx>=0) or + (self.checkcell(stage,-9,-12)!=' ' and self.dx>=0) ) : + self.move(-self.dx*ms/1000.0-.1,0) + if (self.BOUNCE>0): self.dx*=-self.BOUNCE + else: self.dx/=1-self.BOUNCE + + if ( (self.checkcell(stage,+6,0)!=' ' and self.dx<=0) or + (self.checkcell(stage,+9,12)!=' ' and self.dx<=0) or + (self.checkcell(stage,+9,-12)!=' ' and self.dx<=0) ) : + self.move(-self.dx*ms/1000.0+.1,0) + if (self.BOUNCE>0): self.dx*=-self.BOUNCE + else: self.dx/=1-self.BOUNCE + + #if ( (self.checkcell(stage,-4,0)!=' ' and self.dx>0) or + # (self.checkcell(stage,+4,0)!=' ' and self.dx<0) ) : + # self.dx/=1+5*ms/1000.0 + + + # Control de hundimiento + if self.dy>=0: + if (self.checkcell(stage,+12,-3)!=' ' + or self.checkcell(stage,-12,-3)!=' '): + self.move(0,-1) + + # Colisión de techo + elif self.checkcell(stage,0,+1)!=' ' and self.dy<0: + self.move(0,-self.dy*ms/1000.0) + if (self.BOUNCE>0): self.dy*=-self.BOUNCE + else: self.dy/=1-self.BOUNCE + self.dx/=1+self.FRICTION_CEIL[0]*ms/1000.0 + self.dy/=1+self.FRICTION_CEIL[1]*ms/1000.0 + if self.checkcell(stage,0,+2)!=' ' and self.dy<0: + self.dx/=1+self.FRICTION_CEIL[0]*ms/1000.0 + self.dy/=1+self.FRICTION_CEIL[1]*ms/1000.0 + if self.checkcell(stage,0,+3)!=' ' and self.dy<0: + self.dy=0 + + + + # Gravedad + if (self.checkcell(stage,+10,-1)==' ' + and self.checkcell(stage,-10,-1)==' '): + self.dy+=self.GRAVITY + self.in_ground=False + + # Colisión suelo + if (self.checkcell(stage,+10,-2)!=' ' + or self.checkcell(stage,-10,-2)!=' '): + self.dx/=1+self.FRICTION_FLOOR[0]*ms/1000.0 + if self.dy>0: + if (self.BOUNCE>0): self.dy*=-self.BOUNCE + else: self.dy/=1-self.BOUNCE + self.dy/=1+self.FRICTION_FLOOR[1]*ms/1000.0 + self.move(0,-self.dy*ms/1000.0) + + elif self.dy<0: + pass + + self.in_ground=True + + +class Tajundra(qweSprite): + image_flip=None + estado=0 + estado_ms=0 + + def __init__(self, stage): + + qweSprite.__init__(self,stage) + self.image_right = pygame.image.load('tajuA1.png') + self.image_left=pygame.transform.flip(self.image_right,True,False) + + self.imageb_right = pygame.image.load('tajuA2.png') + self.imageb_left=pygame.transform.flip(self.imageb_right,True,False) + + + self.image=self.image_right + self.rect = self.image.get_rect() + pos=stage.simbolos['@'][0] + del stage.simbolos['@'][0] + self.rect.bottomright = pos + self.rect=self.rect.move(stage.BlockSize) + self.x,self.y,self.w,self.h=self.rect + + def selectImage(self): + dx=self.dx + if self.estado==0: + if dx<0: + self.image=self.image_left + else: + self.image=self.image_right + else: + if dx<0: + self.image=self.imageb_left + else: + self.image=self.imageb_right + self.estado_ms+=1 + if self.estado_ms>20: + self.estado_ms=0 + if self.estado==0: + self.estado=1 + else: + self.estado=0 + return self.image + + + + + +class Dragon(qweSprite): + image_flip=None + estado=0 + estado_ms=0 + + def __init__(self, stage): + + qweSprite.__init__(self,stage) + self.image_left = pygame.image.load('dragonN1.png') + self.image_right=pygame.transform.flip(self.image_left,True,False) + + self.imageb_left = pygame.image.load('dragonN2.png') + self.imageb_right=pygame.transform.flip(self.imageb_left,True,False) + + + self.image=self.image_right + self.rect = self.image.get_rect() + pos=stage.simbolos['$'][0] + del stage.simbolos['$'][0] + + self.rect.bottomright = pos + self.rect=self.rect.move(stage.BlockSize) + self.x,self.y,self.w,self.h=self.rect + + def selectImage(self): + dx=self.dx + if self.estado==0: + if dx<0: + self.image=self.image_left + else: + self.image=self.image_right + else: + if dx<0: + self.image=self.imageb_left + else: + self.image=self.imageb_right + self.estado_ms+=1 + if self.estado_ms>20: + self.estado_ms=0 + if self.estado==0: + self.estado=1 + else: + self.estado=0 + return self.image + + + +class qweShoot(qweSprite): + estado=0 + estado_ms=0 + FRICTION_AIR=(1.0,0.0) + FRICTION_FLOOR=(0.0,0.0) + FRICTION_CEIL=(0.0,0.0) + GRAVITY=5 + BOUNCE=.8 + Life=3.0 + fcount=0 + + def __init__(self, stage, pos,dx,dy): + + qweSprite.__init__(self,stage) + self.image = pygame.image.load('hacha1.png') + if dx<0: self.image =pygame.transform.flip(self.image, True, False) + + self.rect = self.image.get_rect() + + self.rect.topleft = pos + self.dx=dx + self.dy=dy + self.x,self.y,self.w,self.h=self.rect + + def tickms(self, ms, stage): + + if (self.Life<0): self.alive=False + else: self.Life-=ms/1000.0 + return qweSprite.tickms(self, ms, stage) + + def draw(self,screen): + self.fcount+=1 + if self.fcount>10/(self.Life+1): + self.fcount=4 + screen.blit(self.selectImage(), self.rect) + + +class Hacha(qweShoot): + FRICTION_AIR=(1.0,0.0) + BOUNCE=.8 + Life=3.0 + fcountrot=0 + angle=0 + + def __init__(self, stage, pos,dx,dy): + + qweSprite.__init__(self,stage) + self.image1 = pygame.image.load('hacha1.png') + self.image = self.image1.copy() + self.rect = self.image.get_rect() + + self.rect.topleft = pos + self.dx=dx + self.dy=dy + self.x,self.y,self.w,self.h=self.rect + + def draw(self,screen): + self.fcountrot+=1 + if self.fcountrot>5/self.Life: + self.image=pygame.transform.rotate(self.image1, self.angle) + self.angle-=90 + self.fcountrot=0 + qweShoot.draw(self,screen) diff --git a/sprites.py b/sprites.py deleted file mode 100644 index 8d1b40a..0000000 --- a/sprites.py +++ /dev/null @@ -1,137 +0,0 @@ -# encoding: UTF-8 -import pygame - -class Tajundra(pygame.sprite.Sprite): - stage=None - image_flip=None - dx=0 - dy=0 - x=y=0 - w=h=32 - estado=0 - estado_ms=0 - in_ground=False - - def __init__(self, stage): - self.stage=stage - - pygame.sprite.Sprite.__init__(self) - self.image_right = pygame.image.load('tajuB1.png') - self.image_left=pygame.transform.flip(self.image_right,True,False) - - self.imageb_right = pygame.image.load('tajuB-salta1.png') - self.imageb_left=pygame.transform.flip(self.imageb_right,True,False) - - - self.image=self.image_right - self.rect = self.image.get_rect() - pos=self.stage.simbolos['@'][0] - self.rect.bottomright = pos - self.rect=self.rect.move(self.stage.BlockSize) - self.x,self.y,self.w,self.h=self.rect - - def setDir(self): - dx=self.dx - if self.estado==0: - if dx<0: - self.image=self.image_left - else: - self.image=self.image_right - else: - if dx<0: - self.image=self.imageb_left - else: - self.image=self.imageb_right - - - def move(self,x,y): - self.x+=x - self.y+=y - - self.rect=self.x,self.y,self.w,self.h - - def draw(self,screen): - self.setDir() - screen.blit(self.image, self.rect) - - def tick(self, fps): - ms=1000.0/fps - self.tickms(ms) - - def tickms(self, ms): - self.checkpos(ms) - self.move(self.dx*ms/1000.0,self.dy*ms/1000.0) - self.dx/=1+0.1*ms/1000.0 - self.dy/=1+0.1*ms/1000.0 - - - def checkcell(self,px,py): - sx,sy=self.stage.BlockSize - x,y,w,h=self.rect - Pantalla=self.stage.StageData - - if px>0: x0=x+px - elif px<0: x0=x+w+px - else: x0=x+w/2 - - if py>0: y0=y+py - elif py<0: y0=y+h+py - else: y0=y+h/2 - - - x0=int(x0)/sx - y0=int(y0)/sy - if y0<0 and x0>=0 and x0=0 and y0=0 and x00) or - (self.checkcell(+4,0)!=' ' and self.dx<0) ) : - self.dx/=1+20*ms/1000.0 - - # Colisión Horizontal - if ( (self.checkcell(-8,0)!=' ' and self.dx>0) or - (self.checkcell(+8,0)!=' ' and self.dx<0) ) : - self.dx/=1+10*ms/1000.0 - self.move(-self.dx*ms/1000.0,0) - - # Control de hundimiento - if self.dy>=0: - if self.checkcell(+12,-3)!=' ' or self.checkcell(-12,-3)!=' ': - self.move(0,-1) - t_estado=1 - - # Colisión de techo - elif self.checkcell(0,+1)!=' ' and self.dy<0: - self.move(0,-self.dy*ms/1000.0) - self.dy/=1.1 - - # Gravedad - if self.checkcell(+10,-1)==' ' and self.checkcell(-10,-1)==' ': - self.dy+=5 - self.in_ground=False - - # Colisión suelo - if self.checkcell(+10,-2)!=' ' or self.checkcell(-10,-2)!=' ': - self.dx/=1.15 - if self.dy>0: - self.dy/=1.02 - self.move(0,-self.dy*ms/1000.0) - - elif self.dy<0: - t_estado=1 - - self.in_ground=True - - if self.estado!=t_estado and self.estado_ms>100: - self.estado=t_estado - self.estado_ms=0 - else: - self.estado_ms+=ms - - diff --git a/stage.py b/stage.py index c6f3bd2..c3ca7bf 100644 --- a/stage.py +++ b/stage.py @@ -19,6 +19,33 @@ class Stage: listasimbolos="!·$%&/()=|@#~" Surface=None + sprites=[] + + def fulldraw(self,screen,msec): + v_rect=[] + for sprite in self.sprites: + v_rect+=sprite.tickms(msec,self) + + + for rect in v_rect: + self.draw(screen,rect) + + keys=[] + lensp=len(self.sprites)-1 + for key,sprite in enumerate(reversed(self.sprites)): + if sprite.alive: + sprite.draw(screen) + else: + del self.sprites[lensp-key] + + #for key in keys: + # del self.sprites[key] + + for rect in v_rect: + pygame.display.update(rect) + + + def draw(self,screen,rect=None): if not self.Surface: self.Surface=screen.copy() diff --git a/stage.pyc b/stage.pyc index 64e7fe9759485058b91168d6e8b636ac6dc8e0c8..d47c5b7ddc21d5823eef01ef922fcb4c58949536 100644 GIT binary patch delta 999 zcwSXeO=}ZT6g_W}nPeuDw6zjyk*IAkQTsuyrbw|M21KbsUxYwyk)iVpLz6b0nbs5% zDzyJ#z_o(7RsNl-IJMl-jcHzCRejv;o?zUr)-^8)NS{}Zoodx(AZ45!yD^BvpxO`|67yq~E zkG>NSO+STh89g8XY8z+KPotMYFO5K;XK>)iz#?Vs4x`a6aj>>gMBmgklt5`F=ZM`! zG?>srocc|8M5+bG`WbXr5Fe%yoBty8)i$nU-9SI9+fq*pJ0lQmX=X|hyU)m>YkC>< zvKYHbp8u7^83b7bwpPL=AJOoEdc~j_AJ8B`#Q_dEktXkiL9C+KB0CN?x7tyhCeshS zrz9L`sqL7zq_+3kD)eF%XXzEHeHBK^rwIVB73?cb&^c&&ZKZkrAnLTd1MS}H_*7V7 z8map*BtO%+<#wbt^=toeNR~EF6loRO$HtaAh;%QK6LqvOawVQvSa`D6YO&feE}bBN zu!I9kjHfb$rwvPtiXvR$h!NwI$-co?X9WX%tn=8Ked zjw9!jyuBOCup7#y8QS*Z~y0+dE1v2GyTmwnUC|Od11J>03ZPR1R_&j8||6} zeFq{7qAbh_^ch4sn5zaCBC16mc&~2DmC;DIb1T9Usw^I#hvB`DU$j@$@pKRiF-fvY z#$u4juE`x8MRE8Pq|$uJP*;UKFFWj%1aihIR+3Sfv6#pOJ7hjqHxMQH&f;oW$;7~G zXSz?!T6_n~yNHThdad<_@k1Cj(}nv<4oWH<0fJytfEJEIFA0a@YLtux_vNDSN=h>H zwtTGf6GRi?%ehyhRg`6A-_9K=c_+WUv&#Y|ErhKv)b0P%+NX%9BWeg-%k|hEqKiPk lI-qrjDT)6v#aT)yu?f=Eq=p;V$LIxX;4}Fqq9K3$n?Gh@Q8oYo diff --git a/stage1.st b/stage1.st index 2a15352..a669a96 100644 --- a/stage1.st +++ b/stage1.st @@ -11,17 +11,17 @@ %StageData 20 15 [ ] -[t @ t ] -[t tb b V ] -[tb t br trb] -[tb R t tt] -[trtrtr t rrt rtt] -[t t ] -[t trtrt bb N ] -[t ttt b rtt] -[t t tb t] -[trtrt trttb rt t] -[ ttttb trt] -[ trtrrt t] -[ btrtrtrt] -[trtrtrtrtrtrb ] +[ @ b ] +[ @ b b] +[ttttttttttttt bbb ] +[ $ b] +[b bbbbbbb b] +[ b ] +[bbbbb bbbbb ] +[ $ b ] +[b bbbb bbbb ] +[ b ] +[b bbb bbb b] +[bb bb] +[bbb NN VV RR bbb] +[bbbbbbbttttttbbbbbbb] diff --git a/stage2.st b/stage2.st new file mode 100644 index 0000000..cfb45e9 --- /dev/null +++ b/stage2.st @@ -0,0 +1,27 @@ +%BlockSize 32 32 +%Texture B dragonN1.png + +%Texture N dragonN1.png +%Texture R dragonR1.png +%Texture V dragonV2.png +%Texture b pedrusco1.png +%Texture t tierra1.png +%Texture r tierra2.png +%StageTitle Prueba1 + +%StageData 20 15 +[ ] +[t@tb t ] +[t tb b b ] +[tb b br b] +[tb R tb $ tt] +[trtrt t brrt rtt] +[t btb ] +[t trtrt bbb N ] +[t ttt bb rtt] +[t b t tt b t] +[trtrt trt rt V t] +[ btttt trt] +[ trtrrt bb ] +[bb @ ttrtrbtrtb ] +[trtr bb] diff --git a/stage3.st b/stage3.st new file mode 100644 index 0000000..7720eac --- /dev/null +++ b/stage3.st @@ -0,0 +1,27 @@ +%BlockSize 32 32 +%Texture B dragonN1.png + +%Texture N dragonN1.png +%Texture R dragonR1.png +%Texture V dragonV2.png +%Texture b pedrusco1.png +%Texture t tierra1.png +%Texture r tierra2.png +%StageTitle Prueba1 + +%StageData 20 15 +[ ] +[t@tb t t b ] +[ @ b b] +[ttttttttttttt bbb ] +[ $ $ b] +[b bbbbbb bbbbbbb b] +[ b b b ] +[bbbbb bbbbb bbbbbb] +[ $ b b ] +[b bbbbb bbbbbb b] +[ b b b ] +[b bbbbbbbbbbbbbb b] +[bb bb] +[bbb NN VV RR bbb] +[bbbbbbbttttttbbbbbbb] diff --git a/taju.py b/taju.py index 8bea852..32ea7b0 100755 --- a/taju.py +++ b/taju.py @@ -5,7 +5,9 @@ import pygame import random import math from stage import Stage -from sprites import Tajundra +from qwesprites import Tajundra +from qwesprites import Dragon +from qwesprites import Hacha pygame.init() @@ -16,7 +18,7 @@ black = (60,16,16) screen = pygame.display.set_mode(size - , pygame.DOUBLEBUF # | pygame.FULLSCREEN + , pygame.DOUBLEBUF | pygame.FULLSCREEN ) ###################################################### @@ -53,7 +55,11 @@ screen.fill(black) screen.blit(fondo,screen.get_rect()) STAGE.draw(screen) pygame.display.update() +t2=Dragon(STAGE) +t2.dy=-10 +t2.dx=50 +STAGE.sprites+=[spriteTajundra, t2,Dragon(STAGE), Tajundra(STAGE)] while not Salir: for event in pygame.event.get(): @@ -61,23 +67,36 @@ while not Salir: if event.type == pygame.KEYDOWN: if event.key==pygame.K_ESCAPE: Salir=True + elif event.key==pygame.K_SPACE: + x,y,w,h=spriteTajundra.rect + pos=x,y + vel=300 + if spriteTajundra.dx<0: vel=-300 + vely=-120 + if keys.has_key(pygame.K_DOWN): vely=50 + if keys.has_key(pygame.K_UP): vely=-200 + STAGE.sprites+=[Hacha(STAGE,pos,spriteTajundra.dx+vel,vely)] else: keys[event.key]=True if event.type == pygame.KEYUP: if keys.has_key(event.key): del keys[event.key] + t2.dx=spriteTajundra.dx + t2.dy=spriteTajundra.dy + if spriteTajundra.in_ground: if keys.has_key(pygame.K_LEFT): spriteTajundra.dx-=15 if keys.has_key(pygame.K_RIGHT): spriteTajundra.dx+=15 - if keys.has_key(pygame.K_UP): spriteTajundra.dy=-200 + if keys.has_key(pygame.K_UP): spriteTajundra.dy=-150 if keys.has_key(pygame.K_DOWN): spriteTajundra.dy+=5 else: + if spriteTajundra.dy<0: - if not keys.has_key(pygame.K_UP): spriteTajundra.dy/=1.02 + if not keys.has_key(pygame.K_UP): spriteTajundra.dy/=1.02 if keys.has_key(pygame.K_LEFT): spriteTajundra.dx-=0.5 if keys.has_key(pygame.K_RIGHT): spriteTajundra.dx+=0.5 else: @@ -102,15 +121,5 @@ while not Salir: time_o=time_aux # msec=reloj_juego.tick(30) - rect1=pygame.Rect(spriteTajundra.rect) - spriteTajundra.tickms(msec) - rect2=spriteTajundra.rect - - x,y,w,h=rect1.union(rect2) - h=w=128 - #screen.fill(black,(x,y,w,h)) - STAGE.draw(screen,(x,y,w,h)) - spriteTajundra.draw(screen) - - pygame.display.update((x,y,w,h)) - #pygame.display.flip() + + STAGE.fulldraw(screen,msec) -- 2.11.4.GIT