cal_culator_demo1.py

Created by heredos-me

Created on November 26, 2020

2.24 KB

the first preview of a cal demake i’m making. do not expect too much of it: first because i’m lazy, second because it’s interpreted python and this calculator don’t have vsync and is not powerful enough to redraw the entire scene each frame. I already know the bug when you are under the right down block and i’m currently fixing it before adding sprites. I really hope you’ll enjoy it!


from kandinsky import *
draw_string("loading....\nplease wait",160,111)
from ion import *
from time import *
from math import *
    

def cubecol(x,y,xvel,yvel,onground,state,x1,y1,x2,y2):
  
  if state==-1:
    xs=20
    ys=5
  else:
    xs=10
    ys=10
  
  if x+xs>x1 and x-xs<x2 and y+ys-yvel>y1 and y-ys-yvel<y2:
    if yvel<0:
      y=y1-ys
      onground=1
    else:
      if onground==1:
        dead=1
      y=y2+ys
    yvel=0
  if y+ys>y1 and y-ys<y2 and x+xs+xvel>x1 and x-xs+xvel<x2:
    onground=1
    x=x-int(xvel)
  return (x,y,xvel,yvel,onground)
    

def player(x,y,state):
  if state==0:
    fill_rect(x-10,y-10,20,20,color(255,255,255))
  elif state==1:
    fill_rect(x-10,y-10,20,20,'grey')
  elif state==-1:
    fill_rect(x-20,y-5,40,10,'blue')

def noplayer(x,y,state):
  if state==-1:
    fill_rect(x-20,y-5,40,10,'black')
  else:
    fill_rect(x-10,y-10,20,20,'black')  

def zero(n):
  if n>0:
    return 1
  if n<0:
    return -1
  if n==0:
    return 0

x=100
xvel=0
onground=1
y=50
yvel=0
maxvel=5
state=0
ox=0
oy=0
os=0
#x=320
#y=222

fill_rect(0,0,320,222,'black')
fill_rect(100,70,100,60,color(50,50,50))
fill_rect(0,200,320,222,color(50,50,50))
fill_rect(230,140,70,50,color(50,50,50))

while (1):
  if keydown(KEY_LEFT)and xvel>-maxvel:
    xvel=xvel-0.5
  elif keydown(KEY_RIGHT)and xvel<maxvel:
    xvel=xvel+0.5
  else:
    xvel=xvel-zero(xvel)
    
    
  if keydown(KEY_UP):
    if state!=1:
      if onground==1:
        state=1
        maxvel=0
        onground=0
        yvel=8
    else:
      onground=0
      state=1
  elif keydown(KEY_DOWN):
    if state==0 :
      y=y+5
    state=-1
    maxvel=6
    onground=0
  else:
    maxvel=3
    state=0
  if keydown(KEY_OK) and onground==1:
    yvel=7
  else:
    if state==0:
      yvel=yvel-0.25
    elif state==-1:
      yvel=yvel-1
    elif yvel>=0:
      yvel=yvel-0.125
    
  onground=0
  x,y,xvel,yvel,onground=cubecol(x,y,xvel,yvel,onground,state,0,200,320,300)
  x,y,xvel,yvel,onground=cubecol(x,y,xvel,yvel,onground,state,100,70,200,130)
  x,y,xvel,yvel,onground=cubecol(x,y,xvel,yvel,onground,state,230,140,300,190)
  
  #print("\nx", x)
  #print("y", y)
  x=x+int(xvel)
  y=y-int(yvel)
  noplayer(ox,oy,os)
  player(x,y,state)
  ox=x
  oy=y
  os=state
  #sleep(1/200)+

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.