Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  changing entire screen after making selection  (Read 1124 times)
0 Members and 1 Guest are viewing this topic.
Offline Painguy

Senior Newbie





« Posted 2011-05-16 07:06:32 »

Hey its me again Tongue 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 Tongue thx in advance.

Main class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
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);
   }  
}
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-05-17 01:40:17 »

I can't seem to find where you handle key or mouse input. Where is your KeyInputHandler class? (btw, you mispelled Handler Wink)

EDIT: Have you thought about adding an "update(long)" method in LevelSelect and Menu? You could update your Animations from there instead of the game loop.

Offline Painguy

Senior Newbie





« Reply #2 - Posted 2011-05-17 03:17:48 »

Oh lol woops. didnt even notice that Tongue The update method sounds like a good idea, but it wouldn't neccesarily change anything right? I think ill fix that up once i get the basic game working.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class KeyInputHandeler extends KeyAdapter {
   public void keyPressed(KeyEvent e) {
      // if we're waiting for an "any key" typed then we don't
     // want to do anything with just a "press"
     if (Game.waitingForKeyPress) {
         return;
      }
      if (e.getKeyCode() == KeyEvent.VK_UP) {
         Game.upPressed = true;
      }
      if (e.getKeyCode() == KeyEvent.VK_DOWN) {
         Game.downPressed = true;
      }
      if (e.getKeyCode() == KeyEvent.VK_LEFT) {
         Game.leftPressed = true;
      }
      if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
         Game.rightPressed = true;
      }
      if(e.getKeyCode() == KeyEvent.VK_ENTER){
         Game.enterPressed = true;
      }
   }
   
   /**
    * Notification from AWT that a key has been released.
    *
    * @param e The details of the key that was released
    */

   public void keyReleased(KeyEvent e) {
      // if we're waiting for an "any key" typed then we don't
     // want to do anything with just a "released"
     if (Game.waitingForKeyPress) {
         return;
      }
      if (e.getKeyCode() == KeyEvent.VK_UP) {
         Game.upPressed = false;
      }
      if (e.getKeyCode() == KeyEvent.VK_DOWN) {
         Game.downPressed = false;
      }
      if (e.getKeyCode() == KeyEvent.VK_LEFT) {
         Game.leftPressed = false;
      }
      if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
         Game.rightPressed = false;
      }
      if(e.getKeyCode() == KeyEvent.VK_ENTER){
         Game.enterPressed = false;
      }
   }

   @Override
      public void keyTyped(KeyEvent e) {
         // if we hit escape, then quit the game

         if (e.getKeyChar() == 27) {
            System.exit(0);
         }
   }

   public void addKeyListner(KeyInputHandeler keyInputHandeler) {
      // TODO Auto-generated method stub
     
   }
   }

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2011-05-17 03:23:26 »

I looked over your code and everything looks like it should work fine. I don't notice any obvious errors or bugs. Try going through your code line by line using a debugger. Be careful of every variable and pay attention to what each line does.

Offline Painguy

Senior Newbie





« Reply #4 - Posted 2011-05-17 06:16:47 »

bad image again Tongue but now i have a new problem haha. so ummm after I load the level selector I setup some stuff to move the pointer around, but when i try it in the game the position isn't updated.

Here's the updated classes

Level Selector
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
import java.awt.Font;
import java.awt.FontFormatException;
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 {
   Font font;
   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;
   private Image h1,h2,h3;
   public Ani p,m,c,hand;
   public static int x =113, y=370;
   
   public void selection() throws InvalidMidiDataException, IOException, MidiUnavailableException, FontFormatException{
      if(Game.leftPressed){
         if(x==225 && y == 370){
            x=225;
            y=370;
         }
      if(Game.rightPressed){
         if(x==113 && y == 370){
            x=225;
            y=370;
         }
      }
      }
   }
   public void loadmap()throws InvalidMidiDataException, IOException, MidiUnavailableException, FontFormatException{
      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();
      h1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\h1.png").getImage();
       h2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\h2.png").getImage();
       h3 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Level Select\\h3.png").getImage();
       hand = new Ani();
      p = new Ani();
      m = new Ani();
      c = new Ani();
      hand.addScene(h1, 150);
       hand.addScene(h2, 150);
       hand.addScene(h3, 150);
      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(), 85, 420, null);
      g.drawImage(hand.getImage(), x, y, null);
   }  
}


Main
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
import java.awt.FontFormatException;
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;
   public Ani h;
   Sequence sequence;
   public Sequencer sequencer;
   
   public void selection() throws InvalidMidiDataException, IOException, MidiUnavailableException, FontFormatException{
      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.ls.loadmap();
         sequencer.stop();
         Game.levelselactive = true;
         Game.menuactive = false;
      }
   }
   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);  
      }
   }
}

sry for constantly asking questions Sad
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2011-05-17 18:30:09 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
if(Game.leftPressed){
            if(x==225 && y == 370){
                x=225;
                y=370;
            }
        if(Game.rightPressed){
            if(x==113 && y == 370){
                x=225;
                y=370;
            }
        }
        }

No duh the positions aren't changing, the X and Y values are the same! Tongue
Plus you forgot another bracket after the first "if(Game.leftPressed)" so "if(Game.rightPressed)" is inside the first if Tongue

Offline Painguy

Senior Newbie





« Reply #6 - Posted 2011-05-18 00:31:43 »

OH LAWL....i knew something was wrong with my IF statements. I was inthe proccess of chaning the x & y values tho. *sigh* i need to look more closely at these things. ok another question. When i call loadmap() I would like to unload everything from when I called loadmenu() so do i just set everything to null?
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2011-05-18 01:02:23 »

Setting the images to null should cause the Garbage Collector to reclaim them sooner or later so yes.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (14 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (59 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!