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

2015/7/15

need help with Asteroids -bullet

1
2
Turtle Turtle

2015/7/15

#
Im an getting a "cannot find symbol - class Vector" in my bullet class.
danpost danpost

2015/7/15

#
Turtle wrote...
Im an getting a "cannot find symbol - class Vector" in my bullet class.
Then you probably did not add, or import, one into your project.
Turtle Turtle

2015/7/15

#
This is what i have, and not quite sure of the command to use to import. import greenfoot.*; /** * A bullet that can hit asteroids. * * @author Tyler Schenk * @verion 15July2015 */ public class Bullet extends SmoothMover { private static final int damage = 16; /** A bullet looses one life each act, and will disappear when life = 0 */ private int life = 30; public Bullet() { } public Bullet(Vector speed, int rotation) { super(speed); setRotation(rotation); addToVelocity(new Vector(rotation, 15)); Greenfoot.playSound("EnergyGun.wav"); } public void act() { if(life <= 0) { getWorld().removeObject(this); } else { life--; move(); checkAsteroidHit(); } } /** * Check whether we have hit an asteroid. */ private void checkAsteroidHit() { Asteroid asteroid = (Asteroid) getOneIntersectingObject(Asteroid.class); if (asteroid != null) { getWorld().removeObject(this); asteroid.hit(damage); } } }
Turtle Turtle

2015/7/15

#
the error occur is at the public Bullet(Vector speed, int rotation) line
danpost danpost

2015/7/15

#
I believe the scenario you got the SmoothMover class from also had the Vector class, which you need to also include into your project.
Turtle Turtle

2015/7/16

#
would import java.util.Vector; be what i would want to insert? And if so, would i want to insert that into the SmoothMover and the Bullet classes? Sorry for all the questions, this is the first time i have ever messed with programming.
Turtle Turtle

2015/7/16

#
ok well i have gotten that issue fixed, now i have a new problem. When i go to compile i get an error stating "java.lang.IllegalArgumentException: java.io.FileNotFoundException: Could not find file: rocketWithThrust.png" but the image is in the greenfoot folder.
danpost danpost

2015/7/16

#
Make sure you use the exact name of the file where case is important for both the name and suffix. For the IllegalArgumentException you need to show the code around which the error occurred (it is best the post the entire class as well as the entire error trace).
Turtle Turtle

2015/7/16

#
import greenfoot.*; /** * A keyboard controlled rocket * space bar fires the bullets, and z fires proton wave * * @author Tyler Schenk * @versoin 15July2015 * * @version 1.0 */ public class Rocket extends SmoothMover { private static final int gunReloadTime = 5; private static final int protonReloadTime = 500; private int reloadDelayCount; private int protonDelayCount; private GreenfootImage rocket = new GreenfootImage("rocket.png"); private GreenfootImage rocketWithThrust = new GreenfootImage("rocketWithThrust.png"); <--------HERE IS WHERE AN ERROR IS public Rocket() { reloadDelayCount = 5; protonDelayCount = 500; addToVelocity(new Vector(13, 0.7)); } public void act() { move(); checkKeys(); checkCollision(); reloadDelayCount++; protonDelayCount++; } private void checkKeys() { ignite(Greenfoot.isKeyDown("up")); if (Greenfoot.isKeyDown("left")) { turn(-5); } if (Greenfoot.isKeyDown("right")) { turn(5); } if (Greenfoot.isKeyDown("space")) { fire(); } if (Greenfoot.isKeyDown("z")) { startProtonWave(); } } private void checkCollision() { Asteroid a = (Asteroid) getOneIntersectingObject(Asteroid.class); if (a != null) { Space space = (Space) getWorld(); space.addObject(new Explosion(), getX(), getY()); space.removeObject(this); space.gameOver(); } } private void ignite(boolean boosterOn) { if (boosterOn) { setImage(rocketWithThrust); addToVelocity(new Vector(getRotation(), 0.3)); } else { setImage(rocket); } } private void fire() { if (reloadDelayCount >= gunReloadTime) { Bullet bullet = new Bullet (getVelocity(), getRotation()); getWorld().addObject (bullet, getX(), getY()); bullet.move (); reloadDelayCount = 0; } } private void startProtonWave() { if (protonDelayCount >= protonReloadTime) { ProtonWave wave = new ProtonWave(); getWorld().addObject (wave, getX(), getY()); protonDelayCount = 0; } } }
Turtle Turtle

2015/7/16

#
java.lang.IllegalArgumentException: java.io.FileNotFoundException: Could not find file: rocketWithThrust.png at Rocket.<init>(Rocket.java:20) at Space.<init>(Space.java:26)
davmac davmac

2015/7/16

#
Turtle wrote...
Could not find file: rocketWithThrust.png" but the image is in the greenfoot folder.
The image should be in the 'images' folder inside the scenario folder.
Turtle Turtle

2015/7/16

#
its there, i have triple checked, im starting think Asteroids has something against me :( is there a setting that needs to be set for it to look in the correct folder?
davmac davmac

2015/7/16

#
Turtle wrote...
its there, i have triple checked, im starting think Asteroids has something against me :( is there a setting that needs to be set for it to look in the correct folder?
How about you post a screenshot of the contents of the images folder (to an image/file sharing service like dropbox, and then post a link here)? I'm guessing the name doesn't match case or that the image format is not valid.
Turtle Turtle

2015/7/16

#
http://i.imgur.com/FRPmYtL.png?1 Will this work?
davmac davmac

2015/7/16

#
The image is scaled down so much that I cannot read the filenames.
There are more replies on the next page.
1
2