Fix mouvement and rotation issues. Add acceleration
This commit is contained in:
parent
bf22a5e62d
commit
7d5fbe0cde
2 changed files with 19 additions and 12 deletions
|
@ -26,8 +26,8 @@
|
|||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.24748737"
|
||||
inkscape:cx="-2542.2953"
|
||||
inkscape:cy="99.716565"
|
||||
inkscape:cx="-3244.5066"
|
||||
inkscape:cy="371.0213"
|
||||
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>
|
||||
|
@ -745,8 +745,8 @@
|
|||
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"
|
||||
style="opacity:1;fill:#7f2aff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.07756615;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
d="M -1142.3163,-27.674654 V 496.18112 h 841.88489 V -27.674654 Z m 327.39963,28.06370188 h 121.60561 V 47.161882 h 159.02271 V 9.7436221 h 196.43983 V 159.41667 h -9.35428 v 102.90026 h 18.70855 v 56.12741 h -28.06284 v 28.06371 h 28.06284 v 121.60936 h -177.73127 v -46.77283 h -74.83421 v -28.06371 h -102.89706 v 28.06371 h -46.77138 v -28.06371 h -112.25134 v 56.12741 H -1104.8992 V 309.08976 h 9.3542 V 9.7436221 h 65.4799 V 28.452751 h 215.14843 z M -1030.0651,75.225584 V 309.08976 h 93.54285 v -84.19111 h -18.70857 v -65.48198 h 140.31415 V 75.225584 Z m 336.75404,37.418276 v 121.60936 h 9.35427 V 355.8626 h 102.89706 v -18.70913 h 102.89706 v 9.35458 h 74.8342 v -28.06371 h -121.60559 v -56.12741 h 18.70854 V 159.41667 h -28.06283 v -46.77281 z m 233.85693,46.77281 v 102.90026 h 65.47995 V 159.41667 Z m -420.94249,65.48198 v 84.19111 h 37.41711 v 46.77284 h 112.25134 v -93.54567 h -84.1885 v -37.41828 z"
|
||||
id="rect4612"
|
||||
inkscape:connector-curvature="0"
|
||||
inkscape:export-filename="/home/grizzly/Documents/Python/tangledmind/maps/map_1.png"
|
||||
|
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
17
models.py
17
models.py
|
@ -10,6 +10,7 @@ from math import atan, degrees,radians, cos, sin
|
|||
img_path = 'asset/'
|
||||
|
||||
cap_speed = 10
|
||||
acceleration = 2
|
||||
deceleration = 1.1
|
||||
|
||||
|
||||
|
@ -70,19 +71,25 @@ class Perso():
|
|||
if keystate[self.key_left] or keystate[self.key_right] or keystate[self.key_up] or keystate[self.key_down]:
|
||||
|
||||
if keystate[self.key_left]:
|
||||
self.speed[0] = -1*cap_speed
|
||||
self.speed[0] -= acceleration
|
||||
if self.speed[0] < -cap_speed: self.speed[0] = -cap_speed
|
||||
|
||||
if keystate[self.key_right]:
|
||||
self.speed[0] = cap_speed
|
||||
self.speed[0] += acceleration
|
||||
if self.speed[0] > cap_speed: self.speed[0] = cap_speed
|
||||
|
||||
if keystate[self.key_up]:
|
||||
self.speed[1] = -1*cap_speed
|
||||
self.speed[1] -= acceleration
|
||||
if self.speed[1] < -cap_speed: self.speed[1] = -cap_speed
|
||||
|
||||
if keystate[self.key_down]:
|
||||
self.speed[1] = cap_speed
|
||||
self.speed[1] += acceleration
|
||||
if self.speed[1] > cap_speed: self.speed[1] = cap_speed
|
||||
|
||||
# Begin the deceleration
|
||||
if not (keystate[self.key_left] or keystate[self.key_right]):
|
||||
self.speed[0] = int(self.speed[0]/deceleration)
|
||||
if not (keystate[self.key_up] or keystate[self.key_down]):
|
||||
self.speed[1] = int(self.speed[1]/deceleration)
|
||||
|
||||
# Update the position
|
||||
|
@ -130,7 +137,7 @@ class Perso():
|
|||
canon = pygame.transform.rotate(self.canon,self.degres_canon)
|
||||
|
||||
# Get rects
|
||||
self.perso_rect = self.img.get_rect()
|
||||
self.perso_rect = perso.get_rect()
|
||||
self.canon_rect = canon.get_rect()
|
||||
|
||||
# Blits
|
||||
|
|
Loading…
Reference in a new issue