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

2012/12/13

Shooting Problem

Motifaded Motifaded

2012/12/13

#
Okay, so i'm creating my own space shooter game as part of my Game Design final but I ran into a few problems I can't seem to figure out. Problem 1: I have two methods to control what the projectile does when it hits something. One removes the enemy when collision occurs, and the other method removes the bullet when it reaches the end of the world. When I put both of these methods into the Act method, the projectile will disappear when it reaches the end of the world, but when it hits an enemy I either get an error that says it can't find the location, or it doesn't shoot the projectile unless there isn't an enemy in the way. I know the basics of the error, I just can't seem to fix it. Problem 2: I have a scoreboard class to take care of points. I want to implement this into my game-over screen, but when it goes to that screen, the score resets. I've tried making the variables static and that caused all kinds of trouble. Projectile Class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Laser_Cannon here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LaserCannon extends Actor
{
    /**
     * Act - do whatever the Laser_Cannon wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Declares lasercannon movement.
        setLocation(getX(),getY() -8);
        // Declares the hit method.
        hit();
        // Declares end method.
        end();
    }
    
    // If laser hits an enemy, it disappears.
    public void hit()
    {
        if(Enemy.isKilled == true){
            getWorld().removeObject(this);
            Enemy.isKilled = false;
        }
    }
    
    // If laser reaches end of screen, it disappears.
    public void end()
    {
        if(this.atWorldEdge() == true){
            getWorld().removeObject(this);
        }
    }
    
    // Defines the world's edges.
    public boolean atWorldEdge()
    {
        if(getX() <= 1 || getX() >= 399)
            return true;
        if(getY() <= 1 || getY() >= 599)
            return true;
        else
            return false;
    }
}
I would REALLY appreciate some help before I have to turn in a non-working game that will bomb my grade. Please and thank you for any help I can get.
davemib123 davemib123

2012/12/13

#
in terms of scoreboard, check this link: http://www.greenfoot.org/scenarios/4981 publish your code, it makes it so much easier to check the code :D
Motifaded Motifaded

2012/12/13

#
Thanks dave, i'll look into that link. As for publishing the game, here it is: Space Survival
Motifaded Motifaded

2012/12/13

#
I fixed the problem.
You need to login to post a reply.