# I need quick help with my codes

**URL:** <https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 22, 2024, 11:40am UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372 "2024-11-22T11:40:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@cain](https://discourse.processing.org/u/cain)\
**Post date:** [November 22, 2024, 11:40am UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/1 "2024-11-22T11:40:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![eightohnine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eightohnine/32/19793_2.png) [@eightohnine](https://discourse.processing.org/u/eightohnine)\
**Post date:** [November 22, 2024, 12:16pm UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/2 "2024-11-22T12:16:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@cain](https://discourse.processing.org/u/cain)\
**Post date:** [November 22, 2024, 12:17pm UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/3 "2024-11-22T12:17:04Z")

</div>

```Processing
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 ☹

---

<div class="post-metadata">

**Author:** ![eightohnine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eightohnine/32/19793_2.png) [@eightohnine](https://discourse.processing.org/u/eightohnine)\
**Post date:** [November 22, 2024, 12:30pm UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/4 "2024-11-22T12:30:15Z")

</div>

Alright.

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

```auto
// 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.

---

<div class="post-metadata">

**Author:** ![cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@cain](https://discourse.processing.org/u/cain)\
**Post date:** [November 22, 2024, 2:47pm UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/5 "2024-11-22T14:47:14Z")

</div>

```Processing
 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…

---

<div class="post-metadata">

**Author:** ![eightohnine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eightohnine/32/19793_2.png) [@eightohnine](https://discourse.processing.org/u/eightohnine)\
**Post date:** [November 22, 2024, 3:08pm UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/6 "2024-11-22T15:08:23Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![ProcessingOrg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/processingorg/32/18341_2.png) [@ProcessingOrg](https://discourse.processing.org/u/ProcessingOrg)\
**Post date:** [November 22, 2024, 6:01pm UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/7 "2024-11-22T18:01:05Z")

</div>

Hello @cain. I edited your posts to format the code for better readability. Please review our [FAQ](https://discourse.processing.org/t/guidelines-asking-questions/2147#is-your-post-formatted-9) for guidance on posting code. Thank you!

![ezgif.com-gif-maker (1)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/4/34521338de6902479873291389bf53a11d12237d.gif)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 29, 2024, 2:03pm UTC](https://discourse.processing.org/t/i-need-quick-help-with-my-codes/45372/8 "2024-11-29T14:03:44Z")

</div>

Is this solved?

Otherwise I can make some comments
