From c7ed14110fd726c4c3850d4feb5bc01a1bf4af0d Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Sat, 28 Mar 2020 22:38:20 -0400 Subject: [PATCH] asset --- asset/asset.svg | 88 +++++++++++++++++++++++++++++++++++++++++++++++ asset/perso1.png | Bin 0 -> 238 bytes asset/perso2.png | Bin 0 -> 238 bytes main.py | 4 +-- models.py | 17 +++++---- 5 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 asset/asset.svg create mode 100644 asset/perso1.png create mode 100644 asset/perso2.png diff --git a/asset/asset.svg b/asset/asset.svg new file mode 100644 index 0000000..64228d0 --- /dev/null +++ b/asset/asset.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/asset/perso1.png b/asset/perso1.png new file mode 100644 index 0000000000000000000000000000000000000000..a23c14847b5f1e27712fc5d2d507b0ae42633445 GIT binary patch literal 238 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-mSQK*5Dp-y;YjHK@;M7UB8wRq z_>O=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0x7o-U3d z8I5l*2l5^;;9v-}vJ^E76b`dK!z8b>d&_qg2Yp__Nqq*p*q_NpM*aEnZl6{A-;)Bf za-B}GPcNRMzG~>y8LWIcM-JG;BGBm7(G}Y2RliK__O=u<5X=vX`rBFiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0x7o-U3d z8I5l*2l5^;;9v-}>fdS*xH(|r876t1-CMr1IOy{VPU zmFskh-8_9--;Uc+i@zMptvezh<($E@(6HqgR)&h_q6EGMzMK3xCfD9~C4Pgg&e IbxsLQ0E#kA!2kdN literal 0 HcmV?d00001 diff --git a/main.py b/main.py index e3a4bdc..c963a09 100644 --- a/main.py +++ b/main.py @@ -20,8 +20,8 @@ WHITE=(255,255,255) BLUE=(0,0,255) RED=(255,0,0) -perso1 = perso('Alice',200,200,50,50,RED,pygame.K_o,pygame.K_l,pygame.K_k,pygame.K_m) -perso2 = perso('Bjorn',600,600,50,50,BLUE,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d) +perso1 = perso('Alice',200,200,pygame.K_o,pygame.K_l,pygame.K_k,pygame.K_m,'asset/perso1.png') +perso2 = perso('Bjorn',600,600,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,'asset/perso2.png') speed = 1 diff --git a/models.py b/models.py index e15065d..fc49fbe 100644 --- a/models.py +++ b/models.py @@ -7,7 +7,7 @@ import pygame class perso(): - def __init__(self,name,posx,posy,width,height,color,key_up,key_down,key_left,key_right): + def __init__(self,name,posx,posy,key_up,key_down,key_left,key_right,texture): self.name = name self.posx = posx self.posy = posy @@ -15,9 +15,8 @@ class perso(): self.key_down = key_down self.key_left = key_left self.key_right = key_right - self.width = width - self.height = height - self.color = color + self.img = pygame.image.load(texture) + self.size = self.img.get_size() def check_move(self,keystate,screen_width,screen_height,speed): if keystate[self.key_left]: @@ -26,16 +25,16 @@ class perso(): self.posx=0 if keystate[self.key_right]: self.posx += speed - if self.posx+self.width > screen_width: - self.posx = screen_width-self.width + if self.posx+self.size[0] > screen_width: + self.posx = screen_width-self.size[0] if keystate[self.key_up]: self.posy -= speed if self.posy < 0: self.posy = 0 if keystate[self.key_down]: self.posy += speed - if self.posy+self.height > screen_height: - self.posy = screen_height-self.height + if self.posy+self.size[1] > screen_height: + self.posy = screen_height-self.size[1] def draw(self,surface): - pygame.draw.rect(surface,self.color,(self.posx,self.posy,self.width,self.height)) \ No newline at end of file + surface.blit(self.img,(self.posx,self.posy)) \ No newline at end of file