Compare commits
1 Commits
ascend
...
player-ani
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c68beb77a |
35
Throot.py
35
Throot.py
@@ -100,7 +100,6 @@ class RoomTitle(Room):
|
|||||||
thumby.display.drawSprite(spr_b)
|
thumby.display.drawSprite(spr_b)
|
||||||
|
|
||||||
class GameLoop(Room):
|
class GameLoop(Room):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.diving_velocity = 10
|
self.diving_velocity = 10
|
||||||
self.diving_accel = 0
|
self.diving_accel = 0
|
||||||
@@ -126,17 +125,13 @@ class GameLoop(Room):
|
|||||||
)
|
)
|
||||||
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
||||||
self.player = Player()
|
self.player = Player()
|
||||||
self.player.speed_y = 16
|
self.player.yspeed = 10
|
||||||
self.player.isdecend = 1
|
|
||||||
self.score = 'score' in event and event['score'] or 0
|
self.score = 'score' in event and event['score'] or 0
|
||||||
self.level = 'level' in event and event['level'] or 0
|
self.level = 'level' in event and event['level'] or 0
|
||||||
|
|
||||||
self.finish_depth = 100 + 5 * self.level ** 2
|
self.finish_depth = 100 + 5 * self.level ** 2
|
||||||
self.finish_height = -self.finish_depth
|
|
||||||
self.camera = Camera(self.player)
|
self.camera = Camera(self.player)
|
||||||
|
|
||||||
self.stage = DESCEND_STAGE
|
|
||||||
|
|
||||||
def get_obstacle_slice(self):
|
def get_obstacle_slice(self):
|
||||||
return OBSTACLE_SLICES[randrange(0, len(OBSTACLE_SLICES))]
|
return OBSTACLE_SLICES[randrange(0, len(OBSTACLE_SLICES))]
|
||||||
|
|
||||||
@@ -206,7 +201,7 @@ class GameLoop(Room):
|
|||||||
"""
|
"""
|
||||||
super().update(tpf)
|
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()
|
self.camera.update_phys()
|
||||||
|
|
||||||
@@ -236,23 +231,15 @@ class GameLoop(Room):
|
|||||||
self.score += int(abs(self.player.ysub - self.player.prev_y) * 10)
|
self.score += int(abs(self.player.ysub - self.player.prev_y) * 10)
|
||||||
|
|
||||||
# finish level
|
# finish level
|
||||||
if self.stage == DESCEND_STAGE:
|
if self.player.y > self.finish_depth + int(thumby.display.height * 1.5):
|
||||||
if self.player.y > self.finish_depth + int(thumby.display.height * 1.5):
|
self.score += 20
|
||||||
self.stage = ASCEND_STAGE
|
self.level += 1
|
||||||
self.player.ysub = 0
|
self.start({
|
||||||
self.player.prev_y = 0
|
'score': self.score,
|
||||||
self.player.speed_y *= -1
|
'level': self.level
|
||||||
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(int(self.player.y < 0))
|
thumby.display.fill(0)
|
||||||
self.draw_sky()
|
self.draw_sky()
|
||||||
# Draw the entities
|
# Draw the entities
|
||||||
for entity in self.entities:
|
for entity in self.entities:
|
||||||
@@ -261,7 +248,7 @@ class GameLoop(Room):
|
|||||||
|
|
||||||
self.draw_water()
|
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):
|
class EndRoom(Room):
|
||||||
|
|||||||
10
constants.py
10
constants.py
@@ -5,13 +5,3 @@ ROOM_MAIN = 1
|
|||||||
ROOM_END = 2
|
ROOM_END = 2
|
||||||
ROOM_NEXT = -1
|
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
|
|
||||||
|
|||||||
23
player.py
23
player.py
@@ -174,12 +174,13 @@ class PlayerAnimation:
|
|||||||
# new root point created exactly on player
|
# new root point created exactly on player
|
||||||
self.add_point()
|
self.add_point()
|
||||||
|
|
||||||
# remove points in list that would make lines off the camera
|
# points are not removed so the camera can pan back up
|
||||||
for point in self.points[1:]:
|
# # remove points in list that would render lines off the camera
|
||||||
if camera.entity_in_camera(point.x, point.y):
|
# for point in self.points[1:]:
|
||||||
break
|
# 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):
|
def update_draw(self, camera, isdecend=1):
|
||||||
# debug render
|
# debug render
|
||||||
@@ -188,7 +189,7 @@ class PlayerAnimation:
|
|||||||
thumby.display.setPixel(int(pix_x), int(pix_y), isdecend)
|
thumby.display.setPixel(int(pix_x), int(pix_y), isdecend)
|
||||||
return
|
return
|
||||||
|
|
||||||
# root always reaches player position
|
# draw line from last point to player
|
||||||
if self.debug_exact:
|
if self.debug_exact:
|
||||||
x1, y1 = camera.relative_to_camera(self.player.x, self.player.y)
|
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)
|
x2, y2 = camera.relative_to_camera(self.points[-1].x, self.points[-1].y)
|
||||||
@@ -200,9 +201,17 @@ class PlayerAnimation:
|
|||||||
isdecend
|
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]
|
point_prev = self.points[-1]
|
||||||
for point in self.points[-2::-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)
|
x1, y1 = camera.relative_to_camera(point_prev.x, point_prev.y)
|
||||||
x2, y2 = camera.relative_to_camera(point.x, point.y)
|
x2, y2 = camera.relative_to_camera(point.x, point.y)
|
||||||
point_prev = point
|
point_prev = point
|
||||||
|
|||||||
28
sprites.py
28
sprites.py
@@ -131,25 +131,17 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
|
|||||||
return set()
|
return set()
|
||||||
|
|
||||||
spawned = set()
|
spawned = set()
|
||||||
if current_depth > 0:
|
max_spawned = randrange(0, difficulty + 1)
|
||||||
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:
|
||||||
else:
|
if random() < 0.2:
|
||||||
max_spawned = randrange(0, int(5 / (0.3 * difficulty + 0.7)))
|
Clazz = Collectible
|
||||||
print(f"Spawning {max_spawned} entities this tick")
|
if current_depth >= 0:
|
||||||
while len(spawned) < max_spawned:
|
sprite_image = collectibleunder
|
||||||
if current_depth > 0:
|
else:
|
||||||
if random() >= (2 * math.pow(difficulty + 0.01, 2)) / (3 * math.pow(difficulty + 0.01, 2) + 20 * (difficulty + 0.01)) + 0.05:
|
sprite_image = collectibleover
|
||||||
print(f"Cancelling obstacles after {len(spawned)} entities")
|
else:
|
||||||
break
|
|
||||||
Clazz = Obstacle
|
Clazz = Obstacle
|
||||||
sprite_image = OBSTACLES[randrange(0, min((difficulty + 1) * 3, len(OBSTACLES)))]
|
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:
|
if sprite_image.width >= thumby.display.width:
|
||||||
x = 0
|
x = 0
|
||||||
else:
|
else:
|
||||||
@@ -165,6 +157,6 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
|
|||||||
error = True
|
error = True
|
||||||
break
|
break
|
||||||
if not error:
|
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))
|
spawned.add(Clazz(x, y, sprite_image.width, sprite_image.height, sprite_image.collision or sprite_image.image, sprite))
|
||||||
return spawned
|
return spawned
|
||||||
|
|||||||
Reference in New Issue
Block a user