# I need help with creating different platforms that my character is able to jump on and making jumping smoother

**URL:** <https://discourse.processing.org/t/i-need-help-with-creating-different-platforms-that-my-character-is-able-to-jump-on-and-making-jumping-smoother/44117>\
**Category:** Coding Questions\
**Created:** [March 18, 2024, 3:31pm UTC](https://discourse.processing.org/t/i-need-help-with-creating-different-platforms-that-my-character-is-able-to-jump-on-and-making-jumping-smoother/44117 "2024-03-18T15:31:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corn](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@Corn](https://discourse.processing.org/u/Corn)\
**Post date:** [March 18, 2024, 3:31pm UTC](https://discourse.processing.org/t/i-need-help-with-creating-different-platforms-that-my-character-is-able-to-jump-on-and-making-jumping-smoother/44117/1 "2024-03-18T15:31:13Z")

</div>

int PlatX = 400; //Platform X-coordinate  
int PlatY = 300; //Platform Y-coordinate  
PImage StonePlatform;  
int yvel = 1;//Setting the speed of the platforms.  
int blocklength = 100;//Setting the length of the platforms.  
int blockheight = 10;//Setting the height of the platforms.  
color c = color(0);//Setting the colour of the platforms.  
int x = 470;  
float CharacterX;  
float Speed = 0;  
float ystart = 534;  
float jmp\_speed = 10;  
float Gravity = 0.55;  
float CharacterY = ystart;  
//(New Tab)  
void setup() {  
size(1000, 600);  
CharacterY=60;  
CharacterX=30;  
}

void draw() {  
background(150);  
rect(0, 575, 600, 20);  
rect(CharacterX, CharacterY, 20, 40);

if (CharacterY+Speed \< ystart) {  
CharacterY+=Speed;  
Speed+=Gravity;  
} else {  
CharacterY = ystart;  
Speed=3;  
}  
if (keyPressed) {  
if ( key == ‘D’ || key == ‘d’) {  
CharacterX=CharacterX+Speed;  
}  
}  
if (keyPressed) {  
if ( key == ‘A’ || key == ‘a’) {  
CharacterX=CharacterX-Speed;  
}  
}  
}

void keyPressed() {

if ( (keyCode == UP || key == ‘w’) && (CharacterY == ystart) )  
{  
Speed=-jmp\_speed;  
}  
}  
//(New tab)  
Plat P = new Plat();  
class Plat {  
float Plat;  
Plat() {  
}  
void Platf() {  
rect(PlatX, PlatY, 20, 20) ;  
//loadImage(“StonePlatform.png”);  
}  
}

---

<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:** [March 18, 2024, 5:20pm UTC](https://discourse.processing.org/t/i-need-help-with-creating-different-platforms-that-my-character-is-able-to-jump-on-and-making-jumping-smoother/44117/2 "2024-03-18T17:20:10Z")

</div>

**Introduction**

You want to have many platforms, so you want to have a **list** of platforms.  
**One** Platform is described in the class Plat.  
Since all platforms have a position, they have the same variables.  
But each platform has different values in the variables.

- Therefore platX and platY and many others (yvel, blocklength, blockheight and c) belong into the class and cannot be global variables.

see [Objects / Processing.org](https://processing.org/tutorials/objects)

**Details**

You have a class Plat; platX and platY etc. belong  
inside the class.

**The List**

Now have an ArrayList of Plat and

```auto
ArrayList<Plat> list = new ArrayList(); // before setup()

```

**Using the List**

In setup you say  
`list.add(new Plat()); // put one new Plat into the list`

Either give them the position (and size!) in the constructor (`list.add(new Plat( 170, 400 ));` ) or just say  
`list.get(0).platX = 120;` etc.

Display them in draw() :

```auto
for(Plat pl : list)
   pl.display ();

```

**collision detection**

Also, you want the collision detection in a for-loop like this.

```auto
for(Plat pl : list) {
   ..... pl ..... 
}

```

---

<div class="post-metadata">

**Author:** ![Corn](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@Corn](https://discourse.processing.org/u/Corn)\
**Post date:** [April 5, 2024, 3:11pm UTC](https://discourse.processing.org/t/i-need-help-with-creating-different-platforms-that-my-character-is-able-to-jump-on-and-making-jumping-smoother/44117/3 "2024-04-05T15:11:45Z")

</div>

I have been trying to use these instructions but I can’t seem to figure out just how to get it working

---

<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:** [April 7, 2024, 4:19pm UTC](https://discourse.processing.org/t/i-need-help-with-creating-different-platforms-that-my-character-is-able-to-jump-on-and-making-jumping-smoother/44117/4 "2024-04-07T16:19:32Z")

</div>

you’ll eventually figure it out…

---

<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:** [April 8, 2024, 1:02pm UTC](https://discourse.processing.org/t/i-need-help-with-creating-different-platforms-that-my-character-is-able-to-jump-on-and-making-jumping-smoother/44117/5 "2024-04-08T13:02:29Z")

</div>

Hello @Corn! To improve readability, kindly format your code by editing your post, selecting the code, and pressing the `</>` button. This will make it easier for us to assist you.

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