Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (105)
games submitted by our members
Games in WIP (524)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Play & Game Design / Re: need help with pokedex QR code generator on: 2011-07-11 05:25:22
Do u know of any good tutorials? :/ I tried looking around but most of it isn't exactly helpful. I have a vague idea of whats going on.
2  Game Development / Game Play & Game Design / need help with pokedex QR code generator on: 2011-07-01 05:00:10
So basically what i'm trying to do is create a pokedex AR code generator. I already know how each is generated, but what i want to do is create a grid tht I would turn into an image. I don't need to generate an image. I could technically just draw the grid & leave it, but I want to learn a bit more. I know there are already programs tht do this, but i just wanted to have a wack at it myself. practice is important right? Tongue I could also directly draw this to the image instead of making a grid first. I was reading & apparently i have to use bufferedimages? i kinda get it, but can anyone elaborate?
3  Game Development / Game Play & Game Design / Re: Enemy for top down shooter on: 2011-05-29 18:55:41
already have that Sad although I'm not using switch statements. using if. could that be the problem?
---Edit----nope...not the problem.
4  Game Development / Game Play & Game Design / Re: Enemy for top down shooter on: 2011-05-29 04:40:41
No matter how slow, java.awt.geom.Area is also good Smiley

I'm not exactly sure on how to use that Sad I looked something up & its like...a shape inside a shape? lol idk

Quote
I need it to require you to let go in order to shoot again.
Set spacePressed to false when you fire.
I tried that & it works for like 5 secs then just stops working afterwards. Also I just recently noticed that I can't move diagonaly to my left & shoot at the same time. I have to do one or the other. Sorry to bombard you guys with questions. Its my first game so i gotz me lotz n lotz of questions
5  Game Development / Game Play & Game Design / Re: Enemy for top down shooter on: 2011-05-28 04:10:44
well it kinda worked. That got it to be a continuous stream, but if u hold the space button it still keeps shooting. I need it to require you to let go in order to shoot again. Also I've recently created a basic boss. I've kinda got that working, but I need to do some collision detection stuff which I've been having a hard time comprehending. I dont want to use the bounding box method for the boss sprite since its so large & has random gaps. How would I get a mask of the sprite? I have a feeling I have to ignore the transparency some how, but Im still new to all of this so I dont know how. I read somethign about getting RBG's of the sprite then storing them in an array or something...idk lol.
6  Game Development / Game Play & Game Design / Re: Enemy for top down shooter on: 2011-05-25 23:17:05
gaaahhh idk how to go about this delay thing Sad
7  Game Development / Game Play & Game Design / Re: Enemy for top down shooter on: 2011-05-24 23:00:53
Just to be clear your expected behavior is for the laser to go from the top of the screen down but keep the same x position as the player as the player moves? If it is then it looks like your code should work like that as long as its being called, maybe add a few System.out.println calls to check.

It seems odd that you are drawing the lasers and ship and them immediately moving them to a different position.

There is some nice game loop code in the tutorials section. Using BufferedImages is a lot better than using ImageIcon. Load your images once and reuse them for all the lasers, there is no reason to store multiple identical images in memory.
well i need to turn in this game on friday & since this is my first game I just want to get the very basics down. After I turn it in ill probably refine it. I'll make sure to checl those tutorials out Smiley. ok one other questio Tongue I got my bullets to work finnaly(i shoot them & once they go offscreen i remove them). What I want to do is force the player to press the shoot button to only get 1 shot. As of now if you press it 1 time it will shoot as long as you have the ur hand on space. thx in advance
8  Game Development / Game Play & Game Design / Re: Enemy for top down shooter on: 2011-05-24 10:03:30
@Zoto:
I think me means like the top-down scrollers where all the enemies fly in patterns past you.
IIRC Commando was also like this.

@OP:
You basically already have your answer.
Each wave will not only have the entities that move around, it would also have a 'waypoint' system upon which the entities move.
The waypoins would basically be a chain of vectors. i.e. Start @x/y and move to x1/y1, then x2/y2. etc pp.

For the shooting you could just put in a radius around the entity and when the player is in that radius, let the entities shoot with a random chance.
For 'shooting in the general direction' just add a random offset to the xp/yp.

