From 15d86a73919e65a6cdcc29be539cb8c985d49e35 Mon Sep 17 00:00:00 2001 From: Neal Finger Date: Sun, 5 Feb 2023 14:59:08 -0700 Subject: [PATCH] general update merge water, update game loop --- Throot.py | 75 ++++++++++++++++++++++++++++++++++++++++++++---- artrepository.py | 9 +++++- player.py | 2 +- sprites.py | 1 - 4 files changed, 78 insertions(+), 9 deletions(-) diff --git a/Throot.py b/Throot.py index 59c26ac..0878d8b 100644 --- a/Throot.py +++ b/Throot.py @@ -7,12 +7,14 @@ import Games.Throot.map import Games.Throot.sprites from random import randrange -from Games.Throot.artrepository import OBSTACLES + +from Games.Throot.artrepository import * from Games.Throot.player import Player, Camera from Games.Throot.map import ObstacleSlice, OBSTACLE_SLICES from Games.Throot.sprites import Obstacle, update_entities from Games.Throot.constants import * + class GameManager: def __init__(self, *rooms): self.rooms = rooms @@ -76,7 +78,6 @@ class RoomTitle(Room): class GameLoop(Room): def __init__(self): - self.current_depth = 0 self.diving_velocity = 10 self.diving_accel = 0 self.current_obstacle_slice = OBSTACLE_SLICES[0] @@ -86,18 +87,67 @@ class GameLoop(Room): self.camera = None self.score = 0 + self.level = 0 + self.finish_depth = 0 + + self.waterx = float(0) def start(self, event): - self.current_depth = 0 self.entities.clear() self.current_obstacle_slice = OBSTACLE_SLICES[0] self.player = Player() self.player.yspeed = 10 self.score = 0 + + self.finish_depth = 100 + 5 * self.level ** 2 self.camera = Camera(self.player) def get_obstacle_slice(self): return OBSTACLE_SLICES[randrange(0, len(OBSTACLE_SLICES))] + + def draw_water(self): + # bookwater + + # exit if depth is less than 2 screens of the finish depth + if self.player.y + thumby.display.height < self.finish_depth: + return + + self.waterx += sprite_water.width / CONST_FPS + if self.waterx > sprite_water.width: + self.waterx = 0 + + # water surface. + for i in range(math.ceil(thumby.display.width / sprite_water.width) + 1): + + x, y = self.camera.relative_to_camera( + (int(self.waterx) - sprite_water.width) + i * sprite_water.width, + self.finish_depth + ) + + thumby.display.blit( + sprite_water[0], + int(x), int(y), + sprite_water.width, sprite_water.height, + 0, + 0, 0 + ) + + # water below surface + x, y = self.camera.relative_to_camera( + 0, + self.finish_depth + ) + + thumby.display.drawFilledRectangle( + int(x), int(y) + sprite_water.height, + thumby.display.width, self.finish_depth + thumby.display.height * 3, + 1, + ) + + # win text + if self.player.y > self.finish_depth + (thumby.display.height // 2): + thumby.display.drawText('water reach!', 0, thumby.display.height // 4, 0) + thumby.display.drawText(f' stage {self.level + 1}', 0, thumby.display.height // 4 + 9, 0) def update(self, tpf): """ @@ -110,7 +160,10 @@ class GameLoop(Room): self.camera.update_phys() # Generate new entities as needed - self.entities |= update_entities(self.entities, 5, self.player.ysub, self.player.prev_y) + if abs(self.player.y) < abs(self.finish_depth): + self.entities |= update_entities(self.entities, 5, self.player.ysub, self.player.prev_y) + else: + self.entities.clear() # Updates the entities to_remove = set() @@ -121,20 +174,30 @@ class GameLoop(Room): if isinstance(entity, Obstacle): return { 'room': ROOM_END, - 'score': self.score + 'score': self.score, + 'level': self.level + 1 } self.entities -= to_remove - self.score = self.player.x#int(abs(self.player.y) * 10) + self.score = int(abs(self.player.y) * 10) + + # finish level + if self.player.y > self.finish_depth + int(thumby.display.height * 1.5): + self.level += 1 + self.start({}) thumby.display.fill(0) + # Draw the entities for entity in self.entities: entity.render(tpf, self.camera) self.player.update_draw(self.camera) + self.draw_water() + thumby.display.drawText(str(self.score), thumby.display.width - (len(str(self.score)) + 2) * 5, 1, 1) + class EndRoom(Room): def __init__(self): self.score = 0 diff --git a/artrepository.py b/artrepository.py index b77bb25..09464ed 100644 --- a/artrepository.py +++ b/artrepository.py @@ -175,4 +175,11 @@ Doritoobstaclelvl5 = SpriteImage( 30 ) -OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, leaf, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle, spaceinv,annoydead,lvl4wall,ballobstaclelvl3,Doritoobstaclelvl5] +sprite_water = SpriteImage( + bytearray([224,240,240,248,252,248,240,240]), + None, + 8, + 8 +) + +OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, leaf, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle, spaceinv,annoydead,lvl4wall,ballobstaclelvl3,Doritoobstaclelvl5] \ No newline at end of file diff --git a/player.py b/player.py index 93187d2..8e87f4c 100644 --- a/player.py +++ b/player.py @@ -33,7 +33,7 @@ class Player: self.accaccx = self.accx self.anim = PlayerAnimation(self.x, self.y) - self.debugvisible = True + self.debugvisible = False def update_phys(self, tpf, camera: Camera): self.prev_x = self.xsub diff --git a/sprites.py b/sprites.py index a57f250..8e81d5f 100644 --- a/sprites.py +++ b/sprites.py @@ -142,6 +142,5 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i break if not error: sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, 0, False, False) - print("Adding obstacle of to (%d, %d) of size (%d, %d)" % (x, y, sprite_image.width, sprite_image.height)) spawned.add(Obstacle(x, y, sprite_image.width, sprite_image.height, sprite_image.collision or sprite_image.image, sprite)) return spawned