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

2021/1/27

how to display background.gif in greenfoot?

ekosanji ekosanji

2021/1/27

#
I don't know how to display the gif.image of my code.
danpost danpost

2021/1/27

#
ekosanji wrote...
I don't know how to display the gif.image of my code.
Do you have the GifImage class in your project yet?
ekosanji ekosanji

2021/1/27

#
I don't think so, but I still don't understand where it went wrong or was lacking. can check my coding. Please help public class Game extends World { /** * The width variable stores the game width resolution. */ static final int width = 600; /** * The width variable stores the game height resolution. */ static final int height = 400; /** * The maxColum and maxRow variables stores the matrix size. */ final private int maxColum = 5, maxRow = 4; /** * The column and row variables stores the current position. */ private int column,row; /** * The difficulty variable stores how hard the game will be. */ private int difficulty; /** * The backGroundMusic variable stores an GreenfootSound object. */ private GreenfootSound backGroundMusic; /** * The backGroundMusic variable stores if the world is playing a background music. */ private boolean isPlaying = false; /** * The Game constructor initializes the game. * The prepare method adds to the world all the objects located in a row, column cell in the matrix. */ public Game(int difficulty) { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. this(false,difficulty); prepare(); } /** * The Game constructor initializes the game.<br> * If the game has not been initialized for the first time we initialize the row and column counter, also, we add our playable hero (Zero).<br> * Here we define the paint order and difficult for the correct game functioning. */ public Game(boolean isGameSet,int difficulty){ super(width,height,1); setPaintOrder(Life.class,Pointer.class,HiddenSpikes.class,Proyectile.class,Item.class,Wall.class,Platform.class,Explosion.class,Hero.class,Enemy.class); this.difficulty = difficulty; if(!isGameSet){ row = 0; column = 0; Hero hero = new Hero(); addObject(hero,80,344); prepare(); } } /** * The setDifficulty method sets the game difficult. */ public void setDifficulty(int value){ difficulty = value; } /** * The getDifficulty method returns the game difficult. * @return The game difficult. */ public int getDifficulty(){ return(difficulty); } /** *The playBackGroundMusic method defines which background music to play.<br> *We play different background music depending on the current stage. We have only four songs */ public void playBackGroundMusic(int stage){ if(!isPlaying){ if(stage == 0){ backGroundMusic = new GreenfootSound("Stages/Stagestart.mp3"); backGroundMusic.playLoop(); isPlaying = true; } else if(stage == 1){ backGroundMusic = new GreenfootSound("Stages/Area2.mp3"); backGroundMusic.playLoop(); isPlaying = true; } else if(stage == 2){ backGroundMusic = new GreenfootSound("Stages/Area3.mp3"); backGroundMusic.playLoop(); isPlaying = true; } else if(stage == 3){ backGroundMusic = new GreenfootSound("Stages/boss.mp3"); backGroundMusic.playLoop(); isPlaying = true; } } } /** *The stopBackGroundMusic method stops the current background music. */ public void stopBackGroundMusic(){ backGroundMusic.stop(); isPlaying = false; } /** *The setPlayingBackGroundMusic method sets the configuration of the isPlaying variable. *That variable indicates if the world is playing background music. */ public void setPlayingBackGroundMusic(boolean value){ isPlaying = value; } /** *The getPlayingBackGroundMusic tell us if the world is playing background music. *@return if the world is playing background music. */ public boolean getPlayingBackGroundMusic(){ return isPlaying; } /** *The getMusic method returns the current background music object. *@return The current background music object. */ public GreenfootSound getMusic(){ return(backGroundMusic); } /** *The setMusic method sets the current background music object. */ public void setMusic(GreenfootSound value){ backGroundMusic = value; } /** *The prepare sets every cell in the matrix. *Every cell in the matrix is a "screen" where we play. *Every cell has different objects, such as, wall, platforms, enemies and items. */ public void prepare(){ if(row == 0 && column == 0) { playBackGroundMusic(0); setBackground("World/Backgrounds/CityBurn.png"); Platform platform1 = new Platform(1,1); Wall wall1 = new Wall(1,1); IncreaseAtk increaseAtk = new IncreaseAtk(); addObject(platform1,300,383); addObject(wall1,16,200); addObject(increaseAtk,200,352); } if(row == 0 && column == 1){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform3 = new Platform(1,3); Platform platform4 = new Platform(1,3); Platform platform5 = new Platform(1,3); Platform platform6 = new Platform(1,3); Platform platform2 = new Platform(2,1); Wall wall2 = new Wall(1,2); Kamikaze enemy1 = new Kamikaze(1,difficulty); Gunslinger enemy2 = new Gunslinger(0,difficulty); Gunslinger enemy3 = new Gunslinger(1,difficulty); addObject(platform2,300,383); addObject(wall2,580,300); addObject(enemy1,400,344); addObject(enemy2,250,344); addObject(enemy3,250,344); addObject(platform3,170,290); addObject(platform4,280,200); addObject(platform5,400,110); addObject(platform6,560,190); } if(row == 0 && column == 2){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform3 = new Platform(3,1); Platform platform4 = new Platform(1,3); Platform platform5 = new Platform(1,3); Platform platform6 = new Platform(1,3); Platform platform2 = new Platform(2,1); Platform platform7 = new Platform(1,3); Wall wall2 = new Wall(1,2); Wall wall1 = new Wall(1,3); Alien alien = new Alien(1,difficulty); Alien alien2 = new Alien(1,difficulty); Alien alien3 = new Alien(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); Kamikaze kamikaze2 = new Kamikaze(1,difficulty); HiddenSpikes spi = new HiddenSpikes(); addObject(platform3,300,383); addObject(platform6,20,190); addObject(platform7,590,190); addObject(wall2,20,300); addObject(wall1,580,250); addObject(platform4,210,190); addObject(platform5,400,190); addObject(alien,469,350); addObject(spi,125,383); alien.setLocation(475,350); addObject(alien2,419,350); alien2.setLocation(422,350); addObject(alien3,245,353); alien3.setLocation(260,353); addObject(kamikaze,210,157); kamikaze.setLocation(200,157); addObject(kamikaze2,405,157); kamikaze2.setLocation(404,157); } if(row == 0 && column == 3){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform1 = new Platform(1,1); Platform platform2 = new Platform(1,3); Platform platform3 = new Platform(1,2); Platform platform4 = new Platform(1,2); Platform platform5 = new Platform(1,2); Platform platform6 = new Platform(1,2); Platform platform7 = new Platform(1,3); Platform platform8 = new Platform(1,3); Wall wall1 = new Wall(1,3); //Wall wall2 = new Wall(1,1); GiveLife giveLife = new GiveLife(); Gunslinger gunslinger = new Gunslinger(1,difficulty); Kamikaze kamikaze = new Kamikaze(0,difficulty); Kamikaze kamikaze3 = new Kamikaze(1,difficulty); IncreaseLife increaseLife = new IncreaseLife(); addObject(platform1,300,383); addObject(wall1,20,250); addObject(platform2,70,190); addObject(giveLife,121,162); giveLife.setLocation(121,161); addObject(platform3,350,352); addObject(platform4,450,352); addObject(platform5,520,320); addObject(platform6,590,290); addObject(platform7,370,190); addObject(platform8,560,150); //addObject(wall2,580,200); addObject(gunslinger,514,241); gunslinger.setLocation(514,253); addObject(kamikaze,367,160); kamikaze.setLocation(369,150); addObject(kamikaze3,293,316); kamikaze3.setLocation(295,311); addObject(increaseLife,534,117); increaseLife.setLocation(520,117); } if(row == 0 && column == 4){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform1 = new Platform(1,1); Teleport t1 = new Teleport(); addObject(t1,560,325); addObject(platform1,300,383); } if(row == 1 && column == 0){ playBackGroundMusic(1); setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,2); Platform platform3 = new Platform(4,3); Platform platform4 = new Platform(4,3); Wall wall1 = new Wall(2,1); addObject(wall1,14,200); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,300,300); addObject(platform3,380,210); addObject(platform4,570,140); } if(row == 1 && column == 1){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,2); Platform platform3 = new Platform(4,3); Platform platform4 = new Platform(4,3); HiddenSpikes spi = new HiddenSpikes(); Wall wall1 = new Wall(2,2); Alien alien = new Alien(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Gunslinger gunslinger = new Gunslinger(1,difficulty); GiveLife giveLife = new GiveLife(); Alien alien2 = new Alien(0,difficulty); addObject(wall1,80,50); addObject(spi,301,201); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,300,290); addObject(platform3,300,200); addObject(platform4,20,140); addObject(gunslinger,313,340); gunslinger.setLocation(319,340); addObject(gunslinger2,440,340); gunslinger2.setLocation(440,340); addObject(alien,410,253); alien.setLocation(418,253); addObject(alien2,178,253); alien2.setLocation(182,253); addObject(giveLife,41,112); } if(row == 1 && column == 2){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,3); Platform platform3 = new Platform(4,3); Platform platform4 = new Platform(4,2); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Alien alien = new Alien(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,200,300); addObject(platform3,300,200); addObject(platform4,515,200); addObject(gunslinger,356,340); gunslinger.setLocation(371,340); addObject(gunslinger2,503,160); gunslinger2.setLocation(462,160); addObject(alien,489,345); alien.setLocation(494,345); addObject(kamikaze,227,260); kamikaze.setLocation(228,260); } if(row == 1 && column == 3){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,1); HiddenSpikes spi = new HiddenSpikes(); //Wall wall1 = new Wall(2,1); IncreaseLife increaseLife = new IncreaseLife(); IncreaseSpeed increaseSpeed = new IncreaseSpeed(); Kamikaze kamikaze = new Kamikaze(1,difficulty); Alien alien3 = new Alien(1,difficulty); Alien alien2 = new Alien(1,difficulty); Alien alien = new Alien(1,difficulty); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Kamikaze kamikaze3 = new Kamikaze(1,difficulty); //addObject(wall1,586,200); addObject(spi,249,201); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,300,200); addObject(increaseLife,544,173); addObject(increaseSpeed,547,352); increaseSpeed.setLocation(530,352); increaseLife.setLocation(530,173); addObject(alien,186,167); alien.setLocation(197,165); addObject(alien2,317,168); alien2.setLocation(326,166); addObject(alien3,434,172); alien3.setLocation(440,165); addObject(kamikaze,508,170); kamikaze.setLocation(509,163); addObject(gunslinger,225,351); gunslinger.setLocation(218,341); addObject(gunslinger2,358,340); gunslinger2.setLocation(364,340); addObject(kamikaze3,469,351); kamikaze3.setLocation(466,343); } if(row == 1 && column == 4){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Teleport t1 = new Teleport(); addObject(t1,560,325); addObject(platform0,300,383); } if(row == 2 && column == 0){ IncreaseSpeed sp = new IncreaseSpeed(); IncreaseLife lf = new IncreaseLife(); playBackGroundMusic(2); setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Wall wall1 = new Wall(3,1); HiddenSpikes spi = new HiddenSpikes(); addObject(wall1,14,200); addObject(platform0,300,10); addObject(platform1,300,383); addObject(sp,150,350); addObject(lf,200,350); addObject(spi,300,384); } if(row == 2 && column == 1){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(6,3); Platform platform3 = new Platform(6,3); Platform platform4 = new Platform(6,3); Platform platform5 = new Platform(6,3); Platform platform6 = new Platform(6,2); Wall wall1 = new Wall(3,2); Kamikaze kamikaze = new Kamikaze(0,difficulty); Gunslinger gunslinger = new Gunslinger(1,difficulty); Kamikaze kamikaze2 = new Kamikaze(0,difficulty); GiveLife giveLife = new GiveLife(); addObject(wall1,590,300); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,400,290); addObject(platform3,250,240); addObject(platform4,100,150); addObject(platform5,550,200); addObject(platform6,400,150); addObject(kamikaze,85,110); kamikaze.setLocation(150,110); addObject(gunslinger,473,342); gunslinger.setLocation(473,342); addObject(kamikaze2,260,200); kamikaze2.setLocation(266,200); addObject(giveLife,50,125); giveLife.setLocation(57,125); } if(row == 2 && column == 2){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(6,3); Platform platform3 = new Platform(6,3); Platform platform4 = new Platform(6,2); Platform platform5 = new Platform(6,2); Platform platform6 = new Platform(6,2); Wall wall1 = new Wall(3,2); IncreaseAtk increaseAtk = new IncreaseAtk(); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); Alien alien = new Alien(0,difficulty); addObject(platform2,50,200); addObject(platform3,100,230); addObject(platform4,100,260); addObject(platform5,160,290); addObject(wall1,9,300); addObject(platform0,300,10); addObject(platform1,300,383); addObject(increaseAtk,44,352); addObject(gunslinger,571,344); addObject(gunslinger2,520,325); gunslinger2.setLocation(533,343); addObject(kamikaze,484,345); kamikaze.setLocation(470,345); addObject(alien,160,347); } if(row == 2 && column == 3){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(6,2); Platform platform3 = new Platform(6,3); Platform platform4 = new Platform(6,2); Platform platform5 = new Platform(6,3); Platform platform6 = new Platform(6,3); //Wall wall1 = new Wall(3,1); Wall wall2 = new Wall(3,2); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Gunslinger gunslinger3 = new Gunslinger(1,difficulty); Gunslinger gunslinger4 = new Gunslinger(1,difficulty); Alien alien = new Alien(0,difficulty); Alien alien2 = new Alien(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); Kamikaze kamikaze3 = new Kamikaze(1,difficulty); Kamikaze kamikaze4 = new Kamikaze(0,difficulty); Kamikaze kamikaze5 = new Kamikaze(1,difficulty); Kamikaze kamikaze6 = new Kamikaze(0,difficulty); GiveLife giveLife = new GiveLife(); addObject(platform2,300,300); addObject(platform3,500,250); addObject(platform4,250,200); addObject(platform5,10,135); addObject(platform6,250,120); //addObject(wall1,590,200); addObject(wall2,5,50); addObject(platform0,300,10); addObject(platform1,300,383); addObject(gunslinger,552,340); gunslinger.setLocation(552,340); addObject(gunslinger2,495,340); gunslinger2.setLocation(495,340); addObject(gunslinger3,446,340); gunslinger3.setLocation(447,340); addObject(gunslinger4,540,210); gunslinger4.setLocation(540,210); addObject(alien,120,163); alien.setLocation(147,163); addObject(alien2,374,163); alien2.setLocation(369,163); addObject(kamikaze,255,160); kamikaze.setLocation(262,160); addObject(kamikaze3,182,260); kamikaze3.setLocation(400,260); addObject(kamikaze4,181,260); kamikaze4.setLocation(184,260); addObject(kamikaze5,298,260); kamikaze5.setLocation(294,260); addObject(kamikaze6,231,260); kamikaze6.setLocation(234,260); addObject(giveLife,56,106); giveLife.setLocation(55,112); } if(row == 2 && column == 4){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); addObject(platform0,300,10); addObject(platform1,300,383); Teleport t1 = new Teleport(); addObject(t1,560,325); } if(row == 3 && column == 0){ playBackGroundMusic(3); setBackground("World/Backgrounds/Ship.png"); Wall wall1 = new Wall(3,1); Wall wall2 = new Wall(3,1); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(5,3); Platform platform3 = new Platform(5,3); Platform platform4 = new Platform(5,3); Platform platform5 = new Platform(5,3); Boss1 boss1 = new Boss1(difficulty); addObject(platform3,196,350); addObject(platform4,355,303); addObject(platform5,503,253); addObject(platform0,300,10); addObject(platform1,300,383); addObject(wall1,16,200); addObject(wall2,584,200); addObject(boss1,300,300); } } /** * The getColumn method returns the current column. * @return The current world column */ public int getColumn(){ return(column); } /** * The getRow method returns the current row. * @return The current world row. */ public int getRow(){ return(row); } /** * The setRow method sets the current row. * @param value The value of the row we want to apply. */ public void setRow(int value){ this.row = value; } /** * The stopped method avoids to reproduce many times the background music. */ @Override public void stopped() { stopBackGroundMusic(); } /** * The stopped method avoids to reproduce many times the background music. */ @Override public void started() { playBackGroundMusic(row); } /** * The setColumn method sets the current column. * @param value The value of the column we want to apply. */ public void setColumn(int value){ this.column = value; } /** * The maxColumn method returns the matrix height. * @return The current world max columns value. */ public int maxColumn(){ return(maxColum); } /** * The maxRow method returns the matrix width. * @return The current world max rows value. */ public int maxRow(){ return(maxRow); } }
danpost danpost

2021/1/27

#
Can you point out where the gif is? I could not find it.
ekosanji ekosanji

2021/1/27

#
from the setbackground changed to background.gif, can you?
ekosanji ekosanji

2021/1/27

#
public void prepare(){ if(row == 0 && column == 0) { playBackGroundMusic(0); setBackground("World/Backgrounds/CityBurn.png"); Platform platform1 = new Platform(1,1); Wall wall1 = new Wall(1,1); IncreaseAtk increaseAtk = new IncreaseAtk(); addObject(platform1,300,383); addObject(wall1,16,200); addObject(increaseAtk,200,352); } if(row == 0 && column == 1){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform3 = new Platform(1,3); Platform platform4 = new Platform(1,3); Platform platform5 = new Platform(1,3); Platform platform6 = new Platform(1,3); Platform platform2 = new Platform(2,1); Wall wall2 = new Wall(1,2); Kamikaze enemy1 = new Kamikaze(1,difficulty); Gunslinger enemy2 = new Gunslinger(0,difficulty); Gunslinger enemy3 = new Gunslinger(1,difficulty); addObject(platform2,300,383); addObject(wall2,580,300); addObject(enemy1,400,344); addObject(enemy2,250,344); addObject(enemy3,250,344); addObject(platform3,170,290); addObject(platform4,280,200); addObject(platform5,400,110); addObject(platform6,560,190); } if(row == 0 && column == 2){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform3 = new Platform(3,1); Platform platform4 = new Platform(1,3); Platform platform5 = new Platform(1,3); Platform platform6 = new Platform(1,3); Platform platform2 = new Platform(2,1); Platform platform7 = new Platform(1,3); Wall wall2 = new Wall(1,2); Wall wall1 = new Wall(1,3); Alien alien = new Alien(1,difficulty); Alien alien2 = new Alien(1,difficulty); Alien alien3 = new Alien(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); Kamikaze kamikaze2 = new Kamikaze(1,difficulty); HiddenSpikes spi = new HiddenSpikes(); addObject(platform3,300,383); addObject(platform6,20,190); addObject(platform7,590,190); addObject(wall2,20,300); addObject(wall1,580,250); addObject(platform4,210,190); addObject(platform5,400,190); addObject(alien,469,350); addObject(spi,125,383); alien.setLocation(475,350); addObject(alien2,419,350); alien2.setLocation(422,350); addObject(alien3,245,353); alien3.setLocation(260,353); addObject(kamikaze,210,157); kamikaze.setLocation(200,157); addObject(kamikaze2,405,157); kamikaze2.setLocation(404,157); } if(row == 0 && column == 3){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform1 = new Platform(1,1); Platform platform2 = new Platform(1,3); Platform platform3 = new Platform(1,2); Platform platform4 = new Platform(1,2); Platform platform5 = new Platform(1,2); Platform platform6 = new Platform(1,2); Platform platform7 = new Platform(1,3); Platform platform8 = new Platform(1,3); Wall wall1 = new Wall(1,3); //Wall wall2 = new Wall(1,1); GiveLife giveLife = new GiveLife(); Gunslinger gunslinger = new Gunslinger(1,difficulty); Kamikaze kamikaze = new Kamikaze(0,difficulty); Kamikaze kamikaze3 = new Kamikaze(1,difficulty); IncreaseLife increaseLife = new IncreaseLife(); addObject(platform1,300,383); addObject(wall1,20,250); addObject(platform2,70,190); addObject(giveLife,121,162); giveLife.setLocation(121,161); addObject(platform3,350,352); addObject(platform4,450,352); addObject(platform5,520,320); addObject(platform6,590,290); addObject(platform7,370,190); addObject(platform8,560,150); //addObject(wall2,580,200); addObject(gunslinger,514,241); gunslinger.setLocation(514,253); addObject(kamikaze,367,160); kamikaze.setLocation(369,150); addObject(kamikaze3,293,316); kamikaze3.setLocation(295,311); addObject(increaseLife,534,117); increaseLife.setLocation(520,117); } if(row == 0 && column == 4){ setBackground("World/Backgrounds/CityBurn.png"); Platform platform1 = new Platform(1,1); Teleport t1 = new Teleport(); addObject(t1,560,325); addObject(platform1,300,383); } if(row == 1 && column == 0){ playBackGroundMusic(1); setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,2); Platform platform3 = new Platform(4,3); Platform platform4 = new Platform(4,3); Wall wall1 = new Wall(2,1); addObject(wall1,14,200); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,300,300); addObject(platform3,380,210); addObject(platform4,570,140); } if(row == 1 && column == 1){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,2); Platform platform3 = new Platform(4,3); Platform platform4 = new Platform(4,3); HiddenSpikes spi = new HiddenSpikes(); Wall wall1 = new Wall(2,2); Alien alien = new Alien(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Gunslinger gunslinger = new Gunslinger(1,difficulty); GiveLife giveLife = new GiveLife(); Alien alien2 = new Alien(0,difficulty); addObject(wall1,80,50); addObject(spi,301,201); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,300,290); addObject(platform3,300,200); addObject(platform4,20,140); addObject(gunslinger,313,340); gunslinger.setLocation(319,340); addObject(gunslinger2,440,340); gunslinger2.setLocation(440,340); addObject(alien,410,253); alien.setLocation(418,253); addObject(alien2,178,253); alien2.setLocation(182,253); addObject(giveLife,41,112); } if(row == 1 && column == 2){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,3); Platform platform3 = new Platform(4,3); Platform platform4 = new Platform(4,2); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Alien alien = new Alien(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,200,300); addObject(platform3,300,200); addObject(platform4,515,200); addObject(gunslinger,356,340); gunslinger.setLocation(371,340); addObject(gunslinger2,503,160); gunslinger2.setLocation(462,160); addObject(alien,489,345); alien.setLocation(494,345); addObject(kamikaze,227,260); kamikaze.setLocation(228,260); } if(row == 1 && column == 3){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Platform platform1 = new Platform(4,1); Platform platform2 = new Platform(4,1); HiddenSpikes spi = new HiddenSpikes(); //Wall wall1 = new Wall(2,1); IncreaseLife increaseLife = new IncreaseLife(); IncreaseSpeed increaseSpeed = new IncreaseSpeed(); Kamikaze kamikaze = new Kamikaze(1,difficulty); Alien alien3 = new Alien(1,difficulty); Alien alien2 = new Alien(1,difficulty); Alien alien = new Alien(1,difficulty); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Kamikaze kamikaze3 = new Kamikaze(1,difficulty); //addObject(wall1,586,200); addObject(spi,249,201); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,300,200); addObject(increaseLife,544,173); addObject(increaseSpeed,547,352); increaseSpeed.setLocation(530,352); increaseLife.setLocation(530,173); addObject(alien,186,167); alien.setLocation(197,165); addObject(alien2,317,168); alien2.setLocation(326,166); addObject(alien3,434,172); alien3.setLocation(440,165); addObject(kamikaze,508,170); kamikaze.setLocation(509,163); addObject(gunslinger,225,351); gunslinger.setLocation(218,341); addObject(gunslinger2,358,340); gunslinger2.setLocation(364,340); addObject(kamikaze3,469,351); kamikaze3.setLocation(466,343); } if(row == 1 && column == 4){ setBackground("World/Backgrounds/galaxy.gif"); Platform platform0 = new Platform(4,1); Teleport t1 = new Teleport(); addObject(t1,560,325); addObject(platform0,300,383); } if(row == 2 && column == 0){ IncreaseSpeed sp = new IncreaseSpeed(); IncreaseLife lf = new IncreaseLife(); playBackGroundMusic(2); setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Wall wall1 = new Wall(3,1); HiddenSpikes spi = new HiddenSpikes(); addObject(wall1,14,200); addObject(platform0,300,10); addObject(platform1,300,383); addObject(sp,150,350); addObject(lf,200,350); addObject(spi,300,384); } if(row == 2 && column == 1){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(6,3); Platform platform3 = new Platform(6,3); Platform platform4 = new Platform(6,3); Platform platform5 = new Platform(6,3); Platform platform6 = new Platform(6,2); Wall wall1 = new Wall(3,2); Kamikaze kamikaze = new Kamikaze(0,difficulty); Gunslinger gunslinger = new Gunslinger(1,difficulty); Kamikaze kamikaze2 = new Kamikaze(0,difficulty); GiveLife giveLife = new GiveLife(); addObject(wall1,590,300); addObject(platform0,300,10); addObject(platform1,300,383); addObject(platform2,400,290); addObject(platform3,250,240); addObject(platform4,100,150); addObject(platform5,550,200); addObject(platform6,400,150); addObject(kamikaze,85,110); kamikaze.setLocation(150,110); addObject(gunslinger,473,342); gunslinger.setLocation(473,342); addObject(kamikaze2,260,200); kamikaze2.setLocation(266,200); addObject(giveLife,50,125); giveLife.setLocation(57,125); } if(row == 2 && column == 2){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(6,3); Platform platform3 = new Platform(6,3); Platform platform4 = new Platform(6,2); Platform platform5 = new Platform(6,2); Platform platform6 = new Platform(6,2); Wall wall1 = new Wall(3,2); IncreaseAtk increaseAtk = new IncreaseAtk(); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); Alien alien = new Alien(0,difficulty); addObject(platform2,50,200); addObject(platform3,100,230); addObject(platform4,100,260); addObject(platform5,160,290); addObject(wall1,9,300); addObject(platform0,300,10); addObject(platform1,300,383); addObject(increaseAtk,44,352); addObject(gunslinger,571,344); addObject(gunslinger2,520,325); gunslinger2.setLocation(533,343); addObject(kamikaze,484,345); kamikaze.setLocation(470,345); addObject(alien,160,347); } if(row == 2 && column == 3){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(6,2); Platform platform3 = new Platform(6,3); Platform platform4 = new Platform(6,2); Platform platform5 = new Platform(6,3); Platform platform6 = new Platform(6,3); //Wall wall1 = new Wall(3,1); Wall wall2 = new Wall(3,2); Gunslinger gunslinger = new Gunslinger(1,difficulty); Gunslinger gunslinger2 = new Gunslinger(1,difficulty); Gunslinger gunslinger3 = new Gunslinger(1,difficulty); Gunslinger gunslinger4 = new Gunslinger(1,difficulty); Alien alien = new Alien(0,difficulty); Alien alien2 = new Alien(1,difficulty); Kamikaze kamikaze = new Kamikaze(1,difficulty); Kamikaze kamikaze3 = new Kamikaze(1,difficulty); Kamikaze kamikaze4 = new Kamikaze(0,difficulty); Kamikaze kamikaze5 = new Kamikaze(1,difficulty); Kamikaze kamikaze6 = new Kamikaze(0,difficulty); GiveLife giveLife = new GiveLife(); addObject(platform2,300,300); addObject(platform3,500,250); addObject(platform4,250,200); addObject(platform5,10,135); addObject(platform6,250,120); //addObject(wall1,590,200); addObject(wall2,5,50); addObject(platform0,300,10); addObject(platform1,300,383); addObject(gunslinger,552,340); gunslinger.setLocation(552,340); addObject(gunslinger2,495,340); gunslinger2.setLocation(495,340); addObject(gunslinger3,446,340); gunslinger3.setLocation(447,340); addObject(gunslinger4,540,210); gunslinger4.setLocation(540,210); addObject(alien,120,163); alien.setLocation(147,163); addObject(alien2,374,163); alien2.setLocation(369,163); addObject(kamikaze,255,160); kamikaze.setLocation(262,160); addObject(kamikaze3,182,260); kamikaze3.setLocation(400,260); addObject(kamikaze4,181,260); kamikaze4.setLocation(184,260); addObject(kamikaze5,298,260); kamikaze5.setLocation(294,260); addObject(kamikaze6,231,260); kamikaze6.setLocation(234,260); addObject(giveLife,56,106); giveLife.setLocation(55,112); } if(row == 2 && column == 4){ setBackground("World/Backgrounds/Ship.png"); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); addObject(platform0,300,10); addObject(platform1,300,383); Teleport t1 = new Teleport(); addObject(t1,560,325); } if(row == 3 && column == 0){ playBackGroundMusic(3); setBackground("World/Backgrounds/Ship.png"); Wall wall1 = new Wall(3,1); Wall wall2 = new Wall(3,1); Platform platform0 = new Platform(5,1); Platform platform1 = new Platform(6,1); Platform platform2 = new Platform(5,3); Platform platform3 = new Platform(5,3); Platform platform4 = new Platform(5,3); Platform platform5 = new Platform(5,3); Boss1 boss1 = new Boss1(difficulty); addObject(platform3,196,350); addObject(platform4,355,303); addObject(platform5,503,253); addObject(platform0,300,10); addObject(platform1,300,383); addObject(wall1,16,200); addObject(wall2,584,200); addObject(boss1,300,300); } }
danpost danpost

2021/1/27

#
First, you need to import the GifImage class. Using main menu bar, select "Edit>>Import...", choose GifImage and click "Import" button. Next, you need a GifImage field in your Game class:
GifImage backgroundGif;
In each matrix case in prepare method, you will need either:
backgroundGif = null;
or
backgroundGif = new GifImage("World/Backgrounds/galaxy.gif");
setBackground(backgroundGif.getCurrentImage());
Finally, in act method of Game class, use:
if (backgroundGif != null) setBackground(backgroundGif.getCurrentImage());
ekosanji ekosanji

2021/1/28

#
I don't have an act method in my game class, what do I do? /** * The getColumn method returns the current column. * @return The current world column */ public int getColumn(){ return(column); } /** * The getRow method returns the current row. * @return The current world row. */ public int getRow(){ return(row); } /** * The setRow method sets the current row. * @param value The value of the row we want to apply. */ public void setRow(int value){ this.row = value; } /** * The stopped method avoids to reproduce many times the background music. */ @Override public void stopped() { stopBackGroundMusic(); } /** * The stopped method avoids to reproduce many times the background music. */ @Override public void started() { playBackGroundMusic(row); } /** * The setColumn method sets the current column. * @param value The value of the column we want to apply. */ public void setColumn(int value){ this.column = value; } /** * The maxColumn method returns the matrix height. * @return The current world max columns value. */ public int maxColumn(){ return(maxColum); } /** * The maxRow method returns the matrix width. * @return The current world max rows value. */ public int maxRow(){ return(maxRow); } }
danpost danpost

2021/1/28

#
ekosanji wrote...
I don't have an act method in my game class, what do I do?
Add one (overriding act in World).
ekosanji ekosanji

2021/1/28

#
Is this how it is written? or what? @Override public act setBackground() { if (backgroundGif != null) setBackground(backgroundGif.getCurrentImage()); }
danpost danpost

2021/1/29

#
ekosanji wrote...
Is this how it is written? or what? public act setBackground()
Change quoted line to:
public void act()
ekosanji ekosanji

2021/1/29

#
okay thank you, for helping me Even though I'm still a beginner doing it, I learned to make this game because I wanted to know how difficult it was to make a game. it turns out hard too huh?
You need to login to post a reply.