I hope this is what you wanted to know.
alright so it was basically what I had in mind. before i get started on that tho i need to fix another problem i have. so i got started on shooting the laser, but I ran into some issues. every time i press space nothing happens. I've already created a counter of the number of times it goes thru & it seems to be working. idk whats wrong. if u dont mind I will post some of my code so u guys can review it. I feel like I'm doing all this inefficiently.

Game loop in Main. Check the level1 if statement portion.
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  
public void run(DisplayMode dm2) throws InvalidMidiDataException, IOException, MidiUnavailableException, FontFormatException{
      s = new Renderer();
      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);
         }
         if(levelselactive){
            ls.selection();
            ls.hand.update(timePassed);
            ls.p.update(timePassed);
            ls.c.update(timePassed);
            ls.m.update(timePassed);
            ls.draw(g);
         }
         if(level1){
            if(spacePressed){
               Laser shot = new Laser();
               shot.loadlasers();
               laser.add(shot);
            }
            if(!laser.isEmpty()){
               for(int i = 0; i<laser.size(); i++){
                  laser.get(i).las1.update(timePassed);
                  laser.get(i).drawlaser(g);
                  laser.get(i).move();
               }
            }
            l1.player.f.update(timePassed);
            l1.drawscroll(g);
            l1.player.drawship(g);
            l1.scroll();
            l1.player.move();
         }
         g.dispose();
         s.update();
         try{
            Thread.sleep(10);
         }catch(Exception ex){}
         }
         s.restoreScreen();
   }
}


Also here is my laser 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  
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;

class Laser {
   private Image blaser,blaser1,blaser2;
   public Ani las1;
   private int y;
   public void move(){
      y+=1;
   }
   public void loadlasers(){
      blaser = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Playership\\Laser\\blas1.png").getImage();
      blaser1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Playership\\Laser\\blas2.png").getImage();
      blaser2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Computer Science Game\\Sprites\\Playership\\Laser\\blas3.png").getImage();
      las1 = new Ani();
      las1.addScene(blaser, 20);
      las1.addScene(blaser1, 20);
      las1.addScene(blaser2, 20);
      y = PlayerShip.y+20;
   }
   public void drawlaser(Graphics2D g){
      g.drawImage(las1.getImage(), PlayerShip.x, y, null);
   }
}
9  Game Development / Game Play & Game Design / Enemy for top down shooter on: 2011-05-23 08:50:01
so im creating a top down shooter as my first game, and i have everything working except for a boss & enemies. What I'm wondering how to do is move the enemies down on the screen in those fancy patterns. Also how would I make enemies shoot in the general direction of the player. I have several ideas on how to do this, but I want the most sure fire way to go about this.
10  Java Game APIs & Engines / Java 2D / Re: changing entire screen after making selection on: 2011-05-18 02: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?
11  Java Game APIs & Engines / Java 2D / Re: changing entire screen after making selection on: 2011-05-17 08: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
12  Java Game APIs & Engines / Java 2D / Re: changing entire screen after making selection on: 2011-05-17 05: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
     
   }
   }

13  Java Game APIs & Engines / Java 2D / changing entire screen after making selection on: 2011-05-16 09: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);
   }  
}
14  Java Game APIs & Engines / Java 2D / Re: Need helping moving character on: 2011-05-16 02:24:11
I c. ok so Compenent is a superclass off all of the following "Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, TextComponent" & I wouldn't diretly imporat the Component package directly but rather one of its subclasses, right? I think what my main problem is is that I need to just improve me overall knowledge of the various parts of the Java API. I just dont know what I need to look up & what I dont. There are so many different things.
15  Java Game APIs & Engines / Java 2D / Re: Need helping moving character on: 2011-05-16 01:37:14
Oh...so addKeyListener is part of my frame? ok.. i have aways to go. I guess it just takes practice & continuous reading.
16  Java Game APIs & Engines / Java 2D / Re: Need helping moving character on: 2011-05-15 23:23:47
What is your exact compiler error? Also, you never seem to actually call "addKeyListener" O.o?
Well i did try to call addKeyListener, but it kept telling me "The method addKeyListener(KeyInputHandler) is undefined for the type Game". So i just got rid of it so I can work on the rest of my game until i figure that problem out.
17  Java Game APIs & Engines / Java 2D / Re: Need help loading images on: 2011-05-15 23:21:03
Im making a very naught program Tongue haha it means cumulative time haha. I don't blame you tho. All my friends were laughing when they saw that haha. It turns out that my Image was using something called Indexed color & I had to change it to RGB. My animations are working fine now Smiley
18  Java Game APIs & Engines / Java 2D / Re: Need help loading images on: 2011-05-14 22:39:20
Ok so apparently my images are messed up Tongue lol. Other pictures work fine. I just don't know exactly whats wrong with it. I can see it find on my picture viewer, but...when I load the image i can't see it at all.. I can't wait till I start to get the hang of this junk. Just remade the image
19  Java Game APIs & Engines / Java 2D / Re: Need helping moving character on: 2011-05-14 22:34:58
Ok so i did that but what my real problem is is that when i try to call addKeyListener it gives me errors saying it is undefined for game type & doesn't allow me to run my game

