We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to make my character jump using the letter 'W' any ideas?
Here's my code:
PImage back;
PImage back2;
boolean start = true;
boolean finish = false;
boolean scrolling = true;
boolean startGame;
Character mickey;
int b=0;
void setup()
{
size(700, 438);
mickey = new Character();
back = loadImage("back.png");
back2 = loadImage("back2.png");
}
void draw() {
image(back, b, 0);
image(back2, b+width, 0);
if (scrolling == true) {
scroll();
}
if (startGame == false) {
startScreen();
}
mickey.display();
mickey.move();
}
void scroll() {
b=b-1;
if (b<-1*width) {
b=0;
}
}
void startScreen() {
noFill();
stroke(255);
textSize(32);
if (finish) {
rect(20, 20, 100, 50);
} else {
rect(15, 40, 670, 50);
rect(250, 370, 200, 50);
if (start) {
text("HELP MICKEY MOUSE FIND HIS FRIENDS", 50, 77);
text("PLAY", 310, 405);
} else {
text("RETRY", 170, 140);
}
}
}
void keyPressed () {
scroll();
if (keyPressed) {
if (key == 'd' || key == 'D') {
}
}
}
void mousePressed() {
if (startGame == false) {
if (mouseX>250 && 450>mouseX && mouseY>370 && 420>mouseY ) {
scrolling=false;
startGame = true;
} else {
scrolling=true;
}
}
}
and my class:
public class Character {
PImage mickey;
int rad; // Width of the shape
float xpos, ypos; // Starting position of shape
int xdirection, ydirection; // Left or Right
int xspeed, yspeed; // Speed of the character
public Character() {
mickey = loadImage("mickey.gif"); //this image is in data folder
rad = 170;
xpos = 200;
ypos = 200;
xdirection = 0;
ydirection = 20;
}
public void display () {
image(mickey, rad, rad, xpos, ypos);
}
public void move() {
// Update the position of the shape
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );
}
}
Answers
See: https://forum.processing.org/two/discussion/25157/help-with-gravity-and-jumping#latest