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

2012/10/15

Problem

1
2
3
BradH BradH

2012/10/15

#
This is my longshot class (my projectile) at the end i have a code to make the projectile disappear at the world's edge but when i typed it in and went to run my game the projectile just appeared by the gun and disappeared right away (not even staying on screen for one second) I know that there probably is a problem with the code that i am using at the end to make the longshot(projectile) disappear at the world's edge, but i am unaware on how to fix it, thanks for your time. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class longshot here. * * @author (your name) * @version (a version number or a date) */ public class Longshot extends Mover { private int life = Greenfoot.getRandomNumber(2) + 8; /** * Act - do whatever the Longshot wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAndTurn(); disappear(); } public void moveAndTurn() { move(3.0); Actor Fly; Fly = getOneObjectAtOffset(0, 0, Fly.class); if (Fly != null) { World world; world = getWorld(); world.removeObject(Fly); } Actor Bee; Bee = getOneObjectAtOffset(0, 0, Bee.class); if (Bee != null) { World world; world = getWorld(); world.removeObject(Bee); } Actor Warrior; Warrior = getOneObjectAtOffset(0, 0, Warrior.class); if (Warrior != null) { World world; world = getWorld(); world.removeObject(Warrior); } } /** * atWorldEdge() method that checks if the Longshot is at the end of the world, if it is, return true, otherwise false */ public void disappear() { if (this.atWorldEdge()) {World world; world = getWorld(); world.removeObject(this); } } }
Game/maniac Game/maniac

2012/10/15

#
Go into the mover class delete the move methods then compile
BradH BradH

2012/10/15

#
you mean go into the mover class which longshot is a subclass of? Wouldn't that effect my other subclasses in mover?
Game/maniac Game/maniac

2012/10/15

#
No
Game/maniac Game/maniac

2012/10/15

#
Greenfoot already has a move method the move method in mover was for the days when greenfoot didn't have a move method
BradH BradH

2012/10/16

#
you are going to hate me for asking this (it is probably a dumb question), but i am just a beginner and could you elaborate (out of the code I posted what needs changed)
Game/maniac Game/maniac

2012/10/16

#
You don't need to change the code you posted you just need to delete the move method from mover
Game/maniac Game/maniac

2012/10/16

#
actually you can if you want take the .0 off of 3.0
BradH BradH

2012/10/16

#
I went to the mover class and deleted the move method, but no luck
Game/maniac Game/maniac

2012/10/16

#
Try doing just atWorldEdge instead of this.atWorldEdge
Game/maniac Game/maniac

2012/10/16

#
If no luck again remove .0 from move(3.0)
BradH BradH

2012/10/16

#
still nothing, would a boolean method work?
Game/maniac Game/maniac

2012/10/16

#
Or you need to do !atWorldEdge() if none of the above work
Game/maniac Game/maniac

2012/10/16

#
Do !atWorldEdge() instead of this.atWorldEdge()
Game/maniac Game/maniac

2012/10/16

#
Did that help?
There are more replies on the next page.
1
2
3