ObjektnoPR wrote...
I should make subclass of actor, not of Mesto, right?public class SimpleActor extends greenfoot.Actor {}public class SimpleActor extends greenfoot.Actor {}public Mesto(String imeValue){
ime = imeValue;
hoverSound = new GreenfootSound(ime + ".mp3");
setImage("mesto.jpg");
//the code for image showing
/*
if (Greenfoot.soundIsPlaying){
SimpleActor bern = new SimpleActor("Bern");
getWorld().setBackground(new GreenfootImage(ime + ".jpg"));
}
if (Greenfoot.!soundIsPlaying){
getWorld().setBackground("Slovenia.jpg")); //that is the old background
}
*/
}public Mesto(String imeValue){
ime = imeValue;
hoverSound = new GreenfootSound(ime + ".mp3");
setImage("mesto.jpg");
//the code for image showing
}public class Mesto extends Actor
{
public boolean izbrano = false;
public String ime;
private GreenfootSound hoverSound;
private GreenfootImage hoverImage;
SimpleActor simpleActor = new SimpleActor();
public Mesto(String imeValue){
ime = imeValue;
hoverSound = new GreenfootSound(ime + ".mp3");
setImage("mesto.jpg");
}
public void act(){
if (Greenfoot.isKeyDown("down") && isTouching(Letalo.class) && ((Start)getWorld()).izbranoMesto == this && !hoverSound.isPlaying()){
hoverSound.play();
}
if (hoverSound.isPlaying() == true) {
simpleActor.setImage(ime + ".jpg");
getWorld().addObject(simpleActor, 500, 300);
}
else {
getWorld().removeObject(simpleActor);
}
}
}// from
else {
// to
else if (simpleActor.getWorld() != null) {public class Mesto extends Actor
{
public boolean izbrano = false;
public String ime;
private GreenfootSound hoverSound;
private SimpleActor cityImage;
public Mesto(String imeValue){
ime = imeValue;
hoverSound = new GreenfootSound(ime + ".mp3");
setImage("mesto.jpg");
cityImage = new SimpleActor();
}
public void act(){
if (Greenfoot.isKeyDown("down") && isTouching(Letalo.class) && ((Start)getWorld()).izbranoMesto == this && !hoverSound.isPlaying()){
hoverSound.play();
getWorld().addObject(cityImage, 500, 300);
}
if (hoverSound.isPlaying() == true) {
cityImage.setImage(ime + ".jpg");
}
else if (cityImage.getWorld() != null) {
getWorld().removeObject(cityImage);
}
}
}if (! hoverSound.isPlaying() && cityImage.getWorld() != null) {
getWorld().removeObject(cityImage);
}public class Start extends World
{
private int nepovratnost = 0;
ArrayList<Mesto> mesta;
Mesto izbranoMesto;
Destinacija destinacija;
Random rnd = new Random();
public Start()
{
// Create a new world with 1000x600 cells with a cell size of 1x1 pixels.
super(1000, 600, 1);
setBackground(new GreenfootImage("mainMenu.jpg"));
mesta = new ArrayList<Mesto>();
rnd.setSeed(System.currentTimeMillis());
}
public void act(){
if(Greenfoot.isKeyDown("space") && nepovratnost == 0) {
setBackground(new GreenfootImage("navodila.jpg"));
}
if(Greenfoot.isKeyDown("backspace") && nepovratnost == 0) {
setBackground(new GreenfootImage("mainMenu.jpg"));
}
if(Greenfoot.isKeyDown("escape")) {
setBackground(new GreenfootImage("escape.jpg"));
List objects = getObjects(null);
removeObjects(objects);
}
if(Greenfoot.isKeyDown("enter") && nepovratnost == 0) {
nepovratnost = 1;
setBackground(new GreenfootImage("Slovenia.jpg"));
Mesto ljubljana = new Mesto("Ljubljana");
addObject(ljubljana, 480, 225);
mesta.add(ljubljana);
Mesto budimpesta = new Mesto("Budimpesta");
addObject(budimpesta, 715, 120);
mesta.add(budimpesta);
Mesto rim = new Mesto("Rim");
addObject(rim, 390, 520);
mesta.add(rim);
Mesto bern = new Mesto("Bern");
addObject(bern, 135, 150);
mesta.add(bern);
Mesto dunaj = new Mesto("Dunaj");
addObject(dunaj, 560, 70);
mesta.add(dunaj);
Mesto zagreb = new Mesto("Zagreb");
addObject(zagreb, 550, 250);
mesta.add(zagreb);
Mesto beograd = new Mesto("Beograd");
addObject(beograd, 770, 315);
mesta.add(beograd);
Mesto sarajevo = new Mesto("Sarajevo");
addObject(sarajevo, 650, 360);
mesta.add(sarajevo);
Mesto sofija = new Mesto("Sofija");
addObject(sofija, 920, 460);
mesta.add(sofija);
Mesto tirana = new Mesto("Tirana");
addObject(tirana, 745, 540);
mesta.add(tirana);
Mesto podgorica = new Mesto("Podgorica");
addObject(podgorica, 705, 470);
mesta.add(podgorica);
Mesto skopje = new Mesto("Skopje");
addObject(skopje, 840, 520);
mesta.add(skopje);
Mesto pristina = new Mesto("Pristina");
addObject(pristina, 800, 465);
mesta.add(pristina);
Letalo potniskoLetalo = new Letalo();
addObject(potniskoLetalo, 480, 225);
destinacija = new Destinacija();
addObject (destinacija, 300, 25);
Points points = new Points();
addObject(points, 75, 25);
izberiMesto();
}
}
public void prepare(){
}
public void izberiMesto()
{
int index = rnd.nextInt(mesta.size()-1);
izbranoMesto = mesta.get(index);
izbranoMesto.izbrano = true;
destinacija.izpisi();
}
}public class Mesto extends Actor
{
public boolean izbrano = false;
public String ime;
private GreenfootSound hoverSound;
private SimpleActor cityImage;
public Mesto(String imeValue){
ime = imeValue;
hoverSound = new GreenfootSound(ime + ".mp3");
setImage("mesto.jpg");
cityImage = new SimpleActor();
cityImage.setImage(ime + ".jpg");
}
public void act(){
if (Greenfoot.isKeyDown("down") && isTouching(Letalo.class) && ((Start)getWorld()).izbranoMesto == this && !hoverSound.isPlaying()){
hoverSound.play();
getWorld().addObject(cityImage, 500, 300);
}
if (! hoverSound.isPlaying() && cityImage.getWorld() != null) {
getWorld().removeObject(cityImage);
}
}
}addObject(bern, 135, 150);
addObject(bern, 135, 150);
private Object[][] mesta =
{
{ new Mesto("Ljubljana"), 480, 225 },
{ new Mesto("Budimpesta"), 715, 120 },
{ new Mesto("Rim"), 390, 520 },
{ new Mesto("Bern"), 135, 150 },
{ new Mesto("Dunaj"), 560, 70 },
{ new Mesto("Zagreb"), 550, 250 },
{ new Mesto("Beograd"), 770, 315 },
{ new Mesto("Sarajevo"), 650, 360 },
{ new Mesto("Sofija"), 920, 460 },
{ new Mesto("Tirana"), 745, 540 },
{ new Mesto("Podgorica"), 705, 470 },
{ new Mesto("Skopje"), 840, 520 },
{ new Mesto("Pristina"), 800, 465 }
};for (int i=0; i<mesta.length; i++)
{
addObject((Actor)mesta[i][0], (Integer)mesta[i][1], (Integer)mesta[i][2]);
}