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

2015/5/12

Help needed with code

YellowThundy YellowThundy

2015/5/12

#
Hey, I need some help with a Computer Programming platform project that requires for and while loops with 5 features. https://mrjoyce.wordpress.com/computer-science/greenfoot-platform-project/ I've got the core skeleton of the game, but I'm having trouble implementing features. Not sure where to begin. Any help would be greatly appreciated!
azazeel azazeel

2015/5/12

#
so where is part of your code that you want to be implemented and requires for and while loops with 5 features ?
YellowThundy YellowThundy

2015/5/12

#
Basically, the 5 features are the aspects of the game such as SlowPack/SpeedPack – This pack, when touched will make all of your enemies slower/faster (easier/harder to defeat). CageGun - when an enemy is hit by a cage bullet, a border of platforms is drawn around it for a fixed amount of time. Alternatively, the obstacles could persist but not completely surround the enemy (leave gaps for escape). Magnet - this weapon will attract enemies to it (and away from you). LandMines - when something touches it, it explodes. If there are any other LandMines in the blast radius they are also triggered (chain). This is what i have so far for Forcefield
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.util.ListIterator;
/**
 * Write a description of class ForceField here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ForceField extends Projectile
{
    /**
     * Act - do whatever the ForceField wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
    public ForceField()
    {
        List<Actor> actors = getObjectsInRange(400,Enemy.class);
        ListIterator<Actor> iter = actors.listIterator();
        while (iter.hasNext())
        {
            setLocation(this.getX()-50, this.getY()-50);
        }
    }
}
I don't know how to start for the other ones though. Thanks!
YellowThundy YellowThundy

2015/5/12

#
{
azazeel wrote...
so where is part of your code that you want to be implemented and requires for and while loops with 5 features ?
Basically, the 5 features are the aspects of the game such as SlowPack/SpeedPack – This pack, when touched will make all of your enemies slower/faster (easier/harder to defeat). CageGun - when an enemy is hit by a cage bullet, a border of platforms is drawn around it for a fixed amount of time. Alternatively, the obstacles could persist but not completely surround the enemy (leave gaps for escape). Magnet - this weapon will attract enemies to it (and away from you). LandMines - when something touches it, it explodes. If there are any other LandMines in the blast radius they are also triggered (chain). This is what i have so far for Forcefield
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.util.ListIterator;
/**
 * Write a description of class ForceField here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ForceField extends Projectile
{
    /**
     * Act - do whatever the ForceField wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
    public ForceField()
    {
        List<Actor> actors = getObjectsInRange(250,Villain.class);
        ListIterator<Actor> iter = actors.listIterator();
        while (iter.hasNext())
        {
            setLocation(this.getX()-30, this.getY()-30);
        }
    }
}
I don't know how to start for the other ones though. Thanks!
danpost danpost

2015/5/12

#
You need to explain what behavior you want for the forcefield -- how it should react with other objects (like the enemies). As is, the behavior is that the forcefield will move diagonally up and to the left quickly with each enemy in range. It could end up moving as much as two-thirds across the screen in under half a second (with just one enemy).
You need to login to post a reply.