Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 / Newbie & Debugging Questions / Re: yet another keyboard input problem on: 2006-02-18 06:39:56
I just checked my keyboard with this: http://www.passmark.com/products/keytest.htm

The program doesn't get down+right+space either. I'll need to try other keyboards...  Angry

I found some combinations which allow u to press 7 keys at once, if you stick to a specific order pressing them. Other combinations allow only 2 keys at once. This is so annoying.

So I have to find a fire key that allows me to press two arrow keys (in any combination) simultaneously...
Can I then be sure that this works with all keyboards?

Thank you for your efforts so far!
Sorry for bothering you, but maybe there's a workaround? *hardly having any hope*
2  Game Development / Newbie & Debugging Questions / Re: yet another keyboard input problem on: 2006-02-18 05:56:03
This is what I do directly in the switch statement for VK_SPACE in keyPressed (I don't have a fire()-method(see above)):

1  
2  
3  
control.setFire(true)
bullet = new Bullet(ship.getXPos() + ship.getWidth()/2 - bullet.getWidth()/2 , ship.getYPos());
bulletList.add(bullet);

bulletList is an ArrayList.

The control class looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
class Control {
   // stores pressed keys
 
   private boolean up=false, down=false, right=false, left=false;
   private boolean fire=false, pause=false;
   
   public synchronized void setUp(boolean b) {up = b;}
   public synchronized void setDown(boolean b) {down = b;}
   public synchronized void setRight(boolean b) {right = b;}
   public synchronized void setLeft(boolean b) {left = b;}
   public synchronized void setFire(boolean b) {fire = b;}
   public synchronized void setPause(boolean b) {pause = b;}
   
   public synchronized boolean isUp() {return up;}
   public synchronized boolean isDown() {return down;}
   public synchronized boolean isRight() {return right;}
   public synchronized boolean isLeft() {return left;}
   public synchronized boolean isFire() {return fire;}
   public synchronized boolean isPause() {return pause;}
   
}


I don't do anything concernig the spacebar anywhere, the only appearances of the control class in the main loop (and anywhere else) are these:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
                                if (io.control.isRight()) 
               io.ship.setXSpeed(io.ship.getSPEED());
            else if (io.control.isLeft())
               io.ship.setXSpeed(-io.ship.getSPEED());
            else
               io.ship.setXSpeed(0);
           
            if (io.control.isDown())
               io.ship.setYSpeed(io.ship.getSPEED());
            else if (io.control.isUp())
               io.ship.setYSpeed(-io.ship.getSPEED());
            else
               io.ship.setYSpeed(0);


If I am not totally mistaken, that's exactly what you do...
3  Game Development / Newbie & Debugging Questions / Re: yet another keyboard input problem on: 2006-02-18 05:37:13
right+down works, as does e.g. right+up+space,  but right+down+space doesn't.

But never the less - that's a good idea, where do I get this JInput test prog, or how can I start it if it's shipped with the developer kit?
4  Game Development / Newbie & Debugging Questions / Re: yet another keyboard input problem on: 2006-02-18 05:17:01
I read somewhere that it's possible to change the system status of keys being pressed. Then they appear like released/not pressed, allthough they are actually held down. Does anyone know how to do this?
5  Game Development / Newbie & Debugging Questions / Re: yet another keyboard input problem on: 2006-02-18 05:09:42
Doesn't work with ifs neither, just tried it this way....

My initial idea was right, everytime you press a key the event is fired and the method keyPressed() is called. So it should work with switch.

Still don't have a clue why it works for  left+down, left+up, right+up. Only right+down doesn't work...

I start wondering if my Keyboard is f***ed, which I can't check right now. I'll try this tomorrow...

Concerning the breaks: they're kind of self-evident to me so I don't want to waste any space for them, but maybe your right to have better readability.
6  Game Development / Newbie & Debugging Questions / Re: yet another keyboard input problem on: 2006-02-18 04:04:19
I see the breaks  Roll Eyes
But thx for the first reply!
7  Game Development / Newbie & Debugging Questions / yet another keyboard input problem on: 2006-02-18 03:40:18
Hi there!

I just programmed my first game in java, a space-invaders like game where you control a spaceship and fire at some astroide-whatevers.

I designed the keyboard input in the following manner, and everything works fine. The problem appears when I hold down the right- and the down-arrow keys and want to fire(press space) simultaneously: the fire-method is not called, allthough this works with all other combinations of arrow keys.

class MyKeyListener extends KeyAdapter {

       public void keyPressed(KeyEvent ke) {
          
          switch(ke.getKeyCode()) {
          case KeyEvent.VK_RIGHT: 
              control.setRight(true);
              control.setLeft(false); break;
           case KeyEvent.VK_LEFT:   
              control.setLeft(true);
              control.setRight(false); break;
           case KeyEvent.VK_UP:   
              control.setUp(true);
              control.setDown(false); break;       
           case KeyEvent.VK_DOWN: 
              control.setDown(true);
              control.setUp(false); break;
           case KeyEvent.VK_SPACE:
              control.setFire(true);
              fire();
              break;   
              }
          }
       }
      
       public void keyReleased(KeyEvent ke) {
          switch(ke.getKeyCode()) {
           case KeyEvent.VK_LEFT: 
              control.setLeft(false); break;        
           case KeyEvent.VK_RIGHT: 
              control.setRight(false); break; 
           case KeyEvent.VK_UP:   
              control.setUp(false); break;       
           case KeyEvent.VK_DOWN: 
              control.setDown(false); break;
           case KeyEvent.VK_SPACE:
              control.setFire(false); break;
          }
       }
   }
}

I tried calling the fire()-method where I am working with the control.booleans for the movement of the ship, but  hitting the spacebar with these two keys down seems to have no effect at all.

So my question is if anyone knows why it's like that. Just a solution to the problem would also be satisfying to me Wink
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.

Riven (5 views)
2014-07-23 20:17:25

ctomni231 (39 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47

Riven (37 views)
2014-07-14 11:51:35

quew8 (33 views)
2014-07-13 13:57:52
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!