Add weapon system
This commit is contained in:
parent
8ec0bbe224
commit
93d54f065e
3 changed files with 173 additions and 98 deletions
9
main.py
9
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)
|
||||
|
||||
|
|
224
maps/rooms.svg
224
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">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
inkscape:snap-midpoints="true"
|
||||
inkscape:document-rotation="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-height="1016"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:guide-bbox="true"
|
||||
showguides="true"
|
||||
inkscape:snap-grids="false"
|
||||
showborder="false"
|
||||
showgrid="true"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:document-units="px"
|
||||
inkscape:cy="3863.9307"
|
||||
inkscape:cx="2694.304"
|
||||
inkscape:zoom="0.25596297"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
borderopacity="1.0"
|
||||
bordercolor="#666666"
|
||||
pagecolor="#ffffff"
|
||||
id="base">
|
||||
<inkscape:grid
|
||||
id="grid1495"
|
||||
type="xygrid" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5200"
|
||||
orientation="0,1"
|
||||
position="-248.70833,306.91668" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5202"
|
||||
orientation="1,0"
|
||||
position="-158.75,254.00001" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5204"
|
||||
orientation="0,1"
|
||||
position="127,42.333333" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5663"
|
||||
orientation="0,1"
|
||||
position="158.75,-10.583334" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<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 />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1"
|
||||
inkscape:groupmode="layer"
|
||||
inkscape:label="size">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="rect1478"
|
||||
d="M 730.25,836.08332 H 994.83334 V 1100.6667 H 730.25 Z"
|
||||
style="display:inline;opacity:1;fill:#eccf2f;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.37309;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||
<path
|
||||
style="display:inline;opacity:1;fill:#e9ac84;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.37309;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
d="M -137.58334,846.66667 H 127 V 1111.25 h -264.58334 z"
|
||||
id="path2243"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="m 862.54167,914.05437 -9.40689,13.21065 v 30.95052 H 824.4761 l -12.23191,10.15929 12.23191,10.15929 h 28.65868 v 30.95088 l 9.40689,13.2106 9.40689,-13.2106 v -30.95088 h 28.65832 l 12.23227,-10.15929 -12.23227,-10.15929 h -28.65832 v -30.95052 z"
|
||||
style="fill:#005500;fill-rule:evenodd;stroke-width:1.95517;stroke-linecap:round"
|
||||
id="rect2253" />
|
||||
<image
|
||||
id="image2292"
|
||||
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA/EAAAPxCAYAAACywS2VAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAA
|
||||
id="defs2">
|
||||
<mask
|
||||
id="mask2300"
|
||||
maskUnits="userSpaceOnUse">
|
||||
<image
|
||||
style="opacity:1"
|
||||
id="image2302"
|
||||
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA/EAAAPxCAYAAACywS2VAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAA
|
||||
B3RJTUUH4gECFDI6MGJ3fQAAIABJREFUeNrsneuS5KiuRrsq6v1fuc6POTnb4wZ052KvFTGxd3dn
|
||||
Om0MQh8I6ev39/f36+vrz+/v75+vr68/dz5///v7+yfC59q960i/kXEPlvt5Gvfn1bRndpuf1j6t
|
||||
9mq1iacvafr7dQxmPuN9fPf+rfdZ6f5a7XH//PX5tb89q02yf0Nq+1V9XXsf2v7deqfWZ7TanBXj
|
||||
|
@ -1720,11 +1649,121 @@ jDRDCZp33kOr53f02SoiymjqPUMc4jUSVd0WMkC7ta9ZrV5U5VVRo/2zFnZ3tk+PNsjfBOAzdBZr
|
|||
H6yi9hGna2bm4Y6z2vfhzPq8Re6ricU9f6PoHrWSV0jGoNUNynOuIvwDVhemvz/7P6zr6J3JpcYb
|
||||
AAAAAElFTkSuQmCC
|
||||
"
|
||||
preserveAspectRatio="none"
|
||||
height="284.76224"
|
||||
width="284.76224"
|
||||
x="1102.1674"
|
||||
y="961.58716" />
|
||||
preserveAspectRatio="none"
|
||||
height="729.64642"
|
||||
width="729.64642"
|
||||
x="-304.80234"
|
||||
y="696.2514" />
|
||||
</mask>
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
inkscape:snap-midpoints="true"
|
||||
inkscape:document-rotation="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-height="1016"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:guide-bbox="true"
|
||||
showguides="true"
|
||||
inkscape:snap-grids="false"
|
||||
showborder="false"
|
||||
showgrid="true"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:document-units="px"
|
||||
inkscape:cy="3580.3529"
|
||||
inkscape:cx="5983.1311"
|
||||
inkscape:zoom="0.25596297"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
borderopacity="1.0"
|
||||
bordercolor="#666666"
|
||||
pagecolor="#ffffff"
|
||||
id="base">
|
||||
<inkscape:grid
|
||||
id="grid1495"
|
||||
type="xygrid" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5200"
|
||||
orientation="0,1"
|
||||
position="-248.70833,306.91668" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5202"
|
||||
orientation="1,0"
|
||||
position="-158.75,254.00001" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5204"
|
||||
orientation="0,1"
|
||||
position="127,42.333333" />
|
||||
<sodipodi:guide
|
||||
inkscape:locked="false"
|
||||
id="guide5663"
|
||||
orientation="0,1"
|
||||
position="158.75,-10.583334" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<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 />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1"
|
||||
inkscape:groupmode="layer"
|
||||
inkscape:label="size">
|
||||
<path
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/rooms/back.png"
|
||||
transform="translate(-108.52813,-67.613049)"
|
||||
mask="url(#mask2300)"
|
||||
style="display:inline;opacity:1;fill:#e6dbc9;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.37309;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
d="M -3.7220193,884.49283 H 260.86132 V 1149.0762 H -3.7220193 Z"
|
||||
id="path2243"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/rooms/back_start.png"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path2304"
|
||||
d="M -3.7220193,884.49283 H 260.86132 V 1149.0762 H -3.7220193 Z"
|
||||
style="display:inline;opacity:1;fill:#e6dbc9;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.37309;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
mask="url(#mask2300)"
|
||||
transform="translate(716.93252,-67.613049)" />
|
||||
<path
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/rooms/back_start.png"
|
||||
d="m 845.50217,926.95623 -3.84709,5.4027 v 12.65767 h -11.72039 l -5.00242,4.1548 5.00242,4.1548 h 11.72039 v 12.65782 l 3.84709,5.40269 3.84709,-5.40269 V 953.3262 h 11.72024 l 5.00257,-4.1548 -5.00257,-4.1548 h -11.72024 v -12.65767 z"
|
||||
style="fill:#005500;fill-rule:evenodd;stroke-width:0.799596;stroke-linecap:round"
|
||||
id="rect2253" />
|
||||
<path
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/rooms/back_stop.png"
|
||||
transform="translate(1538.5855,-67.613049)"
|
||||
mask="url(#mask2300)"
|
||||
style="display:inline;opacity:1;fill:#e6dbc9;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.37309;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
d="M -3.7220193,884.49283 H 260.86132 V 1149.0762 H -3.7220193 Z"
|
||||
id="path2306"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/rooms/back_stop.png"
|
||||
d="m 1667.1523,923.17802 a 25.993445,25.993445 0 0 0 -25.9906,25.9934 25.993445,25.993445 0 0 0 25.9934,25.9935 25.993445,25.993445 0 0 0 25.9935,-25.9935 25.993445,25.993445 0 0 0 -25.9935,-25.9934 z m 0,4.2607 a 21.732733,21.732733 0 0 1 21.7328,21.7327 21.732733,21.732733 0 0 1 -21.7328,21.7328 21.732733,21.732733 0 0 1 -21.7326,-21.7328 21.732733,21.732733 0 0 1 21.7326,-21.7327 z"
|
||||
style="opacity:1;fill:#ff6600;fill-opacity:1;fill-rule:evenodd;stroke-width:0.531691;stroke-linecap:round"
|
||||
id="path2314" />
|
||||
</g>
|
||||
<g
|
||||
inkscape:label="block"
|
||||
|
@ -4658,5 +4697,16 @@ AAAAAElFTkSuQmCC
|
|||
x="607.38525"
|
||||
id="tspan2249"
|
||||
sodipodi:role="line">back_start</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:112.02px;line-height:1.25;font-family:'Kaushan Script';-inkscape-font-specification:'Kaushan Script';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:4.20073"
|
||||
x="1381.676"
|
||||
y="755.5318"
|
||||
id="text2312"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan2310"
|
||||
x="1381.676"
|
||||
y="755.5318"
|
||||
style="stroke-width:4.20073">back_start</tspan></text>
|
||||
</g>
|
||||
</svg>
|
||||
|
|
Before Width: | Height: | Size: 318 KiB After Width: | Height: | Size: 321 KiB |
38
models.py
38
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):
|
||||
|
|
Loading…
Reference in a new issue