Hey its me again So what I’m trying to do is after i select play on my game it should end up going to a level selection screen. The problem is that when i click play my menu screen stays the same, and my level select background doesn’t show.
Heres the code. probably another stupid mistake thx in advance.
Main class
import java.awt.DisplayMode;
import java.awt.Graphics2D;
import java.io.IOException;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiUnavailableException;
public class Game{
public Renderer s;
public PlayerShip player= new PlayerShip();
public Menu m = new Menu();
public static LevelSelect ls = new LevelSelect();
private int moveSpeed = 5;
public static boolean playon = true;
public static boolean exiton = false;
public static boolean menuactive = true;
public static boolean levelselactive = false;
public static boolean waitingForKeyPress = false;
public static boolean upPressed = false;
public static boolean downPressed = false;
public static boolean rightPressed = false;
public static boolean leftPressed = false;
public static boolean enterPressed = false;
public boolean islooping = true;
private static final DisplayMode modes1[] = {
new DisplayMode(800,600,32,0),
new DisplayMode(800,600,24,0),
new DisplayMode(800,600,16,0),
new DisplayMode(640,480,32,0),
new DisplayMode(640,480,24,0),
new DisplayMode(640,480,16,0),
};;
public static void main(String argv[]) throws InvalidMidiDataException, IOException, MidiUnavailableException {
DisplayMode dm = new DisplayMode(800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
Game game = new Game();
game.run(dm);
}
public void run(DisplayMode dm2) throws InvalidMidiDataException, IOException, MidiUnavailableException{
s = new Renderer();
DisplayMode dm = s.find1stcompatmode(modes1);
s.setFullScreen(dm);
s.getFullScreenWindow().addKeyListener(new KeyInputHandeler());
s.getFullScreenWindow().requestFocus();
m.loadmenu();
menuactive = true;
long startTime = System.currentTimeMillis();
long cumTime = startTime;
while(islooping){
long timePassed = System.currentTimeMillis() - cumTime;
cumTime = System.currentTimeMillis();
Graphics2D g = s.getGraphics();
if(menuactive){
m.selection();
m.a.update(timePassed);
m.h.update(timePassed);
if(playon){
m.p.update(timePassed);
}
if(exiton){
m.e.update(timePassed);
}
m.draw(g);
g.dispose();
s.update();
}
if(levelselactive){
ls.p.update(timePassed);
ls.c.update(timePassed);
ls.m.update(timePassed);
ls.draw(g);
g.dispose();
s.update();
}
try{
Thread.sleep(10);
}catch(Exception ex){}
}
s.restoreScreen();
}
/*public void movieLoop(){
long startTime = System.currentTimeMillis();
long cumTime = startTime;
while(cumTime - startTime<2000){
long timePassed = System.currentTimeMillis() - cumTime;
cumTime = System.currentTimeMillis();
player.f.update(timePassed);
a.update(timePassed);
Graphics2D g = s.getGraphics();
draw(g);
g.dispose();
s.update();
try{
Thread.sleep(10);
}catch(Exception ex){}
}
}*/
}
Menu class
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.ImageIcon;
public class Menu {
private Image txt1;
private Image txt2;
private Image txt3;
private Image txt4;
private Image play;
private Image playselect;
private Image playselect1;
private Image exits, exits1, exit;
private Image hand, hand2, hand3;
private Image bg;
public static int x=310, y=430;
public Ani a,p,e,h;
Sequence sequence;
public Sequencer sequencer;
public void selection() throws InvalidMidiDataException, IOException, MidiUnavailableException{
if(Game.leftPressed){
x = 310;
y = 430;
Game.playon = true;
Game.exiton = false;
}
if(Game.rightPressed){
x=410;
y = 450;
Game.playon = false;
Game.exiton = true;
}
if(Game.exiton && Game.enterPressed){
System.exit(1);
}
if(Game.playon && Game.enterPressed){
Game.menuactive = false;
Game.levelselactive = true;
Game.ls.loadmap();
sequencer.stop();
}
}
public void loadmenu() throws InvalidMidiDataException, IOException, MidiUnavailableException{
sequence = MidiSystem.getSequence(new File("C:\\Users\\Nima\\workspace\\Computer Science Game\\Music_Sound\\fzero.mid"));
sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.setSequence(sequence);
sequencer.start();
play = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\playbutt.png").getImage();
playselect = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\playbutt.png").getImage();
playselect1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\playbutt2.png").getImage();
exit = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\exit1.png").getImage();
exits = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\exit1.png").getImage();
exits1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\exit2.png").getImage();
hand = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\h1.png").getImage();
hand2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\h2.png").getImage();
hand3 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\h3.png").getImage();
h = new Ani();
e = new Ani();
p = new Ani();
h.addScene(hand, 150);
h.addScene(hand2, 150);
h.addScene(hand3, 150);
e.addScene(exits, 150);
e.addScene(exits1, 150);
p.addScene(playselect, 160);
p.addScene(playselect1, 160);
bg = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\Untitled-2.jpg").getImage();
txt1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\uf.png").getImage();
txt2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\uf2.png").getImage();
txt3 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\uf3.png").getImage();
txt4 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Menu\\uf4.png").getImage();
a = new Ani();
a.addScene(txt1, 80);
a.addScene(txt2, 80);
a.addScene(txt3, 80);
a.addScene(txt4, 80);
a.addScene(txt3, 80);
a.addScene(txt2, 80);
a.addScene(txt1, 80);
}
public void draw(Graphics2D g){
g.drawImage(bg,0,0, null);
g.drawImage(a.getImage(), 50, 70, null);
g.drawImage(h.getImage(), x, y, null);
if(Game.playon){
g.drawImage(p.getImage(), 300, 408, null);
g.drawImage(exit, 400, 400, null);
}
if(Game.exiton){
g.drawImage(e.getImage(), 400, 408, null);
g.drawImage(play, 300, 408, null);
}
}
}
Level Select Class
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.ImageIcon;
public class LevelSelect {
private Image comet, comet1, comet2;
private Image map, map1, map2, map3;
private Image pl1, pl2,pl3, pl4,pl5,pl6,pl7,pl8,pl9,pl10,pl11,pl12,pl13,pl14;
public Ani p,m,c;
private int x =720, y=510;
public void selection(){
if(Game.leftPressed){
x = 60;
y = 510;
}
if(Game.rightPressed){
}
}
public void loadmap()throws InvalidMidiDataException, IOException, MidiUnavailableException{
Sequence sequence = MidiSystem.getSequence(new File("C:\\Users\\Nima\\workspace\\Computer Science Game\\Music_Sound\\SF64_Map-KM.mid"));
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.setSequence(sequence);
sequencer.start();
map = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\map.png").getImage();
map1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\map1.png").getImage();
map2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\map2.png").getImage();
map3 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\map3.png").getImage();
pl1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l1.png").getImage();
pl2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l2.png").getImage();
pl3 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l3.png").getImage();
pl4 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l4.png").getImage();
pl5 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l5.png").getImage();
pl6 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l6.png").getImage();
pl7 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l7.png").getImage();
pl8 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l8.png").getImage();
pl9 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l9.png").getImage();
pl10 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l10.png").getImage();
pl11 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l11.png").getImage();
pl12 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l12.png").getImage();
pl13 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l13.png").getImage();
pl14 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\l14.png").getImage();
comet = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\comet.png").getImage();
comet1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\comet2.png").getImage();
comet2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\comet3.png").getImage();
p = new Ani();
m = new Ani();
c = new Ani();
p.addScene(pl1, 100);
p.addScene(pl2, 100);
p.addScene(pl3, 100);
p.addScene(pl4, 100);
p.addScene(pl5, 100);
p.addScene(pl6, 100);
p.addScene(pl7, 100);
p.addScene(pl8, 100);
p.addScene(pl9, 100);
p.addScene(pl10, 100);
p.addScene(pl11, 100);
p.addScene(pl12, 100);
p.addScene(pl13, 100);
p.addScene(pl14, 100);
m.addScene(map, 80);
m.addScene(map1, 80);
m.addScene(map2, 80);
m.addScene(map3, 80);
c.addScene(comet,80);
c.addScene(comet1, 80);
c.addScene(comet2, 80);
}
public void draw(Graphics2D g){
g.drawImage(m.getImage(), 0, 0, null);
g.drawImage(p.getImage(), 60, 440, null);
g.drawImage(c.getImage(), x, y, null);
}
}