Compare commits
8 Commits
sprite-gen
...
player_ani
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
176d89ea14 | ||
|
|
4b8eb17ba1 | ||
|
|
8ad6236ff7 | ||
|
|
d0cf8f2a20 | ||
|
|
6004a54e9f | ||
|
|
c668a68097 | ||
|
|
7e454cd8e4 | ||
|
|
11667a1b92 |
94
Throot.py
94
Throot.py
@@ -1,20 +1,79 @@
|
||||
import time
|
||||
import thumby
|
||||
import math
|
||||
|
||||
import thumby
|
||||
|
||||
import Games.Throot.map
|
||||
import Games.Throot.sprites
|
||||
from Games.Throot.artrepository import OBSTACLES
|
||||
from Games.Throot.player import Player
|
||||
|
||||
from random import randrange
|
||||
|
||||
import thumby
|
||||
|
||||
from Games.Throot.artrepository import OBSTACLES
|
||||
from Games.Throot.player import Player
|
||||
from Games.Throot.map import ObstacleSlice, OBSTACLE_SLICES
|
||||
from Games.Throot.sprites import update_entities
|
||||
from Games.Throot.constants import CONST_FPS
|
||||
|
||||
class GameLoop:
|
||||
class GameManager:
|
||||
EVENT_ROOM_CHANGE = {'start': 0, 'main': 1, 'end': 2, 'next': -1}
|
||||
|
||||
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, index):
|
||||
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()
|
||||
|
||||
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(self.EVENT_ROOM_CHANGE[event])
|
||||
|
||||
|
||||
class Room:
|
||||
def start(self):
|
||||
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 '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
|
||||
@@ -23,6 +82,8 @@ class GameLoop:
|
||||
self.entities = set()
|
||||
|
||||
self.player = Player()
|
||||
|
||||
self.score = 0
|
||||
|
||||
def get_obstacle_slice(self):
|
||||
return OBSTACLE_SLICES[randrange(0, len(OBSTACLE_SLICES))]
|
||||
@@ -31,6 +92,7 @@ class GameLoop:
|
||||
"""
|
||||
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
|
||||
@@ -49,26 +111,28 @@ class GameLoop:
|
||||
if not entity.update(tpf, self.current_depth, prev_depth):
|
||||
to_remove.add(entity)
|
||||
self.entities -= to_remove
|
||||
|
||||
self.score = int(self.current_depth * 10)
|
||||
|
||||
thumby.display.fill(0)
|
||||
# Draw the entities
|
||||
for entity in self.entities:
|
||||
entity.render(tpf, self.current_depth, prev_depth)
|
||||
self.player.update_draw(self.current_depth, prev_depth)
|
||||
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.update()
|
||||
|
||||
def main():
|
||||
# Set the FPS (without this call, the default fps is 30)
|
||||
thumby.display.setFPS(60)
|
||||
|
||||
print("Starting game loop")
|
||||
loop = GameLoop()
|
||||
def main():
|
||||
game = GameManager(RoomTitle(), GameLoop())
|
||||
game.start()
|
||||
|
||||
prev_time = 0
|
||||
while True:
|
||||
t0 = time.ticks_ms()
|
||||
tps = (t0 - prev_time) / 1000
|
||||
loop.update(tps)
|
||||
#loop.update(tps)
|
||||
game.update(tps)
|
||||
prev_time = t0
|
||||
|
||||
main()
|
||||
|
||||
63
ThrootArtAssets.py
Normal file
63
ThrootArtAssets.py
Normal file
File diff suppressed because one or more lines are too long
BIN
ThrootTitle.raw
Normal file
BIN
ThrootTitle.raw
Normal file
Binary file not shown.
1
constants.py
Normal file
1
constants.py
Normal file
@@ -0,0 +1 @@
|
||||
CONST_FPS = 60
|
||||
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>
|
||||
27
player.py
27
player.py
@@ -3,11 +3,12 @@ import thumby
|
||||
import math
|
||||
import random
|
||||
|
||||
from Games.Throot.constants import CONST_FPS
|
||||
|
||||
# didplay width 72
|
||||
# display height 40
|
||||
|
||||
# constants
|
||||
CONST_FPS = 60
|
||||
CONST_PL_SCREEN_Y = int((0.5) * thumby.display.height)
|
||||
|
||||
CONST_INP_MOVE_LEFT = thumby.buttonL
|
||||
@@ -64,17 +65,17 @@ class Player:
|
||||
self.y = int(self.ysub)
|
||||
|
||||
# animation
|
||||
self.anim.update_phys(self.x, self.y, CONST_PL_SCREEN_Y)
|
||||
self.anim.update_phys(self.x, self.y, CONST_PL_SCREEN_Y, current_depth)
|
||||
|
||||
def update_draw(self, current_depth, prev_depth):
|
||||
def update_draw(self, plworldy):
|
||||
# debug draw
|
||||
if self.debugvisible:
|
||||
pix_x = self.x
|
||||
pix_y = int(current_depth - self.y)
|
||||
pix_y = int(self.y - plworldy + 20)
|
||||
thumby.display.setPixel(pix_x, pix_y, self.isdecend)
|
||||
|
||||
# animation
|
||||
self.anim.update_draw(current_depth, prev_depth, self.isdecend)
|
||||
self.anim.update_draw(plworldy - 20, self.isdecend)
|
||||
|
||||
|
||||
class Camera:
|
||||
@@ -100,7 +101,9 @@ class PlayerAnimation:
|
||||
self.debugrandomrange = self.RANDOM_RANGE
|
||||
self.debugposrange = self.POS_RANGE
|
||||
|
||||
def update_phys(self, plworldx, plworldy, plscreeny):
|
||||
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
|
||||
@@ -156,19 +159,21 @@ class PlayerAnimation:
|
||||
# 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)
|
||||
if self.poslist[1][self.POS_Y] < plworldy - plscreeny:
|
||||
self.poslist.pop(0)
|
||||
|
||||
#print(len(self.poslist))
|
||||
|
||||
def update_draw(self, current_depth, prev_depth, isdecend=1):
|
||||
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(current_depth - self.poslist[i][self.POS_Y]),
|
||||
int(self.poslist[i][self.POS_Y] - topleft),
|
||||
int(self.poslist[i + 1][self.POS_X]),
|
||||
int(current_depth - self.poslist[i + 1][self.POS_Y]),
|
||||
int(self.poslist[i + 1][self.POS_Y] - topleft),
|
||||
isdecend
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user