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 0000000..afec120 Binary files /dev/null and b/maps/map_1.png differ 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):