Compare commits
2 Commits
negative-s
...
build_upda
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15d86a7391 | ||
|
|
05d5734c66 |
75
Throot.py
75
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
|
||||
|
||||
@@ -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]
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user