Hey, so im making a game for my programming class. The basic idea is to be a simple 2d old school street fighter style game, the problem I'm having happens to be with jumping. I would like to make it, so if the up key is pressed, the character will raise a predetermined amount (A constant I have) and then descend back down to the ground. I;m still rather new to greenfoot and java so please explain how you make something work please :]
Heres my current code that works for walking, but not for jumping.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.*; import java.awt.*; /** * Write a description of class char1 here. * * @author (your name) * @version (a version number or a date) */ public class char1 extends Characters { public static final double TE_SPD = 5.0; public static final double TE_JMP = 100.0; /** * Act - do whatever the char1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move1(); jump1(); } public void move1() { if(Greenfoot.isKeyDown("right")) { int x = (int) Math.round(getX() + TE_SPD); int y = (int) Math.round(getY()); setImage("Char1Right.png"); setLocation(x,y); } if(Greenfoot.isKeyDown("left")) { int x = (int) Math.round(getX() - TE_SPD); int y = (int) Math.round(getY()); setImage("Char1Left.png"); setLocation(x,y); } else { } } public void jump1() { if(Greenfoot.isKeyDown("up")) { jumptiming(); jumptiming(); jumptiming(); gravity(); gravity(); gravity(); } } public void jumptiming() { int x = (int) Math.round(getX()); int y = (int) Math.round(getY() + TE_JMP); setLocation(x,y); try { Thread.sleep(500); } catch(InterruptedException e) { } } public void gravity() { int x = (int) Math.round(getX()); int y = (int) Math.round(getY() - TE_JMP); setLocation(x,y); try { Thread.sleep(500); } catch(InterruptedException e) { } } }