Adds obstacles and obstacles at once.
This commit is contained in:
@@ -5,6 +5,7 @@ import math
|
|||||||
import Games.Throot.map
|
import Games.Throot.map
|
||||||
import Games.Throot.sprites
|
import Games.Throot.sprites
|
||||||
from Games.Throot.artrepository import OBSTACLES
|
from Games.Throot.artrepository import OBSTACLES
|
||||||
|
from Games.Throot.player import Player
|
||||||
|
|
||||||
from random import randrange
|
from random import randrange
|
||||||
|
|
||||||
@@ -21,6 +22,8 @@ class GameLoop:
|
|||||||
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
self.current_obstacle_slice = OBSTACLE_SLICES[0]
|
||||||
self.entities = set()
|
self.entities = set()
|
||||||
|
|
||||||
|
self.player = Player()
|
||||||
|
|
||||||
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))]
|
||||||
|
|
||||||
@@ -35,6 +38,8 @@ class GameLoop:
|
|||||||
if self.current_depth % ObstacleSlice.height < prev_depth % ObstacleSlice.height:
|
if 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)
|
||||||
|
|
||||||
# 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.current_obstacle_slice, self.current_depth, prev_depth)
|
||||||
|
|
||||||
@@ -49,6 +54,7 @@ class GameLoop:
|
|||||||
# 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.player.update_draw(self.current_depth, prev_depth)
|
||||||
thumby.display.update()
|
thumby.display.update()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -65,4 +71,4 @@ def main():
|
|||||||
loop.update(tps)
|
loop.update(tps)
|
||||||
prev_time = t0
|
prev_time = t0
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Player:
|
|||||||
self.anim = PlayerAnimation(self.x, self.y)
|
self.anim = PlayerAnimation(self.x, self.y)
|
||||||
self.debugvisible = True
|
self.debugvisible = True
|
||||||
|
|
||||||
def update_phys(self):
|
def update_phys(self, current_depth, prev_depth):
|
||||||
inp = int(0)
|
inp = int(0)
|
||||||
if CONST_INP_MOVE_LEFT.pressed():
|
if CONST_INP_MOVE_LEFT.pressed():
|
||||||
inp -= 1
|
inp -= 1
|
||||||
@@ -57,7 +57,7 @@ class Player:
|
|||||||
self.xsub = max(min(xx, thumby.display.width - 1), 0)
|
self.xsub = max(min(xx, thumby.display.width - 1), 0)
|
||||||
|
|
||||||
### y movement
|
### y movement
|
||||||
self.ysub += self.yspeed
|
self.ysub = current_depth - (thumby.display.height / 2)
|
||||||
|
|
||||||
### pixel positions
|
### pixel positions
|
||||||
self.x = int(self.xsub)
|
self.x = int(self.xsub)
|
||||||
@@ -66,13 +66,15 @@ class Player:
|
|||||||
# animation
|
# 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)
|
||||||
|
|
||||||
def update_draw(self, cam):
|
def update_draw(self, current_depth, prev_depth):
|
||||||
# debug draw
|
# debug draw
|
||||||
if self.debugvisible:
|
if self.debugvisible:
|
||||||
thumby.display.setPixel(self.x - cam.x, self.y - cam.y, self.isdecend)
|
pix_x = self.x
|
||||||
|
pix_y = int(current_depth - self.y)
|
||||||
|
thumby.display.setPixel(pix_x, pix_y, self.isdecend)
|
||||||
|
|
||||||
# animation
|
# animation
|
||||||
self.anim.update_draw(cam, self.isdecend)
|
self.anim.update_draw(current_depth, prev_depth, self.isdecend)
|
||||||
|
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
@@ -142,8 +144,10 @@ class PlayerAnimation:
|
|||||||
# plworldy + random.randrange(-rad, rad)))
|
# plworldy + random.randrange(-rad, rad)))
|
||||||
|
|
||||||
# move last pos
|
# move last pos
|
||||||
self.poslist[-1] = (plworldx + random.randrange(-rad, rad),
|
self.poslist[-1] = (
|
||||||
plworldy + random.randrange(-rad, rad))
|
plworldx + random.randrange(-rad, rad),
|
||||||
|
plworldy + random.randrange(-rad, rad)
|
||||||
|
)
|
||||||
|
|
||||||
# new pos is perfectly on player
|
# new pos is perfectly on player
|
||||||
self.poslist.append((plworldx, plworldy))
|
self.poslist.append((plworldx, plworldy))
|
||||||
@@ -152,39 +156,19 @@ class PlayerAnimation:
|
|||||||
# self.poslist.append((plworldx, plworldy))
|
# self.poslist.append((plworldx, plworldy))
|
||||||
|
|
||||||
### remove the fist item in the list if its full line is off screen
|
### remove the fist item in the list if its full line is off screen
|
||||||
if self.poslist[1][self.POS_Y] < plworldy - plscreeny:
|
#if self.poslist[1][self.POS_Y] < plworldy - plscreeny:
|
||||||
self.poslist.pop(0)
|
# self.poslist.pop(0)
|
||||||
|
|
||||||
#print(len(self.poslist))
|
#print(len(self.poslist))
|
||||||
|
|
||||||
def update_draw(self, cam, isdecend=1):
|
def update_draw(self, current_depth, prev_depth, isdecend=1):
|
||||||
### draw line from first position to next
|
### draw line from first position to next
|
||||||
|
|
||||||
for i in range(len(self.poslist) - 1):
|
for i in range(len(self.poslist) - 1):
|
||||||
thumby.display.drawLine(self.poslist[i][self.POS_X] - cam.x, self.poslist[i][self.POS_Y] - cam.y,
|
thumby.display.drawLine(
|
||||||
self.poslist[i + 1][self.POS_X] - cam.x, self.poslist[i + 1][self.POS_Y] - cam.y, isdecend)
|
int(self.poslist[i][self.POS_X]),
|
||||||
|
int(current_depth - self.poslist[i][self.POS_Y]),
|
||||||
|
int(self.poslist[i + 1][self.POS_X]),
|
||||||
### start
|
int(current_depth - self.poslist[i + 1][self.POS_Y]),
|
||||||
# Set the FPS (without this call, the default fps is 30)
|
isdecend
|
||||||
thumby.display.setFPS(CONST_FPS)
|
)
|
||||||
|
|
||||||
pl = Player()
|
|
||||||
cam = Camera(pl)
|
|
||||||
|
|
||||||
print("game ready")
|
|
||||||
|
|
||||||
|
|
||||||
### game loop
|
|
||||||
while(True):
|
|
||||||
t0 = time.ticks_ms() # Get time (ms)
|
|
||||||
thumby.display.fill(0) # Fill canvas to black
|
|
||||||
|
|
||||||
# update physics
|
|
||||||
pl.update_phys()
|
|
||||||
cam.update_phys(CONST_PL_SCREEN_Y)
|
|
||||||
|
|
||||||
# update drawing
|
|
||||||
pl.update_draw(cam)
|
|
||||||
|
|
||||||
thumby.display.update()
|
|
||||||
Reference in New Issue
Block a user