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

2020/10/23

My Platforms dont work with My gravity

1
2
MrSkyPanda MrSkyPanda

2020/10/23

#
i'm trying to make a recreation of the 8-bit super mario bros for a school project. I've worked out the movement, jump, and gravity. But when i want my character to land on my platform, it falls right through. How do i fix that?
danpost danpost

2020/10/23

#
MrSkyPanda wrote...
i'm trying to make a recreation of the 8-bit super mario bros for a school project. I've worked out the movement, jump, and gravity. But when i want my character to land on my platform, it falls right through. How do i fix that?
Cannot fix unseen code. Please provide Mario class codes (at minimum).
MrSkyPanda MrSkyPanda

2020/10/23

#
int vSpeed = 0;
    int accel = 0;
    private int gravity;
    public void act() 
    {
        checkFalling();
        fall();
        gravity--;
        setLocation(getX(), getY() - gravity);
        checkForJump();
        if(Greenfoot.isKeyDown("left")) {
            move(-3);
        }        
        if(Greenfoot.isKeyDown("right")) {
            move(3);
        }   // Add your action code here.
        
    }  
    
    public void fall()
    {
        
        setLocation(getX(), getY() + vSpeed);

    }
    
    public void checkFalling()
    {
        if(!isTouching(Wide.class))
        {
            vSpeed++;
        }
        else
            vSpeed = 0;
    }
    public void jump()
    {
        if(Greenfoot.isKeyDown("up"))
        {
            vSpeed = -10;
        }
    }
    private void checkForJump()
    {
        if (Greenfoot.isKeyDown("up"))
        { gravity = 20; // this will make the character jump
        }

    }   
MrSkyPanda MrSkyPanda

2020/10/23

#
There is no code in the Wide.class
danpost danpost

2020/10/23

#
MrSkyPanda wrote...
<< Code Omitted >>
Out of curiosity ... did you watch a youtube tutorial for some of this code?
danpost danpost

2020/10/24

#
MrSkyPanda wrote...
when i want my character to land on my platform, it falls right through. How do i fix that?
You should probably check out my Jump and Run Demo w/Moving Platform scenario. Just run it and click the appropriate code button along bottom to view the codes.
MrSkyPanda MrSkyPanda

2020/10/24

#
ya i did look up a tutorial on youtube
MrSkyPanda MrSkyPanda

2020/10/24

#
which code in your demo would i have to use in my game?
danpost danpost

2020/10/24

#
MrSkyPanda wrote...
which code in your demo would i have to use in my game?
It would be in the moveVertically method of the Who class.
MrSkyPanda MrSkyPanda

2020/10/24

#
i copied it exactly and i had no syntax errors but it still didnt work. is there another way to contact you to make this convo easier?
danpost danpost

2020/10/24

#
MrSkyPanda wrote...
i copied it exactly and i had no syntax errors but it still didnt work
Post current class codes that did not work.
MrSkyPanda MrSkyPanda

2020/10/24

#
i just posted it you can look at it from there
danpost danpost

2020/10/24

#
MrSkyPanda wrote...
i just posted it you can look at it from there
It still has the original broken code. I need to see your attempted copied code -- to see how you tried to implement it.
MrSkyPanda MrSkyPanda

2020/10/24

#
so i figured out how the platforms work but that caused my characters to lose the ability to jump
 int vSpeed = 0;
    int accel = 0;
    private int gravity;
    public void act() 
    {
        checkFalling();
        fall();
        gravity--;
        setLocation(getX(), getY());
        
        checkForJump();
        jump();
        
        
        if(Greenfoot.isKeyDown("left")) {
            move(-3);
        }        
        if(Greenfoot.isKeyDown("right")) {
            move(3);
        }   // Add your action code here.
        
    }  
    public void jump()
    {
        if(Greenfoot.isKeyDown("up"))
        {
            vSpeed = -10;
            gravity = 20;
        }
        else
        {
            vSpeed = 0;
        }
    }
    public void fall()
    {
        
        setLocation(getX(), getY() + vSpeed - gravity);

    }
    public void checkForJump()
    {
        if(Greenfoot.isKeyDown("up"))
        {
            vSpeed = -10;
            gravity = 20;
        }
    }
    
    public void checkFalling()
    {
        if(!isTouching(Ground.class))
        {
            vSpeed = 0;
            gravity = 0;
        }
        
    }
    
    
    
    

       
    


}
danpost danpost

2020/10/24

#
MrSkyPanda wrote...
so i figured out how the platforms work but that caused my characters to lose the ability to jump << Code Omitted >>
That code is nowhere close to what I have in my demo.
There are more replies on the next page.
1
2