Compare commits
3 Commits
water
...
random-obs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5967359e70 | ||
|
|
81822ee80a | ||
|
|
3c6e070716 |
107
Throot.py
107
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 *
|
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 Obstacle, update_entities
|
from Games.Throot.sprites import Obstacle, update_entities
|
||||||
from Games.Throot.constants import *
|
from Games.Throot.constants import CONST_FPS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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,14 +24,13 @@ 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, event):
|
def room_goto(self, index):
|
||||||
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(event)
|
self.rooms[self.room_index].start()
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
self.room_index = 0
|
self.room_index = 0
|
||||||
@@ -42,11 +41,11 @@ class GameManager:
|
|||||||
thumby.display.update()
|
thumby.display.update()
|
||||||
|
|
||||||
if event:
|
if event:
|
||||||
self.room_goto(event)
|
self.room_goto(self.EVENT_ROOM_CHANGE[event])
|
||||||
|
|
||||||
|
|
||||||
class Room:
|
class Room:
|
||||||
def start(self, event):
|
def start(self):
|
||||||
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
|
||||||
|
|
||||||
@@ -59,9 +58,7 @@ class RoomTitle(Room):
|
|||||||
super().update(tpf)
|
super().update(tpf)
|
||||||
|
|
||||||
if thumby.inputPressed():
|
if thumby.inputPressed():
|
||||||
return {
|
return 'main'
|
||||||
'room': ROOM_MAIN
|
|
||||||
}
|
|
||||||
|
|
||||||
# draw title sprite
|
# draw title sprite
|
||||||
title_text = 'press a to start'
|
title_text = 'press a to start'
|
||||||
@@ -87,56 +84,9 @@ class GameLoop(Room):
|
|||||||
self.player = Player()
|
self.player = Player()
|
||||||
|
|
||||||
self.score = 0
|
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):
|
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.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):
|
def update(self, tpf):
|
||||||
"""
|
"""
|
||||||
@@ -168,55 +118,22 @@ class GameLoop(Room):
|
|||||||
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):
|
||||||
return {
|
print("Hit!")
|
||||||
'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(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)
|
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.current_depth, prev_depth)
|
||||||
|
|
||||||
self.draw_water()
|
|
||||||
|
|
||||||
self.player.update_draw(self.player.y)
|
self.player.update_draw(self.player.y)
|
||||||
|
|
||||||
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(), EndRoom())
|
game = GameManager(RoomTitle(), GameLoop())
|
||||||
game.start()
|
game.start()
|
||||||
|
|
||||||
prev_time = 0
|
prev_time = 0
|
||||||
|
|||||||
@@ -175,11 +175,4 @@ Doritoobstaclelvl5 = SpriteImage(
|
|||||||
30
|
30
|
||||||
)
|
)
|
||||||
|
|
||||||
sprite_water = SpriteImage(
|
OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, leaf, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle, spaceinv,annoydead,lvl4wall,ballobstaclelvl3,Doritoobstaclelvl5]
|
||||||
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,6 +1 @@
|
|||||||
CONST_FPS = 60
|
CONST_FPS = 60
|
||||||
|
|
||||||
ROOM_START = 0
|
|
||||||
ROOM_MAIN = 1
|
|
||||||
ROOM_END = 2
|
|
||||||
ROOM_NEXT = -1
|
|
||||||
@@ -123,7 +123,7 @@ class PlayerAnimation:
|
|||||||
# if plworldy < self.poslist[-1][self.POS_Y] + self.debugposrange:
|
# if plworldy < self.poslist[-1][self.POS_Y] + self.debugposrange:
|
||||||
# return
|
# return
|
||||||
|
|
||||||
if plworldy < self.poslist[-1][self.POS_Y] + random.randint(1, self.POS_RANGE):
|
if plworldy < self.poslist[-1][self.POS_Y] + self.POS_RANGE:
|
||||||
return
|
return
|
||||||
|
|
||||||
### get new position
|
### get new position
|
||||||
|
|||||||
Reference in New Issue
Block a user