Hmm… I dont know if problem is in my jump system or in the velocity thing.
If you want i can send full code if you wanna test it. I think you will know faster where is problem.
Hope we found a problem together. Velocity change didnt helped, feels like it doesnt respond to key press but if that is problem it would give error… Hmm
Hahmo ha;
int wid = 1200;
int rez = 800;
int score = 0;
PImage hahmo;
PImage este;
boolean jump;
float velocity;
float velocityconst;
float baseY, px, py, vy, ay, w, h;
float ypos, xpos;
PVector gravity = new PVector(0, 0.5);
ArrayList<Este> Esteet = new ArrayList<Este>();
void setup() {
size(1200, 800);
ha = new Hahmo(color(255,0,0),0,height/2,10);
velocityconst = -5.0;
velocity =velocityconst;
Esteet.add(new Este());
//hahmo = loadImage("hahmo.png");
//este = loadImage("este.png");
}
void draw() {
background(0);
if(jump == true) {
ha.jump();
}
if (frameCount % 180 == 0) {
Esteet.add(new Este());
}
ha.update();
ha.show();
boolean safe = true;
for (int i = Esteet.size() - 1; i >= 0; i--) {
Este p = Esteet.get(i);
p.update();
if (p.hits(ha)) {
p.show(true);
safe = false;
} else {
p.show(false);
}
if (p.x < -p.w) {
Esteet.remove(i);
}
}
if (safe) {
score++;
} else {
score -= 50;
}
fill(255, 0, 255);
textSize(64);
text(score, width/2, 50);
score = constrain(score, 0, score);
vy+=ay;
py+=vy;
rect(px, py-h, w, h);
}
class Hahmo {
color c;
PVector pos;
PVector vel;
PVector acc;
float r = 16;
float xpos;
float ypos;
float xspeed;
Hahmo(color clr, float xPos, float yPos, float xSpeed) {
c = clr;
pos = new PVector(50, height/1);
vel = new PVector(0, 0);
acc = new PVector();
xpos = xPos;
ypos = yPos;
xspeed = xSpeed;
}
void applyForce(PVector force) {
acc.add(force);
}
void jump() {
velocity = velocity + 0.5;
if(ypos + velocity > (height/2)) {
ypos = height/2;
jump = false;
velocity = velocityconst;
} else {
ypos -= velocity;
}
}
void update() {
applyForce(gravity);
pos.add(vel);
vel.add(acc);
vel.limit(4);
acc.mult(0);
if (pos.y > height) {
pos.y = height;
vel.mult(0);
}
}
void show() {
stroke(255);
fill(255);
ellipse(pos.x, pos.y, r*2, r*2);
}
}
class Este {
float x;
float bottom;
float w = 40;
Este() {
x = wid + w;
bottom = random(30, height/15);
}
boolean hits(Hahmo ha) {
if ((ha.pos.x > x) && (ha.pos.x < (x + w))) {
if ((ha.pos.y > (height - bottom - ha.r))) {
return true;
}
}
return false;
}
void update() {
x -= 3;
}
void show(boolean hit) {
stroke(255);
if (hit) {
fill(255, 0, 0);
} else {
fill(255);
}
rect(x, height - bottom, w, bottom);
}
}
void keyPressed() {
if (key == ' ' || key == ' ') {
jump = true;
}
}
Btw sorry for messy code . I have tested many things so there would be remains from those.
I cant reply anymore because reply limit of new users. You can reply here but i will edit my answers to this message. Also if you have discord we can talk there and try to fix my code.
@anon68884268
Do you mean velocity what is in void setup() ?
I disabled those but not anything difference.
Hmm you are not wrong maybe. Lets check that tomorrow But i will go sleep too in 30mins but if i dont solve this i will need you tomorrow ! But awesome you have community like this. So awesome that people get help to their problems here. @anon68884268 See you tomorrow.
Also guys if you know working method to do jumping. Or you want to help me and make it to my script i will be so happy.