1 Commits

Author SHA1 Message Date
Neal Finger
1c68beb77a player animation
-all points for root animation are kept
-rendering lines will only render lines that are in the camera
2023-02-12 20:42:07 -07:00
4 changed files with 140 additions and 162 deletions

View File

@@ -100,7 +100,6 @@ class RoomTitle(Room):
thumby.display.drawSprite(spr_b)
class GameLoop(Room):
def __init__(self):
self.diving_velocity = 10
self.diving_accel = 0
@@ -126,17 +125,13 @@ class GameLoop(Room):
)
self.current_obstacle_slice = OBSTACLE_SLICES[0]
self.player = Player()
self.player.speed_y = 16
self.player.isdecend = 1
self.player.yspeed = 10
self.score = 'score' in event and event['score'] or 0
self.level = 'level' in event and event['level'] or 0
self.finish_depth = 100 + 5 * self.level ** 2
self.finish_height = -self.finish_depth
self.camera = Camera(self.player)
self.stage = DESCEND_STAGE
def get_obstacle_slice(self):
return OBSTACLE_SLICES[randrange(0, len(OBSTACLE_SLICES))]
@@ -206,7 +201,7 @@ class GameLoop(Room):
"""
super().update(tpf)
self.player.update_phys(tpf, self.stage in (DESCEND_STAGE, ASCEND_STAGE) and self.camera or None)
self.player.update_phys(tpf, self.camera)
self.camera.update_phys()
@@ -236,15 +231,7 @@ class GameLoop(Room):
self.score += int(abs(self.player.ysub - self.player.prev_y) * 10)
# finish level
if self.stage == DESCEND_STAGE:
if self.player.y > self.finish_depth + int(thumby.display.height * 1.5):
self.stage = ASCEND_STAGE
self.player.ysub = 0
self.player.prev_y = 0
self.player.speed_y *= -1
self.player.isdecend = 0
elif self.stage == ASCEND_STAGE:
if self.player.y < self.finish_height - int(thumby.display.height * 1.5):
self.score += 20
self.level += 1
self.start({
@@ -252,7 +239,7 @@ class GameLoop(Room):
'level': self.level
})
thumby.display.fill(int(self.player.y < 0))
thumby.display.fill(0)
self.draw_sky()
# Draw the entities
for entity in self.entities:
@@ -261,7 +248,7 @@ class GameLoop(Room):
self.draw_water()
thumby.display.drawText(str(self.score), thumby.display.width - (len(str(self.score)) + 2) * 5, 1, int(self.player.y > 0))
thumby.display.drawText(str(self.score), thumby.display.width - (len(str(self.score)) + 2) * 5, 1, 1)
class EndRoom(Room):

View File

@@ -5,13 +5,3 @@ ROOM_MAIN = 1
ROOM_END = 2
ROOM_NEXT = -1
# The first part of the level, where we are reaching the water
DESCEND_STAGE = 0
# The transition to the second part of the level, where the camera travels
# back to the surface
WATER_STAGE = 1
# The second part of the level, where we are growing into the sky
ASCEND_STAGE = 2
# The "level complete" animation
BLOOM_STAGE = 3

View File

@@ -174,12 +174,13 @@ class PlayerAnimation:
# new root point created exactly on player
self.add_point()
# remove points in list that would make lines off the camera
for point in self.points[1:]:
if camera.entity_in_camera(point.x, point.y):
break
# points are not removed so the camera can pan back up
# # remove points in list that would render lines off the camera
# for point in self.points[1:]:
# if camera.entity_in_camera(point.x, point.y):
# break
self.points.pop(0)
# self.points.pop(0)
def update_draw(self, camera, isdecend=1):
# debug render
@@ -188,7 +189,7 @@ class PlayerAnimation:
thumby.display.setPixel(int(pix_x), int(pix_y), isdecend)
return
# root always reaches player position
# draw line from last point to player
if self.debug_exact:
x1, y1 = camera.relative_to_camera(self.player.x, self.player.y)
x2, y2 = camera.relative_to_camera(self.points[-1].x, self.points[-1].y)
@@ -200,9 +201,17 @@ class PlayerAnimation:
isdecend
)
# draw line from first position to next
# draw line from last point to previous
point_off_camera_count = 2
point_prev = self.points[-1]
for point in self.points[-2::-1]:
# break if entire line is off camera
if not camera.entity_in_camera(point.x, point.y):
point_off_camera_count -= 1
if point_off_camera_count <= 0:
break
x1, y1 = camera.relative_to_camera(point_prev.x, point_prev.y)
x2, y2 = camera.relative_to_camera(point.x, point.y)
point_prev = point

View File

@@ -131,25 +131,17 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
return set()
spawned = set()
if current_depth > 0:
max_spawned = randrange(0, difficulty + 1)
while len(spawned) < max_spawned and random() < (2 * math.pow(difficulty + 0.01, 2)) / (3 * math.pow(difficulty + 0.01, 2) + 20 * (difficulty + 0.01)) + 0.05:
if random() < 0.2:
Clazz = Collectible
if current_depth >= 0:
sprite_image = collectibleunder
else:
sprite_image = collectibleover
else:
max_spawned = randrange(0, int(5 / (0.3 * difficulty + 0.7)))
print(f"Spawning {max_spawned} entities this tick")
while len(spawned) < max_spawned:
if current_depth > 0:
if random() >= (2 * math.pow(difficulty + 0.01, 2)) / (3 * math.pow(difficulty + 0.01, 2) + 20 * (difficulty + 0.01)) + 0.05:
print(f"Cancelling obstacles after {len(spawned)} entities")
break
Clazz = Obstacle
sprite_image = OBSTACLES[randrange(0, min((difficulty + 1) * 3, len(OBSTACLES)))]
else:
if random() >= 1 / (math.pow(difficulty, 2) + 3):
print(f"Cancelling obstacles after {len(spawned)} entities")
break
Clazz = Collectible
sprite_image = collectibleover
if sprite_image.width >= thumby.display.width:
x = 0
else:
@@ -165,6 +157,6 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
error = True
break
if not error:
sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, int(y < 0), False, False)
sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, 0, False, False)
spawned.add(Clazz(x, y, sprite_image.width, sprite_image.height, sprite_image.collision or sprite_image.image, sprite))
return spawned