177 lines
5.1 KiB
Python
177 lines
5.1 KiB
Python
from gg_data import *
|
|
from casioplot import *
|
|
|
|
BG_COLORS = [(79,95,106), (146,163,175), (170,201,223), (255,255,255)]
|
|
TILE_COLORS = [None, (63, 131, 150), (79, 95, 106), (90, 108, 130), (104, 85, 100), (144, 199, 240), (145, 135, 143), (146, 163, 175), (197, 205, 216), (233, 223, 170), (236, 236, 238)]
|
|
SPRITE_COLORS = [None, (35, 27, 22), (38, 33, 39), (67, 46, 42), (104, 60, 54), (135, 83, 87), (152, 115, 109), (153, 140, 137), (154, 38, 50), (160, 127, 126), (190, 81, 80), (196, 200, 105), (228, 200, 147), (229, 84, 84), (238, 240, 236)]
|
|
|
|
def renderBGLine(y, x, xmin, xmax):
|
|
for b in bg[y-53]:
|
|
c = BG_COLORS[b // 64]
|
|
x2 = min(x + (b & 63) + 1, xmax)
|
|
x = max(x, min(xmin, x2))
|
|
while x < x2:
|
|
set_pixel(x, y, c)
|
|
x += 1
|
|
if x >= xmax:
|
|
return
|
|
|
|
def renderBG(xmin, xmax, y, ymax):
|
|
c2 = BG_COLORS[2]
|
|
c0 = BG_COLORS[0]
|
|
while y < min(ymax, 53):
|
|
for x in range(xmin, xmax):
|
|
set_pixel(x, y, c2)
|
|
y += 1
|
|
if xmax < 192:
|
|
while y < min(ymax, 162):
|
|
renderBGLine(y, 0, xmin, xmax)
|
|
y += 1
|
|
elif xmin >= 192:
|
|
while y < min(ymax, 162):
|
|
renderBGLine(y, 192, xmin, xmax)
|
|
y += 1
|
|
else:
|
|
while y < min(ymax, 162):
|
|
renderBGLine(y, 0, xmin, xmax)
|
|
renderBGLine(y, 192, xmin, xmax)
|
|
y += 1
|
|
while y < ymax:
|
|
for x in range(xmin, xmax):
|
|
set_pixel(x, y, c0)
|
|
y += 1
|
|
|
|
def renderTile(x, y, num):
|
|
for dy in range(16):
|
|
for dx in range(16):
|
|
c = tiles[num][16*dy+dx]-48
|
|
if c:
|
|
set_pixel(x+dx, y+dy, TILE_COLORS[c])
|
|
|
|
def renderLevel(num):
|
|
renderBG(0, 384, 0, 192)
|
|
for value in levels[num]:
|
|
if value < 0:
|
|
pos = -value
|
|
else:
|
|
renderTile(16 * (pos % 24), 16 * (pos // 24), value)
|
|
pos += 1
|
|
|
|
def renderPlayer(x, y, num, flipped):
|
|
x -= 5
|
|
y = y if flipped else y-20
|
|
for dy in range(21):
|
|
for dx in range(16):
|
|
c = sprites[num][16*dy+dx]-48
|
|
if c:
|
|
set_pixel(x+dx, y+20-dy if flipped else y+dy, SPRITE_COLORS[c])
|
|
|
|
def erasePlayer(num, x, y, flipped):
|
|
x -= 5
|
|
y = y if flipped else y-20
|
|
renderBG(x, x+16, y, y+21)
|
|
|
|
for tx in (x, x+15):
|
|
for ty in (y, y+10, y+20):
|
|
bx, by = tx // 16, ty // 16
|
|
block = getTile(num, 24 * by + bx)
|
|
if block >= 0:
|
|
renderTile(16*bx, 16*by, block)
|
|
|
|
def loadLevel(num):
|
|
clear_screen()
|
|
draw_string(152, 78, "Niveau {}".format(num+1), (0,0,0), "small")
|
|
draw_string(152, 90, "Chargement...", (0,0,0), "small")
|
|
show_screen()
|
|
renderLevel(num)
|
|
show_screen()
|
|
|
|
def getTile(num, index):
|
|
i = 0
|
|
for value in levels[num]:
|
|
i = -value if value < 0 else i+1
|
|
if i > index:
|
|
return max(value, -1)
|
|
return -1
|
|
|
|
def collision(num, ox, oy, nx, ny, flipped):
|
|
if nx < 0 or nx >= 384 or ny < 0 or ny >= 192:
|
|
return nx, ny, False
|
|
block = getTile(num, 24*(ny//16) + (nx//16))
|
|
if block >= 0:
|
|
correct_ny = (ny//16) * 16 + (16 if flipped else -1)
|
|
return nx, correct_ny, True
|
|
else:
|
|
return nx, ny, False
|
|
|
|
def playLevel(num):
|
|
loadLevel(num)
|
|
x, y, vy, ay = 5, 16*[6,9,4][num], 0-(num==2), 1-2*(num==2)
|
|
frame = 0
|
|
action = False
|
|
standing = False
|
|
while True:
|
|
try:
|
|
if action:
|
|
y += 20 * ((ay < 0) - (ay > 0))
|
|
ay = -ay
|
|
vy = ay
|
|
action = False
|
|
while x < 379:
|
|
renderPlayer(x, y, frame // 2 if standing else 0, vy < 0)
|
|
show_screen()
|
|
erasePlayer(num, x, y, vy < 0)
|
|
frame = (frame + 1) % 4
|
|
|
|
vy = min(4, max(-4, vy + ay))
|
|
x, y, standing = collision(num, x, y, x+2, y+vy, vy < 0)
|
|
|
|
if y < 0 or y > 192:
|
|
return False
|
|
return True
|
|
except KeyboardInterrupt:
|
|
action = standing
|
|
|
|
def startcard():
|
|
clear_screen()
|
|
draw_string(152, 20, "Gravity Guy !", (0,0,0), "small")
|
|
draw_string(15, 40, "Inversez la sens de gravitation en appuyant sur la", (0,0,0), "small")
|
|
draw_string(15, 55, "touche [AC/ON] pour sauter de plateforme en", (0,0,0), "small")
|
|
draw_string(15, 70, "platforme et atteindre la fin de chaque niveau.", (0,0,0), "small")
|
|
draw_string(15, 90, "[AC/ON]: C'est parti !", (0,0,0), "small")
|
|
show_screen()
|
|
|
|
try:
|
|
while True:
|
|
pass
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
def endcard():
|
|
clear_screen()
|
|
draw_string(136, 84, "Bravo Gravity Guy!", (0,0,0), "small")
|
|
show_screen()
|
|
|
|
def main():
|
|
startcard()
|
|
num = 0
|
|
while True:
|
|
b = playLevel(num)
|
|
if not b:
|
|
print("Essayer encore ?")
|
|
print("EXE:Ok Saisie:Non")
|
|
if input():
|
|
break
|
|
elif num+1 == len(levels):
|
|
print("Bravo!")
|
|
endcard()
|
|
break
|
|
else:
|
|
print("Niveau suivant?")
|
|
print("EXE:Ok Saisie:Non")
|
|
if input():
|
|
break
|
|
num += 1
|
|
|
|
main()
|