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

2018/5/30

I’m making a sort of zombie game

1
2
NervousNeep NervousNeep

2018/5/30

#
Basically I’m making a zombie game that involves me shooting a gun at a target, however I can get the shot bullet to move towards the mouse but it stops when it reaches the mouse and if the mouses moves in direction, so does the bullet. Pls help me make it move in a straight line to the edge of the map (I have a program to delete it after that) and also I’d like to note that I’m new to Greenfoot or Java as a whole
danpost danpost

2018/5/30

#
NervousNeep wrote...
I can get the shot bullet to move towards the mouse but it stops when it reaches the mouse and if the mouses moves in direction, so does the bullet. Pls help me make it move in a straight line to the edge of the map
Show class code of bullet.
NervousNeep NervousNeep

2018/5/30

#
public void shoot() { MouseInfo mouse=Greenfoot.getMouseInfo(); if(Greenfoot.mousePressed(null)) { Bullet newBullet; newBullet = new Bullet(); World world; world = getWorld(); int z = getRotation(); int x = getX() + 67; int y = getY() + 14; world.addObject(newBullet, x, y); } }
NervousNeep NervousNeep

2018/5/30

#
this code is located in the Player 1 code (you would control him) but i don't have anything i the actual bullet class.
SirScotty SirScotty

2018/5/30

#
I also have the same problem, but whenever i try to use Bullet.setRotation(getRotation()) in the gun class; it says that non-static method cant be referenced from static content. What does this mean? and any ideas how to fix it?
danpost danpost

2018/5/30

#
NervousNeep wrote...
this code is located in the Player 1 code (you would control him) but i don't have anything i the actual bullet class.
Well, the bullet does not have a mind of its own. It has to be told to move (use the act method in the bullet class).
danpost danpost

2018/5/30

#
SirScotty wrote...
I also have the same problem, but whenever i try to use Bullet.setRotation(getRotation()) in the gun class; it says that non-static method cant be referenced from static content. What does this mean? and any ideas how to fix it?
@SirScotty, you should start your own discussion thread for your issue -- and show a bit more code.
NervousNeep NervousNeep

2018/5/30

#
I’ve tried the move method, however I will try again, but it just moves toward the mouse and stops at the mouse, it also moves if I move the mouse in any direction. Neither of these I want
danpost danpost

2018/5/30

#
NervousNeep wrote...
I’ve tried the move method, however I will try again, but it just moves toward the mouse and stops at the mouse, it also moves if I move the mouse in any direction. Neither of these I want
Sounds like you have a bit more than just move in your act method -- show what you tried.
NervousNeep NervousNeep

2018/5/30

#
I’ll get to, just give me a couple of minutes please. While I’m away I would just like to make my intentions for this code a little more clearer: I want the bullet to basically just ignore the mouse cursor after it is shot, moving in a straight line
danpost danpost

2018/5/30

#
NervousNeep wrote...
I’ll get to, just give me a couple of minutes please. While I’m away I would just like to make my intentions for this code a little more clearer: I want the bullet to basically just ignore the mouse cursor after it is shot, moving in a straight line
You must already have some code in your project which is causing this behavior. I cannot tell you what code to remove without seeing what you have.
NervousNeep NervousNeep

2018/5/30

#
public void act() { Aim(); Movement(); } public void Aim() { MouseInfo mouse=Greenfoot.getMouseInfo(); if (mouse!= null) { turnTowards(mouse.getX(), mouse.getY()); } } public void Movement() { move(20); }
NervousNeep NervousNeep

2018/5/30

#
there is the code for bullet, not very advanced.
danpost danpost

2018/5/30

#
NervousNeep wrote...
there is the code for bullet, not very advanced.
Too advanced for what you want. All you should have is:
public void act()
{
    move(20);
    if (isAtEdge()) getWorld().removeObject(this);
}
The setting of its rotation should be done in the player's code when shooting the gun. Like I said, the bullet is dumb. It should not care which direction it is to move. It is the player that directs the bullet.
NervousNeep NervousNeep

2018/5/30

#
So how would you link the direction of the bullet to say another actor called gun
There are more replies on the next page.
1
2