Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6195803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:31:56+00:00 2026-05-24T03:31:56+00:00

So I made a little game in java with slick2D, but I want my

  • 0

So I made a little game in java with slick2D,
but I want my character to jump.
Now I have this:

if (container.getInput().isKeyPressed(Input.KEY_UP) && !jumping) { 
             verticalSpeed = -1.0f * delta;//negative value indicates an upward movement 
             jumping = true;

        }
        if (jumping) { 
             verticalSpeed += .007f * delta;//change this value to alter gravity strength 

        } 

        playerY += verticalSpeed;
        playerPoly.setY(playerY);

Well that makes my sprite jump and fall down…for ever.
So how can you make it stop from falling when it hits the ground?
I tried this:

if (entityCollisionWith()){
jumping = false;
}

But it doesn’t work 🙁

my code with jumping:

import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;    
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.tiled.TiledMap;


public class Game extends BasicGame {

public BlockMap map;
Image player = null;
float playerX = 320;
float playerY = 288;
float scale = 1f;
private Polygon playerPoly;
 boolean jumping = false; 
 float verticalSpeed = 0.0f;


public Game() {
    super("my game");
}
public void init(GameContainer container) throws SlickException {
         map = new BlockMap("data/Map01.TMX");
         player = new Image("data/rightSprite.png");

         playerPoly = new Polygon(new float[]{
                playerX,playerY,
                playerX+17,playerY,
                playerX+17,playerY+48,
                playerX,playerY+48
        });

}        
    public void update(GameContainer container, int delta) throws SlickException {
        if (container.getInput().isKeyDown(Input.KEY_LEFT)) {
            playerX-=0.15;
            playerPoly.setX(playerX);
            if (entityCollisionWith()){
                playerX+=0.15;
                playerPoly.setX(playerX);
            }
        }
        if (container.getInput().isKeyDown(Input.KEY_RIGHT)) {

            playerX+=0.15;
            playerPoly.setX(playerX);
            if (entityCollisionWith()){
                playerX-=0.15;
                playerPoly.setX(playerX);
            }
        }
        if (container.getInput().isKeyPressed(Input.KEY_UP) && !jumping) { 
             verticalSpeed = -1.0f * delta;//negative value indicates an upward movement 
             jumping = true;

        }
        if (entityCollisionWith()){
            jumping = false;
            verticalSpeed = -1.1f;
            verticalSpeed = 0;
        }

        if (jumping) { 
             verticalSpeed += .01f * delta;//change this value to alter gravity strength 

        } 

        playerY += verticalSpeed;
        playerPoly.setY(playerY);

        if (entityCollisionWith()){
            jumping = false;
            verticalSpeed = 0;
        }

    }



    public boolean entityCollisionWith() throws SlickException {
        for (int i = 0; i < BlockMap.entities.size(); i++) {
            Block entity1 = (Block) BlockMap.entities.get(i);
            if (playerPoly.intersects(entity1.poly)) {
                return true;
            }       
        }       
        return false;
    }


public void render(GameContainer container, Graphics g)  {
    BlockMap.tmap.render(0, 0);
    player.draw(playerX, playerY, scale);
    g.draw(playerPoly);
}
public static void main(String[] argv) throws SlickException {

    AppGameContainer container = new AppGameContainer(new Game(), 640, 480,         false);
        container.start();
}
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:31:56+00:00Added an answer on May 24, 2026 at 3:31 am

    You should also reset the speed variable after stop jumping:

    if (entityCollisionWith()){
        jumping = false;
        verticalSpeed = 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a silly little game that I made just for myself, but I
I made a little minesweeper game and I want to send it to a
When running a java applet that I made (a basic little number-guessing game), whenever
I made a little Shooter game with two ships firing at each other. I
I made this little Cocoa app with a WebView that displays Google Maps in
I have made a little app for signing up for an event. User input
I've made a little forum and I want parse the date on newest posts
Made this nice little loop for hiding and showing div's, works as a charm
I've got a little game that a friend and I are writing in Java.
I've made a little game as an application for the web in silverlight using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.