This commit is contained in:
grisel-davy 2020-03-28 22:38:20 -04:00
parent f9025ba480
commit c7ed14110f
5 changed files with 98 additions and 11 deletions

88
asset/asset.svg Normal file
View file

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg8"
inkscape:version="0.92.4 5da689c313, 2019-01-14"
sodipodi:docname="asset.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="11.2"
inkscape:cx="-1065.1419"
inkscape:cy="195.80413"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
showborder="false"
inkscape:window-width="1920"
inkscape:window-height="1023"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid817" />
</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></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.05785796;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect815"
width="13.229167"
height="13.229167"
x="-283.10416"
y="237.46875"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
<rect
style="opacity:1;fill:#5555ff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.22474444;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4525"
width="7.9374938"
height="7.9375"
x="-280.45831"
y="240.11458"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
<rect
style="opacity:1;fill:#ff6600;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4529"
width="2.6458333"
height="1.3229166"
x="-277.8125"
y="238.79167"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
asset/perso1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

BIN
asset/perso2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

View file

@ -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

View file

@ -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))
surface.blit(self.img,(self.posx,self.posy))