A simple endless falling game:
fn srt() [
background("rgb(10,10,10)");
]
fn upt() [
if (game) [
score += 0.01;
clear();
shape();
text(int(score),10,30,"#AAA",30,"courier new");
player.show();
player.dir[0] = (MOUSEX-player.x)/100;
player.grounded = false;
player.update();
fr ground in rng(grounds.length) [
if (player.y+player.h>grounds[ground].y && player.y+player.h/2<grounds[ground].y) [
if (player.x+player.w>grounds[ground].x && player.x<grounds[ground].x+grounds[ground].w) [
player.dir[1] = -(int(player.dir[1]/1.5))-(0.1+score/50);
player.y -= 1;
player.grounded = YES;
]
]
grounds[ground].show();
grounds[ground].y -= 0.1+score/50;
if (grounds[ground].y+grounds[ground].h<0) [
grounds.splice(ground,1);
newGround(500);
]
]
if (player.y>500 || player.y+player.h<-5) [
player = new character(240.75,100,20,40);
clear();
shape();
text(int(score),30,100,"#AAA",100,"courier new");
game = !game;
score = 0;
]
]
]
//---ground class-----//
cl groundy [
make(x,y,w,h) [
me.x = x;
me.y = y;
me.w = w;
me.h = h;
]
cf show() [
shape();
rect(me.x,me.y,me.w,me.h);
fill("rgb(30,30,30)");
]
]
//----player class-----//
cl character [
make(x,y,w,h) [
me.x = x;
me.y = y;
me.w = w;
me.h = h;
me.dir = [0,0];
me.grav = 0.1;
me.grounded = NO;
]
cf show() [
shape();
rect(me.x,me.y,me.w,me.h);
fill("rgb(50,100,255)");
]
cf update() [
me.dir[1] += me.grav;
me.x += me.dir[0];
me.y += me.dir[1];
]
]
//----initiation of variables----//
let grounds = [];
let player = new character(240,100,20,40);
grounds.push(new groundy(player.x-50,player.y+player.h,100,10));
MOUSEX = player.x;
let score = 0;
let game = YES;
fn newGround(extra=0) [
let w = 50+RANDOM*100
let x = RANDOM*(500-w);
let y = RANDOM*500;
if (extra>0) [
y = extra;
]
rtn grounds.push(new groundy(x,y,w,10));
]
fr i in rng(5) [
newGround();
]