Compare commits
21 Commits
subpixel-c
...
build_upda
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15d86a7391 | ||
|
|
05d5734c66 | ||
|
|
8d90129dbd | ||
|
|
05dd0a1cfd | ||
|
|
518bf5f5e6 | ||
|
|
e03d74be36 | ||
|
|
b80c215d98 | ||
|
|
2c4584e05b | ||
|
|
a4e87421bb | ||
|
|
e73eb5a765 | ||
|
|
ad4a5de10e | ||
|
|
e25a5dd9cc | ||
|
|
15e3c33c87 | ||
|
|
9dd1c7df90 | ||
|
|
df4fd1228e | ||
|
|
176d89ea14 | ||
|
|
6cd766a848 | ||
|
|
4b8eb17ba1 | ||
|
|
f2c7f19d96 | ||
|
|
8ad6236ff7 | ||
|
|
d0cf8f2a20 |
150
Throot.py
150
Throot.py
@@ -7,15 +7,15 @@ import Games.Throot.map
|
|||||||
import Games.Throot.sprites
|
import Games.Throot.sprites
|
||||||
|
|
||||||
from random import randrange
|
from random import randrange
|
||||||
from Games.Throot.artrepository import OBSTACLES
|
|
||||||
from Games.Throot.player import Player
|
from Games.Throot.artrepository import *
|
||||||
|
from Games.Throot.player import Player, Camera
|
||||||
from Games.Throot.map import ObstacleSlice, OBSTACLE_SLICES
|
from Games.Throot.map import ObstacleSlice, OBSTACLE_SLICES
|
||||||
from Games.Throot.sprites import Obstacle, update_entities
|
from Games.Throot.sprites import Obstacle, update_entities
|
||||||
from Games.Throot.constants import CONST_FPS
|
from Games.Throot.constants import *
|
||||||
|
|
||||||
|
|
||||||
class GameManager:
|
class GameManager:
|
||||||
EVENT_ROOM_CHANGE = {'start': 0, 'main': 1, 'end': 2, 'next': -1}
|
|
||||||
|
|
||||||
def __init__(self, *rooms):
|
def __init__(self, *rooms):
|
||||||
self.rooms = rooms
|
self.rooms = rooms
|
||||||
self.room_index = 0
|
self.room_index = 0
|
||||||
@@ -24,13 +24,14 @@ class GameManager:
|
|||||||
# Set the FPS (without this call, the default fps is 30)
|
# Set the FPS (without this call, the default fps is 30)
|
||||||
thumby.display.setFPS(CONST_FPS)
|
thumby.display.setFPS(CONST_FPS)
|
||||||
|
|
||||||
def room_goto(self, index):
|
def room_goto(self, event):
|
||||||
|
index = event['room']
|
||||||
if index < 0:
|
if index < 0:
|
||||||
self.room_index = min(self.room_index + 1, len(self.rooms))
|
self.room_index = min(self.room_index + 1, len(self.rooms))
|
||||||
else:
|
else:
|
||||||
self.room_index = index
|
self.room_index = index
|
||||||
|
|
||||||
self.rooms[self.room_index].start()
|
self.rooms[self.room_index].start(event)
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
self.room_index = 0
|
self.room_index = 0
|
||||||
@@ -41,11 +42,11 @@ class GameManager:
|
|||||||
thumby.display.update()
|
thumby.display.update()
|
||||||
|
|
||||||
if event:
|
if event:
|
||||||
self.room_goto(self.EVENT_ROOM_CHANGE[event])
|
self.room_goto(event)
|
||||||
|
|
||||||
|
|
||||||
class Room:
|
class Room:
|
||||||
def start(self):
|
def start(self, event):
|
||||||
t0 = time.ticks_ms() # Get time (ms)
|
t0 = time.ticks_ms() # Get time (ms)
|
||||||
thumby.display.fill(0) # Fill canvas to black
|
thumby.display.fill(0) # Fill canvas to black
|
||||||
|
|
||||||
@@ -58,7 +59,9 @@ class RoomTitle(Room):
|
|||||||
super().update(tpf)
|
super().update(tpf)
|
||||||
|
|
||||||
if thumby.inputPressed():
|
if thumby.inputPressed():
|
||||||
return 'main'
|
return {
|
||||||
|
'room': ROOM_MAIN
|
||||||
|
}
|
||||||
|
|
||||||
# draw title sprite
|
# draw title sprite
|
||||||
title_text = 'press a to start'
|
title_text = 'press a to start'
|
||||||
@@ -75,65 +78,148 @@ class RoomTitle(Room):
|
|||||||
|
|
||||||
class GameLoop(Room):
|
class GameLoop(Room):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.current_depth = 0
|
|
||||||
self.diving_velocity = 10
|
self.diving_velocity = 10
|
||||||
self.diving_accel = 0
|
self.diving_accel = 0
|
||||||
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
||||||
self.entities = set()
|
self.entities = set()
|
||||||
|
|
||||||
self.player = Player()
|
self.player = None
|
||||||
|
self.camera = None
|
||||||
|
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
self.level = 0
|
||||||
|
self.finish_depth = 0
|
||||||
|
|
||||||
|
self.waterx = float(0)
|
||||||
|
|
||||||
|
def start(self, event):
|
||||||
|
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):
|
def get_obstacle_slice(self):
|
||||||
return OBSTACLE_SLICES[randrange(0, len(OBSTACLE_SLICES))]
|
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):
|
def update(self, tpf):
|
||||||
"""
|
"""
|
||||||
Executes one tick of the game
|
Executes one tick of the game
|
||||||
"""
|
"""
|
||||||
super().update(tpf)
|
super().update(tpf)
|
||||||
prev_depth = self.current_depth
|
|
||||||
self.diving_velocity += self.diving_accel * tpf
|
|
||||||
self.current_depth += self.diving_velocity * tpf
|
|
||||||
|
|
||||||
#print("%f (%f)" % (self.current_depth, self.current_depth % ObstacleSlice.height))
|
self.player.update_phys(tpf, self.camera)
|
||||||
|
|
||||||
#print("%f -> %f: %f -> %f" % (prev_depth, self.current_depth, prev_depth % ObstacleSlice.height, self.current_depth % ObstacleSlice.height))
|
self.camera.update_phys()
|
||||||
if (
|
|
||||||
self.current_depth > prev_depth and self.current_depth % ObstacleSlice.height < prev_depth % ObstacleSlice.height
|
|
||||||
or self.current_depth < prev_depth and self.current_depth % ObstacleSlice.height > prev_depth % ObstacleSlice.height
|
|
||||||
):
|
|
||||||
self.current_obstacle_slice = self.get_obstacle_slice()
|
|
||||||
|
|
||||||
self.player.update_phys(self.current_depth, prev_depth)
|
|
||||||
|
|
||||||
# Generate new entities as needed
|
# Generate new entities as needed
|
||||||
self.entities |= update_entities(self.current_obstacle_slice, self.current_depth, prev_depth)
|
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
|
# Updates the entities
|
||||||
to_remove = set()
|
to_remove = set()
|
||||||
for entity in self.entities:
|
for entity in self.entities:
|
||||||
if not entity.update(tpf, self.current_depth, prev_depth):
|
if not entity.update(tpf, self.player, self.camera) or abs(entity.y - self.player.y) > self.camera.height * 1.5:
|
||||||
to_remove.add(entity)
|
to_remove.add(entity)
|
||||||
elif entity.intersects_pixel(self.player.xsub, self.player.ysub):
|
elif entity.intersects_pixel(self.player.xsub, self.player.ysub):
|
||||||
if isinstance(entity, Obstacle):
|
if isinstance(entity, Obstacle):
|
||||||
print("Hit!")
|
return {
|
||||||
|
'room': ROOM_END,
|
||||||
|
'score': self.score,
|
||||||
|
'level': self.level + 1
|
||||||
|
}
|
||||||
self.entities -= to_remove
|
self.entities -= to_remove
|
||||||
|
|
||||||
self.score = int(self.current_depth * 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)
|
thumby.display.fill(0)
|
||||||
|
|
||||||
# Draw the entities
|
# Draw the entities
|
||||||
for entity in self.entities:
|
for entity in self.entities:
|
||||||
entity.render(tpf, self.current_depth, prev_depth)
|
entity.render(tpf, self.camera)
|
||||||
self.player.update_draw(self.current_depth, prev_depth)
|
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)
|
thumby.display.drawText(str(self.score), thumby.display.width - (len(str(self.score)) + 2) * 5, 1, 1)
|
||||||
thumby.display.update()
|
|
||||||
|
|
||||||
|
class EndRoom(Room):
|
||||||
|
def __init__(self):
|
||||||
|
self.score = 0
|
||||||
|
|
||||||
|
def start(self, event):
|
||||||
|
self.score = event['score']
|
||||||
|
# Used to make sure that we aren't triggering from input mean't for the game.
|
||||||
|
self.still_pressed = thumby.inputPressed()
|
||||||
|
|
||||||
|
def update(self, tpf):
|
||||||
|
if not thumby.inputPressed():
|
||||||
|
self.still_pressed = False
|
||||||
|
elif not self.still_pressed and thumby.inputPressed():
|
||||||
|
return {
|
||||||
|
'room': ROOM_START
|
||||||
|
}
|
||||||
|
thumby.display.fill(0)
|
||||||
|
thumby.display.drawText("Final Score:", (thumby.display.width - 60) // 2, 1, 1)
|
||||||
|
thumby.display.drawText(str(self.score), (thumby.display.width - (len(str(self.score)) * 5)) // 2, 9, 1)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
game = GameManager(RoomTitle(), GameLoop())
|
game = GameManager(RoomTitle(), GameLoop(), EndRoom())
|
||||||
game.start()
|
game.start()
|
||||||
|
|
||||||
prev_time = 0
|
prev_time = 0
|
||||||
|
|||||||
BIN
ThrootTitle.raw
Normal file
BIN
ThrootTitle.raw
Normal file
Binary file not shown.
@@ -122,13 +122,64 @@ bigdoritoobstacle = SpriteImage(
|
|||||||
)
|
)
|
||||||
# BITMAP: width: 16, height: 16
|
# BITMAP: width: 16, height: 16
|
||||||
leaf = SpriteImage(
|
leaf = SpriteImage(
|
||||||
bytearray([128,1,1,1,3,3,3,71,135,15,15,31,63,255,255,255,255,254,252,248,240,240,224,224,192,193,194,196,200,144,1,63]),
|
bytearray([127,254,254,254,252,252,252,184,120,240,240,224,192,0,0,0,
|
||||||
|
0,1,3,7,15,15,31,31,63,62,61,59,55,111,254,192]),
|
||||||
None,
|
None,
|
||||||
16,
|
16,
|
||||||
16
|
16
|
||||||
)
|
)
|
||||||
|
|
||||||
UNDERGROUND_OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle]
|
annoydead = SpriteImage(
|
||||||
OVERGROUND_OBSTACLES = [spaceinv, leaf]
|
bytearray([0,240,214,236,54,190,214,238,212,254,248,240,224,192,192,128,128,128,128,240,0,
|
||||||
|
0,63,255,254,126,126,254,255,127,127,127,127,127,255,255,127,127,255,255,31,0,
|
||||||
|
0,0,1,0,0,0,3,1,0,0,0,0,0,3,1,0,0,1,0,0,0]),
|
||||||
|
None,
|
||||||
|
21,
|
||||||
|
19
|
||||||
|
)
|
||||||
|
|
||||||
OBSTACLES = UNDERGROUND_OBSTACLES + OVERGROUND_OBSTACLES
|
flowerpetals = SpriteImage(
|
||||||
|
bytearray([0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,252,254,254,254,254,252,248,
|
||||||
|
0,0,0,0,0,252,254,255,255,255,255,255,254,254,223,63,255,255,255,255,255,255,
|
||||||
|
0,224,248,252,252,252,255,255,255,247,239,239,223,255,255,255,255,255,251,255,255,255]),
|
||||||
|
None,
|
||||||
|
22,
|
||||||
|
24
|
||||||
|
)
|
||||||
|
|
||||||
|
flowerpetalanim = SpriteImage(
|
||||||
|
bytearray([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,191,191,7,55,231,227,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,191,191,191,7,115,249,253,252,254,252,255,255,255,255,255,31,79,239,231,224,238,223,223,223,191,255,254,248,243,255,255,255,255,255,255,255,255,255,127,127,127,127,127,127,127,7,241,252,254,254,254,254,253,249,255,255,255,255,1,252,254,255,255,255,255,255,254,254,223,63,255,255,255,255,255,255,15,227,249,253,253,252,255,255,255,247,239,239,223,255,255,255,255,255,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,207,247,243,251,243,247,199,255,255,255,255,255,15,231,243,249,253,253,253,253,252,254,247,231,207,255,255,255,255,255,31,199,243,251,250,248,255,255,239,223,191,255,255,255,255,255,255,255,255,255,255]),
|
||||||
|
None,
|
||||||
|
22,
|
||||||
|
24
|
||||||
|
)
|
||||||
|
|
||||||
|
lvl4wall = SpriteImage(
|
||||||
|
bytearray([255,255,254,254,252,252,248,248,240,240,224,224,192,192,192,128,128,0,0,0,0,224,240,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,240,224,0,0,0,224,240,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,63,0,0,0,0,63,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,31,0,0,0,63,127,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,63,31,31,15,15,7,7,3,3,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),
|
||||||
|
None,
|
||||||
|
72,
|
||||||
|
30
|
||||||
|
)
|
||||||
|
|
||||||
|
ballobstaclelvl3 = SpriteImage(
|
||||||
|
bytearray([0,0,0,0,0,0,0,0,192,224,240,240,248,252,252,252,254,254,254,254,254,254,252,252,252,248,240,240,224,192,0,0,0,0,0,0,0,0,0,0,192,224,240,240,248,252,252,252,254,254,254,254,254,254,252,252,252,248,240,240,224,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,240,0,0,0,0,240,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,240,0,0,0,0,0,0,0,0,0,0,0,0,3,31,63,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,31,3,0,0,0,0,3,31,63,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,31,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,3,7,15,15,15,31,31,31,31,31,31,15,15,15,7,3,3,1,0,0,0,0,0,0,0,0,0,0,0,0,1,3,3,7,15,15,15,31,31,31,31,31,31,15,15,15,7,3,3,1,0,0,0,0,0,0,0,0,0,0,0]),
|
||||||
|
None,
|
||||||
|
72,
|
||||||
|
30
|
||||||
|
)
|
||||||
|
|
||||||
|
Doritoobstaclelvl5 = SpriteImage(
|
||||||
|
bytearray([254,254,254,254,254,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,248,248,248,248,248,248,248,248,248,248,248,248,248,240,224,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,128,192,192,224,224,240,248,248,252,252,254,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,63,31,31,15,7,3,3,3,3,1,0,0,0,0,0,0,128,128,192,224,224,240,240,248,252,252,254,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,63,63,31,31,31,15,15,7,7,7,3,3,1,1,1,0,0,0,0,0,0,0,0,128,128,192,224,240,248,248,252,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,3,3,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15]),
|
||||||
|
None,
|
||||||
|
72,
|
||||||
|
30
|
||||||
|
)
|
||||||
|
|
||||||
|
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]
|
||||||
@@ -1 +1,6 @@
|
|||||||
CONST_FPS = 60
|
CONST_FPS = 60
|
||||||
|
|
||||||
|
ROOM_START = 0
|
||||||
|
ROOM_MAIN = 1
|
||||||
|
ROOM_END = 2
|
||||||
|
ROOM_NEXT = -1
|
||||||
|
|||||||
1
flowerpetal.raw
Normal file
1
flowerpetal.raw
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?؟؟7هك<D987><D983><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>؟؟؟s<><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Oُهـَ<D980><D98E><EFBFBD>؟<EFBFBD><D89F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ّ<><D991><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><01><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<3F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ك<><D983><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ُُ<D98F><D98F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>د<><D8AF><EFBFBD><EFBFBD><EFBFBD>ا<EFBFBD><D8A7><EFBFBD><EFBFBD><EFBFBD>ه<><D987><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>هد<D987><D8AF><EFBFBD><EFBFBD><EFBFBD>ا<><D8A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ُ<EFBFBD>؟<EFBFBD><D89F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
59
player.py
59
player.py
@@ -17,6 +17,8 @@ CONST_INP_MOVE_RIGHT = thumby.buttonA
|
|||||||
# classes
|
# classes
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.prev_x = 0
|
||||||
|
self.prev_y = 0
|
||||||
self.xsub = float(thumby.display.width / 2)
|
self.xsub = float(thumby.display.width / 2)
|
||||||
self.ysub = float(0)
|
self.ysub = float(0)
|
||||||
self.x = int(self.xsub)
|
self.x = int(self.xsub)
|
||||||
@@ -26,14 +28,16 @@ class Player:
|
|||||||
self.isdecend = 1
|
self.isdecend = 1
|
||||||
|
|
||||||
self.xspeed = 32 / CONST_FPS
|
self.xspeed = 32 / CONST_FPS
|
||||||
self.yspeed = 32 / CONST_FPS
|
self.yspeed = 32
|
||||||
self.accx = 1 / (CONST_FPS * 4)
|
self.accx = 1 / (CONST_FPS * 4)
|
||||||
self.accaccx = self.accx
|
self.accaccx = self.accx
|
||||||
|
|
||||||
self.anim = PlayerAnimation(self.x, self.y)
|
self.anim = PlayerAnimation(self.x, self.y)
|
||||||
self.debugvisible = True
|
self.debugvisible = False
|
||||||
|
|
||||||
def update_phys(self, current_depth, prev_depth):
|
def update_phys(self, tpf, camera: Camera):
|
||||||
|
self.prev_x = self.xsub
|
||||||
|
self.prev_y = self.ysub
|
||||||
inp = int(0)
|
inp = int(0)
|
||||||
if CONST_INP_MOVE_LEFT.pressed():
|
if CONST_INP_MOVE_LEFT.pressed():
|
||||||
inp -= 1
|
inp -= 1
|
||||||
@@ -58,35 +62,44 @@ class Player:
|
|||||||
self.xsub = max(min(xx, thumby.display.width - 1), 0)
|
self.xsub = max(min(xx, thumby.display.width - 1), 0)
|
||||||
|
|
||||||
### y movement
|
### y movement
|
||||||
self.ysub = current_depth - (thumby.display.height / 2)
|
|
||||||
|
self.ysub += self.yspeed * tpf
|
||||||
|
|
||||||
### pixel positions
|
### pixel positions
|
||||||
self.x = int(self.xsub)
|
self.x = int(self.xsub)
|
||||||
self.y = int(self.ysub)
|
self.y = int(self.ysub)
|
||||||
|
|
||||||
# animation
|
# animation
|
||||||
self.anim.update_phys(self.x, self.y, CONST_PL_SCREEN_Y)
|
self.anim.update_phys(self.x, self.y, camera)
|
||||||
|
|
||||||
def update_draw(self, current_depth, prev_depth):
|
def update_draw(self, camera):
|
||||||
# debug draw
|
# debug draw
|
||||||
if self.debugvisible:
|
if self.debugvisible:
|
||||||
pix_x = self.x
|
pix_x, pix_y = camera.relative_to_camera(self.x, self.y)
|
||||||
pix_y = int(current_depth - self.y)
|
thumby.display.setPixel(int(pix_x), int(pix_y), self.isdecend)
|
||||||
thumby.display.setPixel(pix_x, pix_y, self.isdecend)
|
|
||||||
|
|
||||||
# animation
|
# animation
|
||||||
self.anim.update_draw(current_depth, prev_depth, self.isdecend)
|
self.anim.update_draw(camera, self.isdecend)
|
||||||
|
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
def __init__(self, target):
|
def __init__(self, target):
|
||||||
self.x = int(0)
|
self.x = int(0)
|
||||||
self.y = int(0)
|
self.y = int(0)
|
||||||
|
self.width = thumby.display.width
|
||||||
|
self.height = thumby.display.height
|
||||||
|
self.offset = -self.height / 2
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|
||||||
def update_phys(self, plscreeny):
|
def entity_in_camera(self, ent_x, ent_y, ent_width = 0, ent_height = 0) -> bool:
|
||||||
|
return ent_x + ent_width >= self.x and ent_y + ent_height >= self.y and ent_x < self.x + self.width and ent_y < self.y + self.height
|
||||||
|
|
||||||
|
def relative_to_camera(self, global_x, global_y):
|
||||||
|
return (global_x - self.x, global_y - self.y)
|
||||||
|
|
||||||
|
def update_phys(self):
|
||||||
# position player
|
# position player
|
||||||
self.y = self.target.y - plscreeny
|
self.y = self.target.y + self.offset
|
||||||
|
|
||||||
|
|
||||||
class PlayerAnimation:
|
class PlayerAnimation:
|
||||||
@@ -101,7 +114,9 @@ class PlayerAnimation:
|
|||||||
self.debugrandomrange = self.RANDOM_RANGE
|
self.debugrandomrange = self.RANDOM_RANGE
|
||||||
self.debugposrange = self.POS_RANGE
|
self.debugposrange = self.POS_RANGE
|
||||||
|
|
||||||
def update_phys(self, plworldx, plworldy, plscreeny):
|
def update_phys(self, plworldx, plworldy, camera):
|
||||||
|
|
||||||
|
#print(plworldx, plworldy, plscreeny, current_depth)
|
||||||
|
|
||||||
### exit if player y pos less than random range
|
### exit if player y pos less than random range
|
||||||
# # debug change random range
|
# # debug change random range
|
||||||
@@ -157,19 +172,23 @@ class PlayerAnimation:
|
|||||||
# self.poslist.append((plworldx, plworldy))
|
# self.poslist.append((plworldx, plworldy))
|
||||||
|
|
||||||
### remove the fist item in the list if its full line is off screen
|
### remove the fist item in the list if its full line is off screen
|
||||||
#if self.poslist[1][self.POS_Y] < plworldy - plscreeny:
|
if not camera.entity_in_camera(self.poslist[1][self.POS_X], self.poslist[1][self.POS_Y]):
|
||||||
# self.poslist.pop(0)
|
self.poslist.pop(0)
|
||||||
|
|
||||||
#print(len(self.poslist))
|
#print(len(self.poslist))
|
||||||
|
|
||||||
def update_draw(self, current_depth, prev_depth, isdecend=1):
|
def update_draw(self, camera, isdecend=1):
|
||||||
### draw line from first position to next
|
### draw line from first position to next
|
||||||
|
|
||||||
|
#print(topleft)
|
||||||
|
|
||||||
for i in range(len(self.poslist) - 1):
|
for i in range(len(self.poslist) - 1):
|
||||||
|
x1, y1 = camera.relative_to_camera(self.poslist[i][self.POS_X], self.poslist[i][self.POS_Y])
|
||||||
|
x2, y2 = camera.relative_to_camera(self.poslist[i + 1][self.POS_X], self.poslist[i + 1][self.POS_Y])
|
||||||
thumby.display.drawLine(
|
thumby.display.drawLine(
|
||||||
int(self.poslist[i][self.POS_X]),
|
int(x1),
|
||||||
int(current_depth - self.poslist[i][self.POS_Y]),
|
int(y1),
|
||||||
int(self.poslist[i + 1][self.POS_X]),
|
int(x2),
|
||||||
int(current_depth - self.poslist[i + 1][self.POS_Y]),
|
int(y2),
|
||||||
isdecend
|
isdecend
|
||||||
)
|
)
|
||||||
|
|||||||
73
sprites.py
73
sprites.py
@@ -1,8 +1,10 @@
|
|||||||
from random import randint
|
import math
|
||||||
|
from random import randrange, random
|
||||||
|
|
||||||
import thumby
|
import thumby
|
||||||
|
|
||||||
from Games.Throot.map import ObstacleSlice
|
from Games.Throot.map import ObstacleSlice
|
||||||
|
from Games.Throot.player import Player, Camera
|
||||||
from Games.Throot.artrepository import OBSTACLES
|
from Games.Throot.artrepository import OBSTACLES
|
||||||
|
|
||||||
class Entity:
|
class Entity:
|
||||||
@@ -35,9 +37,9 @@ class Entity:
|
|||||||
return False
|
return False
|
||||||
rel_x = int(loc_x - self.x)
|
rel_x = int(loc_x - self.x)
|
||||||
rel_y = int(loc_y - self.y)
|
rel_y = int(loc_y - self.y)
|
||||||
return bool((self.collision[rel_x] >> (self.height - rel_y)) & 1)
|
return bool((self.collision[rel_x] >> (rel_y)) & 1)
|
||||||
|
|
||||||
def can_render(self, current_depth: int) -> bool:
|
def can_render(self, camera: Camera) -> bool:
|
||||||
"""
|
"""
|
||||||
Checks to see if this sprite is within the game screen.
|
Checks to see if this sprite is within the game screen.
|
||||||
|
|
||||||
@@ -48,15 +50,9 @@ class Entity:
|
|||||||
:return:
|
:return:
|
||||||
True if the sprite shows up on screen in any capacity, false otherwise.
|
True if the sprite shows up on screen in any capacity, false otherwise.
|
||||||
"""
|
"""
|
||||||
if self.x < -self.width or self.x >= thumby.display.width:
|
return camera.entity_in_camera(self.x, self.y, self.width, self.height)
|
||||||
return False
|
|
||||||
max = current_depth
|
|
||||||
min = max - thumby.display.height
|
|
||||||
if self.y < (min - self.height) or self.y > max:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def update(self, tpf: float, current_depth: int, prev_depth: int) -> bool:
|
def update(self, tpf: float, player: Player, camera: Camera) -> bool:
|
||||||
"""
|
"""
|
||||||
Updates the state of the entity based on the game state.
|
Updates the state of the entity based on the game state.
|
||||||
|
|
||||||
@@ -73,7 +69,7 @@ class Entity:
|
|||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def render(self, tpf: float, current_depth: int, prev_depth: int) -> bool:
|
def render(self, tpf: float, camera: Camera) -> bool:
|
||||||
"""
|
"""
|
||||||
Sets the position of the sprite and draws it.
|
Sets the position of the sprite and draws it.
|
||||||
|
|
||||||
@@ -89,19 +85,20 @@ class Entity:
|
|||||||
should be hidden.
|
should be hidden.
|
||||||
"""
|
"""
|
||||||
if self.sprite:
|
if self.sprite:
|
||||||
self.sprite.y = int(self.y - current_depth + thumby.display.height)
|
coordinates = camera.relative_to_camera(self.x, self.y)
|
||||||
self.sprite.x = int(self.x)
|
self.sprite.x = coordinates[0]
|
||||||
if self.can_render(current_depth):
|
self.sprite.y = coordinates[1]
|
||||||
|
if self.can_render(camera):
|
||||||
thumby.display.drawSprite(self.sprite)
|
thumby.display.drawSprite(self.sprite)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class Obstacle(Entity):
|
class Obstacle(Entity):
|
||||||
def update(self, tpf: float, current_depth: int, prev_depth: int) -> bool:
|
def update(self, tpf: float, player: Player, camera: Camera) -> bool:
|
||||||
return self.can_render(current_depth)
|
return True
|
||||||
|
|
||||||
|
|
||||||
def update_entities(current_slice: ObstacleSlice, current_depth: int, prev_depth: int):
|
def update_entities(entities, difficulty: int, current_depth: int, prev_depth: int):
|
||||||
"""
|
"""
|
||||||
Checks the current game state and generates new sprites based on said state.
|
Checks the current game state and generates new sprites based on said state.
|
||||||
|
|
||||||
@@ -118,24 +115,32 @@ def update_entities(current_slice: ObstacleSlice, current_depth: int, prev_depth
|
|||||||
:return:
|
:return:
|
||||||
A list of entities to generate this tick.
|
A list of entities to generate this tick.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
OBSTACLE_BUFFER = 10
|
||||||
|
|
||||||
if current_depth == prev_depth:
|
if current_depth == prev_depth:
|
||||||
# If we haven't moved, we don't need to spawn anything
|
# If we haven't moved, we don't need to spawn anything
|
||||||
return set()
|
return set()
|
||||||
# Local y relative to the top of the slice
|
|
||||||
slice_y = (current_depth) % ObstacleSlice.height
|
|
||||||
slice_prev_y = (prev_depth) % ObstacleSlice.height
|
|
||||||
if prev_depth < current_depth and slice_prev_y > slice_y:
|
|
||||||
slice_prev_y -= ObstacleSlice.height
|
|
||||||
elif current_depth < prev_depth and slice_y > slice_prev_y:
|
|
||||||
slice_prev_y += ObstacleSlice.height
|
|
||||||
min_y = min(slice_prev_y, slice_y)
|
|
||||||
max_y = max(slice_prev_y, slice_y)
|
|
||||||
spawned = set()
|
spawned = set()
|
||||||
for entity in current_slice.obstacle_map:
|
max_spawned = randrange(0, difficulty + 1)
|
||||||
# The position the entity should spawn at, relative to the slice top
|
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:
|
||||||
entity_y = entity[1]
|
sprite_image = OBSTACLES[randrange(0, min((difficulty + 1) * 3, len(OBSTACLES)))]
|
||||||
if entity_y >= min_y and entity_y < max_y:
|
if sprite_image.width >= thumby.display.width:
|
||||||
sprite_image = OBSTACLES[entity[2]]
|
x = 0
|
||||||
sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, 0, entity[3], entity[4])
|
else:
|
||||||
spawned.add(Obstacle(entity[0], entity_y + current_depth // ObstacleSlice.height * ObstacleSlice.height, sprite_image.width, sprite_image.height, sprite_image.collision or sprite_image.image, sprite))
|
x = randrange(0, thumby.display.width - sprite_image.width)
|
||||||
|
y = current_depth
|
||||||
|
if current_depth > prev_depth:
|
||||||
|
y += thumby.display.height // 2
|
||||||
|
elif current_depth < prev_depth:
|
||||||
|
y -= thumby.display.height // 2 + sprite_image.height
|
||||||
|
error = False
|
||||||
|
for entity in entities | spawned:
|
||||||
|
if x > (entity.x - OBSTACLE_BUFFER) and x <= (entity.x + entity.width + OBSTACLE_BUFFER) and y > (entity.y - OBSTACLE_BUFFER) and y <= (entity.y + entity.height + OBSTACLE_BUFFER):
|
||||||
|
error = True
|
||||||
|
break
|
||||||
|
if not error:
|
||||||
|
sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, 0, False, False)
|
||||||
|
spawned.add(Obstacle(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