heres my new loop method.

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  
public void run(DisplayMode dm2){
      s = new Renderer();
      DisplayMode dm = s.find1stcompatmode(modes1);
      s.setFullScreen(dm);
      loadmenu();
      player.loadplayer();
      long startTime = System.currentTimeMillis();
      long cumTime = startTime;
      while(islooping){
         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();
         player.setHorizontalMovement(0);
         if ((leftPressed) && (!rightPressed)) {
            player.setHorizontalMovement(-moveSpeed);
         } else if ((rightPressed) && (!leftPressed)) {
            player.setHorizontalMovement(moveSpeed);
         }
         try{
            Thread.sleep(10);
         }catch(Exception ex){}
         }
         s.restoreScreen();
   }
20  Java Game APIs & Engines / Java 2D / Need helping moving character on: 2011-05-14 07:07:48
So i've gotten the very basics of my game working, but am having a hard time moving my character. I have my Inputmanager class, but I can't seem to use addKeyListner. Also is their anything else that seems problematic with my code?

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  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import javax.swing.ImageIcon;

public class Game {
   public Renderer s;
   public PlayerShip player= new PlayerShip();
   private Image bg;
   private Image txt1;
   private Image txt2;
   private Image txt3;
   private Image txt4;
   private Ani a;
   private int moveSpeed = 5;
   public boolean waitingForKeyPress = false;
   public boolean upPressed = false;
   public boolean downPressed = false;
   public boolean rightPressed = false;
   public boolean leftPressed = 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 void run(DisplayMode dm2){

      s = new Renderer();
      DisplayMode dm = s.find1stcompatmode(modes1);
      s.setFullScreen(dm);
      loadmenu();
      player.loadplayer();
      movieLoop();
      while(islooping){
         movieLoop();
         player.setHorizontalMovement(0);
         if ((leftPressed) && (!rightPressed)) {
            player.setHorizontalMovement(-moveSpeed);
         } else if ((rightPressed) && (!leftPressed)) {
            player.setHorizontalMovement(moveSpeed);
         }
      }
         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){}
         }
      }
   public void loadmenu(){
      bg = new ImageIcon("J:\\New folder (2)\\Untitled-2.jpg").getImage();
      txt1 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner.png").getImage();
      txt2 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner2.png").getImage();
      txt3 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner3.png").getImage();
      txt4 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner4.png").getImage();
      a = new Ani();
      a.addScene(txt1, 80);
      a.addScene(txt2, 80);
      a.addScene(txt3, 80);
      a.addScene(txt4, 80);
   }
   
   public void draw(Graphics2D g){
      g.drawImage(bg,0,0, null);
      g.drawImage(player.f.getImage(), player.getX() ,player.getY(), null);
      g.drawImage(a.getImage(), 400, 150, null);
   }
 class KeyInputHandler extends KeyAdapter {
   
   /**
    * Notification from AWT that a key has been pressed. Note that
    * a key being pressed is equal to being pushed down but *NOT*
    * released. Thats where keyTyped() comes in.
    *
    * @param e The details of the key that was pressed
    */

   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 (waitingForKeyPress) {
         return;
      }
      if (e.getKeyCode() == KeyEvent.VK_UP) {
         upPressed = true;
      }
      if (e.getKeyCode() == KeyEvent.VK_DOWN) {
         downPressed = true;
      }
      if (e.getKeyCode() == KeyEvent.VK_LEFT) {
         leftPressed = true;
      }
      if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
         rightPressed = 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 (waitingForKeyPress) {
         return;
      }
      if (e.getKeyCode() == KeyEvent.VK_UP) {
         upPressed = false;
      }
      if (e.getKeyCode() == KeyEvent.VK_DOWN) {
         downPressed = false;
      }
      if (e.getKeyCode() == KeyEvent.VK_LEFT) {
         leftPressed = false;
      }
      if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
         rightPressed = false;
      }
   }
   }
