I need quick help with my codes

I need 2 different images to fall from the top (not bounce!) And when the image1 comes up user should press enter or they lose. If image2 comes up they shouldn’t press the enter button or they will lose again. Can i atleast get a starting point please?

1 Like

Hi cain, welcome to the community!

Can you share any code you’ve managed to come up so far? It’s easier to guide you if we know what you’ve tried and what part is giving you trouble.

  • Have you successfully loaded and displayed an image?
  • Do you know how to make things move on screen, using x and y positions?
  • Can you check for key presses with keyPressed()?
  • Have you written your own functions yet, e.g. for restarting or win/loose conditions?
  • Can you compare conditions using if()?
  • Do you understand booleans?
1 Like
int y = 250;
int hiz=3;
int can=3;
background(255);
y= y+ hiz;
fill(110, 100, 50, 60);
println(y);
PImage mayın;

mayın=loadImage("mayın.png");
size(500, 500);
image(mayın, 210, 10, width/5, height/5);

// here is what i wrote first but it’s not moving at all im confused :frowning:

Alright.

You know several key elements, but you are missing a proper structure to your sketch.

// anything up here will be in global scope, e.g. your main variables used in the sketch

void setup() {
 // here you put everything you only call once, e.g. canvas size and loading images
}

void draw() {
// here you put everything that gets changed or touched on every drawing cycle, e.g. refreshing the canvas (by drawing the background), updating position values, displaying images
}

Since you want to animate the falling images and listen for key press interactions, you need to use draw(), so that you can change the values every frame.

 PImage mayin;
void setup() {
  size(500, 500);
  background(255);

  mayin = loadImage("mayin.png");
  image(mayin, 210, 10, width/5, height/5);
}
float xyon = 0.3;
float yyon = 3.5;
 int x = 0;
  int y = 0;
  int hiz = -1;
void draw() {
  y = y + hiz;
  if (y>500) {
    y=0;
    x = parseInt(random(50, 500-50));  //x random olarak degisir
  }
    textSize(32);
  fill(0);
  text("x:"+x, 10, 50);
  text("y:"+y, 10, 100);
}

// so i arranged everything and added a parameter on the top corner to see if it moves but i have a problem with y…

I’m on mobile in the subway, so I’ll need to keep it short…

You’re currently drawing the image just once, to a fixed position, in setup(). To make the image move, you need to draw it in draw() and make sure you can change its position variables.

 // Draw the image at (x, y)
 image(mayin, x, y, width / 5, height / 5);

Hello @cain. I edited your posts to format the code for better readability. Please review our FAQ for guidance on posting code. Thank you!

ezgif.com-gif-maker (1)

Is this solved?

Otherwise I can make some comments

1 Like