Compare commits
14 Commits
collectibl
...
ascend
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ccb425057 | ||
|
|
33ed9c062a | ||
|
|
3c41ef7535 | ||
|
|
09870bfa81 | ||
|
|
c37d9d9911 | ||
|
|
f34883b84f | ||
|
|
00f03652eb | ||
|
|
81bce7fe63 | ||
|
|
5d3f661411 | ||
|
|
bcd3715a9e | ||
|
|
6c05beaba0 | ||
|
|
77fd56b7b8 | ||
|
|
5acb279226 | ||
|
|
51be611e2f |
74
Throot.py
74
Throot.py
@@ -46,6 +46,9 @@ class GameManager:
|
|||||||
|
|
||||||
|
|
||||||
class Room:
|
class Room:
|
||||||
|
def __init__(self):
|
||||||
|
self.ind_button = 0
|
||||||
|
|
||||||
def start(self, event):
|
def start(self, event):
|
||||||
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
|
||||||
@@ -64,19 +67,40 @@ class RoomTitle(Room):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# draw title sprite
|
# draw title sprite
|
||||||
title_text = 'press a to start'
|
#thumby.display.drawSprite(sprite_title.width, sprite_title.height, sprite_title.image)
|
||||||
|
|
||||||
chr_len = 5
|
thumby.display.blit(sprite_title.image, 0, 0, sprite_title.width, sprite_title.height,
|
||||||
x = int(round(thumby.display.width / 2 - (chr_len * len(title_text)) / 2))
|
-1, 0, 0)
|
||||||
y = int(round(thumby.display.height / 2 - chr_len / 2))
|
|
||||||
|
|
||||||
|
# title text
|
||||||
|
chrx = 5
|
||||||
|
chry = 7
|
||||||
buff = 2
|
buff = 2
|
||||||
w = chr_len * len(title_text) + buff
|
|
||||||
h = chr_len + buff
|
x = 14#int(round(thumby.display.width / 2 - (chr_len * len(title_text)) / 2))
|
||||||
thumby.display.drawFilledRectangle(x - buff, y - buff, w, h, 1)
|
y = 40 - chry - buff#int(round(thumby.display.height / 2 - chr_len / 2))
|
||||||
thumby.display.drawText(title_text, x, y, 0)
|
|
||||||
|
w = chrx * 6 + buff
|
||||||
|
h = chry + buff
|
||||||
|
thumby.display.drawFilledRectangle(x - buff, y - buff, w, h * 2 + buff, 0)
|
||||||
|
#thumby.display.drawText('press a', x, y, 0)
|
||||||
|
thumby.display.drawText('start', x, y, 1)
|
||||||
|
|
||||||
|
spr_b = thumby.Sprite(sprite_buttona1.width, sprite_buttona1.height, sprite_buttona1.image + sprite_buttona2.image, 2, 40 - 8,
|
||||||
|
-1, 0, 0)
|
||||||
|
|
||||||
|
# thumby.display.blit(sprite_buttona.image, 2, 40 - 8, sprite_buttona.width, sprite_buttona.height,
|
||||||
|
# -1, 0, 0)
|
||||||
|
|
||||||
|
self.ind_button = (self.ind_button + 1) % (2 * CONST_FPS)
|
||||||
|
spr_b.setFrame(self.ind_button // (2 * CONST_FPS))
|
||||||
|
|
||||||
|
#print(self.ind_button // CONST_FPS)
|
||||||
|
|
||||||
|
thumby.display.drawSprite(spr_b)
|
||||||
|
|
||||||
class GameLoop(Room):
|
class GameLoop(Room):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.diving_velocity = 10
|
self.diving_velocity = 10
|
||||||
self.diving_accel = 0
|
self.diving_accel = 0
|
||||||
@@ -102,13 +126,17 @@ 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.speed_y = 16
|
||||||
|
self.player.isdecend = 1
|
||||||
self.score = 'score' in event and event['score'] or 0
|
self.score = 'score' in event and event['score'] or 0
|
||||||
self.level = 'level' in event and event['level'] 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.finish_height = -self.finish_depth
|
||||||
self.camera = Camera(self.player)
|
self.camera = Camera(self.player)
|
||||||
|
|
||||||
|
self.stage = DESCEND_STAGE
|
||||||
|
|
||||||
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))]
|
||||||
|
|
||||||
@@ -178,7 +206,7 @@ class GameLoop(Room):
|
|||||||
"""
|
"""
|
||||||
super().update(tpf)
|
super().update(tpf)
|
||||||
|
|
||||||
self.player.update_phys(tpf, self.camera)
|
self.player.update_phys(tpf, self.stage in (DESCEND_STAGE, ASCEND_STAGE) and self.camera or None)
|
||||||
|
|
||||||
self.camera.update_phys()
|
self.camera.update_phys()
|
||||||
|
|
||||||
@@ -208,15 +236,23 @@ class GameLoop(Room):
|
|||||||
self.score += int(abs(self.player.ysub - self.player.prev_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.stage == DESCEND_STAGE:
|
||||||
self.score += 20
|
if self.player.y > self.finish_depth + int(thumby.display.height * 1.5):
|
||||||
self.level += 1
|
self.stage = ASCEND_STAGE
|
||||||
self.start({
|
self.player.ysub = 0
|
||||||
'score': self.score,
|
self.player.prev_y = 0
|
||||||
'level': self.level
|
self.player.speed_y *= -1
|
||||||
})
|
self.player.isdecend = 0
|
||||||
|
elif self.stage == ASCEND_STAGE:
|
||||||
|
if self.player.y < self.finish_height - int(thumby.display.height * 1.5):
|
||||||
|
self.score += 20
|
||||||
|
self.level += 1
|
||||||
|
self.start({
|
||||||
|
'score': self.score,
|
||||||
|
'level': self.level
|
||||||
|
})
|
||||||
|
|
||||||
thumby.display.fill(0)
|
thumby.display.fill(int(self.player.y < 0))
|
||||||
self.draw_sky()
|
self.draw_sky()
|
||||||
# Draw the entities
|
# Draw the entities
|
||||||
for entity in self.entities:
|
for entity in self.entities:
|
||||||
@@ -225,7 +261,7 @@ class GameLoop(Room):
|
|||||||
|
|
||||||
self.draw_water()
|
self.draw_water()
|
||||||
|
|
||||||
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, int(self.player.y > 0))
|
||||||
|
|
||||||
|
|
||||||
class EndRoom(Room):
|
class EndRoom(Room):
|
||||||
|
|||||||
BIN
ThrootTitle.bmp
Normal file
BIN
ThrootTitle.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
BIN
ThrootTitleSingleFrame.bmp
Normal file
BIN
ThrootTitleSingleFrame.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -203,4 +203,25 @@ sprite_water = SpriteImage(
|
|||||||
8
|
8
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sprite_title = SpriteImage(
|
||||||
|
bytearray([32,128,40,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,0,0,0,0,0,0,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,160,128,32,0,72,0,192,96,24,8,4,6,2,2,2,2,2,4,12,24,112,192,0,0,0,3,3,3,3,3,255,255,255,3,251,251,251,3,3,251,251,251,3,251,251,155,155,155,155,99,99,0,248,248,24,24,24,251,251,3,251,251,27,27,27,251,251,3,255,255,255,3,3,3,0,1,0,31,48,96,64,64,64,98,50,30,0,0,192,96,48,16,24,15,12,24,48,96,192,0,0,0,255,255,255,0,255,255,255,7,7,255,255,255,0,255,255,1,1,1,3,255,255,0,255,255,128,128,128,255,255,0,255,255,128,128,128,255,255,0,255,255,255,0,0,0,0,192,64,96,32,32,69,192,10,0,4,0,0,127,129,0,0,0,0,0,0,0,96,48,29,7,0,0,63,255,255,192,149,85,85,84,84,85,85,85,84,85,85,84,84,84,84,85,85,84,85,85,85,85,85,85,85,84,85,85,85,85,85,85,21,192,255,255,127,0,0,0,3,7,4,132,128,192,96,29,70,0,0,0,0,0,1,6,12,8,24,16,248,140,4,4,108,72,120,48,0,128,193,255,255,127,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,252,254,255,183,99,65,64,64,96,48,24,30,99,65,64,194,128,133,0,2,0,128,96,24,12,4,2,2,1,1]),
|
||||||
|
None,
|
||||||
|
72,
|
||||||
|
40
|
||||||
|
)
|
||||||
|
|
||||||
|
sprite_buttona1 = SpriteImage(
|
||||||
|
bytearray([60,98,221,203,203,221,98,60]),
|
||||||
|
None,
|
||||||
|
8,
|
||||||
|
8
|
||||||
|
)
|
||||||
|
|
||||||
|
sprite_buttona2 = SpriteImage(
|
||||||
|
bytearray([56,68,186,150,150,186,68,56]),
|
||||||
|
None,
|
||||||
|
8,
|
||||||
|
8
|
||||||
|
)
|
||||||
|
|
||||||
OBSTACLES = [skull, pizza, boulder, ball, steve, mathroot, leaf, robot, dinoskull, dinojaw, dinospine, bone, bigdinohead, bigboneddiag, bigdoritoobstacle, spaceinv,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]
|
||||||
|
|||||||
10
constants.py
10
constants.py
@@ -5,3 +5,13 @@ ROOM_MAIN = 1
|
|||||||
ROOM_END = 2
|
ROOM_END = 2
|
||||||
ROOM_NEXT = -1
|
ROOM_NEXT = -1
|
||||||
|
|
||||||
|
|
||||||
|
# The first part of the level, where we are reaching the water
|
||||||
|
DESCEND_STAGE = 0
|
||||||
|
# The transition to the second part of the level, where the camera travels
|
||||||
|
# back to the surface
|
||||||
|
WATER_STAGE = 1
|
||||||
|
# The second part of the level, where we are growing into the sky
|
||||||
|
ASCEND_STAGE = 2
|
||||||
|
# The "level complete" animation
|
||||||
|
BLOOM_STAGE = 3
|
||||||
|
|||||||
228
player.py
228
player.py
@@ -2,19 +2,26 @@ import time
|
|||||||
import thumby
|
import thumby
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
from Games.Throot.constants import CONST_FPS
|
from Games.Throot.constants import CONST_FPS
|
||||||
|
|
||||||
# didplay width 72
|
# didplay width 72
|
||||||
# display height 40
|
# display height 40
|
||||||
|
|
||||||
# constants
|
class Input:
|
||||||
CONST_PL_SCREEN_Y = int((0.5) * thumby.display.height)
|
def move_right(self):
|
||||||
|
return (
|
||||||
|
thumby.buttonA.pressed() or
|
||||||
|
thumby.buttonR.pressed()
|
||||||
|
)
|
||||||
|
|
||||||
CONST_INP_MOVE_LEFT = thumby.buttonL
|
def move_left(self):
|
||||||
CONST_INP_MOVE_RIGHT = thumby.buttonA
|
return thumby.buttonL.pressed()
|
||||||
|
|
||||||
# classes
|
inp = Input()
|
||||||
|
|
||||||
|
### classes
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prev_x = 0
|
self.prev_x = 0
|
||||||
@@ -24,61 +31,74 @@ class Player:
|
|||||||
self.x = int(self.xsub)
|
self.x = int(self.xsub)
|
||||||
self.y = int(self.ysub)
|
self.y = int(self.ysub)
|
||||||
|
|
||||||
self.movespeed = 32 / CONST_FPS
|
|
||||||
self.isdecend = 1
|
self.isdecend = 1
|
||||||
|
|
||||||
self.xspeed = 32 / CONST_FPS
|
self.input_x = float(0)
|
||||||
self.yspeed = 32
|
|
||||||
self.accx = 1 / (CONST_FPS * 4)
|
# constants
|
||||||
self.accaccx = self.accx
|
self.speed_x_start = 32
|
||||||
|
self.speed_x_max = 200
|
||||||
|
self.acc_x_start = 64
|
||||||
|
self.jerk_x = 128
|
||||||
|
|
||||||
|
self.speed_x = self.speed_x_start
|
||||||
|
self.acc_x = self.acc_x_start
|
||||||
|
|
||||||
|
# y speed is constant
|
||||||
|
self.speed_y = 16
|
||||||
|
|
||||||
|
self.anim = PlayerAnimation(self)
|
||||||
|
|
||||||
self.anim = PlayerAnimation(self.x, self.y)
|
|
||||||
self.debugvisible = False
|
|
||||||
|
|
||||||
def update_phys(self, tpf, camera: Camera):
|
def update_phys(self, tpf, camera: Camera):
|
||||||
|
# prevoius sub pixel position
|
||||||
self.prev_x = self.xsub
|
self.prev_x = self.xsub
|
||||||
self.prev_y = self.ysub
|
self.prev_y = self.ysub
|
||||||
inp = int(0)
|
|
||||||
if CONST_INP_MOVE_LEFT.pressed():
|
|
||||||
inp -= 1
|
|
||||||
if CONST_INP_MOVE_RIGHT.pressed():
|
|
||||||
inp += 1
|
|
||||||
|
|
||||||
# debug visible
|
|
||||||
if thumby.buttonU.pressed():
|
|
||||||
self.debugvisible = not self.debugvisible
|
|
||||||
|
|
||||||
### x movement
|
### x movement
|
||||||
self.xspeed += self.accx
|
|
||||||
self.accx += self.accaccx
|
|
||||||
|
|
||||||
if (inp == 0) and (self.xspeed > self.movespeed):
|
# x input
|
||||||
self.xspeed = self.movespeed
|
if inp.move_left() and (not inp.move_right()):
|
||||||
self.accx = self.accaccx
|
self.input_x = -1
|
||||||
|
|
||||||
xx = self.xsub + inp * self.xspeed
|
if inp.move_right() and (not inp.move_left()):
|
||||||
|
self.input_x = 1
|
||||||
|
|
||||||
# clamp to screen
|
if (not inp.move_left()) and (not inp.move_right()):
|
||||||
self.xsub = max(min(xx, thumby.display.width - 1), 0)
|
self.input_x = 0
|
||||||
|
|
||||||
|
# acceleration and jerk
|
||||||
|
self.speed_x += self.acc_x * tpf
|
||||||
|
self.acc_x += self.jerk_x * tpf
|
||||||
|
|
||||||
|
# limit speed
|
||||||
|
self.speed_x = min(self.speed_x_max, self.speed_x)
|
||||||
|
|
||||||
|
# reset speed and acceleration if no input
|
||||||
|
if (self.input_x == 0) and (self.speed_x != self.speed_x_start):
|
||||||
|
self.speed_x = self.speed_x_start
|
||||||
|
self.acc_x = self.acc_x_start
|
||||||
|
|
||||||
|
# set x sub pixel position
|
||||||
|
self.xsub += self.speed_x * tpf * self.input_x
|
||||||
|
|
||||||
### y movement
|
### y movement
|
||||||
|
|
||||||
self.ysub += self.yspeed * tpf
|
# set y sub pixel position
|
||||||
|
self.ysub += self.speed_y * tpf
|
||||||
|
|
||||||
|
### stay in world bounds
|
||||||
|
self.xsub = max(min(self.xsub, thumby.display.width - 1), 0)
|
||||||
|
|
||||||
### pixel positions
|
### pixel positions
|
||||||
self.x = int(self.xsub)
|
self.x = int(self.xsub)
|
||||||
self.y = int(self.ysub)
|
self.y = int(self.ysub)
|
||||||
|
|
||||||
# animation
|
### animation physics
|
||||||
self.anim.update_phys(self.x, self.y, camera)
|
self.anim.update_phys(camera)
|
||||||
|
|
||||||
def update_draw(self, camera):
|
def update_draw(self, camera):
|
||||||
# debug draw
|
### animation render
|
||||||
if self.debugvisible:
|
|
||||||
pix_x, pix_y = camera.relative_to_camera(self.x, self.y)
|
|
||||||
thumby.display.setPixel(int(pix_x), int(pix_y), self.isdecend)
|
|
||||||
|
|
||||||
# animation
|
|
||||||
self.anim.update_draw(camera, self.isdecend)
|
self.anim.update_draw(camera, self.isdecend)
|
||||||
|
|
||||||
|
|
||||||
@@ -101,90 +121,92 @@ class Camera:
|
|||||||
# position player
|
# position player
|
||||||
self.y = self.target.y + self.offset
|
self.y = self.target.y + self.offset
|
||||||
|
|
||||||
|
|
||||||
class PlayerAnimation:
|
class PlayerAnimation:
|
||||||
# width and height of range bounding box
|
MAX_ROOT_OFFSET = int(4)
|
||||||
RANDOM_RANGE = int(7)
|
|
||||||
POS_RANGE = int(3)
|
|
||||||
POS_X = int(0)
|
|
||||||
POS_Y = int(1)
|
|
||||||
|
|
||||||
def __init__(self, plworldx, plworldy):
|
MAX_GROW_DISTANCE = int(6)#int(3)
|
||||||
self.poslist = [(plworldx, plworldy)]
|
MIN_GROW_DISTANCE = int(2)
|
||||||
self.debugrandomrange = self.RANDOM_RANGE
|
|
||||||
self.debugposrange = self.POS_RANGE
|
|
||||||
|
|
||||||
def update_phys(self, plworldx, plworldy, camera):
|
Point = namedtuple("Point", ["x", "y"])
|
||||||
|
|
||||||
#print(plworldx, plworldy, plscreeny, current_depth)
|
def __init__(self, player):
|
||||||
|
self.player = player
|
||||||
|
|
||||||
### exit if player y pos less than random range
|
self.root_offset = self.MAX_ROOT_OFFSET
|
||||||
# # debug change random range
|
self.grow_distance = self.MAX_GROW_DISTANCE
|
||||||
# inp = int(0)
|
|
||||||
# if thumby.buttonD.justPressed():
|
|
||||||
# inp -= 1
|
|
||||||
# if thumby.buttonU.justPressed():
|
|
||||||
# inp += 1
|
|
||||||
|
|
||||||
# if inp != 0:
|
self.points = []
|
||||||
# self.debugposrange = max(self.debugposrange + inp * 2, 1)
|
self.add_point()
|
||||||
# print('debugposrange: ', self.debugposrange)
|
|
||||||
|
|
||||||
# # if plworldy < self.poslist[-1][self.POS_Y] + random.randint(1, self.debugposrange):
|
self.debug_visible = False
|
||||||
# # return
|
self.debug_exact = True
|
||||||
|
|
||||||
# if plworldy < self.poslist[-1][self.POS_Y] + self.debugposrange:
|
def add_point(self):
|
||||||
# return
|
self.points.append(self.Point(self.player.x, self.player.y))
|
||||||
|
|
||||||
if plworldy < self.poslist[-1][self.POS_Y] + self.POS_RANGE:
|
def update_phys(self, camera):
|
||||||
return
|
# debug visible
|
||||||
|
if thumby.buttonB.justPressed():
|
||||||
|
self.debug_visible = not self.debug_visible
|
||||||
|
|
||||||
### get new position
|
# debug exact
|
||||||
rad = self.RANDOM_RANGE // 2
|
if thumby.buttonU.justPressed():
|
||||||
|
self.debug_exact = not self.debug_exact
|
||||||
|
|
||||||
# # debug change random range
|
# exit if distance from player to last root point is less than gorw distance
|
||||||
# inp = int(0)
|
dist_sqr = (
|
||||||
# if thumby.buttonB.justPressed():
|
(self.player.x - self.points[-1].x) ** 2 +
|
||||||
# inp -= 1
|
(self.player.y - self.points[-1].y) ** 2
|
||||||
# if thumby.buttonA.justPressed():
|
|
||||||
# inp += 1
|
|
||||||
|
|
||||||
# if inp != 0:
|
|
||||||
# self.debugrandomrange = max(self.debugrandomrange + inp * 2, 1)
|
|
||||||
# print('debugrandomrange:', self.debugrandomrange)
|
|
||||||
|
|
||||||
# rad = max(self.debugrandomrange // 2, 1)
|
|
||||||
|
|
||||||
# vector int
|
|
||||||
# self.poslist.append((plworldx + random.randrange(-rad, rad),
|
|
||||||
# plworldy + random.randrange(-rad, rad)))
|
|
||||||
|
|
||||||
# move last pos
|
|
||||||
self.poslist[-1] = (
|
|
||||||
plworldx + random.randrange(-rad, rad),
|
|
||||||
plworldy + random.randrange(-rad, rad)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# new pos is perfectly on player
|
if dist_sqr < self.grow_distance ** 2:
|
||||||
self.poslist.append((plworldx, plworldy))
|
return
|
||||||
|
|
||||||
# # debug
|
# set new grow distance
|
||||||
# self.poslist.append((plworldx, plworldy))
|
self.grow_distance = random.randint(self.MIN_GROW_DISTANCE, self.MAX_GROW_DISTANCE)
|
||||||
|
|
||||||
### remove the fist item in the list if its full line is off screen
|
# offset last root point to look random
|
||||||
if not camera.entity_in_camera(self.poslist[1][self.POS_X], self.poslist[1][self.POS_Y]):
|
self.points[-1] = self.Point(
|
||||||
self.poslist.pop(0)
|
self.points[-1].x + random.randrange(-self.root_offset, self.root_offset),
|
||||||
|
self.points[-1].y + random.randrange(-self.root_offset, self.root_offset)
|
||||||
|
)
|
||||||
|
|
||||||
#print(len(self.poslist))
|
# new root point created exactly on player
|
||||||
|
self.add_point()
|
||||||
|
|
||||||
|
# remove points in list that would make lines off the camera
|
||||||
|
for point in self.points[1:]:
|
||||||
|
if camera.entity_in_camera(point.x, point.y):
|
||||||
|
break
|
||||||
|
|
||||||
|
self.points.pop(0)
|
||||||
|
|
||||||
def update_draw(self, camera, isdecend=1):
|
def update_draw(self, camera, isdecend=1):
|
||||||
### draw line from first position to next
|
# debug render
|
||||||
|
if self.debug_visible:
|
||||||
|
pix_x, pix_y = camera.relative_to_camera(self.player.x, self.player.y)
|
||||||
|
thumby.display.setPixel(int(pix_x), int(pix_y), isdecend)
|
||||||
|
return
|
||||||
|
|
||||||
|
# root always reaches player position
|
||||||
|
if self.debug_exact:
|
||||||
|
x1, y1 = camera.relative_to_camera(self.player.x, self.player.y)
|
||||||
|
x2, y2 = camera.relative_to_camera(self.points[-1].x, self.points[-1].y)
|
||||||
|
thumby.display.drawLine(
|
||||||
|
int(x1),
|
||||||
|
int(y1),
|
||||||
|
int(x2),
|
||||||
|
int(y2),
|
||||||
|
isdecend
|
||||||
|
)
|
||||||
|
|
||||||
|
# draw line from first position to next
|
||||||
|
point_prev = self.points[-1]
|
||||||
|
for point in self.points[-2::-1]:
|
||||||
|
x1, y1 = camera.relative_to_camera(point_prev.x, point_prev.y)
|
||||||
|
x2, y2 = camera.relative_to_camera(point.x, point.y)
|
||||||
|
point_prev = point
|
||||||
|
|
||||||
#print(topleft)
|
|
||||||
|
|
||||||
for i in range(len(self.poslist) - 1):
|
|
||||||
x1, y1 = camera.relative_to_camera(self.poslist[i][self.POS_X], self.poslist[i][self.POS_Y])
|
|
||||||
x2, y2 = camera.relative_to_camera(self.poslist[i + 1][self.POS_X], self.poslist[i + 1][self.POS_Y])
|
|
||||||
thumby.display.drawLine(
|
thumby.display.drawLine(
|
||||||
int(x1),
|
int(x1),
|
||||||
int(y1),
|
int(y1),
|
||||||
|
|||||||
28
sprites.py
28
sprites.py
@@ -131,17 +131,25 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
|
|||||||
return set()
|
return set()
|
||||||
|
|
||||||
spawned = set()
|
spawned = set()
|
||||||
max_spawned = randrange(0, difficulty + 1)
|
if current_depth > 0:
|
||||||
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:
|
max_spawned = randrange(0, difficulty + 1)
|
||||||
if random() < 0.2:
|
else:
|
||||||
Clazz = Collectible
|
max_spawned = randrange(0, int(5 / (0.3 * difficulty + 0.7)))
|
||||||
if current_depth >= 0:
|
print(f"Spawning {max_spawned} entities this tick")
|
||||||
sprite_image = collectibleunder
|
while len(spawned) < max_spawned:
|
||||||
else:
|
if current_depth > 0:
|
||||||
sprite_image = collectibleover
|
if random() >= (2 * math.pow(difficulty + 0.01, 2)) / (3 * math.pow(difficulty + 0.01, 2) + 20 * (difficulty + 0.01)) + 0.05:
|
||||||
else:
|
print(f"Cancelling obstacles after {len(spawned)} entities")
|
||||||
|
break
|
||||||
Clazz = Obstacle
|
Clazz = Obstacle
|
||||||
sprite_image = OBSTACLES[randrange(0, min((difficulty + 1) * 3, len(OBSTACLES)))]
|
sprite_image = OBSTACLES[randrange(0, min((difficulty + 1) * 3, len(OBSTACLES)))]
|
||||||
|
else:
|
||||||
|
if random() >= 1 / (math.pow(difficulty, 2) + 3):
|
||||||
|
print(f"Cancelling obstacles after {len(spawned)} entities")
|
||||||
|
break
|
||||||
|
Clazz = Collectible
|
||||||
|
sprite_image = collectibleover
|
||||||
|
|
||||||
if sprite_image.width >= thumby.display.width:
|
if sprite_image.width >= thumby.display.width:
|
||||||
x = 0
|
x = 0
|
||||||
else:
|
else:
|
||||||
@@ -157,6 +165,6 @@ def update_entities(entities, difficulty: int, current_depth: int, prev_depth: i
|
|||||||
error = True
|
error = True
|
||||||
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, int(y < 0), False, False)
|
||||||
spawned.add(Clazz(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