From b79f0fa7040f28627d8e529eb6be119c9084e767 Mon Sep 17 00:00:00 2001 From: Neal Finger Date: Sat, 4 Feb 2023 16:25:05 -0700 Subject: [PATCH] Update player_animations.py player movement acceleration --- player_animations.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/player_animations.py b/player_animations.py index a721f6f..c2ba898 100644 --- a/player_animations.py +++ b/player_animations.py @@ -21,9 +21,13 @@ class Player: self.x = int(self.xsub) self.y = int(self.ysub) - self.yspeed = 32 / CONST_FPS self.movespeed = 32 / CONST_FPS - self.isRoot = 1 + self.isdecend = 1 + + self.xspeed = 32 / CONST_FPS + self.yspeed = 32 / CONST_FPS + self.accx = 1 / (CONST_FPS * 4) + self.accaccx = self.accx self.anim = PlayerAnimation(self.x, self.y) self.debugvisible = True @@ -34,15 +38,28 @@ class Player: inp -= 1 if CONST_INP_MOVE_RIGHT.pressed(): inp += 1 - + # debug visible if thumby.buttonU.pressed(): self.debugvisible = not self.debugvisible + ### x movement + self.xspeed += self.accx + self.accx += self.accaccx + + if (inp == 0) and (self.xspeed > self.movespeed): + self.xspeed = self.movespeed + self.accx = self.accaccx + + xx = self.xsub + inp * self.xspeed + # clamp to screen - self.xsub = max(min(self.xsub + inp * self.movespeed, thumby.display.width), 0) + self.xsub = max(min(xx, thumby.display.width - 1), 0) + + ### y movement self.ysub += self.yspeed + ### pixel positions self.x = int(self.xsub) self.y = int(self.ysub) @@ -52,10 +69,10 @@ class Player: def update_draw(self, cam): # debug draw if self.debugvisible: - thumby.display.setPixel(self.x - cam.x, self.y - cam.y, self.isRoot) + thumby.display.setPixel(self.x - cam.x, self.y - cam.y, self.isdecend) # animation - self.anim.update_draw(cam, self.isRoot) + self.anim.update_draw(cam, self.isdecend) class Camera: @@ -140,12 +157,12 @@ class PlayerAnimation: #print(len(self.poslist)) - def update_draw(self, cam, isRoot=1): + def update_draw(self, cam, isdecend=1): ### draw line from first position to next for i in range(len(self.poslist) - 1): thumby.display.drawLine(self.poslist[i][self.POS_X] - cam.x, self.poslist[i][self.POS_Y] - cam.y, - self.poslist[i + 1][self.POS_X] - cam.x, self.poslist[i + 1][self.POS_Y] - cam.y, isRoot) + self.poslist[i + 1][self.POS_X] - cam.x, self.poslist[i + 1][self.POS_Y] - cam.y, isdecend) ### start