creating "walls" with PVector
in
Programming Questions
•
3 years ago
Hi all,
i’m new to processing and i want to make a Mappy like 2D cat chase mouse game by PVectors, the mouse is trying to get the cheese while avoiding the cat. So far it's still very beta and i’ve had trouble with creating a simple maze in the game, some obstacle that will block both mouse and cat.
i’ve tried a few ways but none of them works, if anyone can help me i’ll be very appreciate, Thanks!
this is my code:
Mouse M;
Cat C;
Cheese E;
PImage T;
Cat C;
Cheese E;
PImage T;
void setup()
{
T= loadImage("Cat.JPG");
size(500,500);
{
T= loadImage("Cat.JPG");
size(500,500);
M = new Mouse(width/2, height /2, 0, 1);
C = new Cat(width/4, height/4, 0, 1);
E = new Cheese();
smooth();
C = new Cat(width/4, height/4, 0, 1);
E = new Cheese();
smooth();
stroke(210,200,180);
fill(210,200,180);
cursor(CROSS);
}
fill(210,200,180);
cursor(CROSS);
}
void draw() {
background(0);
M.display();
C.display();
}
C.display();
}
void drawVector(PVector p, PVector d, float rad) {
pushMatrix();
translate(p.x, p.y);
strokeWeight(1);
ellipse(0, 0, rad, rad);
ellipse(0, 0, rad, rad);
popMatrix();
}
}
class Cat {
PImage C;
PVector pos;
PVector dir;
PImage C;
PVector pos;
PVector dir;
Cat(float x, float y, float mx, float my) {
C = loadImage("Cat.JPG");
pos = new PVector(x,y);
dir = new PVector(mx, my);
}
dir = new PVector(mx, my);
}
void display() {
smooth();
stroke(255,255,0);
fill(255,255,0);
cursor(CROSS);
stroke(255,255,0);
fill(255,255,0);
cursor(CROSS);
dir.x = mouseX - pos.x;
dir.y = mouseY - pos.y;
dir.normalize();
pos.add(dir);
drawVector( pos, dir, 20);
}
}
dir.y = mouseY - pos.y;
dir.normalize();
pos.add(dir);
drawVector( pos, dir, 20);
}
}
class Cheese {
Cheese() {
}
}
void display() {
}
}
class Mouse {
PVector pos;
PVector dir;
PVector dir;
Mouse(float x, float y, float mx, float my) {
pos = new PVector(x,y);
dir = new PVector(mx, my);
}
dir = new PVector(mx, my);
}
void display() {
smooth();
stroke(210,200,180);
fill(210,200,180);
cursor(CROSS);
stroke(210,200,180);
fill(210,200,180);
cursor(CROSS);
dir.x = mouseX - pos.x;
dir.y = mouseY - pos.y;
dir.normalize();
pos.add(dir);
drawVector( pos, dir, 20);
dir.y = mouseY - pos.y;
dir.normalize();
pos.add(dir);
drawVector( pos, dir, 20);
}
}
}
1