Adaptation of the script for Casio “gg.py”. Simple and short Gravity Guy game.
Needs “gg_data2” (https://my.numworks.com/python/mathieu-croslacoste/gg_data2) to run.
from gg_data2 import* from kandinsky import set_pixel as S,fill_rect as F,draw_string as D from ion import keydown as K from time 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 C():F(0,0,320,222,(255,)*3) 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:S(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):S(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):S(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:S(x+dx,y+dy,TILE_COLORS[c]) def renderLevel(num): renderBG(0,320,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:S(x+dx, y+20-dy if flipped else y+dy,SPRITE_COLORS[c]) def erasePlayer(num,x,y,flipped): x-=5 if flipped^1: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):C();D("Niveau {}".format(num+1),152,78);D("Chargement...",152,108);renderLevel(num) 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,0 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,1 else:return nx,ny,0 def playLevel(num): loadLevel(num);frame=0;action=0;standing=0;x,y,vy,ay=5,16*xlist[num],0-(num==2),1-2*(num==2);t=0;ox,oy,ovy=x,y,vy while 1: while x<379: if(K(4)|K(52))and standing:y+=20*((ay<0)-(ay>0));ay=-ay;vy=ay;action=0 erasePlayer(num,x-2,oy,ovy<0);oy,ovy=y,vy;renderPlayer(x,y,int(frame)//2 if standing else 0,vy<0);frame=(frame+0.5)%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 0 while monotonic()-t<.005:0 t=monotonic() return 1 def startcard(): C();D("Gravity Guy !\nInversez la gravite en appuyant\nsur la touche [OK]/[EXE].\nIl y a 3 niveaux.\n[OK]/[EXE]: C'est parti !",95,20) while(K(4)|K(52))^1:0 def endcard(): C();renderBG(0,320,0,222);D("Bravo Gravity Guy!",86,84);z=1;x=0 while(K(4)|K(52))^1:renderBG(x-16,x,100,121);renderPlayer(x,120,int(z)//2,0);z=(z+0.5)%4;x+=1;x%=336 def main(): startcard();num=0 while 1: b=playLevel(num) if not b: print("Essayer encore ?\nEXE:Ok Saisie:Non") if input():break elif num+1==len(levels):print("Bravo!");endcard();break else: print("Niveau suivant?\nEXE:Ok Saisie:Non") if input():break num+=1 xlist=[6,9,4];main()