Compare commits
33 Commits
art-cleanu
...
water
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf910238b9 | ||
|
|
e03d74be36 | ||
|
|
2c4584e05b | ||
|
|
a4e87421bb | ||
|
|
e73eb5a765 | ||
|
|
ad4a5de10e | ||
|
|
e25a5dd9cc | ||
|
|
15e3c33c87 | ||
|
|
9dd1c7df90 | ||
|
|
df4fd1228e | ||
|
|
176d89ea14 | ||
|
|
6cd766a848 | ||
|
|
4b8eb17ba1 | ||
|
|
f2c7f19d96 | ||
|
|
ce1436b1c2 | ||
|
|
8ad6236ff7 | ||
|
|
d0cf8f2a20 | ||
|
|
6004a54e9f | ||
|
|
c668a68097 | ||
|
|
7e454cd8e4 | ||
|
|
11667a1b92 | ||
|
|
c356965c2d | ||
|
|
1dbab66aa1 | ||
|
|
90b4e0f8d5 | ||
|
|
803b09e1b6 | ||
|
|
2240e42640 | ||
|
|
b79f0fa704 | ||
|
|
21deb06d84 | ||
|
|
67ea2d6c00 | ||
|
|
0860df7cea | ||
|
|
d69ea1b6c7 | ||
|
|
a218536601 | ||
|
|
8aeceffb7c |
230
Throot.py
Normal file
230
Throot.py
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
import time
|
||||||
|
import math
|
||||||
|
|
||||||
|
import thumby
|
||||||
|
|
||||||
|
import Games.Throot.map
|
||||||
|
import Games.Throot.sprites
|
||||||
|
|
||||||
|
from random import randrange
|
||||||
|
from Games.Throot.artrepository import *
|
||||||
|
from Games.Throot.player import Player
|
||||||
|
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
|
||||||
|
self.room_index = 0
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
# Set the FPS (without this call, the default fps is 30)
|
||||||
|
thumby.display.setFPS(CONST_FPS)
|
||||||
|
|
||||||
|
def room_goto(self, event):
|
||||||
|
index = event['room']
|
||||||
|
if index < 0:
|
||||||
|
self.room_index = min(self.room_index + 1, len(self.rooms))
|
||||||
|
else:
|
||||||
|
self.room_index = index
|
||||||
|
|
||||||
|
self.rooms[self.room_index].start(event)
|
||||||
|
|
||||||
|
def restart(self):
|
||||||
|
self.room_index = 0
|
||||||
|
|
||||||
|
def update(self, tpf):
|
||||||
|
event = self.rooms[self.room_index].update(tpf)
|
||||||
|
|
||||||
|
thumby.display.update()
|
||||||
|
|
||||||
|
if event:
|
||||||
|
self.room_goto(event)
|
||||||
|
|
||||||
|
|
||||||
|
class Room:
|
||||||
|
def start(self, event):
|
||||||
|
t0 = time.ticks_ms() # Get time (ms)
|
||||||
|
thumby.display.fill(0) # Fill canvas to black
|
||||||
|
|
||||||
|
def update(self, tpf):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class RoomTitle(Room):
|
||||||
|
def update(self, tpf):
|
||||||
|
super().update(tpf)
|
||||||
|
|
||||||
|
if thumby.inputPressed():
|
||||||
|
return {
|
||||||
|
'room': ROOM_MAIN
|
||||||
|
}
|
||||||
|
|
||||||
|
# draw title sprite
|
||||||
|
title_text = 'press a to start'
|
||||||
|
|
||||||
|
chr_len = 5
|
||||||
|
x = int(round(thumby.display.width / 2 - (chr_len * len(title_text)) / 2))
|
||||||
|
y = int(round(thumby.display.height / 2 - chr_len / 2))
|
||||||
|
|
||||||
|
buff = 2
|
||||||
|
w = chr_len * len(title_text) + buff
|
||||||
|
h = chr_len + buff
|
||||||
|
thumby.display.drawFilledRectangle(x - buff, y - buff, w, h, 1)
|
||||||
|
thumby.display.drawText(title_text, x, y, 0)
|
||||||
|
|
||||||
|
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]
|
||||||
|
self.entities = set()
|
||||||
|
|
||||||
|
self.player = Player()
|
||||||
|
|
||||||
|
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.score = 0
|
||||||
|
|
||||||
|
self.finish_depth = 100 + 5 * self.level ** 2
|
||||||
|
|
||||||
|
|
||||||
|
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.current_depth + thumby.display.height * 2 < self.finish_depth:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.waterx += sprite_water.width / CONST_FPS
|
||||||
|
if self.waterx > sprite_water.width:
|
||||||
|
self.waterx = 0
|
||||||
|
|
||||||
|
to_screeny = int(thumby.display.height - self.current_depth)
|
||||||
|
|
||||||
|
# water surface.
|
||||||
|
for i in range(math.ceil(thumby.display.width / sprite_water.width) + 1):
|
||||||
|
thumby.display.blit(
|
||||||
|
sprite_water[0],
|
||||||
|
(int(self.waterx) - sprite_water.width) + i * sprite_water.width,
|
||||||
|
self.finish_depth - sprite_water.height + to_screeny, sprite_water.width, sprite_water.height,
|
||||||
|
0, 0, 0
|
||||||
|
)
|
||||||
|
|
||||||
|
# water below surface
|
||||||
|
thumby.display.drawFilledRectangle(
|
||||||
|
0, self.finish_depth + to_screeny,
|
||||||
|
thumby.display.width, self.finish_depth + thumby.display.height * 3,
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# win text
|
||||||
|
if self.current_depth > self.finish_depth + (thumby.display.height // 2):
|
||||||
|
thumby.display.drawText('water reach!', 0, thumby.display.height // 2, 0)
|
||||||
|
|
||||||
|
def update(self, tpf):
|
||||||
|
"""
|
||||||
|
Executes one tick of the game
|
||||||
|
"""
|
||||||
|
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))
|
||||||
|
|
||||||
|
#print("%f -> %f: %f -> %f" % (prev_depth, self.current_depth, prev_depth % ObstacleSlice.height, self.current_depth % ObstacleSlice.height))
|
||||||
|
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
|
||||||
|
self.entities |= update_entities(self.entities, 5, self.current_depth, prev_depth)
|
||||||
|
|
||||||
|
# Updates the entities
|
||||||
|
to_remove = set()
|
||||||
|
for entity in self.entities:
|
||||||
|
if not entity.update(tpf, self.current_depth, prev_depth):
|
||||||
|
to_remove.add(entity)
|
||||||
|
elif entity.intersects_pixel(self.player.xsub, self.player.ysub):
|
||||||
|
if isinstance(entity, Obstacle):
|
||||||
|
return {
|
||||||
|
'room': ROOM_END,
|
||||||
|
'score': self.score,
|
||||||
|
'level': self.level + 1
|
||||||
|
}
|
||||||
|
self.entities -= to_remove
|
||||||
|
|
||||||
|
self.score = int(self.current_depth * 10)
|
||||||
|
|
||||||
|
# finish level
|
||||||
|
if self.current_depth > 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.current_depth, prev_depth)
|
||||||
|
|
||||||
|
self.draw_water()
|
||||||
|
|
||||||
|
self.player.update_draw(self.player.y)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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():
|
||||||
|
game = GameManager(RoomTitle(), GameLoop(), EndRoom())
|
||||||
|
game.start()
|
||||||
|
|
||||||
|
prev_time = 0
|
||||||
|
while True:
|
||||||
|
t0 = time.ticks_ms()
|
||||||
|
tps = (t0 - prev_time) / 1000
|
||||||
|
#loop.update(tps)
|
||||||
|
game.update(tps)
|
||||||
|
prev_time = t0
|
||||||
|
|
||||||
|
main()
|
||||||
BIN
ThrootTitle.raw
Normal file
BIN
ThrootTitle.raw
Normal file
Binary file not shown.
119
artrepository.py
119
artrepository.py
@@ -1,31 +1,24 @@
|
|||||||
from collections.namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
SpriteImage = namedtuple("SpriteImage", ["image", "collision", "width", "height"])
|
SpriteImage = namedtuple("SpriteImage", ["image", "collision", "width", "height"])
|
||||||
|
|
||||||
# BITMAP: width: 8, height: 8
|
# BITMAP: width: 8, height: 8
|
||||||
skull = SpriteImage(
|
skull = SpriteImage(
|
||||||
bytearray([227,29,102,126,38,222,221,227]),
|
bytearray([0,28,102,126,38,30,28,0]),
|
||||||
None,
|
None,
|
||||||
8,
|
8,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 8, height: 8
|
# BITMAP: width: 8, height: 8
|
||||||
pizza = SpriteImage(
|
pizza = SpriteImage(
|
||||||
bytearray([127,63,95,111,87,107,125,0]),
|
bytearray([0,0,64,96,80,104,124,0]),
|
||||||
None,
|
None,
|
||||||
8,
|
8,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 10, height: 10
|
# BITMAP: width: 10, height: 10
|
||||||
boulder = SpriteImage(
|
boulder = SpriteImage(
|
||||||
bytearray([31,175,119,183,107,251,115,7,15,31,3,2,1,0,1,0,0,0,0,2]),
|
bytearray([224,80,136,72,148,4,140,248,240,224,0,1,2,3,2,3,3,3,3,1]),
|
||||||
None,
|
|
||||||
10,
|
|
||||||
10
|
|
||||||
)
|
|
||||||
# BITMAP: width: 10, height: 10
|
|
||||||
ball = SpriteImage(
|
|
||||||
bytearray([135,43,85,170,124,254,122,229,123,135,3,3,2,0,1,0,1,2,3,3]),
|
|
||||||
None,
|
None,
|
||||||
10,
|
10,
|
||||||
10
|
10
|
||||||
@@ -39,28 +32,21 @@ ball = SpriteImage(
|
|||||||
)
|
)
|
||||||
# BITMAP: width: 10, height: 10
|
# BITMAP: width: 10, height: 10
|
||||||
steve = SpriteImage(
|
steve = SpriteImage(
|
||||||
bytearray([0,240,252,92,188,188,92,252,240,0,0,1,1,0,0,0,0,1,1,0]),
|
bytearray([255,1,225,249,185,121,121,185,249,225,1,255,15,8,11,11,8,9,9,8,11,11,8,15]),
|
||||||
None,
|
None,
|
||||||
10,
|
12,
|
||||||
10
|
12
|
||||||
)
|
)
|
||||||
# BITMAP: width: 11, height: 8
|
# BITMAP: width: 11, height: 8
|
||||||
spaceinv = SpriteImage(
|
spaceinv = SpriteImage(
|
||||||
bytearray([143,231,130,73,67,195,67,73,130,231,143]),
|
bytearray([112,24,125,182,188,60,188,182,125,24,112,7,152,125,54,60,60,60,54,125,152,7]),
|
||||||
None,
|
|
||||||
11,
|
|
||||||
8
|
|
||||||
)
|
|
||||||
# BITMAP: width: 11, height: 8
|
|
||||||
spaceinv2 = SpriteImage(
|
|
||||||
bytearray([248,103,130,201,195,195,195,201,130,103,248]),
|
|
||||||
None,
|
None,
|
||||||
11,
|
11,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 11, height: 8
|
# BITMAP: width: 11, height: 8
|
||||||
mathroot = SpriteImage(
|
mathroot = SpriteImage(
|
||||||
bytearray([255,255,239,207,159,63,1,193,249,249,255]),
|
bytearray([0,0,16,48,96,192,254,62,6,6,0]),
|
||||||
None,
|
None,
|
||||||
11,
|
11,
|
||||||
8
|
8
|
||||||
@@ -68,69 +54,132 @@ mathroot = SpriteImage(
|
|||||||
#/ = bytearray([255,255,239,239,72,10,192,10,72,239,239])
|
#/ = bytearray([255,255,239,239,72,10,192,10,72,239,239])
|
||||||
# BITMAP: width: 11, height: 8
|
# BITMAP: width: 11, height: 8
|
||||||
robot = SpriteImage(
|
robot = SpriteImage(
|
||||||
bytearray([255,255,239,239,72,10,192,10,72,239,239]),
|
bytearray([0,16,16,183,245,63,245,183,16,16,0]),
|
||||||
None,
|
None,
|
||||||
11,
|
11,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 11, height: 8
|
# BITMAP: width: 11, height: 8
|
||||||
dinoskull = SpriteImage(
|
dinoskull = SpriteImage(
|
||||||
bytearray([240,246,246,245,238,237,219,221,235,247,255]),
|
bytearray([15,9,9,10,17,18,36,34,20,8,0]),
|
||||||
None,
|
None,
|
||||||
11,
|
11,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 11, height: 8
|
# BITMAP: width: 11, height: 8
|
||||||
dinojaw = SpriteImage(
|
dinojaw = SpriteImage(
|
||||||
bytearray([193,190,190,62,118,242,126,249,87,239,31]),
|
bytearray([62,65,65,193,137,13,129,6,168,16,224]),
|
||||||
None,
|
None,
|
||||||
11,
|
11,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 11, height: 8
|
# BITMAP: width: 11, height: 8
|
||||||
dinospine = SpriteImage(
|
dinospine = SpriteImage(
|
||||||
bytearray([199,187,215,187,199,199,187,215,187,199,255]),
|
bytearray([56,68,40,68,56,56,68,40,68,56,0]),
|
||||||
None,
|
None,
|
||||||
11,
|
11,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 11, height: 8
|
# BITMAP: width: 11, height: 8
|
||||||
bone = SpriteImage(
|
bone = SpriteImage(
|
||||||
bytearray([215,171,187,215,215,215,215,215,187,171,215]),
|
bytearray([40,84,68,40,40,40,40,40,68,84,40]),
|
||||||
None,
|
None,
|
||||||
11,
|
11,
|
||||||
8
|
8
|
||||||
)
|
)
|
||||||
# BITMAP: width: 70, height: 40
|
# BITMAP: width: 70, height: 40
|
||||||
bigdinohead = SpriteImage(
|
bigdinohead = 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,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,127,127,127,127,127,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,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,231,193,157,124,254,118,243,243,225,225,243,159,158,140,253,153,243,247,207,159,63,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,249,250,247,246,244,245,243,245,243,245,243,245,243,245,251,253,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,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,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]),
|
bytearray([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,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,128,128,128,128,128,128,128,128,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,24,62,98,131,1,137,12,12,30,30,12,96,97,115,2,102,12,8,48,96,192,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,6,5,8,9,11,10,12,10,12,10,12,10,12,10,4,2,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,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,
|
None,
|
||||||
70,
|
70,
|
||||||
40
|
40
|
||||||
)
|
)
|
||||||
# BITMAP: width: 70, height: 40
|
# BITMAP: width: 70, height: 40
|
||||||
bigboneddiag = SpriteImage(
|
bigboneddiag = 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,255,255,255,255,255,255,255,255,255,255,255,255,255,127,127,63,223,223,63,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,255,255,255,255,255,252,251,251,251,247,239,222,189,123,247,239,223,191,127,127,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,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,254,241,239,239,243,251,251,252,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,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,255,255,255,255,255,255,255]),
|
bytearray([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,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,128,128,192,32,32,192,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,0,0,0,
|
||||||
|
3,4,4,4,8,16,33,66,132,8,16,32,64,128,128,128,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,0,0,0,1,14,16,16,12,4,4,3,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,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,0,0,0]),
|
||||||
None,
|
None,
|
||||||
70,
|
70,
|
||||||
40
|
40
|
||||||
)
|
)
|
||||||
# BITMAP: width: 70, height: 40
|
# BITMAP: width: 70, height: 40
|
||||||
bigdoritoobstacle = SpriteImage(
|
bigdoritoobstacle = SpriteImage(
|
||||||
bytearray([254,244,253,219,251,247,175,207,223,223,223,191,63,127,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,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,223,255,247,255,255,255,249,255,239,254,254,252,252,249,219,243,183,167,239,207,223,191,63,127,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,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,255,127,191,95,191,95,191,87,47,87,47,151,175,155,151,203,215,235,231,235,231,235,231,235,231,235,231,234,246,245,241,243,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,127,127,127,127,127,127,127,63,191,191,191,250,249,248,253,252,254,254,254,254,255,255,255,255,255,255,255,255,255,255,255,255,127,127,127,127,127,127,127,127,127,127,127,127,191,191,159,223,223,223,223,223,239,239,239,239,239,239,231,231,243,123,251,253,254,254,254,254,255,239,251,255,255,255,255,251,255,253,251,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,253,253,253,253,253,249,251,251,251,245,243,237,235,229,235,215,203,223,215,203,215,222,219,203,213,203,215,207,215,207,215,223,207,215,207,215,159,151,175,183,171,183,175,183,191,159,55,127]),
|
bytearray([1,11,2,36,4,8,80,48,32,32,32,64,192,128,128,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,32,0,8,0,0,0,6,0,16,1,1,3,3,6,36,12,72,88,16,48,32,64,192,128,128,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,128,0,128,64,160,64,160,64,168,208,168,208,104,80,100,104,52,40,20,24,20,24,20,24,20,24,20,24,21,9,10,14,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,128,128,128,128,128,128,128,128,192,64,64,64,
|
||||||
|
5,6,7,2,3,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,128,128,128,128,128,128,128,128,128,128,128,128,64,64,96,32,32,32,32,32,16,16,16,16,16,16,24,24,12,132,4,2,1,1,1,1,0,16,4,0,0,0,0,4,0,2,4,1,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,6,4,4,4,10,12,18,20,26,20,40,52,32,40,52,40,33,36,52,42,52,40,48,40,48,40,32,48,40,48,40,96,104,80,72,84,72,80,72,64,96,200,128]),
|
||||||
None,
|
None,
|
||||||
70,
|
70,
|
||||||
40
|
40
|
||||||
)
|
)
|
||||||
# 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, bigdoritotoobstacle]
|
annoydead = SpriteImage(
|
||||||
OVERGROUND_OBSTACLES = [spaveinv, spaceinv2, 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]
|
||||||
6
constants.py
Normal file
6
constants.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
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>
|
||||||
37
map.py
Normal file
37
map.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import thumby
|
||||||
|
|
||||||
|
class ObstacleSlice:
|
||||||
|
"""
|
||||||
|
The game world is divided up into distinct "slices," where each slice is a predefined set of
|
||||||
|
obstacles in specific positions. These slices are then put forward in random order
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
How many units an obstacle slice is high
|
||||||
|
"""
|
||||||
|
height=max(80, thumby.display.height * 2)
|
||||||
|
|
||||||
|
def __init__(self, obstacle_map, difficulty: int):
|
||||||
|
"""
|
||||||
|
Creates an obstacle slice
|
||||||
|
|
||||||
|
:param obstacle_map:
|
||||||
|
A two-dimensional list description what obstacles are here. Each tuple describes a
|
||||||
|
single obstacle, its x, and y position, the obstacle type, the x mirror, and the y
|
||||||
|
mirror.
|
||||||
|
:param difficulty:
|
||||||
|
The difficulty of the game. This influences when this slice appears.
|
||||||
|
"""
|
||||||
|
self.obstacle_map = obstacle_map
|
||||||
|
self.difficulty = difficulty
|
||||||
|
|
||||||
|
OBSTACLE_SLICES = [
|
||||||
|
ObstacleSlice(
|
||||||
|
[
|
||||||
|
(10, 0, 0, 0, 0),
|
||||||
|
(53, 30, 1, 0, 0),
|
||||||
|
(5, 45, 0, 0, 0)
|
||||||
|
],
|
||||||
|
0
|
||||||
|
)
|
||||||
|
]
|
||||||
179
player.py
Normal file
179
player.py
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
import time
|
||||||
|
import thumby
|
||||||
|
import math
|
||||||
|
import random
|
||||||
|
|
||||||
|
from Games.Throot.constants import CONST_FPS
|
||||||
|
|
||||||
|
# didplay width 72
|
||||||
|
# display height 40
|
||||||
|
|
||||||
|
# constants
|
||||||
|
CONST_PL_SCREEN_Y = int((0.5) * thumby.display.height)
|
||||||
|
|
||||||
|
CONST_INP_MOVE_LEFT = thumby.buttonL
|
||||||
|
CONST_INP_MOVE_RIGHT = thumby.buttonA
|
||||||
|
|
||||||
|
# classes
|
||||||
|
class Player:
|
||||||
|
def __init__(self):
|
||||||
|
self.xsub = float(thumby.display.width / 2)
|
||||||
|
self.ysub = float(0)
|
||||||
|
self.x = int(self.xsub)
|
||||||
|
self.y = int(self.ysub)
|
||||||
|
|
||||||
|
self.movespeed = 32 / CONST_FPS
|
||||||
|
self.isdecend = 1
|
||||||
|
|
||||||
|
self.xspeed = 32 / CONST_FPS
|
||||||
|
self.yspeed = 32 / CONST_FPS
|
||||||
|
self.accx = 1 / (CONST_FPS * 4)
|
||||||
|
self.accaccx = self.accx
|
||||||
|
|
||||||
|
self.anim = PlayerAnimation(self.x, self.y)
|
||||||
|
self.debugvisible = True
|
||||||
|
|
||||||
|
def update_phys(self, current_depth, prev_depth):
|
||||||
|
inp = int(0)
|
||||||
|
if CONST_INP_MOVE_LEFT.pressed():
|
||||||
|
inp -= 1
|
||||||
|
if CONST_INP_MOVE_RIGHT.pressed():
|
||||||
|
inp += 1
|
||||||
|
|
||||||
|
# debug visible
|
||||||
|
if thumby.buttonU.pressed():
|
||||||
|
self.debugvisible = not self.debugvisible
|
||||||
|
|
||||||
|
### x movement
|
||||||
|
self.xspeed += self.accx
|
||||||
|
self.accx += self.accaccx
|
||||||
|
|
||||||
|
if (inp == 0) and (self.xspeed > self.movespeed):
|
||||||
|
self.xspeed = self.movespeed
|
||||||
|
self.accx = self.accaccx
|
||||||
|
|
||||||
|
xx = self.xsub + inp * self.xspeed
|
||||||
|
|
||||||
|
# clamp to screen
|
||||||
|
self.xsub = max(min(xx, thumby.display.width - 1), 0)
|
||||||
|
|
||||||
|
### y movement
|
||||||
|
self.ysub = current_depth - (thumby.display.height / 2)
|
||||||
|
|
||||||
|
### pixel positions
|
||||||
|
self.x = int(self.xsub)
|
||||||
|
self.y = int(self.ysub)
|
||||||
|
|
||||||
|
# animation
|
||||||
|
self.anim.update_phys(self.x, self.y, CONST_PL_SCREEN_Y, current_depth)
|
||||||
|
|
||||||
|
def update_draw(self, plworldy):
|
||||||
|
# debug draw
|
||||||
|
if self.debugvisible:
|
||||||
|
pix_x = self.x
|
||||||
|
pix_y = int(self.y - plworldy + 20)
|
||||||
|
thumby.display.setPixel(pix_x, pix_y, self.isdecend)
|
||||||
|
|
||||||
|
# animation
|
||||||
|
self.anim.update_draw(plworldy - 20, self.isdecend)
|
||||||
|
|
||||||
|
|
||||||
|
class Camera:
|
||||||
|
def __init__(self, target):
|
||||||
|
self.x = int(0)
|
||||||
|
self.y = int(0)
|
||||||
|
self.target = target
|
||||||
|
|
||||||
|
def update_phys(self, plscreeny):
|
||||||
|
# position player
|
||||||
|
self.y = self.target.y - plscreeny
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerAnimation:
|
||||||
|
# width and height of range bounding box
|
||||||
|
RANDOM_RANGE = int(7)
|
||||||
|
POS_RANGE = int(3)
|
||||||
|
POS_X = int(0)
|
||||||
|
POS_Y = int(1)
|
||||||
|
|
||||||
|
def __init__(self, plworldx, plworldy):
|
||||||
|
self.poslist = [(plworldx, plworldy)]
|
||||||
|
self.debugrandomrange = self.RANDOM_RANGE
|
||||||
|
self.debugposrange = self.POS_RANGE
|
||||||
|
|
||||||
|
def update_phys(self, plworldx, plworldy, plscreeny, current_depth):
|
||||||
|
|
||||||
|
#print(plworldx, plworldy, plscreeny, current_depth)
|
||||||
|
|
||||||
|
### exit if player y pos less than random range
|
||||||
|
# # debug change random range
|
||||||
|
# inp = int(0)
|
||||||
|
# if thumby.buttonD.justPressed():
|
||||||
|
# inp -= 1
|
||||||
|
# if thumby.buttonU.justPressed():
|
||||||
|
# inp += 1
|
||||||
|
|
||||||
|
# if inp != 0:
|
||||||
|
# self.debugposrange = max(self.debugposrange + inp * 2, 1)
|
||||||
|
# print('debugposrange: ', self.debugposrange)
|
||||||
|
|
||||||
|
# # if plworldy < self.poslist[-1][self.POS_Y] + random.randint(1, self.debugposrange):
|
||||||
|
# # return
|
||||||
|
|
||||||
|
# if plworldy < self.poslist[-1][self.POS_Y] + self.debugposrange:
|
||||||
|
# return
|
||||||
|
|
||||||
|
if plworldy < self.poslist[-1][self.POS_Y] + random.randint(1, self.POS_RANGE):
|
||||||
|
return
|
||||||
|
|
||||||
|
### get new position
|
||||||
|
rad = self.RANDOM_RANGE // 2
|
||||||
|
|
||||||
|
# # debug change random range
|
||||||
|
# inp = int(0)
|
||||||
|
# if thumby.buttonB.justPressed():
|
||||||
|
# inp -= 1
|
||||||
|
# if thumby.buttonA.justPressed():
|
||||||
|
# inp += 1
|
||||||
|
|
||||||
|
# if inp != 0:
|
||||||
|
# self.debugrandomrange = max(self.debugrandomrange + inp * 2, 1)
|
||||||
|
# print('debugrandomrange:', self.debugrandomrange)
|
||||||
|
|
||||||
|
# rad = max(self.debugrandomrange // 2, 1)
|
||||||
|
|
||||||
|
# vector int
|
||||||
|
# self.poslist.append((plworldx + random.randrange(-rad, rad),
|
||||||
|
# plworldy + random.randrange(-rad, rad)))
|
||||||
|
|
||||||
|
# move last pos
|
||||||
|
self.poslist[-1] = (
|
||||||
|
plworldx + random.randrange(-rad, rad),
|
||||||
|
plworldy + random.randrange(-rad, rad)
|
||||||
|
)
|
||||||
|
|
||||||
|
# new pos is perfectly on player
|
||||||
|
self.poslist.append((plworldx, plworldy))
|
||||||
|
|
||||||
|
# # debug
|
||||||
|
# self.poslist.append((plworldx, plworldy))
|
||||||
|
|
||||||
|
### remove the fist item in the list if its full line is off screen
|
||||||
|
if self.poslist[1][self.POS_Y] < plworldy - plscreeny:
|
||||||
|
self.poslist.pop(0)
|
||||||
|
|
||||||
|
#print(len(self.poslist))
|
||||||
|
|
||||||
|
def update_draw(self, topleft, prev_depth, isdecend=1):
|
||||||
|
### draw line from first position to next
|
||||||
|
|
||||||
|
#print(topleft)
|
||||||
|
|
||||||
|
for i in range(len(self.poslist) - 1):
|
||||||
|
thumby.display.drawLine(
|
||||||
|
int(self.poslist[i][self.POS_X]),
|
||||||
|
int(self.poslist[i][self.POS_Y] - topleft),
|
||||||
|
int(self.poslist[i + 1][self.POS_X]),
|
||||||
|
int(self.poslist[i + 1][self.POS_Y] - topleft),
|
||||||
|
isdecend
|
||||||
|
)
|
||||||
146
sprites.py
Normal file
146
sprites.py
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
import math
|
||||||
|
from random import randrange, random
|
||||||
|
|
||||||
|
import thumby
|
||||||
|
|
||||||
|
from Games.Throot.map import ObstacleSlice
|
||||||
|
from Games.Throot.artrepository import OBSTACLES
|
||||||
|
|
||||||
|
class Entity:
|
||||||
|
"""
|
||||||
|
An entity exists within the game world. It has coordinates, bounds, and optionally collision and sprite
|
||||||
|
"""
|
||||||
|
def __init__(self, x: int = 0, y: int = 0, width: int = 8, height: int = 8, collision: bytearray = None, sprite: thumby.Sprite = None):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.sprite = sprite
|
||||||
|
self.collision = collision
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
|
||||||
|
def intersects_pixel(self, loc_x: int, loc_y: int) -> bool:
|
||||||
|
"""
|
||||||
|
Checks to see if this entity intersects a location in the game world.
|
||||||
|
|
||||||
|
:param loc_x:
|
||||||
|
An global x location within the game world.
|
||||||
|
:param loc_y:
|
||||||
|
A global y position within the game world.
|
||||||
|
:return:
|
||||||
|
True if the collision shape of this entity intersects a point in the world,
|
||||||
|
False otherwise.
|
||||||
|
"""
|
||||||
|
if not self.collision:
|
||||||
|
return False
|
||||||
|
if loc_x < self.x or loc_x >= self.x + self.width or loc_y < self.y or loc_y >= self.y + self.height:
|
||||||
|
return False
|
||||||
|
rel_x = int(loc_x - self.x)
|
||||||
|
rel_y = int(loc_y - self.y)
|
||||||
|
return bool((self.collision[rel_x] >> (self.height - rel_y)) & 1)
|
||||||
|
|
||||||
|
def can_render(self, current_depth: int) -> bool:
|
||||||
|
"""
|
||||||
|
Checks to see if this sprite is within the game screen.
|
||||||
|
|
||||||
|
:param current_depth:
|
||||||
|
The current depth, as measured from the top of the screen. We can display anything
|
||||||
|
up to the screen height down from this number.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
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 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:
|
||||||
|
"""
|
||||||
|
Updates the state of the entity based on the game state.
|
||||||
|
|
||||||
|
:param tpf:
|
||||||
|
The number of seconds since the last tick.
|
||||||
|
:param current_depth:
|
||||||
|
The current depth the game is on.
|
||||||
|
:param prev_depth:
|
||||||
|
The depth the game was on last tick.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
True if the game should keep this entity, false if the game should drop
|
||||||
|
this entity from memory.
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
|
def render(self, tpf: float, current_depth: int, prev_depth: int) -> bool:
|
||||||
|
"""
|
||||||
|
Sets the position of the sprite and draws it.
|
||||||
|
|
||||||
|
:param tpf:
|
||||||
|
The number of seconds since the last tick.
|
||||||
|
:param current_depth:
|
||||||
|
The current depth the game is on.
|
||||||
|
:param prev_depth:
|
||||||
|
The depth the game was on last tick.
|
||||||
|
|
||||||
|
:return:
|
||||||
|
True if the game should actually draw the sprite, false the sprite
|
||||||
|
should be hidden.
|
||||||
|
"""
|
||||||
|
if self.sprite:
|
||||||
|
self.sprite.y = int(self.y - current_depth + thumby.display.height)
|
||||||
|
self.sprite.x = int(self.x)
|
||||||
|
if self.can_render(current_depth):
|
||||||
|
thumby.display.drawSprite(self.sprite)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
class Obstacle(Entity):
|
||||||
|
def update(self, tpf: float, current_depth: int, prev_depth: int) -> bool:
|
||||||
|
return self.can_render(current_depth)
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
:param current_slice:
|
||||||
|
The current obstacle slice we are using. Once the bottom of the slice displays, we switch
|
||||||
|
to a new slice.
|
||||||
|
:param current_depth:
|
||||||
|
The global world depth we are at. This is modulused by the slice height to determine how
|
||||||
|
far through the slice we are.
|
||||||
|
:param prev_depth:
|
||||||
|
The depth we were at during the last tick. This helps make sure we don't miss spawning
|
||||||
|
entities
|
||||||
|
|
||||||
|
:return:
|
||||||
|
A list of entities to generate this tick.
|
||||||
|
"""
|
||||||
|
|
||||||
|
OBSTACLE_BUFFER = 10
|
||||||
|
|
||||||
|
if current_depth == prev_depth:
|
||||||
|
# If we haven't moved, we don't need to spawn anything
|
||||||
|
return set()
|
||||||
|
|
||||||
|
spawned = set()
|
||||||
|
max_spawned = 1#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:
|
||||||
|
sprite_image = OBSTACLES[randrange(0, min((difficulty + 1) * 3, len(OBSTACLES)))]
|
||||||
|
if sprite_image.width >= thumby.display.width:
|
||||||
|
x = 0
|
||||||
|
else:
|
||||||
|
x = randrange(0, thumby.display.width - sprite_image.width)
|
||||||
|
y = current_depth
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user