gg_up.py

Created by mathieu-croslacoste

Created on September 16, 2025

3.25 KB

Adaptation of the script for Casio “gg.py”. Simple and short Gravity Guy game.

Needs “gg_data_up” (https://my.numworks.com/python/mathieu-croslacoste/gg_data_up) to run.


from gg_data_up import*
from kandinsky import set_pixel,fill_rect as F,draw_string as D
from ion import keydown as K
from time import*
P_BG=[(79,95,106),(146,163,175),(170,201,223),"w"]
P_TILE=[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,)*3]
P_SPRT=[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,"w")
def BGLine(y,x,xmin,xmax):
 S=set_pixel;pal=P_BG
 for b in bg[y-53]:
  c=pal[b>>6];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 BG(xmin,xmax,y,ymax):
 S=set_pixel;c2=P_BG[2];c0=P_BG[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):BGLine(y,0,xmin,xmax);y+=1
 elif xmin>=192:
  while y<min(ymax,162):BGLine(y,192,xmin,xmax);y+=1
 else:
  while y<min(ymax,162):BGLine(y,0,xmin,xmax);BGLine(y,192,xmin,xmax);y+=1
 while y<ymax:
  for x in range(xmin,xmax):S(x,y,c0)
  y+=1
 F(0,192,320,30,c0)
def dTile(x,y,num):
 S=set_pixel;pal,co=P_TILE,tiles[num]
 for dy in range(16):
  dy16=dy<<4;p=y+dy
  for dx in range(16):
   c=co[dy16+dx]-48
   if c:S(x+dx,p,pal[c])
def dLv(num):
 BG(0,320,0,192)
 for val in lvs[num]:
  if val<0:pos=-val
  else:dTile((pos%24)<<4,(pos//24)<<4,val);pos+=1
def dP(x,y,num,flip):
 S=set_pixel;pal,co=P_SPRT,sprts[num];x-=5
 if 1-flip:y-=20
 for dy in range(21):
  dy16=dy<<4;p=flip and y+20-dy or y+dy
  for dx in range(16):
   c=co[dy16+dx]-48
   if c:S(x+dx,p,pal[c])
def cP(num,x,y,flip):
 x-=5
 if 1-flip:y-=20
 BG(x,x+16,y,y+21)
 for tx in(x,x+15):
  bx=tx>>4;bx2=bx<<4
  for ty in(y,y+10,y+20):
   by=ty>>4;b=getT(num,24*by+bx)
   if b>=0:dTile(bx2,by<<4,b)
def loadLv(num):C();D("Niveau "+str(num+1),152,78);D("Chargement...",152,108);dLv(num)
def getT(num,id):
 i=0
 for val in lvs[num]:
  i=-val if val<0 else i+1
  if i>id:return max(val,-1)
 return-1
def coll(num,ox,oy,nx,ny,flip):
 if nx>370 or not 0<=ny<193:return nx,ny,0
 b=getT(num,24*(ny>>4)+(nx>>4))
 if b>=0:return nx,((ny>>4)<<4)+(16 if flip else-1),1
 else:return nx,ny,0
def play(num):
 M=monotonic;loadLv(num);frame=0;act=0;stand=0;x,y,vy,ay=5,xlist[num]<<4,-(num==2),1-2*(num==2);t=0;ox,oy,ovy=x,y,vy
 while 1:
  while x<360:
   if K(4)+K(52)and stand:y+=20*((ay<0)-(ay>0));ay=-ay;vy=ay;act=0
   cP(num,x-2,oy,ovy<0);oy,ovy=y,vy;dP(x,y,frame>>2 if stand else 0,vy<0);frame=(frame+1)%8;vy=min(4,max(-4,vy+ay));x,y,stand=coll(num,x,y,x+2,y+vy,vy<0)
   if not 0<y<193:return 0
   while M()-t<.02:0
   t=M()
  return 1
def start():
 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 1-K(4)-K(52):0
def end():
 C();BG(0,320,0,222);D("Bravo Gravity Guy!",86,84);z=1;x=0
 while K(4)+K(52):0
 while 1-K(4)-K(52):sleep(.01);BG(x-16,x,100,121);dP(x,120,z>>2,0);z=(z+1)%8;x=(x+1)%336
def main():
 start();num=0
 while 1:
  b=play(num)
  if not b:
   print("Essayer encore ?\nEXE:Ok   Saisie:Non")
   if input():break
  elif num+1==len(lvs):print("Bravo!");end();return
  else:
   print("Niveau suivant?\nEXE:Ok   Saisie:Non")
   if input():break
   num+=1
xlist=(6,9,4);main()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.