diff --git a/asset/asset.svg b/asset/asset.svg index f2a26f4..e2196d8 100644 --- a/asset/asset.svg +++ b/asset/asset.svg @@ -25,9 +25,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="2.8" - inkscape:cx="-990.35093" - inkscape:cy="138.68996" + inkscape:zoom="22.4" + inkscape:cx="-1033.5604" + inkscape:cy="234.95109" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -277,5 +277,15 @@ id="rect890" style="opacity:1;fill:#ff6600;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" transform="rotate(90)" /> + + diff --git a/asset/projectile_down.png b/asset/projectile_down.png new file mode 100644 index 0000000..283bb72 Binary files /dev/null and b/asset/projectile_down.png differ diff --git a/asset/projectile_left.png b/asset/projectile_left.png new file mode 100644 index 0000000..04d38d4 Binary files /dev/null and b/asset/projectile_left.png differ diff --git a/asset/projectile_right.png b/asset/projectile_right.png new file mode 100644 index 0000000..f1b83f8 Binary files /dev/null and b/asset/projectile_right.png differ diff --git a/asset/projectile_up.png b/asset/projectile_up.png new file mode 100644 index 0000000..dcd5b48 Binary files /dev/null and b/asset/projectile_up.png differ diff --git a/models.py b/models.py index 019a487..e5cd621 100644 --- a/models.py +++ b/models.py @@ -54,19 +54,27 @@ class Perso(): self.direction = (0,1) if keystate[self.key_fire]: - self.fire('asset/missile') + self.fire('fireball','asset/projectile') def draw(self,surface): - surface.blit(self.img,(self.posx,self.posy)) - for proj in self.projectiles: - proj.move() - proj.draw(surface) + to_remove = [] + for k,proj in enumerate(self.projectiles): + if not proj.is_out(surface): + proj.move() + proj.draw(surface) + else: + to_remove.append(k) + if to_remove != []: + for k in to_remove[::-1]: + del self.projectiles[k] - def fire(self,name): - print(time()) + surface.blit(self.img,(self.posx,self.posy)) + print("Projectiles for {}: {}".format(self.name,len(self.projectiles))) + + def fire(self,name,texture): if (time()-self.last_fire> 0.2): - new_proj = Projectile(name,2,(self.posx,self.posy),self.direction) + new_proj = Projectile(name,texture,2,(self.posx+int(self.img.get_height()/2),self.posy+int(self.img.get_width()/2)),self.direction) self.projectiles.append(new_proj) self.last_fire = time() @@ -74,15 +82,34 @@ class Perso(): class Projectile(): - def __init__(self,name,speed,position,direction): + def __init__(self,name,texture,speed,position,direction): self.name = name - self.img = pygame.image.load(name+'.png') self.speed = speed self.position = position self.direction = direction + if direction[0]!=0: + if direction[0]>0: + self.img = pygame.image.load(texture+'_right.png') + else: + self.img = pygame.image.load(texture+'_left.png') + else: + if direction[1]>0: + self.img = pygame.image.load(texture+'_down.png') + else: + self.img = pygame.image.load(texture+'_up.png') + def move(self): self.position = (self.position[0]+self.speed*self.direction[0],self.position[1]+self.speed*self.direction[1]) def draw(self,surface): - surface.blit(self.img,self.position) \ No newline at end of file + surface.blit(self.img,self.position) + + def is_out(self,surface): + if (self.position[0]<0-self.img.get_width() or + self.position[1]<0-self.img.get_height() or + self.position[0]>surface.get_width()+self.img.get_width() or + self.position[1]>surface.get_height()+self.img.get_height()): + return True + else: + return False