4 Commits

Author SHA1 Message Date
Markil3
6ccb425057 Sets collectibles for ascending. 2023-02-25 12:57:56 -07:00
Markil3
33ed9c062a Adds a second stage for ascending. 2023-02-25 04:47:02 -07:00
Neal Finger
3c41ef7535 Merge pull request #14 from Markil3/player-animation-update
Update player.py
2023-02-12 13:30:00 -07:00
Neal Finger
c37d9d9911 Merge pull request #13 from Markil3/player-animation-update
Player animation update
2023-02-12 13:25:32 -07:00
4 changed files with 164 additions and 142 deletions

View File

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

View File

@@ -5,3 +5,13 @@ 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,13 +174,12 @@ class PlayerAnimation:
# new root point created exactly on player
self.add_point()
# 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
# 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
# self.points.pop(0)
self.points.pop(0)
def update_draw(self, camera, isdecend=1):
# debug render
@@ -189,7 +188,7 @@ class PlayerAnimation:
thumby.display.setPixel(int(pix_x), int(pix_y), isdecend)
return
# draw line from last point to player
# root always reaches player position
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)
@@ -201,17 +200,9 @@ class PlayerAnimation:
isdecend
)
# draw line from last point to previous
point_off_camera_count = 2
# draw line from first position to next
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,17 +131,25 @@ 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:
@@ -157,6 +165,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, 0, False, False)
sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, int(y < 0), False, False)
spawned.add(Clazz(x, y, sprite_image.width, sprite_image.height, sprite_image.collision or sprite_image.image, sprite))
return spawned