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

2018/4/11

Need help making player fire bullets in the direction its facing...

IlikeThePrequels IlikeThePrequels

2018/4/11

#
This is what I have and I'm getting errors stating the constructor requires int,found no arguments, and reason is actual and formal arguments differ in length. Here is my player code import greenfoot.*; /** * Write a description of class Airplane here. * * @author (your name) * @version (a version number or a date) */ public class Bee extends Actor { private GreenfootImage image3; private GreenfootImage image4; /** * Act - do whatever the Airplane wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Bee() { image3 = new GreenfootImage("bee.png"); image4 = new GreenfootImage("bee2.png"); setImage(image3); } public void act() { checkKeys(); switchImage(); } private void checkKeys() { if (Greenfoot.isKeyDown("right")) { turn(5); } if (Greenfoot.isKeyDown("left")) { turn(-5); } if (Greenfoot.isKeyDown("space")) { shoot(); } } public void shoot() { Stinger stinger =new Stinger(); getWorld() .addObject(new Stinger(getRotation()), getX(), getY()); setRotation(getRotation()); } public void switchImage() { if (getImage() == image3) { setImage(image4); } else { setImage(image3); } } } Here is my bullet code import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class bullet here. * * @author (your name) * @version (a version number or a date) */ public class Stinger extends Actor { private int direction, speed; public Stinger(int dir) { direction = dir; speed = 10; } public void act() { setRotation(direction); move(speed); checkCollision(); } public void checkCollision() { Actor bee2 = (Actor) getOneIntersectingObject(Bee2.class); if(bee2 != null) { getWorld().removeObject(bee2); } if (isTouching(Stinger.class)) { getWorld().removeObject(this); return; } } }
IlikeThePrequels IlikeThePrequels

2018/4/11

#
I gotbit never mind.
You need to login to post a reply.