Maze like game; Easing, and collision troubles.
in
Programming Questions
•
1 year ago
So I'm definitely new to processing, as well as to programming in general. My professor for a class has us messing around with processing, and I myself find it fascinating. Anyway, I'm thoroughly confused as to how to get an ellipse to gain easing on all four sides of a constrain for starters. Another problem I'm having is that I would like lines to stop the ellipse and force you to traverse the maze to the end.
Below is the code I have so far. Any help is GREATLY appreciated.
float x;
float y;
int w=56;
int w2=56;
int w3=56;
int w4=56;
float easing = 0.03;
int ln;
int radius = 10;
int edge = 56;
int inner = edge + radius;
void setup() {
size (500, 500);
strokeWeight(1);
smooth();
ellipseMode(RADIUS);
rectMode(CORNERS);
}
void draw() {
background(35);
drawMovement();
fill(255);
rect(edge, edge, width-edge, height-edge);
fill(0, 255, 0);
rect(76, 76, 56, 56);
fill(255, 0, 0);
rect(444, 444, 424, 424);
fill(216, 117, 11);
ellipse(x, y, radius, radius);
//
ln();
}
void ln() {
line(320, 320, 320, 56);
line(56, 76, 300, 76);
}
void drawMovement() {
if (keyPressed && (key == CODED)) {
if (keyCode == LEFT) {
x -= (x--)*easing;
}
else if (keyCode == RIGHT) {
x += (x++)*easing;
}
else if (keyCode == UP) {
y -= (y--)*easing;
}
else if (keyCode == DOWN) {
y += (y++)*easing;
}
x = constrain(x, inner, width-inner);
y = constrain(y, inner, height-inner);
}
}
Below is the code I have so far. Any help is GREATLY appreciated.
float x;
float y;
int w=56;
int w2=56;
int w3=56;
int w4=56;
float easing = 0.03;
int ln;
int radius = 10;
int edge = 56;
int inner = edge + radius;
void setup() {
size (500, 500);
strokeWeight(1);
smooth();
ellipseMode(RADIUS);
rectMode(CORNERS);
}
void draw() {
background(35);
drawMovement();
fill(255);
rect(edge, edge, width-edge, height-edge);
fill(0, 255, 0);
rect(76, 76, 56, 56);
fill(255, 0, 0);
rect(444, 444, 424, 424);
fill(216, 117, 11);
ellipse(x, y, radius, radius);
//
ln();
}
void ln() {
line(320, 320, 320, 56);
line(56, 76, 300, 76);
}
void drawMovement() {
if (keyPressed && (key == CODED)) {
if (keyCode == LEFT) {
x -= (x--)*easing;
}
else if (keyCode == RIGHT) {
x += (x++)*easing;
}
else if (keyCode == UP) {
y -= (y--)*easing;
}
else if (keyCode == DOWN) {
y += (y++)*easing;
}
x = constrain(x, inner, width-inner);
y = constrain(y, inner, height-inner);
}
}
1