11 Commits

Author SHA1 Message Date
William Hubbard
5967359e70 Refines the difficulty curve. 2023-02-05 10:30:42 -07:00
William Hubbard
81822ee80a Merge branch 'master' into random-obstacles 2023-02-05 09:45:32 -07:00
William Hubbard
ad4a5de10e Fixes a few art assets 2023-02-05 09:45:20 -07:00
William Hubbard
3c6e070716 Changes the obstacle generation system.
More random, less level design needed.
2023-02-05 09:40:18 -07:00
William Hubbard
e25a5dd9cc Adds the rest of the art assets. 2023-02-05 08:50:30 -07:00
CostaRic
15e3c33c87 Merge branch 'master' of https://github.com/Markil3/Throot 2023-02-04 23:31:30 -07:00
CostaRic
9dd1c7df90 Update ThrootArtAssets.py
aupdted Throot Art Asset Library
2023-02-04 23:31:24 -07:00
Neal Finger
df4fd1228e Merge pull request #7 from Markil3/player_animation_fix
take out print
2023-02-04 23:21:14 -07:00
Neal Finger
6cd766a848 Merge pull request #6 from Markil3/player_animation_fix
player animation fix
2023-02-04 22:59:17 -07:00
William Hubbard
f2c7f19d96 Merge pull request #5 from Markil3/subpixel-collisions
Adds sub-pixel collisions
2023-02-04 22:21:16 -07:00
William Hubbard
ce1436b1c2 Adds sub-pixel collisions 2023-02-04 22:11:39 -07:00
4 changed files with 113 additions and 116 deletions

View File

@@ -10,7 +10,7 @@ from random import randrange
from Games.Throot.artrepository import OBSTACLES from Games.Throot.artrepository import OBSTACLES
from Games.Throot.player import Player from Games.Throot.player import Player
from Games.Throot.map import ObstacleSlice, OBSTACLE_SLICES from Games.Throot.map import ObstacleSlice, OBSTACLE_SLICES
from Games.Throot.sprites import update_entities from Games.Throot.sprites import Obstacle, update_entities
from Games.Throot.constants import CONST_FPS from Games.Throot.constants import CONST_FPS
class GameManager: class GameManager:
@@ -97,19 +97,28 @@ class GameLoop(Room):
self.diving_velocity += self.diving_accel * tpf self.diving_velocity += self.diving_accel * tpf
self.current_depth += self.diving_velocity * tpf self.current_depth += self.diving_velocity * tpf
if self.current_depth % ObstacleSlice.height < prev_depth % ObstacleSlice.height: #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.current_obstacle_slice = self.get_obstacle_slice()
self.player.update_phys(self.current_depth, prev_depth) 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) self.entities |= update_entities(self.entities, 5, self.current_depth, prev_depth)
# 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.current_depth, prev_depth):
to_remove.add(entity) to_remove.add(entity)
elif entity.intersects_pixel(self.player.xsub, self.player.ysub):
if isinstance(entity, Obstacle):
print("Hit!")
self.entities -= to_remove self.entities -= to_remove
self.score = int(self.current_depth * 10) self.score = int(self.current_depth * 10)

File diff suppressed because one or more lines are too long

View File

@@ -4,28 +4,21 @@ 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,125 @@ 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, bigdoritoobstacle] annoydead = SpriteImage(
OVERGROUND_OBSTACLES = [spaceinv, 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
)
OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, leaf, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle, spaceinv,annoydead,lvl4wall,ballobstaclelvl3,Doritoobstaclelvl5]

View File

@@ -1,4 +1,5 @@
from random import randint import math
from random import randrange, random
import thumby import thumby
@@ -33,8 +34,8 @@ class Entity:
return False 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: 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 return False
rel_x = loc_x - self.x rel_x = int(loc_x - self.x)
rel_y = 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] >> (self.height - rel_y)) & 1)
def can_render(self, current_depth: int) -> bool: def can_render(self, current_depth: int) -> bool:
@@ -101,7 +102,7 @@ class Obstacle(Entity):
return self.can_render(current_depth) return self.can_render(current_depth)
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,20 +119,28 @@ 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 slice_prev_y > slice_y:
slice_prev_y -= ObstacleSlice.height
spawned = set() spawned = set()
for entity in current_slice.obstacle_map: max_spawned = 1#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 >= slice_prev_y and entity_y < slice_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, sprite)) 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 return spawned