hello sketchers, I am a newb here, newb in programming. I have a project for one of my classes, and I am using Quarks AI for 2D Games to get a basic functionality. I am unsure how many people have used this library yet, but, I am trying to figure out how to get my ‘motor’ to get recognized by the physics engine.
programming is not my second language (artist!!), so any ideas would be beneficial…
import g4p_controls.*;
import game2dai.*;
import game2dai.entities.*;
import game2dai.entityshapes.*;
import game2dai.entityshapes.ps.*;
import game2dai.fsm.*;
import game2dai.graph.*;
import game2dai.maths.*;
import game2dai.steering.*;
import game2dai.utils.*;
// GettingStarted_01, both of these are required to run the world
World world;
StopWatch sw;
MovingEntity mover0;
Motor motor;
//set up bools for keyboard:
boolean[] keys;
public void setup() {
frameRate (45);
size(480, 320);
world = new World(width, height);
sw = new StopWatch();
motor = new Motor();
// Other setup code here
// Create the mover
mover0 = new MovingEntity(
new Vector2D(width/2, height/2), // position
32, // collision radius
new Vector2D(50, 0), // velocity
40, // maximum speed
new Vector2D(1, 1), // heading
1, // mass
120, // turning rate
200 // max force
);
PersonPic view = new PersonPic(this);
view.showHints(Hints.HINT_COLLISION | Hints.HINT_HEADING | Hints.HINT_VELOCITY);
mover0.renderer(view);
Domain d = new Domain(60, 60, width-60, height-60);
mover0.worldDomain(d, SBF.REBOUND);
world.add(mover0);
// set up keys boolean, to be a,w,d,SPACE
keys = new boolean[4];
for (int i = 0; i < keys.length; i++){
keys[i] = false;
}// end of keys
sw.reset(); // should always be last line in setup
}// end of setup
public void draw() {
double elapsedTime = sw.getElapsedTime();
world.update(elapsedTime);
background(200, 255, 200);
//make the movers constraint area visible
Domain d = mover0.worldDomain();
fill(255, 200, 200);
noStroke();
rect((float)d.lowX, (float)d.lowY, (float)d.width, (float)d.height);
motor.display();
motor.move();
world.draw(elapsedTime);
}// end of draw
void keyPressed(){
if (key == 'w' || key == 'W')
keys[2] = true;
if (key == 's' || key == 'S')
keys[3] = true;
if (key == 'a' || key == 'A')
keys[0] = true;
if (key == 'd' || key == 'D')
keys[1] = true;
}// end of key pressed
void keyReleased(){
if (key == 'w' || key == 'W')
keys[2] = false;
if (key == 's' || key == 'S')
keys[3] = false;
if (key == 'a' || key == 'A')
keys[0] = false;
if (key == 'd' || key == 'D')
keys[1] = false;
}// end of key release
class Motor{
PVector pos;
PVector vel;
PVector gravity;
float rotation;
int x;
int y;
int r = 8;
Motor(){
pos = new PVector(width/2, height/2);
vel = new PVector(5, 5);
gravity = new PVector(0, 0.01);
rotation = 0;
};
void move(){
//vel.add(gravity);
//pos.add(gravity);
//pos.add(vel);
if (keys[0]) { //a
pos.x = pos.x - 3;
}
if (keys[1]) { //d
pos.x = pos.x + 3;
}
if (keys[2]) {
pos.y = pos.y - 3;
}
if (keys[3]) {
pos.y = pos.y + 3;
}
if (pos.y < 0) pos.y = 0;
if (pos.y + 80 > height) pos.y = height - 80;
if (pos.x > width+ r || pos.x < 0-r) pos.y = 190;
}// end of class
void display(){
fill(255);
stroke(255,0,255);
rect(pos.x, pos.y, 32, 32);
}// end of display
}// end of class