public static void main(String argv[]) {
   DisplayMode dm = new DisplayMode(800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
   Game game = new Game();
   game.run(dm);
}
}


Player 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  
import java.awt.Image;
import javax.swing.ImageIcon;

public class PlayerShip{
   public Ani f;
   Image sf1;
   Image sf2;
   Image sf3;
   int x=400;
   int y=150;
   int dy;
   int dx;
   public PlayerShip() {
   }
   public void setHorizontalMovement(int dx) {
      this.dx= dx;
   }
   public void setVerticalMovement(int dy) {
      this.dy= dy;
   }
   public double getHorizontalMovement() {
      return dx;
   }
   public double getVerticalMovement() {
      return dy;
   }
   public void move(long delta) {
      if ((dx < 0) && (x < 10)) {
         return;
      }
      if ((dx > 0) && (x > 780)) {
         return;
      }
      x += dx;
      y += dy;
   }
   public int getX() {
      return (int) x;
   }
   public int getY() {
      return (int) y;
   }
   public void loadplayer(){
      sf1 = new ImageIcon("C:\\Users\\Nima\\workspace\\Compsci Game\\Sprites\\Playership\\stable fight\\f1playerstable.png").getImage();
      sf2 = new ImageIcon("C:\\Users\\Nima\\workspace\\Compsci Game\\Sprites\\Playership\\stable fight\\f2playerstable.png").getImage();
      sf3 = new ImageIcon("C:\\Users\\Nima\\workspace\\Compsci Game\\Sprites\\Playership\\stable fight\\f3playerstable.png").getImage();
      f = new Ani();
      f.addScene(sf1, 25);
      f.addScene(sf2, 25);
      f.addScene(sf3, 25);
   }
}


Screen Manager
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  
108  
109  
110  
111  
112  
113  
114  
115  
import java.awt.*;
import javax.swing.JFrame;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;

public class Renderer{
   
   private GraphicsDevice vc;
   
   public Renderer(){
      GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
      vc = e.getDefaultScreenDevice();
   }
   
   public DisplayMode[] getCompatibleDisplayModes(){
      return vc.getDisplayModes();
   }
   
   public DisplayMode find1stcompatmode(DisplayMode modes[]){
      DisplayMode goodModes[] = vc.getDisplayModes();
      for(int x=0; x<modes.length; x++){
         for(int y =0; y<goodModes.length;y++){
            if(displayModeMatch(modes[x], goodModes[y])){
               return modes[x];
            }
         }
      }
      return null;
   }
   public DisplayMode getCurrentDisplayMode(){
      return vc.getDisplayMode();
   }
   public boolean displayModeMatch(DisplayMode m1, DisplayMode m2){  
      if(m1.getWidth() != m2.getWidth() || m1.getHeight() != m2.getHeight()){
         return false;
      }
      if(m1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && m2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && m1.getBitDepth() != m2.getBitDepth()){
         return false;
      }
      if(m1.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN && m2.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN && m1.getRefreshRate() != m2.getRefreshRate()){
         return false;
      }
      return true;
   }
   
   public void setFullScreen(DisplayMode dm){
      JFrame f = new JFrame();
      f.setUndecorated(true);
      f.setIgnoreRepaint(true);
      f.setResizable(false);
      vc.setFullScreenWindow(f);
      if(dm != null && vc.isDisplayChangeSupported()){
         try{
            vc.setDisplayMode(dm);
         }catch(Exception ex){}
      }
      f.createBufferStrategy(2);
   }
   
