Hey,
So I've been working on a school project in which we are supposed to modify a game. We're using this game as a base.
I want to make it so you can only shoot a certain type of alien (right now, I am using the soldier image and alien image as placeholders). You're only supposed to shoot the soldier, and therefore the soldier is supposed to be the image. The problem is that each alien constantly switched between soldier and alien in a blinking manner, and I have no idea why. Here's the code for the alien:
Please help, if you can.
Thanks.
-D
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Alien extends Actor { int SPEED = -7; // Speed of 10 in left direction "-" public Alien() { } public void act() { move (SPEED); Actor Bullet = getOneIntersectingObject(Bullet.class); boolean isSeen; isSeen = true; int tempType = (int)((Math.random() * 3) + 1); if (isSeen = true) { if (tempType == 2) { setImage("Soldier.png"); isSeen = false; }else { setImage("Alien.png"); isSeen = false; } } // If alien touches left side of screen - Game Over if (getX()<0) { Greenfoot.playSound("game_over.mp3"); GameOver gameover = new GameOver(); getWorld().addObject(gameover, getWorld().getWidth()/2, getWorld().getHeight()/2); Greenfoot.stop(); } // If Bullet touches alien - Game Over if (Bullet !=null) { if (tempType == 2){ Greenfoot.playSound("explosion.wav"); getWorld(). removeObject(Bullet); ((SpaceLand)(getWorld())).score.add(50); getWorld().removeObject(this); //remove alien from screen isSeen = false; } else { Greenfoot.playSound("game_over.mp3"); GameOver gameover = new GameOver(); getWorld().addObject(gameover, getWorld().getWidth()/2, getWorld().getHeight()/2); Greenfoot.stop(); isSeen = false; } } } }