Jump Landing
in
Programming Questions
•
10 months ago
Basically in my game whenever I jump i land at a different y height everytime. It's like every 2 jumps it goes down by one and then after it goes down 4 it brings it back up.
Here is the class
Here is the class
Mario myMario;
void setup () {
size(1200, 500);
background(0);
smooth();
myMario = new Mario(5, 475);
}
void draw () {
background(0);
fill(255, 255, 0);
stroke(255, 255, 0);
rectMode(CORNER);
rect(0, 480, 100, 25);
myMario.DrawMario();
myMario.keyReleased();
myMario.MoveMario();
myMario.detect();
}
//Code
class Mario {
//Global Variables
PFont font;
float MX;//x cor
float MY;//y cor
float gravity = .35;//fall speed
float MYspeed = 0;
int L, R, EC, stupid;
color c, t;//color deetect
//Constructor
Mario(float MX2, float MY2) {
MX = MX2;
MY = MY2;
}
//Functionality
void DrawMario () {
font = createFont("Arial", 16, true);
text(t, 5, 10);
text(c, 5, 20);
text(stupid, 5, 100);
text(MYspeed, 5, 30);
text(gravity, 5, 40);
rectMode(CENTER);
fill(255);
stroke(0);
rect(MX, MY, 5, 5);
}
void MoveMario () {
if (keyPressed) {
if (key == 'a') {
L= 1;
}
if (key == 'd') {
R = 1;
}
if (key == 'w' && EC==0) {
EC = 1;
MYspeed = -7.8;
stupid += 1;
}
}
if (L== 1 && MX >= 5) {
MX -= 3;
}
if (R==1 && MX <= 1195) {
MX +=3;
}
if ( MY <= 500) {
MY += MYspeed;
MYspeed += gravity;
}
if (MY >= 500) {
EC = 0;
MY = 495;
}
if (MYspeed >= 5.0) {
MYspeed = 5.0;
}
}
void detect () {
int RMX = round(MX);
int RMY = round(MY);
t = get(mouseX, mouseY);
c = get(RMX, RMY+7);
text(RMX, 5, 50);
text(RMY, 5, 60);
if (c == -256) {
EC = 0;
MYspeed = 0;
}
if (c == -53956) {
MX = 5;
MY = 475;
}
if (stupid == 2 && c == -256) {
}
}
void keyReleased () {
if (key == 'a') {
L=0;
}
if (key =='d') {
R = 0;
}
}
}
1