Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  input >_<  (Read 1566 times)
0 Members and 1 Guest are viewing this topic.
Offline Valodim

Junior Member




*sigh*


« Posted 2004-12-27 01:47:09 »

hey guys Smiley

started working on a 2d fighting game 2 weeks ago, got basic graphics, basic script parser and some other stuff done. next is input device handler...

since it's a fighting game, I need it to recognize commands like the wellknown QCF motion (for those who don't know: quarter circle forward. "hadouken"), and I have absolutely no idea where to start o_O
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #1 - Posted 2004-12-27 02:40:12 »

implement KeyListener, call addKeyListener(this) to whatever context you're using (Applet, Frame, etc), then:
1  
2  
3  
public void keyPressed(KeyEvent ke) {
      keyQueue.add(KeyEvent.KEY_PRESSED, ke.getKeyCode(), ke.getWhen());
}

where keyQueue is a key of some sort... you pick your data structure you wanna use.  The idea though is that you push all keys coming on to the top, and read them from the bottom and check to see if they make up a move.

Perhaps you could time so you only read from the queue every .2 seconds or something, which would account for your leniency for keys being pressed simultaneously.

So you start at the bottom whenever you decide to read from it and if a key on the queue begins in one of your special moves, then check further to see if that move was inputted.  If it does, evaluate that special move.  Otherwise, evaluate what the individual keys should do on their own.

To explain why I passed 3 parameters to the "add" method in that code snippet, consider what you want to know.  I passed whether or not the key was pressed or released, which key it was, and when exactly it happened.  This way you can have a move that has specific sequences such as: "Up, Down, Hold Punch & Forward, Kick, Kick, Release Punch, Kick, Release Forward".  With the structure I've given you, you can check if all of that has happened.

Put in some of that and see what you come up with.  I look forward to see what you do with this and what questions beyond this you might have!  Good luck Smiley

EDIT: typos

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Valodim

Junior Member




*sigh*


« Reply #2 - Posted 2004-12-27 16:15:07 »

just used this simple structure for the addQueue and it's very slow (wildly pressing buttons slows down the animations noticeable already)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void addQueue(int key, int pressed, long time){
    System.arraycopy(buffer, 0, buffer, 1, buffer.length-1);
    buffer[0] = new queuedEvent(key, pressed, time);
}

private class queuedEvent {
    public int key, pressed;
    public long time;

    queuedEvent(int key, int pressed, long time){
        this.key = key;
        this.pressed = pressed;
        this.time = time;
    }
}


I guess it's the array shifting which slows down the whole process... any idea on how to handle that more effectively? >_>
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #3 - Posted 2004-12-27 16:41:05 »

Oh wow, that is slow Smiley  Just stick the queued events on top.  You want to read them back in the order they came, so when you read them, start from the bottom.  The typical structure of a queue is that you keep one index to mark the front, and one index to mark the end.  You move them both up mod the length of the buffer.  Generally you waste 1 space because if the thing gets full and your beginning index is the same as the end index, your check for isFull() and isEmpty() will both return true Wink  Do some research on how to set up on efficient queue if that wasn't clear enough.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Valodim

Junior Member




*sigh*


« Reply #4 - Posted 2004-12-27 22:32:42 »

I keep getting this error

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
     at vMugen.keyPressed(vMugen.java:144)
     at java.awt.Component.processKeyEvent(Unknown Source)
     at java.awt.Component.processEvent(Unknown Source)
     at java.awt.Container.processEvent(Unknown Source)
     at java.awt.Window.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Window.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
     at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
     at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
     at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
     at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Window.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)

and I have no idea why. the line it points me to reads
       instances[0].cmd.addQueue(ke.getKeyCode(), KeyEvent.KEY_PRESSED, ke.getWhen());
which works fine, the error doesn't interrupt the program Angry
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #5 - Posted 2004-12-28 03:20:43 »

I guess you never initialize the element 0 in array instances

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Valodim

Junior Member




*sigh*


« Reply #6 - Posted 2004-12-28 10:34:29 »

I'm not that newless Tongue

it is initialized, I even get the System.out.println from the addQueue() method
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #7 - Posted 2004-12-28 14:51:02 »

give more code! Smiley

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Valodim

Junior Member




*sigh*


« Reply #8 - Posted 2004-12-29 01:31:03 »

*sigh* ok I'm more newless than I thought, works fine now... I forgot to initialize cmd in instance Roll Eyes

and it's faster now Smiley

ok, I thought I can handle it like this:

keyPressed passes the pressed keys to all instances' cmd, which adds the key to a queue (assuming it's one of the keys this instance uses).

now, if the parser finds a command trigger in some expression, it calls the trigger() method of the cmd, which processes using a copy of the input queue to check whether the command was pulled of or not.

problem: the buffer shouldn't be more than X events (100 or something), but calling
if(queue.size()>100)
 queue.remove();
doesn't seem very effective to me... is there any queue-type which automatically removes the oldest element if a certain number is exceeded?

I might put X dummy queue elements at the beginning and call remove() everytime... :|
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #9 - Posted 2004-12-29 03:23:31 »

do a google search for how to build an efficient queue.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #10 - Posted 2004-12-29 12:34:30 »

What you want is a circular list. i.e.:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
//Makes a queue that can contain 100 items
Object[] queue = new Object[100];
int pos = 0;

//returns locations behind the current one, starting at 1
public Object get(int i)
{
    int location = pos-i;

    if(location < 0) location += queue.length;

    return queue[location];
}

public void add(Object obj)
{
     queue[pos] = obj;
     pos = (pos + 1) % queue.length;
}

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Valodim

Junior Member




*sigh*


« Reply #11 - Posted 2004-12-29 14:17:49 »

I'll try that, thanks Cheesy
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.

E.R. Fleming (13 views)
2014-07-29 03:07:13

E.R. Fleming (4 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

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

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

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

MustardPeter (44 views)
2014-07-16 23:30:00
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!