   public Graphics2D getGraphics(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         BufferStrategy s = w.getBufferStrategy();
         return(Graphics2D)s.getDrawGraphics();
      }else{
         return null;
      }
   }
   
   public void update(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         BufferStrategy s = w.getBufferStrategy();
         if(!s.contentsLost()){
            s.show();
         }
      }
   }
   public Window getFullScreenWindow(){
      return vc.getFullScreenWindow();
   }
   
   public int getWidth(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         return w.getWidth();
      }else{
         return 0;
      }
   }
   public int getHeight(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         return w.getHeight();
      }else{
         return 0;
      }
   }
   public void restoreScreen(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         w.dispose();
      }
      vc.setFullScreenWindow(null);
   }
   
   public BufferedImage createCompatibleImage(int w, int h, int t){
      Window win = vc.getFullScreenWindow();
      if(win != null){
         GraphicsConfiguration gc = win.getGraphicsConfiguration();
         return gc.createCompatibleImage(w,h,t);
      }
      return null;
   }
}


Animation 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  
import java.awt.Image;
import java.util.ArrayList;

public class Ani {
   
   private ArrayList<OneScene> scenes;
   private int sceneIndex;
   private long movieTime;
   private long totalTime;
   
   public Ani(){
      scenes = new ArrayList<OneScene>();
      totalTime = 0;
      start();
   }
   
   public synchronized void addScene(Image i, long t){
      totalTime+= t;
      scenes.add(new OneScene(i, totalTime));
   }
   public synchronized void start(){
      movieTime = 0;
      sceneIndex = 0;
   }
   
   public synchronized void update(long timePassed){
      if(scenes.size()>1){
         movieTime += timePassed;
         if (movieTime >= totalTime){
            movieTime = 0;
            sceneIndex = 0;
         }
         while(movieTime >  getScene(sceneIndex).endTime){
            sceneIndex++;
         }
      }
   }
   public synchronized Image getImage(){
      if(scenes.size()==0){
         return null;
      }else{
         return getScene(sceneIndex).pic;
      }
   }
   protected OneScene getScene(int x){
      return (OneScene)scenes.get(x);
   }
}
   class OneScene{
      Image pic;
      long endTime;
      public OneScene(Image pic, long endTime){
         this.pic = pic;
         this.endTime = endTime;
      }
}



21  Java Game APIs & Engines / Java 2D / Re: Need help loading images on: 2011-05-14 06:12:22
already tried that Sad
22  Java Game APIs & Engines / Java 2D / Re: Need help loading images on: 2011-05-14 04:32:30
oh i c sry about that.
yeah the animation doesn't run at all Sad
23  Java Game APIs & Engines / Java 2D / Re: Need help loading images on: 2011-05-14 04:13:03
In order to keep the number of new threads down I'll just ask my question here. I created another animation which I'm trying to load. this time i tried to not make any stupid mistakes Tongue Ill post the parts i changed. this is in the Game class only. I have everything loaded & playing except the new animation.
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  
   public void run(DisplayMode dm2){
      s = new Renderer();
      try{
         DisplayMode dm = s.find1stcompatmode(modes1);
         s.setFullScreen(dm);
         loadmenu();
         player.loadplayer();
         movieLoop();
      }finally{
         s.restoreScreen();
      }
   }
   public void movieLoop(){
      long startTime = System.currentTimeMillis();
      long cumTime = startTime;
      while(cumTime - startTime<2000){
         long timePassed = System.currentTimeMillis() - cumTime;
         cumTime += timePassed;
         player.f.update(timePassed);
         a.update(timePassed);
         Graphics2D g = s.getGraphics();
         draw(g);
         g.dispose();
         s.update();
         try{
            Thread.sleep(10);
         }catch(Exception ex){}
         }
      }
   public void loadmenu(){
      bg = new ImageIcon("J:\\New folder (2)\\Untitled-2.jpg").getImage();
      txt1 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner.png").getImage();
      txt2 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner2.png").getImage();
      txt3 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner3.png").getImage();
      txt4 = new ImageIcon("C:\\Users\\Nima\\workspace\\ulimate gunner4.png").getImage();
      a = new Ani();
      a.addScene(txt1, 80);
      a.addScene(txt2, 80);
      a.addScene(txt3, 80);
      a.addScene(txt4, 80);
   }
   
   public void draw(Graphics2D g){
      g.drawImage(bg,0,0, null);
      g.drawImage(player.f.getImage(), 400,450, null);
      g.drawImage(a.getImage(), 400, 150, null);
   }

