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

2020/3/15

program error idk how to fix HELP DANPOST!!!

CieloMungcal CieloMungcal

2020/3/15

#
i used this code and copied most of it from dan post tank game but there seems to be a problem check code for comment bottom of program import greenfoot.*; public class luigi extends Actor { private Actor turret; private int targetX, targetY; private int trackTimer; public luigi() { GreenfootImage image = getImage(); image.scale(image.getWidth() - 150, image.getHeight() - 200); setImage(image); turret = Terrain.getNewActor(); turret.setImage("turret.png"); } protected void addedToWorld(World level1) { if(turret.getWorld() != world) world.addObject(turret, getX(), getY()); else turret.setLocation(getX(), getY()); targetX = world.getWidth()/2; targetY = world.getHeight()/2; turnTowards(targetX,targetY); turret.turnTowards(targetX, targetY); } public void act() { if(Greenfoot.mouseMoved(null)|| Greenfoot.mousedragged(null)) { MouseInfo mouse = Greenfoot.getMouseInfo(); targetX = mouse.getX(); targetY = mouse.getY(); } } int angleToTarget = (int)(Math.atan2(getY()-targetY,getX()-targetX)*180/Math.PI); int rotationToTarget = (turret.getRotation()-angleToTarget+540)%360-180; int directionOfRotation = (int)Math.signum(rotationToTarget); turret.turn(VAL*3/3*directionOfRotation); //error here saying that there shouldbe an identifier after 'VAL' if(Greenfoot.mouseClicked(null)&&getObjectInRange(150,Shot.class).isEmpty()) // error illegal start { Shot shot = new Shot(); getWorld().addObject(shot, getX(), getY()); //error shot.move(VAL*30); //error }
danpost danpost

2020/3/15

#
Will need to see Shot class codes as well.
CieloMungcal CieloMungcal

2020/3/15

#
import greenfoot.*; public class Shot extends Actor { } only that
CieloMungcal CieloMungcal

2020/3/15

#
how to fix? public void fire() { if (Greenfoot.isKeyDown("space") && shotDelay <= 0 && fireDuration > 0) { Shot s = new Shot(); //creates a new Shot object //ERROR HERE s.setRotation(getRotation()); //sets the rotation of the new Shot object to the same rotation as the shooting object getWorld().addObject(s, getX(), getY()); //adds the object to the world shotDelay = 75; }
danpost danpost

2020/3/15

#
CieloMungcal[code wrote...
]import greenfoot.*; public class Shot extends Actor{} only that
Where do you define VAL?
danpost danpost

2020/3/15

#
CieloMungcal wrote...
how to fix? << Code Omitted
There does not appear to be anything wrong with the given code.
CieloMungcal CieloMungcal

2020/3/15

#
can u give me a sample code where, when i shoot using a player, the shot shot go towards the mouse
danpost danpost

2020/3/15

#
CieloMungcal wrote...
can u give me a sample code where, when i shoot using a player, the shot shot go towards the mouse
Something like this:
if (Greenfoot.mouseClicked(null))
{
    MouseInfo mouse = Greenfoot.getMouseInfo();
    Shot s = new Shot();
    getWorld().addObject(s, getX(), getY());
    s.turnTowards(mouse.getX(), mouse,getY());
    s.move(30);
}
CieloMungcal CieloMungcal

2020/3/15

#
Shot s = new Shot(); problem with that again
CieloMungcal CieloMungcal

2020/3/15

#
error saying: required: greenfoot.actor found:no arguments reason: actual and formal argumwnt lists differ in length
danpost danpost

2020/3/15

#
Did you correct my error on line 6 above where comma should be a dot before getY? Show entire class codes. --- OH ... and please use code tags.
You need to login to post a reply.