Added demo class

This commit is contained in:
61616
2022-05-16 10:39:25 -04:00
parent 9423701450
commit 391c52dc48
2 changed files with 31 additions and 0 deletions

26
Demo.pde Normal file
View File

@@ -0,0 +1,26 @@
class Demo{
PVector pos;
Demo(PVector _pos){
pos = _pos.copy();
}
Demo(float x, float y){
this(new PVector(x,y));
}
void display(){ // Move and then draw a circle when display is called
move();
noStroke();
fill(100);
circle(pos.x,pos.y,10);
}
// Check if each key is in the keys array.
// Notice I do not use else if, because I want multiple to be able to trigger at once.
private void move(){
if(findInt(keys,'w') != -1){ pos.y -= 2; }
if(findInt(keys,'a') != -1){ pos.x -= 2; }
if(findInt(keys,'s') != -1){ pos.y += 2; }
if(findInt(keys,'d') != -1){ pos.x += 2; }
}
}