Compare commits
3 Commits
master
...
random-obs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5967359e70 | ||
|
|
81822ee80a | ||
|
|
3c6e070716 |
@@ -109,7 +109,7 @@ class GameLoop(Room):
|
|||||||
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()
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ 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
|
||||||
@@ -174,4 +175,4 @@ Doritoobstaclelvl5 = SpriteImage(
|
|||||||
30
|
30
|
||||||
)
|
)
|
||||||
|
|
||||||
OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle, spaceinv, leaf,annoydead,lvl4wall,ballobstaclelvl3,Doritoobstaclelvl5]
|
OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, leaf, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle, spaceinv,annoydead,lvl4wall,ballobstaclelvl3,Doritoobstaclelvl5]
|
||||||
|
|||||||
41
sprites.py
41
sprites.py
@@ -1,4 +1,5 @@
|
|||||||
from random import randint
|
import math
|
||||||
|
from random import randrange, random
|
||||||
|
|
||||||
import thumby
|
import thumby
|
||||||
|
|
||||||
@@ -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,24 +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 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 = 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 >= 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
|
||||||
|
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