Yeah that makes alot of sense quark.
There was a problem with my {}s in the draw function.
Now it can't find the mover class.
Here is the rest of the sketch
- mover tab -
Code:class Mover
{
int mr = 8; //mover radias
PVector location;
PVector velocity;
PVector acceleration;
float topspeed;
Mover()
{
location = new PVector(width/2,height/2);
velocity = new PVector(0,0);
acceleration = new PVector(0,0);
topspeed = 5;
}
void update(char x)
{
if(x == 'w' || x == 'W')
{
acceleration.y = -10;
}
else if (x == 's' || x == 'S')
{
acceleration.y = +5;
}
else if (x == 'a' || x == 'A')
{
acceleration.x = -5;
}
else if (x == 'd' || x == 'D')
{
acceleration.x = +5;
}
velocity.add(acceleration);
velocity.limit(topspeed);
location.add(velocity);
}
void gravity()
{
//acceleration.y = 5;
velocity.add(acceleration);
velocity.limit(topspeed);
location.add(velocity);
}
void display()
{
stroke(0);
fill(230,0,140);
ellipse(location.x,location.y,16,16);
fill(100,0,200);
ellipse((location.x - 3 ),(location.y -3 ),3,3);
ellipse((location.x + 3 ),(location.y -3 ),3,3);
}
void checkEdges()
{
//Dealing with collision with a rectangle not the edges
if(rectCircleIntersect( 30, 300, 40, 50, location.x, location.y, mr) == true)
{
// X collison is working by itself.
if(location.x >= (30 - mr) && location.x <= 50 )
{
location.x = (30 - mr);
}
else if(location.x < (70 + mr) )
{
location.x = (70 + mr);
}
///////////
// Y collison is working by itself.
if(location.y >= (300 - mr) && location .y <= 325 )
{
location.y = (300 - mr);
}
else if(location.y < (350 + mr) )
{
location.y = (350 +mr);
}
/////////
}
// the edges
if (location.x >= (width - mr))
{
location.x = (width - mr);
}
else if (location.x <= mr)
{
location.x = (mr);
}
if (location.y >= (height - mr))
{
location.y = (height - mr);
}
else if (location.y <= mr)
{
location.y = (mr);
}
}
}
boolean rectCircleIntersect(float rx, float ry, float rw, float rh, float cx, float cy, float cr)
{
float circleDistanceX = abs(cx - rx - rw/2);
float circleDistanceY = abs(cy - ry - rh/2);
if (circleDistanceX > (rw/2 + cr)) { return false; }
if (circleDistanceY > (rh/2 + cr)) { return false; }
if (circleDistanceX <= rw/2) { return true; }
if (circleDistanceY <= rh/2) { return true; }
float cornerDistance = pow(circleDistanceX - rw/2, 2) + pow(circleDistanceY - rh/2, 2);
return cornerDistance <= pow(cr, 2);
}
-main tab-
Code:Mover mover;
void setup()
{
size(400,400);
mover = new Mover();
}
void draw()
{
background(230,100,00);
rect(30, 300, 40,50);
mover.checkEdges();
mover.display();
mover.gravity();
while(keyPressed)
{
char x = key;
mover.update(x);
}
It's pretty messy I left a few things unfinished because I was getting stuck.