Add map and move map instead of player
This commit is contained in:
parent
a93f0dc9bd
commit
489d6b6446
4 changed files with 60 additions and 40 deletions
|
@ -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 @@
|
|||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
|
@ -58,12 +58,12 @@
|
|||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<rect
|
||||
style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.38599998;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.44453022;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="rect907"
|
||||
width="114.71026"
|
||||
width="152.13541"
|
||||
height="84.800301"
|
||||
x="-297.65625"
|
||||
y="212.33334" />
|
||||
x="-289.71875"
|
||||
y="216.30208" />
|
||||
<rect
|
||||
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.04628637;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="rect815"
|
||||
|
@ -136,15 +136,6 @@
|
|||
width="10.583341"
|
||||
id="rect860"
|
||||
style="opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.04628637;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||
<rect
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
y="240.11458"
|
||||
x="-246.0625"
|
||||
height="7.9375"
|
||||
width="7.9374938"
|
||||
id="rect856"
|
||||
style="opacity:1;fill:#0000b9;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.22474444;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||
<rect
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:export-xdpi="96"
|
||||
|
@ -154,16 +145,28 @@
|
|||
width="7.9374938"
|
||||
id="rect862"
|
||||
style="opacity:1;fill:#0000b9;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.22474444;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||
<g
|
||||
id="g5223">
|
||||
<rect
|
||||
inkscape:export-ydpi="96"
|
||||
style="opacity:1;fill:#0000b9;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="rect856"
|
||||
width="7.9374938"
|
||||
height="7.9375"
|
||||
x="-246.0625"
|
||||
y="240.11458"
|
||||
inkscape:export-xdpi="96"
|
||||
y="236.80208"
|
||||
x="242.76042"
|
||||
height="1.3229166"
|
||||
width="2.6458333"
|
||||
id="rect858"
|
||||
inkscape:export-ydpi="96" />
|
||||
<rect
|
||||
transform="rotate(90)"
|
||||
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"
|
||||
transform="rotate(90)" />
|
||||
id="rect858"
|
||||
width="2.6458333"
|
||||
height="1.3229166"
|
||||
x="242.76042"
|
||||
y="236.80208"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96" />
|
||||
</g>
|
||||
<rect
|
||||
transform="rotate(90)"
|
||||
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"
|
||||
|
@ -741,5 +744,13 @@
|
|||
sodipodi:nodetypes="ccsccc"
|
||||
inkscape:export-xdpi="133.33333"
|
||||
inkscape:export-ydpi="133.33333" />
|
||||
<path
|
||||
style="opacity:1;fill:#7f2aff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.09939253;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
d="M -1170.0253,-37.508936 V 496.94939 h 858.95088 V -37.508936 Z m 334.03644,28.6316967 h 124.07069 V 38.842252 h 162.24628 V 0.66666667 H -349.25 V 153.36902 h -9.54391 v 104.9829 h 19.08779 v 57.2634 h -28.6317 v 28.6317 h 28.6317 V 468.31769 H -521.04019 V 420.5982 h -76.35119 v -28.6317 h -104.9829 v 28.6317 h -47.71949 v -28.6317 h -114.52679 v 57.2634 H -1131.8497 V 306.07141 h 9.5438 V 0.66666667 h 66.8073 V 19.754459 h 219.50974 z M -1055.4986,67.473949 V 306.07141 h 95.43907 v -85.89509 h -19.0878 v -66.8073 h 143.15847 V 67.473949 Z m 343.58043,38.175601 v 124.07067 h 9.54389 V 353.7909 h 104.9829 v -19.08779 h 104.98289 v 9.54391 h 76.35118 v -28.6317 h -124.07067 v -57.2634 h 19.08779 v -104.9829 h -28.6317 v -47.71947 z m 238.59747,47.71947 v 104.9829 h 66.8073 v -104.9829 z m -429.47546,66.8073 v 85.89509 h 38.1756 v 47.71949 h 114.52679 v -95.43898 h -85.89509 v -38.1756 z"
|
||||
id="rect4612"
|
||||
inkscape:connector-curvature="0"
|
||||
inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/map_1.png"
|
||||
inkscape:export-xdpi="94.092171"
|
||||
inkscape:export-ydpi="94.092171" />
|
||||
</g>
|
||||
</svg>
|
||||
|
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 44 KiB |
10
main.py
10
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()
|
||||
|
||||
|
|
BIN
maps/map_1.png
Normal file
BIN
maps/map_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
25
models.py
25
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):
|
||||
|
|
Loading…
Reference in a new issue