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

2013/4/15

Mario HELP

SWAG SWAG

2013/4/15

#
I am making a Mario game and my Mario shoots straight, but how do I make him shoot the way he does in the game. (the bullets go over ground)
JetLennit JetLennit

2013/4/16

#
Could you please specify what mario was shooting?
SWAG SWAG

2013/4/16

#
he is shooting a fireball and it goes straight. I want to be like how he shoots in a game. I want it to shoot like that: http://i.imgur.com/WeVx5.gif
What I would do is have the fireball have a gravity, so it falls down. To sense if the fireball is on the ground, I'd use getOneObjectAtOffset to see if the ground is beneath it. Then have it bounce up by lowering it's gravity. Then continue until a counter reaches a specific point, removing the fireball, or until it hits a wall or an enemy.
SWAG SWAG

2013/4/16

#
Could you type a small part of the code. I'm new to greenfoot.
Here's some of it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Fireball extends Actor
{
    private int gravity = /*Some Negative Number */;
    private static final int DEF_GRAV = gravity;
    //Whatever other variables and constructors you have
 
    public void act()
    {
        if (!onGround() || gravity < 0)
             fall();
        else
              jump();
        //Whatever else you have
    }
 
    public void fall()
    {
        gravity++;
        setLocation(getX(), getY() - gravity);
    }
 
    public void jump()
    {
        gravity = DEF_GRAV;
    }
 
    public boolean onGround()
    {
        int height = getImage().getHeight();
        Ground ground = (Ground)getOneObjectAtOffset(0, height/2 + 1, Ground.class);  //Basically looks for a ground object beneath it. If nothing there, it will equal null
        return ground != null//If it exists, return true, if not, return false
    }
}
You will have to add code to have it hurt enemies, stop after a time limit, or hits a wall. But the above is the main part for jumping/falling.
SWAG SWAG

2013/4/16

#
The method above doesn't work properly. The bullets go in the sky. Also could it have some for explanations because I also get an error after a few tries of using it in the game. I started using Greenfoot only last week.
JetLennit JetLennit

2013/4/16

#
If you just started last week i wouldn't go doing such a hard project.....
Ya, this is a harder project. You might want to get used to greenfoot before you start doing more advanced stuff. Or, you could work on other parts of you game. If you haven't already, you should try moving around, jumping, and going through pipes. Also, if you were to post what you have already with source code, people could look at your code and help out more.
Also, with your problem, did you make sure to start gravity with a negative number? Also, make sure that you increase the gravity. If you don't have a positive number, it won't fall. When it's negative, the fireball should rise. When positive, it should fall, until it hits the ground, and that's when it goes up again.
You need to login to post a reply.