mirror of
https://github.com/opus-tango/KeyPressesBasic.git
synced 2026-03-20 03:55:28 +00:00
Added demo class
This commit is contained in:
26
Demo.pde
Normal file
26
Demo.pde
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,12 +7,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int[] keys; // Declare key tracking array
|
int[] keys; // Declare key tracking array
|
||||||
|
Demo d; // Declare a demo object
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
|
size(400,400);
|
||||||
keys = new int[0]; // Initialize key tracking array
|
keys = new int[0]; // Initialize key tracking array
|
||||||
|
d = new Demo(width/2,height/2); // Initialize demo object
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(){
|
void draw(){
|
||||||
|
background(196);
|
||||||
|
d.display(); // Display demo object
|
||||||
|
|
||||||
// Output for demostration and debugging
|
// Output for demostration and debugging
|
||||||
for(int i = 0; i < keys.length; i++){
|
for(int i = 0; i < keys.length; i++){
|
||||||
|
|||||||
Reference in New Issue
Block a user