diff --git a/Throot.py b/Throot.py index b34d960..36e6e7c 100644 --- a/Throot.py +++ b/Throot.py @@ -5,6 +5,7 @@ import math import Games.Throot.map import Games.Throot.sprites from Games.Throot.artrepository import OBSTACLES +from Games.Throot.player import Player from random import randrange @@ -21,6 +22,8 @@ class GameLoop: self.current_obstacle_slice = OBSTACLE_SLICES[0] self.entities = set() + self.player = Player() + def get_obstacle_slice(self): return OBSTACLE_SLICES[randrange(0, len(OBSTACLE_SLICES))] @@ -35,6 +38,8 @@ class GameLoop: if self.current_depth % ObstacleSlice.height < prev_depth % ObstacleSlice.height: self.current_obstacle_slice = self.get_obstacle_slice() + self.player.update_phys(self.current_depth, prev_depth) + # Generate new entities as needed self.entities |= update_entities(self.current_obstacle_slice, self.current_depth, prev_depth) @@ -49,6 +54,7 @@ class GameLoop: # Draw the entities for entity in self.entities: entity.render(tpf, self.current_depth, prev_depth) + self.player.update_draw(self.current_depth, prev_depth) thumby.display.update() def main(): @@ -65,4 +71,4 @@ def main(): loop.update(tps) prev_time = t0 -main() \ No newline at end of file +main() diff --git a/player_animations.py b/player.py similarity index 78% rename from player_animations.py rename to player.py index c2ba898..3895be1 100644 --- a/player_animations.py +++ b/player.py @@ -32,7 +32,7 @@ class Player: self.anim = PlayerAnimation(self.x, self.y) self.debugvisible = True - def update_phys(self): + def update_phys(self, current_depth, prev_depth): inp = int(0) if CONST_INP_MOVE_LEFT.pressed(): inp -= 1 @@ -57,7 +57,7 @@ class Player: self.xsub = max(min(xx, thumby.display.width - 1), 0) ### y movement - self.ysub += self.yspeed + self.ysub = current_depth - (thumby.display.height / 2) ### pixel positions self.x = int(self.xsub) @@ -66,13 +66,15 @@ class Player: # animation self.anim.update_phys(self.x, self.y, CONST_PL_SCREEN_Y) - def update_draw(self, cam): + def update_draw(self, current_depth, prev_depth): # debug draw if self.debugvisible: - thumby.display.setPixel(self.x - cam.x, self.y - cam.y, self.isdecend) + pix_x = self.x + pix_y = int(current_depth - self.y) + thumby.display.setPixel(pix_x, pix_y, self.isdecend) # animation - self.anim.update_draw(cam, self.isdecend) + self.anim.update_draw(current_depth, prev_depth, self.isdecend) class Camera: @@ -142,8 +144,10 @@ class PlayerAnimation: # plworldy + random.randrange(-rad, rad))) # move last pos - self.poslist[-1] = (plworldx + random.randrange(-rad, rad), - plworldy + random.randrange(-rad, rad)) + self.poslist[-1] = ( + plworldx + random.randrange(-rad, rad), + plworldy + random.randrange(-rad, rad) + ) # new pos is perfectly on player self.poslist.append((plworldx, plworldy)) @@ -152,39 +156,19 @@ class PlayerAnimation: # self.poslist.append((plworldx, plworldy)) ### remove the fist item in the list if its full line is off screen - if self.poslist[1][self.POS_Y] < plworldy - plscreeny: - self.poslist.pop(0) + #if self.poslist[1][self.POS_Y] < plworldy - plscreeny: + # self.poslist.pop(0) #print(len(self.poslist)) - def update_draw(self, cam, isdecend=1): + def update_draw(self, current_depth, prev_depth, 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, isdecend) - - -### start -# Set the FPS (without this call, the default fps is 30) -thumby.display.setFPS(CONST_FPS) - -pl = Player() -cam = Camera(pl) - -print("game ready") - - -### game loop -while(True): - t0 = time.ticks_ms() # Get time (ms) - thumby.display.fill(0) # Fill canvas to black - - # update physics - pl.update_phys() - cam.update_phys(CONST_PL_SCREEN_Y) - - # update drawing - pl.update_draw(cam) - - thumby.display.update() + thumby.display.drawLine( + int(self.poslist[i][self.POS_X]), + int(current_depth - self.poslist[i][self.POS_Y]), + int(self.poslist[i + 1][self.POS_X]), + int(current_depth - self.poslist[i + 1][self.POS_Y]), + isdecend + )