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

2014/1/15

HOLY GUACAMOLE MY ISU IS DUE SOON

Conrox27 Conrox27

2014/1/15

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class playerOne here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class playerOne extends Mover
{
 /**
     * Constructor 
     */
    public playerOne()
    {
        this.velocity = 4;
    }    
/**
     * Act - do whatever the playerOne wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        checkKeys();
    } 

    /**
     * Check if a key is pressed
     */
    public void checkKeys()
    {
        // move the player right
        if(Greenfoot.isKeyDown("right"))
        {
            setLocation(getX()+velocity, getY());
        }
        //move the player left
        if(Greenfoot.isKeyDown("left"))
        {
            setLocation(getX()-velocity, getY());
        }
        //move the player up
        if(Greenfoot.isKeyDown("up"))
        {
            setLocation(getX(), getY()-velocity);
        }
        //move the player down
        if(Greenfoot.isKeyDown("down"))
        {
            setLocation(getX(), getY()+velocity);
        }
    }
}
____________________________________________________

Player Two

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class playerOne here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PlayerTwo extends Mover
{
 /**
     * Constructor 
     */
    public PlayerTwo()
    {
        this.velocity = 4;
    }    
/**
     * Act - do whatever the playerOne wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        checkKeys();
    } 

    /**
     * Check if a key is pressed
     */
    public void checkKeys()
    {
        // move the player right
        if(Greenfoot.isKeyDown("d"))
        {
            setLocation(getX()+velocity, getY());
        }
        //move the player left
        if(Greenfoot.isKeyDown("a"))
        {
            setLocation(getX()-velocity, getY());
        }
        //move the player up
        if(Greenfoot.isKeyDown("w"))
        {
            setLocation(getX(), getY()-velocity);
        }
        //move the player down
        if(Greenfoot.isKeyDown("s"))
        {
            setLocation(getX(), getY()+velocity);
        }
    }
}
Hi ive been making a vs game with two space ships fighting eachother but I can,t figure out how to make them shoot to save my life. if someone could please help me with this heres the code for both actors someone please help this is 20% of my final mark :'(
danpost danpost

2014/1/15

#
You need to create a class for whatever it is that is being shot (bullet, missile, light-beam, torpedo, phaser, whatever). Add the code for what it does into the class. Then have your ships create them when whatever condition you set becomes true. After you attempt to accomplish this, if you have specific problems, post back.
You need to login to post a reply.