thx in advance.
24  Java Game APIs & Engines / Java 2D / Re: Need help loading images on: 2011-05-13 04:08:06
OH LOL thx guys. Im such an idiot. I cant believe i didnt initialize the object lol. Yeah i got that class from thenewboston Tongue I figured I might aswell get started somewhere. thx guys I RLY appreciate it Cheesy
25  Java Game APIs & Engines / Java 2D / Need help loading images on: 2011-05-12 23:01:29
hey guys so im starting my first java game & I ran into a problem. What I'm trying to do do is load the sprites from the player class then run them in the main. Im gonna have 2 more classes for enemies doing the same thing. here is my code so u can see. Here's the error.

Exception in thread "main" java.lang.NullPointerException
        at Game.run(Game.java:41)
        at Game.main(Game.java:32)

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  
import java.awt.*;
import javax.swing.ImageIcon;

public class Game {
   public Renderer s;
   public PlayerShip player;
   private Image bg;
   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 Ani f;
   Image sf1;
   Image sf2;
   Image sf3;
   public static void main(String argv[]) {
      DisplayMode dm = new DisplayMode(300, 240, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
      Game g = new Game();
      g.run(dm);
   }

   public void run(DisplayMode dm2){
      s = new Renderer();
      try{
         DisplayMode dm = s.find1stcompatmode(modes1);
         s.setFullScreen(dm);
         bg = new ImageIcon("C:\\Documents and Settings\\n17289\\My Documents\\JCreator LE\\MyProjects\\CompSci Game\\Sprites\\Hard Vacuum\\Misc\\Test2.bmp").getImage();
         player.loadplayer();
         movieLoop();

      }finally{
         s.restoreScreen();
      }
   }
   public void movieLoop(){
      long startTime = System.currentTimeMillis();
      long cumTime = startTime;
      while(cumTime - startTime<2000){
         long timePassed = System.currentTimeMillis() - cumTime;
         cumTime += timePassed;
         //player.f.update(timePassed);
        Graphics2D g = s.getGraphics();
         draw(g);
         g.dispose();
         s.update();
         try{
            Thread.sleep(10);
         }catch(Exception ex){}
         }
      }
   public void draw(Graphics g){
      g.drawImage(bg,0,0, null);
      //g.drawImage(f.getImage(), 540,405, null);
  }

}

Player clas
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
import java.awt.*;
import javax.swing.ImageIcon;
public class PlayerShip{
   public Ani f;
   Image sf1;
   Image sf2;
   Image sf3;

   public PlayerShip() {
   }

   public void loadplayer(){
      sf1 = new ImageIcon("C:\\Documents and Settings\\n17289\\My Documents\\JCreator LE\\MyProjects\\CompSci Game\\Sprites\\ayership\\stable fight\\f1playerstable.png").getImage();
      sf2 = new ImageIcon("C:\\Documents and Settings\\n17289\\My Documents\\JCreator LE\\MyProjects\\CompSci Game\\Sprites\\ayership\\stable fight\\f2playerstable.png").getImage();
      sf3 = new ImageIcon("C:\\Documents and Settings\\n17289\\My Documents\\JCreator LE\\MyProjects\\CompSci Game\\Sprites\\ayership\\stable fight\\f3playerstable.png").getImage();
      f = new Ani();
      f.addScene(sf1, 250);
      f.addScene(sf2, 250);
      f.addScene(sf3, 250);
   }
}

Screen 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  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
import java.awt.*;
import javax.swing.JFrame;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;

public class Renderer{
   
   private GraphicsDevice vc;
   
   public Renderer(){
      GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
      vc = e.getDefaultScreenDevice();
   }
   
   public DisplayMode[] getCompatibleDisplayModes(){
      return vc.getDisplayModes();
   }
   
