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

2017/1/24

Need help with Tron Game

KidDiamond11 KidDiamond11

2017/1/24

#
I am making a Tron Game where you and three others drive four different motorcycles around the world with the "lasers" coming out of the back of the motorcycles. I need help with having the motorcycles spawn their respectivly colored laser at the same coordinates as that bike.
danpost danpost

2017/1/24

#
What have you tried. Show some attempt at having the motorcycles creating their laser objects as they move. Show your attempted code (motorcycle movement w/creating lasers and the class of the laser.
KidDiamond11 KidDiamond11

2017/1/24

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

/**
 * Write a description of class GreenBiker here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GreenBiker extends Bikers
{
    /**
     * Act - do whatever the GreenBiker wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        checkKeyPress();
        laser();
    }
    
    public void checkKeyPress()
    {
        if(Greenfoot.isKeyDown("left"))
        {
            turn(-5);
        }
        if(Greenfoot.isKeyDown("right"))
        {
            turn(5);
        }
        if(Greenfoot.isKeyDown("up"))
        {
            move();
        }
    }
    
    public void laser()
    {
        getWorld().addObject((new GreenExhaust()),? ,?);
    }
}
This is the code for the green biker with the GreenExhaust being the laser coming out of the back of the bike.
Super_Hippo Super_Hippo

2017/1/24

#
The ?? could be getX() and getY() to get the current location.
You need to login to post a reply.