Skip to content

Instantly share code, notes, and snippets.

@pandr
Created March 30, 2017 17:05
Show Gist options
  • Save pandr/9185694b97cd0f097de5b1a146a99171 to your computer and use it in GitHub Desktop.
Save pandr/9185694b97cd0f097de5b1a146a99171 to your computer and use it in GitHub Desktop.
function setup() {
createCanvas(400, 400);
}
var pilop = 38;
var pilned = 40;
var pilhøjre = 39;
var pilvenstre = 37;
var x = 2;
var y = 2;
var xret = 0
var yret = 0
var sxs = [];
var sys = [];
function draw() {
fill (39,209,42);
//rect(x,y,20,20);
//background(200);
rect(x*20,y*20,20,20);
frameRate(5);
if (xret!=0 || yret!=0) {
sxs.push(x);
sys.push(y);
console.log(sxs);
console.log(sys);
}
var i=0;
while(i<sxs.length) {
i+=1;
fill (39,209,42);
//rect(x,y,20,20);
//background(200);
rect(sxs[i]*20,sys[i]*20,20,20);
}
if (xret==1)
{
x+=1;
yret=0;
}
if (yret==1)
{
y+=1;
xret=0;
}
if (yret==-1)
{
y+=-1;
xret=0;
}
if (xret==-1)
{
x+=-1;
yret=0;
}
}
function keyPressed() {
if(keyCode == UP_ARROW) {
yret=-1;
xret=0;
}
if(keyCode == DOWN_ARROW) {
yret=1;
xret=0;
}
if(keyCode == LEFT_ARROW) {
xret=-1;
yret=0;
}
if(keyCode == RIGHT_ARROW) {
xret=1;
yret=0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment