diff --git a/main.py b/main.py
index fb99e8f..a6c436a 100644
--- a/main.py
+++ b/main.py
@@ -6,7 +6,7 @@
import pygame
import yaml
-from models import Game, Player, Carte, Camera, Enemy, Hud
+from models import Game, Player, Carte, Camera, Enemy, Hud, Weapon
from utils import enemy_placement
pygame.init()
@@ -40,10 +40,13 @@ for positions in enemy_placement(carte.carte):
for position in positions:
enemies.append(Enemy('Plop',position,path_enemy))
+
+# Generate instances:
start_pos = carte.player_start_pos
-player = Player('Alice',start_pos,center_screen,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,323,path_player,path_canon,path_projectile)
+player = Player('Alice',start_pos,center_screen,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,323,path_player,path_canon)
+base_weapon = Weapon('Base', 25, 0, 30, path_projectile)
+player.add_weapon(base_weapon)
camera = Camera(start_pos,screen_width,screen_height,0.3)
-#enemies = [Enemy('Plop',(300,300),'perso.png')]
hud = Hud(player)
game = Game(carte,player,camera,enemies,hud)
diff --git a/maps/rooms.svg b/maps/rooms.svg
index aa30692..3f9310a 100644
--- a/maps/rooms.svg
+++ b/maps/rooms.svg
@@ -8,6 +8,9 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ inkscape:export-ydpi="96"
+ inkscape:export-xdpi="96"
+ inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/rooms/back_stop.png"
sodipodi:docname="rooms.svg"
inkscape:version="1.0 (4035a4fb49, 2020-05-01)"
id="svg8"
@@ -16,88 +19,14 @@
height="297mm"
width="210mm">
-
-
-
-
-
-
-
-
-
-
- image/svg+xml
-
-
-
-
-
-
-
-
-
-
+
+
+ preserveAspectRatio="none"
+ height="729.64642"
+ width="729.64642"
+ x="-304.80234"
+ y="696.2514" />
+
+
+
+
+
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+
+
+
+
back_start
+ back_start
diff --git a/models.py b/models.py
index 3dad00a..4c78b36 100644
--- a/models.py
+++ b/models.py
@@ -83,7 +83,7 @@ class Hud():
pygame.draw.rect(surface,(255,0,0),(10,10,round(self.player.life/100*surface.get_width()/3),health_width),0)
pygame.draw.rect(surface,(255,255,255),(10,10,int(surface.get_width()/3),health_width),3)
- text = self.font_large.render(str(self.player.ammo), True, (255, 255, 255))
+ text = self.font_large.render(str(self.player.equipped_weapon.ammo), True, (255, 255, 255))
surface.blit(text, (int(surface.get_width()-1.5*text.get_width()),int(surface.get_height()-1.5*text.get_height())))
def write_fps(self,surface,time_mili):
@@ -133,7 +133,7 @@ class Camera():
class Player():
- def __init__(self,name,start_pos,center_screen,key_up,key_down,key_left,key_right,key_fire,texture,texture_canon,texture_proj):
+ def __init__(self,name,start_pos,center_screen,key_up,key_down,key_left,key_right,key_fire,texture,texture_canon):
self.name = name
self.posx = start_pos[0]
self.posy = start_pos[1]
@@ -155,14 +155,14 @@ class Player():
self.canon_rect = self.canon.get_rect()
self.degres_player = 0
self.degres_canon = 0
- self.texture_proj = texture_proj
self.projectiles = []
self.last_fire = time()
# RP attributes:
self.life = 100
- self.ammo = 50
+ self.weapons = []
+ self.equipped_weapon = None
def check_keys(self,keystate,screen_width,screen_height,carte,camera):
@@ -282,11 +282,17 @@ class Player():
#pygame.draw.rect(surface, (255,0,0), (int(move_box_ratio*scwidth),int(move_box_ratio*scheight),int(scwidth*(1-2*move_box_ratio)),int(scheight*(1-2*move_box_ratio))), 2)
def fire(self,name,texture):
- if (time()-self.last_fire> 1/max_fire_rate):
- new_proj = Projectile(name,self.texture_proj,(self.posx,self.posy),20,self.degres_canon,50)
- self.projectiles.append(new_proj)
+ if self.equipped_weapon and (time()-self.last_fire> 1/max_fire_rate):
+ self.equipped_weapon.fire(self)
self.last_fire = time()
- self.ammo = self.ammo -1
+
+ def add_weapon(self,weapon):
+ self.weapons.append(weapon)
+ if len(self.weapons) == 1:
+ self.equipped_weapon = self.weapons[0]
+
+ def change_weapon(self,index):
+ self.equipped_weapon = self.weapons[index]
class Enemy():
@@ -315,6 +321,22 @@ class Enemy():
del game.enemies[index]
+class Weapon():
+ """ Base model for a weapon. All weapons will child class of this one."""
+
+ def __init__(self, name, damages, spray, ammo, texture_proj):
+ self.ammo = ammo
+ self.name = name
+ self.damages = damages
+ self.spray = spray
+ self.texture_proj = texture_proj
+
+ def fire(self,player):
+ if self.ammo > 0:
+ player.projectiles.append(Projectile('plop',self.texture_proj,(player.posx,player.posy),20,player.degres_canon,50))
+ self.ammo = self.ammo -1
+
+
class Projectile():
def __init__(self,name,texture,position,speed,angle,damage):