diff --git a/Throot.py b/Throot.py index 0b64b1e..0b3a2c7 100644 --- a/Throot.py +++ b/Throot.py @@ -10,7 +10,7 @@ from random import randrange from Games.Throot.artrepository import OBSTACLES from Games.Throot.player import Player from Games.Throot.map import ObstacleSlice, OBSTACLE_SLICES -from Games.Throot.sprites import update_entities +from Games.Throot.sprites import Obstacle, update_entities from Games.Throot.constants import CONST_FPS class GameManager: @@ -96,8 +96,14 @@ class GameLoop(Room): prev_depth = self.current_depth self.diving_velocity += self.diving_accel * tpf self.current_depth += self.diving_velocity * tpf + + #print("%f (%f)" % (self.current_depth, self.current_depth % ObstacleSlice.height)) - if self.current_depth % ObstacleSlice.height < prev_depth % ObstacleSlice.height: + #print("%f -> %f: %f -> %f" % (prev_depth, self.current_depth, prev_depth % ObstacleSlice.height, self.current_depth % ObstacleSlice.height)) + if ( + self.current_depth > prev_depth and self.current_depth % ObstacleSlice.height < prev_depth % ObstacleSlice.height + or self.current_depth < prev_depth and 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) @@ -110,6 +116,9 @@ class GameLoop(Room): for entity in self.entities: if not entity.update(tpf, self.current_depth, prev_depth): to_remove.add(entity) + elif entity.intersects_pixel(self.player.xsub, self.player.ysub): + if isinstance(entity, Obstacle): + print("Hit!") self.entities -= to_remove self.score = int(self.current_depth * 10) @@ -118,7 +127,7 @@ class GameLoop(Room): # 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) + self.player.update_draw(self.player.y) thumby.display.drawText(str(self.score), thumby.display.width - (len(str(self.score)) + 2) * 5, 1, 1) thumby.display.update() diff --git a/artrepository.py b/artrepository.py index 127633d..51ea28a 100644 --- a/artrepository.py +++ b/artrepository.py @@ -4,28 +4,21 @@ SpriteImage = namedtuple("SpriteImage", ["image", "collision", "width", "height" # BITMAP: width: 8, height: 8 skull = SpriteImage( - bytearray([227,29,102,126,38,222,221,227]), + bytearray([0,28,102,126,38,30,28,0]), None, 8, 8 ) # BITMAP: width: 8, height: 8 pizza = SpriteImage( - bytearray([127,63,95,111,87,107,125,0]), + bytearray([0,0,64,96,80,104,124,0]), None, 8, 8 ) # BITMAP: width: 10, height: 10 boulder = SpriteImage( - bytearray([31,175,119,183,107,251,115,7,15,31,3,2,1,0,1,0,0,0,0,2]), - None, - 10, - 10 -) -# BITMAP: width: 10, height: 10 -ball = SpriteImage( - bytearray([135,43,85,170,124,254,122,229,123,135,3,3,2,0,1,0,1,2,3,3]), + bytearray([224,80,136,72,148,4,140,248,240,224,0,1,2,3,2,3,3,3,3,1]), None, 10, 10 @@ -39,28 +32,21 @@ ball = SpriteImage( ) # BITMAP: width: 10, height: 10 steve = SpriteImage( - bytearray([0,240,252,92,188,188,92,252,240,0,0,1,1,0,0,0,0,1,1,0]), + bytearray([255,1,225,249,185,121,121,185,249,225,1,255,15,8,11,11,8,9,9,8,11,11,8,15]), None, - 10, - 10 + 12, + 12 ) # BITMAP: width: 11, height: 8 spaceinv = SpriteImage( - bytearray([143,231,130,73,67,195,67,73,130,231,143]), - None, - 11, - 8 -) -# BITMAP: width: 11, height: 8 -spaceinv2 = SpriteImage( - bytearray([248,103,130,201,195,195,195,201,130,103,248]), + bytearray([112,24,125,182,188,60,188,182,125,24,112,7,152,125,54,60,60,60,54,125,152,7]), None, 11, 8 ) # BITMAP: width: 11, height: 8 mathroot = SpriteImage( - bytearray([255,255,239,207,159,63,1,193,249,249,255]), + bytearray([0,0,16,48,96,192,254,62,6,6,0]), None, 11, 8 @@ -68,56 +54,68 @@ mathroot = SpriteImage( #/ = bytearray([255,255,239,239,72,10,192,10,72,239,239]) # BITMAP: width: 11, height: 8 robot = SpriteImage( - bytearray([255,255,239,239,72,10,192,10,72,239,239]), + bytearray([0,16,16,183,245,63,245,183,16,16,0]), None, 11, 8 ) # BITMAP: width: 11, height: 8 dinoskull = SpriteImage( - bytearray([240,246,246,245,238,237,219,221,235,247,255]), + bytearray([15,9,9,10,17,18,36,34,20,8,0]), None, 11, 8 ) # BITMAP: width: 11, height: 8 dinojaw = SpriteImage( - bytearray([193,190,190,62,118,242,126,249,87,239,31]), + bytearray([62,65,65,193,137,13,129,6,168,16,224]), None, 11, 8 ) # BITMAP: width: 11, height: 8 dinospine = SpriteImage( - bytearray([199,187,215,187,199,199,187,215,187,199,255]), + bytearray([56,68,40,68,56,56,68,40,68,56,0]), None, 11, 8 ) # BITMAP: width: 11, height: 8 bone = SpriteImage( - bytearray([215,171,187,215,215,215,215,215,187,171,215]), + bytearray([40,84,68,40,40,40,40,40,68,84,40]), None, 11, 8 ) # BITMAP: width: 70, height: 40 bigdinohead = SpriteImage( - bytearray([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,127,127,127,127,127,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,231,193,157,124,254,118,243,243,225,225,243,159,158,140,253,153,243,247,207,159,63,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,250,247,246,244,245,243,245,243,245,243,245,243,245,251,253,254,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]), + bytearray([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,128,128,128,128,128,128,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,24,62,98,131,1,137,12,12,30,30,12,96,97,115,2,102,12,8,48,96,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,6,5,8,9,11,10,12,10,12,10,12,10,12,10,4,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), None, 70, 40 ) # BITMAP: width: 70, height: 40 bigboneddiag = SpriteImage( - bytearray([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,63,223,223,63,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,251,251,251,247,239,222,189,123,247,239,223,191,127,127,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,241,239,239,243,251,251,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]), + bytearray([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,128,128,192,32,32,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 3,4,4,4,8,16,33,66,132,8,16,32,64,128,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,1,14,16,16,12,4,4,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), None, 70, 40 ) # BITMAP: width: 70, height: 40 bigdoritoobstacle = SpriteImage( - bytearray([254,244,253,219,251,247,175,207,223,223,223,191,63,127,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,223,255,247,255,255,255,249,255,239,254,254,252,252,249,219,243,183,167,239,207,223,191,63,127,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,255,127,191,95,191,95,191,87,47,87,47,151,175,155,151,203,215,235,231,235,231,235,231,235,231,235,231,234,246,245,241,243,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,127,127,127,127,127,127,127,63,191,191,191,250,249,248,253,252,254,254,254,254,255,255,255,255,255,255,255,255,255,255,255,255,127,127,127,127,127,127,127,127,127,127,127,127,191,191,159,223,223,223,223,223,239,239,239,239,239,239,231,231,243,123,251,253,254,254,254,254,255,239,251,255,255,255,255,251,255,253,251,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,253,253,253,253,253,249,251,251,251,245,243,237,235,229,235,215,203,223,215,203,215,222,219,203,213,203,215,207,215,207,215,223,207,215,207,215,159,151,175,183,171,183,175,183,191,159,55,127]), + bytearray([1,11,2,36,4,8,80,48,32,32,32,64,192,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,32,0,8,0,0,0,6,0,16,1,1,3,3,6,36,12,72,88,16,48,32,64,192,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,128,0,128,64,160,64,160,64,168,208,168,208,104,80,100,104,52,40,20,24,20,24,20,24,20,24,20,24,21,9,10,14,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,128,128,128,128,128,128,128,128,192,64,64,64, + 5,6,7,2,3,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,128,128,128,128,128,128,128,128,128,128,128,128,64,64,96,32,32,32,32,32,16,16,16,16,16,16,24,24,12,132,4,2,1,1,1,1,0,16,4,0,0,0,0,4,0,2,4,1,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,6,4,4,4,10,12,18,20,26,20,40,52,32,40,52,40,33,36,52,42,52,40,48,40,48,40,32,48,40,48,40,96,104,80,72,84,72,80,72,64,96,200,128]), None, 70, 40 @@ -131,6 +129,6 @@ leaf = SpriteImage( ) UNDERGROUND_OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle] -OVERGROUND_OBSTACLES = [spaceinv, spaceinv2, leaf] +OVERGROUND_OBSTACLES = [spaceinv, leaf] OBSTACLES = UNDERGROUND_OBSTACLES + OVERGROUND_OBSTACLES diff --git a/player.py b/player.py index 783a911..08b0235 100644 --- a/player.py +++ b/player.py @@ -65,17 +65,17 @@ class Player: self.y = int(self.ysub) # animation - self.anim.update_phys(self.x, self.y, CONST_PL_SCREEN_Y) + self.anim.update_phys(self.x, self.y, CONST_PL_SCREEN_Y, current_depth) - def update_draw(self, current_depth, prev_depth): + def update_draw(self, plworldy): # debug draw if self.debugvisible: pix_x = self.x - pix_y = int(current_depth - self.y) + pix_y = int(self.y - plworldy + 20) thumby.display.setPixel(pix_x, pix_y, self.isdecend) # animation - self.anim.update_draw(current_depth, prev_depth, self.isdecend) + self.anim.update_draw(plworldy - 20, self.isdecend) class Camera: @@ -101,7 +101,9 @@ class PlayerAnimation: self.debugrandomrange = self.RANDOM_RANGE self.debugposrange = self.POS_RANGE - def update_phys(self, plworldx, plworldy, plscreeny): + def update_phys(self, plworldx, plworldy, plscreeny, current_depth): + + #print(plworldx, plworldy, plscreeny, current_depth) ### exit if player y pos less than random range # # debug change random range @@ -157,19 +159,21 @@ 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, current_depth, prev_depth, isdecend=1): + def update_draw(self, topleft, prev_depth, isdecend=1): ### draw line from first position to next + #print(topleft) + for i in range(len(self.poslist) - 1): thumby.display.drawLine( int(self.poslist[i][self.POS_X]), - int(current_depth - self.poslist[i][self.POS_Y]), + int(self.poslist[i][self.POS_Y] - topleft), int(self.poslist[i + 1][self.POS_X]), - int(current_depth - self.poslist[i + 1][self.POS_Y]), + int(self.poslist[i + 1][self.POS_Y] - topleft), isdecend ) diff --git a/sprites.py b/sprites.py index f37ef6f..06e73c2 100644 --- a/sprites.py +++ b/sprites.py @@ -33,8 +33,8 @@ class Entity: return False if loc_x < self.x or loc_x >= self.x + self.width or loc_y < self.y or loc_y >= self.y + self.height: return False - rel_x = loc_x - self.x - rel_y = loc_y - self.y + rel_x = int(loc_x - self.x) + rel_y = int(loc_y - self.y) return bool((self.collision[rel_x] >> (self.height - rel_y)) & 1) def can_render(self, current_depth: int) -> bool: @@ -124,14 +124,18 @@ def update_entities(current_slice: ObstacleSlice, current_depth: int, prev_depth # Local y relative to the top of the slice slice_y = (current_depth) % ObstacleSlice.height slice_prev_y = (prev_depth) % ObstacleSlice.height - if slice_prev_y > slice_y: + if prev_depth < current_depth and slice_prev_y > slice_y: slice_prev_y -= ObstacleSlice.height + elif current_depth < prev_depth and slice_y > slice_prev_y: + slice_prev_y += ObstacleSlice.height + min_y = min(slice_prev_y, slice_y) + max_y = max(slice_prev_y, slice_y) spawned = set() for entity in current_slice.obstacle_map: # The position the entity should spawn at, relative to the slice top entity_y = entity[1] - if entity_y >= slice_prev_y and entity_y < slice_y: + if entity_y >= min_y and entity_y < max_y: sprite_image = OBSTACLES[entity[2]] sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, 0, entity[3], entity[4]) - spawned.add(Obstacle(entity[0], entity_y + current_depth // ObstacleSlice.height * ObstacleSlice.height, sprite_image.width, sprite_image.height, sprite_image.collision, sprite)) + spawned.add(Obstacle(entity[0], entity_y + current_depth // ObstacleSlice.height * ObstacleSlice.height, sprite_image.width, sprite_image.height, sprite_image.collision or sprite_image.image, sprite)) return spawned