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

2017/4/4

help please!!!

jaycee1021 jaycee1021

2017/4/4

#
so i am working on a project for school and i need my rocket to move in all directions and shoot. it moves but when it shoot it decides to stop. What can i do to change this? import greenfoot.*; public class Me extends Actor { int eX, eY, aX, aY; static int shoot = 1; int speed = 3; public void act() { String key = Greenfoot.getKey(); if(getWorld().getObjects(EnemyBullet.class).size() != 0) { if(Greenfoot.isKeyDown("right")) { setRotation(0); move(5); } if(Greenfoot.isKeyDown("down")) { setRotation(90); move(5); } if(Greenfoot.isKeyDown("left")) { setRotation(180); move(5); } if(Greenfoot.isKeyDown("up")) { setRotation(270); move(5); if(isAtEdge()) { Greenfoot.setWorld(new world2()); } } if(shoot == 1) { getWorld().addObject(new Bullet(),getX(),getY()); shoot = 0; } } else if(getWorld().getObjects(Enemy.class).size() != 0) { eX = ((Enemy)getWorld().getObjects(Enemy.class).get(0)).getX(); eY = ((Enemy)getWorld().getObjects(Enemy.class).get(0)).getY(); turnTowards(eX, eY); if(eX < getWorld().getWidth()/2) { if(shoot == 1) { getWorld().addObject(new Bullet(),getX(),getY()); shoot = 0; } } } if("space".equals(key)) { getWorld().addObject(new Bullet(),getX(), getY()); } } } this is the code i am using, i would like to change worlds when i get to the end of the world also, can anyone help? if so it would be appreciated!!
danpost danpost

2017/4/4

#
Line 11 restrict movement to only when an EnemyBullet object is in the world.
jaycee1021 jaycee1021

2017/4/10

#
I got it to work, thank you!
You need to login to post a reply.