2 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
4 changed files with 158 additions and 127 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,15 +236,23 @@ class GameLoop(Room):
self.score += int(abs(self.player.ysub - self.player.prev_y) * 10)
# finish level
if self.player.y > self.finish_depth + int(thumby.display.height * 1.5):
self.score += 20
self.level += 1
self.start({
'score': self.score,
'level': self.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({
'score': self.score,
'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

@@ -131,17 +131,25 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
return set()
spawned = set()
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:
if current_depth > 0:
max_spawned = randrange(0, difficulty + 1)
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