From 489d6b64464c4dbf6c09afd14640bf2e699fdc4c Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Mon, 13 Apr 2020 20:43:09 -0400 Subject: [PATCH] Add map and move map instead of player --- asset/asset.svg | 65 ++++++++++++++++++++++++++++-------------------- main.py | 10 +++++--- maps/map_1.png | Bin 0 -> 32066 bytes models.py | 25 ++++++++++++------- 4 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 maps/map_1.png diff --git a/asset/asset.svg b/asset/asset.svg index 86b73c4..e103936 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="5.6" - inkscape:cx="-978.35637" - inkscape:cy="195.0211" + inkscape:zoom="0.24748737" + inkscape:cx="-2542.2953" + inkscape:cy="99.716565" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -49,7 +49,7 @@ image/svg+xml - + @@ -58,12 +58,12 @@ inkscape:groupmode="layer" id="layer1"> + x="-289.71875" + y="216.30208" /> - - + + + + + diff --git a/main.py b/main.py index 65b5893..41df023 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ import pygame -from models import Perso +from models import Perso, Carte pygame.init() @@ -21,8 +21,8 @@ WHITE=(255,255,255) BLUE=(0,0,255) RED=(255,0,0) -perso = Perso('Alice',200,200,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,pygame.K_SPACE,'perso1_right.png','canon.png','projectile1_right.png') - +perso = Perso('Alice',int(screen_width/2),int(screen_height/2),pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,323,'perso1_right.png','canon.png','projectile1_right.png') +carte = Carte('map_1.png') clock = pygame.time.Clock() @@ -32,11 +32,13 @@ while not done: done = True - keystate = pygame.key.get_pressed() + keystate = pygame.key.get_pressed() + pygame.mouse.get_pressed() + perso.check_keys(keystate,screen_width,screen_height) screen.fill(BACKGROUND) + carte.draw(screen,(0,0),perso) perso.draw(screen) pygame.display.flip() diff --git a/maps/map_1.png b/maps/map_1.png new file mode 100644 index 0000000000000000000000000000000000000000..afec1208caa51cfd8277f3156a1f8e48208660f7 GIT binary patch literal 32066 zcmeHQd010d-aZjz5dkTVNI?W~iqEKZ!9qkrT(G#*t#&|hA%Z1Uwy;Ckg3Ew|fIfY` zYAS@bjxtVIA_#~mT-HzNrVUUjL02ERkCK<6&K! zwQgr10D58QKSi+J{%5$+IB4yTpzVI1L81Esz6GJ7p`Rb{^$PUZ$NKhjzX0YLx&5aA zn1l6>tG)?Kk=2&`qdFLrb@(Ogf2%QP;TP(k*nCkn`ACrdYu!z;%bv~%QnPShGcCwy zVZP=nAA?x;HCum((fiA}3(c2Yx6Nzr9dfAbySBHH*`HLC4+9sIER&e+RLGZ=pr>@JDM2G}|A>PkoQPz(yk-wUSw zG$oLgRa~3jcwaiZyqKcCm)=nk*73?K*AMT6uL3(-Yy4x{l51=M;KZfahp?}*2Qq7H z#Y2>+2zGbjcL?y*(E|**>Ne`FM6q5UjHMc9SFNqFE$Kl7dvB=B6@ql zQKGqOi#bYcJ#pTW+ed4xIBFf;GaFxy@XAJ9xa4*PWFZhNPA{A3SK&|^Vi>>@@1E@u zNmZ(|%s1;3+(Cwy({Ep1it==UP;*~B%`_Z?G+rmC$Z%?NOQH=2nhlx&cGd+%XC5Gz!iV9FYS$r_UBeZ)m+@Z(8RS}MrJa=~e>EEa%1HhU$ zXm>lzvs)W**2qhtxB|f5flxEHT;GUmKFDXTzscS6Zq4*$q$NUgO?hQ%)`#FtZ z%5cckPiwsYc#;}>+jwr0z}4uduYJxvq{bS4w`{|)o4Tgz+rD$0?w-0bXO41cg>^&d zq0m^BX=PwJ*1}qObG((bWW0fOTxAC0Pyq5!9EoWpOgIuGCH|i&vA@U;fT0)rJ$*Bh z;H5AB)Mnl35sZ0N0B}h=sm9^Az82c=m<1gttW}lFrdzFA_&sJ7m$%{{Rd1X%`^J0a zyx3kI^KTKv0rN@frUGg)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i literal 0 HcmV?d00001 diff --git a/models.py b/models.py index 09690af..d50545c 100644 --- a/models.py +++ b/models.py @@ -14,11 +14,21 @@ img_path = 'asset/' cap_speed = 10 deceleration = 1.1 +class Carte(): + def __init__(self,texture): + self.img = pygame.image.load('maps/'+texture).convert_alpha() + + def draw(self,surface,position,perso): + surface.blit(self.img,(-perso.startx-perso.posx,-perso.starty-perso.posy)) + + class Perso(): def __init__(self,name,posx,posy,key_up,key_down,key_left,key_right,key_fire,texture,texture_canon,texture_proj): self.name = name + self.startx = posx self.posx = posx + self.starty = posy self.posy = posy self.speed = [0,0] self.direction = [0,-1] @@ -104,8 +114,6 @@ class Perso(): for k in to_remove[::-1]: del self.projectiles[k] - # select img - #Calculate player rotation: if self.direction[0]!=0: self.degres_perso = -1*degrees(atan(self.direction[1]/self.direction[0])) @@ -117,10 +125,10 @@ class Perso(): #Calculate canon rotation: x_mouse, y_mouse = pygame.mouse.get_pos() - if x_mouse==self.posx: + if x_mouse==self.startx: x_mouse+=0.1 - self.degres_canon = -1*degrees(atan((y_mouse-self.posy)/(x_mouse-self.posx))) - if x_mouse < self.posx: + self.degres_canon = -1*degrees(atan((y_mouse-self.starty)/(x_mouse-self.startx))) + if x_mouse < self.startx: self.degres_canon = 180+self.degres_canon canon = pygame.transform.rotate(self.canon,self.degres_canon) @@ -129,19 +137,18 @@ class Perso(): canon_rect = canon.get_rect() # Blits - surface.blit(perso,(self.posx-perso_rect.center[0],self.posy-perso_rect.center[1])) - surface.blit(canon,(self.posx-canon_rect.center[0],self.posy-canon_rect.center[1])) + surface.blit(perso,(self.startx-perso_rect.center[0],self.starty-perso_rect.center[1])) + surface.blit(canon,(self.startx-canon_rect.center[0],self.starty-canon_rect.center[1])) #pygame.draw.circle(surface, (200,0,0), (self.posx,self.posy), 10) def fire(self,name,texture): if (time()-self.last_fire> 0.2): - new_proj = Projectile(name,self.texture_proj,(self.posx,self.posy),20,self.degres_canon) + new_proj = Projectile(name,self.texture_proj,(self.startx,self.starty),20,self.degres_canon) self.projectiles.append(new_proj) self.last_fire = time() - class Projectile(): def __init__(self,name,texture,position,speed,angle):