Adds collectibles and fixes score
This commit is contained in:
16
Throot.py
16
Throot.py
@@ -11,7 +11,7 @@ from random import randrange
|
|||||||
from Games.Throot.artrepository import *
|
from Games.Throot.artrepository import *
|
||||||
from Games.Throot.player import Player, Camera
|
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, Collectible, update_entities
|
||||||
from Games.Throot.constants import *
|
from Games.Throot.constants import *
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +97,8 @@ class GameLoop(Room):
|
|||||||
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
||||||
self.player = Player()
|
self.player = Player()
|
||||||
self.player.yspeed = 10
|
self.player.yspeed = 10
|
||||||
self.score = 0
|
self.score = 'score' in event and event['score'] or 0
|
||||||
|
self.level = 'level' in event and event['level'] or 0
|
||||||
|
|
||||||
self.finish_depth = 100 + 5 * self.level ** 2
|
self.finish_depth = 100 + 5 * self.level ** 2
|
||||||
self.camera = Camera(self.player)
|
self.camera = Camera(self.player)
|
||||||
@@ -177,14 +178,21 @@ class GameLoop(Room):
|
|||||||
'score': self.score,
|
'score': self.score,
|
||||||
'level': self.level + 1
|
'level': self.level + 1
|
||||||
}
|
}
|
||||||
|
elif isinstance(entity, Collectible):
|
||||||
|
self.score += entity.score
|
||||||
|
to_remove.add(entity)
|
||||||
self.entities -= to_remove
|
self.entities -= to_remove
|
||||||
|
|
||||||
self.score = int(abs(self.player.y) * 10)
|
self.score += int(abs(self.player.ysub - self.player.prev_y) * 10)
|
||||||
|
|
||||||
# finish level
|
# finish level
|
||||||
if self.player.y > self.finish_depth + int(thumby.display.height * 1.5):
|
if self.player.y > self.finish_depth + int(thumby.display.height * 1.5):
|
||||||
|
self.score += 20
|
||||||
self.level += 1
|
self.level += 1
|
||||||
self.start({})
|
self.start({
|
||||||
|
'score': self.score,
|
||||||
|
'level': self.level
|
||||||
|
})
|
||||||
|
|
||||||
thumby.display.fill(0)
|
thumby.display.fill(0)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,27 @@ from collections import namedtuple
|
|||||||
|
|
||||||
SpriteImage = namedtuple("SpriteImage", ["image", "collision", "width", "height"])
|
SpriteImage = namedtuple("SpriteImage", ["image", "collision", "width", "height"])
|
||||||
|
|
||||||
|
seed = SpriteImage(
|
||||||
|
bytearray([8,20,46,46,62,62,46,62,46,12,0]),
|
||||||
|
None,
|
||||||
|
11,
|
||||||
|
7
|
||||||
|
)
|
||||||
|
|
||||||
|
collectibleover = SpriteImage(
|
||||||
|
bytearray([9,4,6,9]),
|
||||||
|
None,
|
||||||
|
4,
|
||||||
|
4
|
||||||
|
)
|
||||||
|
|
||||||
|
collectibleunder = SpriteImage(
|
||||||
|
bytearray([6,11,9,6]),
|
||||||
|
None,
|
||||||
|
4,
|
||||||
|
4
|
||||||
|
)
|
||||||
|
|
||||||
# BITMAP: width: 8, height: 8
|
# BITMAP: width: 8, height: 8
|
||||||
skull = SpriteImage(
|
skull = SpriteImage(
|
||||||
bytearray([0,28,102,126,38,30,28,0]),
|
bytearray([0,28,102,126,38,30,28,0]),
|
||||||
|
|||||||
22
sprites.py
22
sprites.py
@@ -5,7 +5,7 @@ import thumby
|
|||||||
|
|
||||||
from Games.Throot.map import ObstacleSlice
|
from Games.Throot.map import ObstacleSlice
|
||||||
from Games.Throot.player import Player, Camera
|
from Games.Throot.player import Player, Camera
|
||||||
from Games.Throot.artrepository import OBSTACLES
|
from Games.Throot.artrepository import *
|
||||||
|
|
||||||
class Entity:
|
class Entity:
|
||||||
"""
|
"""
|
||||||
@@ -97,6 +97,14 @@ class Obstacle(Entity):
|
|||||||
def update(self, tpf: float, player: Player, camera: Camera) -> bool:
|
def update(self, tpf: float, player: Player, camera: Camera) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
class Collectible(Entity):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.score = 'score' in kwargs and kwargs['score'] or 10
|
||||||
|
|
||||||
|
def update(self, tpf: float, player: Player, camera: Camera) -> bool:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def update_entities(entities, difficulty: int, current_depth: int, prev_depth: int):
|
def update_entities(entities, difficulty: int, current_depth: int, prev_depth: int):
|
||||||
"""
|
"""
|
||||||
@@ -125,7 +133,15 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
|
|||||||
spawned = set()
|
spawned = set()
|
||||||
max_spawned = randrange(0, difficulty + 1)
|
max_spawned = 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:
|
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 random() < 0.2:
|
||||||
|
Clazz = Collectible
|
||||||
|
if current_depth >= 0:
|
||||||
|
sprite_image = collectibleunder
|
||||||
|
else:
|
||||||
|
sprite_image = collectibleover
|
||||||
|
else:
|
||||||
|
Clazz = Obstacle
|
||||||
|
sprite_image = OBSTACLES[randrange(0, min((difficulty + 1) * 3, len(OBSTACLES)))]
|
||||||
if sprite_image.width >= thumby.display.width:
|
if sprite_image.width >= thumby.display.width:
|
||||||
x = 0
|
x = 0
|
||||||
else:
|
else:
|
||||||
@@ -142,5 +158,5 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
|
|||||||
break
|
break
|
||||||
if not error:
|
if not error:
|
||||||
sprite = thumby.Sprite(sprite_image.width, sprite_image.height, sprite_image.image, 0, 0, 0, False, False)
|
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))
|
spawned.add(Clazz(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