This site requires JavaScript, please enable it in your browser!
Greenfoot back
Homicdle_moth
Homicdle_moth wrote ...

2013/5/30

Help with jumping on top of objects

Homicdle_moth Homicdle_moth

2013/5/30

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class Human here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Human extends Mover
{
    private static int jumpStrength = 16;
    private double speed;
    private int speed2 = 3;
    int counter;
    public void act()
    {
        move();
        checkFall();
        jumpup();
        obsicles();
    }

    public void move()
    {
        if(Greenfoot.isKeyDown("a"))
        {
            move(-speed2);
        }
        if(Greenfoot.isKeyDown("d"))
        {
            move(speed2);
        }
        if (Greenfoot.isKeyDown("space") )
        {
            if (floor())
            {
                jump();
            }
        }
    } 

    public void obsicles()
    {
        while(getOneObjectAtOffset(0, getImage().getHeight()/2+1, Brick.class)!=null)
        {
            setLocation(getX(),getY()-1);
        }
        
    }

    private void jump()
    {
        setVSpeed(-jumpStrength);
        fall();
    }

    public void jump2()
    { 
        jumpStrength = 32;
        fall();
    }

    private void checkFall()
    {
        if (floor()) {
            setVSpeed(0);
        }
        else {
            fall();
        }
    }

    public void jumpup()
    {
        Actor c = getOneIntersectingObject(Powerup.class);
        if( c != null)
        {
            getWorld().removeObject(c);
            jump2();
        }
        if( counter >= 30)
        {
            jumpStrength = 16;
        }
    }
}
this is my character code and i want him to land on the block and stay there but instead he stands there for 1 second then falls through the block.....please help me
Homicdle_moth Homicdle_moth

2013/5/30

#
by the way the human is a subclass of the Mover method i found in a helper class.
You need to login to post a reply.