   public DisplayMode find1stcompatmode(DisplayMode modes[]){
      DisplayMode goodModes[] = vc.getDisplayModes();
      for(int x=0; x<modes.length; x++){
         for(int y =0; y<goodModes.length;y++){
            if(displayModeMatch(modes[x], goodModes[y])){
               return modes[x];
            }
         }
      }
      return null;
   }
   public DisplayMode getCurrentDisplayMode(){
      return vc.getDisplayMode();
   }
   public boolean displayModeMatch(DisplayMode m1, DisplayMode m2){  
      if(m1.getWidth() != m2.getWidth() || m1.getHeight() != m2.getHeight()){
         return false;
      }
      if(m1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && m2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && m1.getBitDepth() != m2.getBitDepth()){
         return false;
      }
      if(m1.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN && m2.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN && m1.getRefreshRate() != m2.getRefreshRate()){
         return false;
      }
      return true;
   }
   
   public void setFullScreen(DisplayMode dm){
      JFrame f = new JFrame();
      f.setUndecorated(true);
      f.setIgnoreRepaint(true);
      f.setResizable(false);
      vc.setFullScreenWindow(f);
      if(dm != null && vc.isDisplayChangeSupported()){
         try{
            vc.setDisplayMode(dm);
         }catch(Exception ex){}
      }
      f.createBufferStrategy(2);
   }
   
   public Graphics2D getGraphics(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         BufferStrategy s = w.getBufferStrategy();
         return(Graphics2D)s.getDrawGraphics();
      }else{
         return null;
      }
   }
   
   public void update(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         BufferStrategy s = w.getBufferStrategy();
         if(!s.contentsLost()){
            s.show();
         }
      }
   }
   public Window getFullScreenWindow(){
      return vc.getFullScreenWindow();
   }
   
   public int getWidth(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         return w.getWidth();
      }else{
         return 0;
      }
   }
   public int getHeight(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         return w.getHeight();
      }else{
         return 0;
      }
   }
   public void restoreScreen(){
      Window w = vc.getFullScreenWindow();
      if(w != null){
         w.dispose();
      }
      vc.setFullScreenWindow(null);
   }
   
   public BufferedImage createCompatibleImage(int w, int h, int t){
      Window win = vc.getFullScreenWindow();
      if(win != null){
         GraphicsConfiguration gc = win.getGraphicsConfiguration();
         return gc.createCompatibleImage(w,h,t);
      }
      return null;
   }
}

Animation 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  
import java.awt.Image;
import java.util.ArrayList;

public class Ani {
   
   private ArrayList<OneScene> scenes;
   private int sceneIndex;
   private long movieTime;
   private long totalTime;
   
   public Ani(){
      scenes = new ArrayList<OneScene>();
      totalTime = 0;
      start();
   }
   
   public synchronized void addScene(Image i, long t){
      totalTime+= t;
      scenes.add(new OneScene(i, totalTime));
   }
   public synchronized void start(){
      movieTime = 0;
      sceneIndex = 0;
   }
   
   public synchronized void update(long timePassed){
      if(scenes.size()>1){
         movieTime += timePassed;
         if (movieTime >= totalTime){
            movieTime = 0;
            sceneIndex = 0;
         }
         while(movieTime >  getScene(sceneIndex).endTime){
            sceneIndex++;
         }
      }
   }
   public synchronized Image getImage(){
      if(scenes.size()==0){
         return null;
      }else{
         return getScene(sceneIndex).pic;
      }
   }
   protected OneScene getScene(int x){
      return (OneScene)scenes.get(x);
   }
}
   class OneScene{
      Image pic;
      long endTime;
      public OneScene(Image pic, long endTime){
         this.pic = pic;
         this.endTime = endTime;
      }
}

thx in advance guys. Im probably gonna be back with more questions
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

SHC (24 views)
2014-07-12 17:50:04

Riven (31 views)
2014-07-10 20:20:18

CopyableCougar4 (29 views)
2014-07-10 02:26:14

CopyableCougar4 (32 views)
2014-07-09 02:55:38

Code Mage (33 views)
2014-07-08 23:57:00

Code Mage (20 views)
2014-07-08 23:49:08

AppleSauce (28 views)
2014-07-08 19:25:32

CopyableCougar4 (29 views)
2014-07-06 01:51:26

ipe369 (35 views)
2014-07-05 14:18:25

vastrolorde (44 views)
2014-07-04 18:45:44
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!