How 2 implement keyboard controls for 2 players simultaneusly in java game?

I ' m making this fighting game . 2 players can fight at a time. I got my 2 characters on the screen at the same time. The 1st player should be controlled with Arrow keys and number key pad.
The 2nd player should be controlled with Z for left C for RIGHT , S for UP( jump), X for duck. and then use BNM, GHJ and TYU to do the same as the number keys for the first player
When i tried this , it worked if i performed moves from player 1 , then trie d player 2,, but i noticed when i pushed buttons at the same time ( i pushed one key from player 1 's side of the keyboard and one key from player 2's side) it did't work because no move was executed. And i know it's because i'm pushing 2 keys at once . so one character sees that i'm pushing 2 keys, but he doesn't know what to do cause i didn't make a case of pushing 2 keys that would move him and another character.
So i have this in keyDown()
//THIS IS FOR 1 PLAYER MODE : you against enemy
switch( key){
case Even.UP:
if( player1 is michaelCharacter ){
michaelCharacter.jump()
else if( player1 is johnsonCharacter){
johnsonCharacter.jump();
break;
etcc... all player 1 keys in this way, acconrding to which character he chose to play with
//then i have this swich that supposedly is used if there is a second player
if( gameType = 2Player mode ){
switch( key ){
case 's':
if( player2 = michaelChacter)
michaelCharacter.jump():
if( player2 = johnsonCharacter)
johnsoncharacter.jump();
break;
//etc
So that works if each character does his move But there is no overlap of moves, that is you don't have player1 and player2 executing a move at the same time.
well, how would i do it? Is it possible ?

Hi,
It's bit tricky to do check keyboard simultaneously...
you need to check KeyPressed() and KeyReleased(), and do a "log key-event history" to find out what keys are still in pressed.
alternatively,
If you don't mind, you can use Fly game library...
initialisation part:
// initialisation & make game screen resolution to 800x600
Game g = new Game();
g.init(800,600,false);
...and then on your key trapping logic, just do a standard logic. I'm surely it will works:
if (g.getKeyboard().isKeyPressed(KeyEvent.VK_UP)) {
if (g.getKeyboard().isKeyPressed(KeyEvent.VK_DOWN)) {
}the library can be downloaded here:
[Fly Game Engine|http://fly.engine.googlepages.com]
Just follow the tutorial / download example for more info....
good luck

Similar Messages

  • Implementing keyboard control on a window

    Hi, I'm currently trying to implement keyboard control for a tetris game I'm attempting to make, but I've done it a rather dodgy way. I've implemented it on a Jpanel instead.
    What I want to do is, implement the keyboard control on the window, however I've been unable to do so. I'm new to java (this is quite an ambitious project - but I'm trying to learn) so any help would be really appreciated.
    This is the code for constructing the window with the Panels:
    please note: I have omitted the import statements.
    public class MainWindow extends JFrame
        public MainWindow()
            setTitle("Tetris!");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            Container contentPane;
            contentPane = this.getContentPane();
            contentPane.setLayout(new BorderLayout());
            Game game;
            game = new Game(10, 20);
            GameView gameView = new GameView(game);
            contentPane.add(gameView, BorderLayout.CENTER);
            InfoPanel infoPanel = new InfoPanel(game);
            contentPane.add(infoPanel, BorderLayout.EAST);
            KeyboardControl keyboardControl = new KeyboardControl(game);
            contentPane.add(keyboardControl, BorderLayout.SOUTH);
            this.pack();
            game.start();
    }This is the code for the keyboard control:
    public class KeyboardControl extends JPanel implements KeyListener
        private Game game;
        public KeyboardControl(Game game)
            this.game = game;
            setLayout(new GridLayout(0,-1));
            setFocusable(true);
            addKeyListener(this);
        public void keyPressed(KeyEvent event)
               int key = event.getKeyCode();
                if (key == event.VK_LEFT)
                    // Move the block left
                    game.moveLeft();
                    else if (key == event.VK_RIGHT)
                        // Move the block right
                        game.moveRight();
                        else if (key == event.VK_UP)
                            // Rotate the block
                            game.rotate();
                            else if (key == event.VK_DOWN)
                                // Drop the block
                                game.drop();
        public void keyReleased(KeyEvent event)
        public void keyTyped(KeyEvent event)
    }Can anyone provide any hints and sites to look at? I've been through the java tutorials, and the above is what I have achieved.

    Your implementation of the keyboard control (or listener) looks correct.
    To change it to listen to keyword on the window, would require only a
    small change.. See below code.
    public class MainWindow extends JFrame implements KeyListener
        public MainWindow()
            setTitle("Tetris!");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            Container contentPane;
            contentPane = this.getContentPane();
            contentPane.setLayout(new BorderLayout());
            Game game;
            game = new Game(10, 20);
            GameView gameView = new GameView(game);
            contentPane.add(gameView, BorderLayout.CENTER);
            InfoPanel infoPanel = new InfoPanel(game);
            contentPane.add(infoPanel, BorderLayout.EAST);
           addKeyListener(this);      
            //KeyboardControl keyboardControl = new KeyboardControl(game);
            //contentPane.add(keyboardControl, BorderLayout.SOUTH);
            this.pack();
            game.start();
       public void keyPressed(KeyEvent event)
               int key = event.getKeyCode();
                if (key == event.VK_LEFT)
                    // Move the block left
                    game.moveLeft();
                    else if (key == event.VK_RIGHT)
                        // Move the block right
                        game.moveRight();
                        else if (key == event.VK_UP)
                            // Rotate the block
                            game.rotate();
                            else if (key == event.VK_DOWN)
                                // Drop the block
                                game.drop();
        public void keyReleased(KeyEvent event)
        public void keyTyped(KeyEvent event)
    }

  • How to implement Ajax toolkit for SharePoint2013?

    Hi All,
    How to implement Ajax toolkit for SharePoint2013?

    Hi Sam,
    Based on your description,
    I can suggest as follows:
    Use the “SharePoint AJAX 3.5 for 2010 and 2013”
    solution.
    Download URL:
    http://sharepointajax.codeplex.com/
    2.    
    Use the Ajax Control Toolkit with ASP.NET 4.5.
    Download correct version of Ajax Control Toolkit.
    http://ajaxcontroltoolkit.codeplex.com/releases/view/109918
    Add AjaxControlToolkit.dll reference to your project.
    Add Ajax Control Toolkit ScriptManager in master page.
    Register Ajax Control Toolkit namespaces in SharePoint package Designer.
    More information:
    http://timscyclingblog.wordpress.com/2013/03/22/ajaxcontroltoolkit-version-7-0123-with-net-4-5/
    http://sampathnarsingam.blogspot.in/2012/05/how-to-make-ajax-control-toolkit.html
    Please inform me freely if you have any questions.
    Thanks
    Qiao Wei
    TechNet Community Support
    Is it possible to use version AJAX
    Control Toolkit .NET 4.5 along with SharePoint 2013?
    As far as I know with SharePoint we can use only version AjaxControlToolkit(3.0.30930.0). Isnt it?

  • How to implement Change pointers for Purchase order - ME22N - Custom Fields

    Hi Experts,
    Can you please tell me how to implement - Change Pointer for Custom fields in IDOC.
    I am working on IDOC - For purchase order - acknowledgements - in custom screen/tab in ME22N.
    Everything is working fine according to my requirement.
    All i need to know is the process of - Creating/Change - Change pointers for Custom fields.
    1.How to implement change pointers for custom fields.
    2.Can we maintain - Change Document - for custom fields at data element level?
    P.S. - I have browsed many previous - forums before posting a new discussion.
    please share your inputs...
    explaining how to create/implement - change pointers for custom fields will help me .
    Regards,
    Karthik Rali.

    Hi,
    To maintain Change Document for custom field:
    1. Check if "Change document" checkbox is set in data element.
    2. Find Change Document Object for transaction.
       You can use SQL trace - ST05.
       Look there for line with table CDHDR and statement insert values
       (for example for transaction KA02 Change Document Object is KSTAR)
    3. Regenerate update program for this Change Document Object in transaction SCDO
    Change documents for z-fields schould be generated.
    I am not sure about change pointers but they are configured somehow in BD61 and BD50.

  • How to add keyboard control key to menu bar as shown

    how to add keyboard control key to menu bar as shown bellow
    Please help

    why, nobody can give me any suggestion?!
    I want to know how to get the specific Control from the Line which does not has this kind of Control. Currently, I met this problem -- the line does not support EnumControl.Type.REVERB, however, I want to exert the reverb control to the line.
    please. thank you very much!

  • How to add keyboard control on our tree.

    hi,
    any body can kindly tell me that how can we add keyboard control on out tree widget.
    I am also anxious to know that when I compiled and loaded the PnlTreeView sample in Debug mode, keyboard control on this panel was also not working fine, it worked sometime and not on the other.
    Can anybody help me for the above 2 questions.

    There's no calendar control per-se, but you have an option - create an HTML image-map prompt - that should work....the only problem would be making it dynamic, but I'm sure you can create a big image map

  • How to Install Grid control for 10g (WINDOWS)

    Dear All,
    This is the first time i am going to test on Grid control. i have lot of droughts from the beginning...
    what is the first step to install, database or grid control tool.(*Windows*)
    i am downloading the below software from e-delivery
    Oracle Enterprise Manager 10g Release 5 Grid Control (10.2.0.5.0) Patch for Microsoft Windows (32-bit) (Part 1 of 2)      V15628-01 Part 1 of 2      1.1G
    Oracle Enterprise Manager 10g Release 5 Grid Control (10.2.0.5.0) Patch for Microsoft Windows (32-bit) (Part 2 of 2)      V15628-01 Part 2 of 2      1.1G
    Is the above software containing _10g database alone_, or its with Grid control, if its with grid control kindly let me know how to install ,, kindly don't give me oracle documents. please explain me int his blog itself or some different blogs.
    Any one explain me what is the step i have to take after this,, ??
    Thanks
    Abdull
    Edited by: user9111553 on Nov 23, 2010 12:01 AM

    Hi Miguel,
    Could you help me? Full and base version of what?
    For instance, i have Oracle 10.2.0.4 version and did not check EM during instalation oracle sw. So what is the first step to install and configure Grid Control? i downloaded Grid Control and read readme file. There is information that i need to install OEM and then Grid Control. did i understand right way or misunderstood? could you show me steps for implement Grid Control with 10g on Windows?
    regards and thanks,
    rustam

  • How to change keyboard shortcut for cycle through open tabs in PS and AI CC 2014

    I would love to set my own keyboard shortcuts for cycling through open tabs in PS and AI 2014 on OS X. I found out that this can be achieved with ctrl+tab in PS, but I couldn't manage to make any of the suggestions in the forum work for AI. As said, I would like to set a more "standard" shortcut like alt+cmd+arrow-keys for both of the apps. If that shouldn't be possible, does anyone know a shortcut in AI CC 2014?
    Many thanks!
    Amadeus

    Thanks! The shortcut can be set like this in AI, although all key combinations I would want to use are not allowed. Too bad. But anyways, thank you very much for the tip!
    cmd+~ is not an option for me, I guess, since the swiss/german keyboard layout has no dedicated tilde key.
    So, I have a working shortcut in PS (ctrl+tab / of which I still don't know how to change, if possible at all) and thanks to you, I can now set one in AI as well. Unfortunately, I can not set it to be identical as in PS, since the "cmd" key needs to be included in AI's shortcut assignment dialogue, but I guess, this is as good as it gets.

  • How to implement tool-tip for the list items for the Choice column in SharePoint 2013

    I had created a simple list with a "Choice" column, i have three entries in my drop-down, 
    First Entry
    Second Entry
    Third Entry.
    If i select any entries in drop-down and hour-over (Second Entry), a
    tool-tip need need to show. 
    Is it possible? If yes how to implement any help will be appreciated.

    Hi,
    We can use JavaScript to achieve it.
    The following code for your reference:
    <script type="text/javascript" src="/sites/DennisSite/Shared%20Documents/js/wz_tooltip.js"></script>
    <script type="text/javascript" src="/sites/DennisSite/Shared%20Documents/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
    $(function () {
    $("select[title='Choice']").change(function(){
    Tip($(this).val());
    $("select[title='Choice']").mouseout(function(){
    UnTip();
    </script>
    Download wz_tooltip.js:
    http://www.walterzorn.de/en/tooltip/tooltip_e.htm#download
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How to implement SEARCH HELP for input field in WDA

    Hi All,
    I am doing a tool for my team. in this tool there are 4 input fields to show different processes. I implemented the 4 input fields and also bind the respective tables to these fields successfully. Actually I want to filter the data between 2 fields . Means the data in the 2nd input field should be based on the 1st input field. Means when I'll select for example 'CHI' (code for CHINA) in the 1st input field the 2nd field meant for country name should show all country name with value 'CHINA'. But the problem is that all values related to each field are in different table with no foreign key relationship and also some combinations are in single table..
    I have tried the import and export parameter method for search help but no luck till now.
    Can anyone please suggest me how to implement this scenario..
    Thanks in advance...
    sekhar

    Hi sekhar,
    Your Requirement can be implemented by OVS(Object Value selector) This is the custom search help .So that you can define on what basis the value has to be fetched.
    Look at the below link
    http://wiki.sdn.sap.com/wiki/display/WDABAP/ABAPWDObjectValueSelector(OVS)
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/606288d6-04c6-2c10-b5ae-a240304c88ea?quicklink=index&overridelayout=true
    You need to use the component WDR_OVS.
    It has 3 phases
    In phase 1
         You will fetch the value from input field to F4 help dialog box.
    In phase 2
         You will generate the search results , in this phase look for the input value given in field 2 and accordingly generate search result for the field 3.
    In phase 3
         The selected value will be returned to the original screen.
    Regards
    Karthiheyan M

  • How to implement password policy for a software in oracle (sql) forms & reports 6i ?

    Hi all , I have to implement password policy for an already existing software which was created 2 to 3 years before.
    What exactly i want to do is I must alert the user every month to change his/her password. I have no idea about it.
    Can anyone help me how to start with it? Or can you provide me the links where i can learn & implement in the software?
    Oracle Forms & Reports Builder 6i.
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production.
    Thank You.

    You can try this:
    Establishing Security Policies
    Using database policy, you can force user to change password with Oracle forms 6i.
    Regards

  • How to enable keyboard shortcuts for configuration entry point?

    Hello All,
        In my process model, I have a configuration entry point sequence (sequence). I can able to select the corresponding entry from the menu bar ie. configure --> options (for eg). Now I need to have a keyboard shortcut for the same. In my case if I press (for eg) ctrl+w, the configuration entry point sequence must be called.
    Note - I have to do this using .NET programmatically.
    Is there any way I can incorporate this mechanism...?
    Thanks
    Arun

    Hello Arun,
    At this time there is not anyway to customize the keyboard shortcut keys for menu items you add to the TestStand sequence editor.  R&D is looking into implementing this in a future version of TestStand.  I'll pass along your feedback to them, and let them know there are others interrested in this feature.
    Kristen
    National Instruments

  • How to implement parent entity for core data

    Hi there.
    I am starting a document-based Core Data application (Cocoa) and developed the following data model;
    The 'invoice' entity is a parent entity of 'items', because ideally I would want there to be many items for each invoice. I guess my first point here is - is what I am trying to do going to be achieved using this method?
    If so, I have been trying several ways in Interface Builder to sort out how to implement this structure with cocoa bindings. I have made a Core Data app before, just with one entity. So this time, I have two separate instances of NSArrayController's connected to tables with relevant columns. I can add new 'invoice' entities fine, but I can't get corresponding 'items' to add.
    I tried setting the Managed Object Context of the 'item' NSArrayController to this;
    I thought this would resolve the issue, but I still have found no resolution to the problem.
    If anyone done something similar to this, I'd appreciate any help
    Thanks in advance,
    Ricky.

    Second, when you create a Core Data Document Based application, XCode generates the MyDocument class, derivating from NSPersistentDocument. This class is dedicated to maintain the Managed Object Model and the Managed Object Context of each document of your application.
    There is only one Context and generally one Model for each Document.
    In Interface Builder, the Managed Object Context must be bound to the managedObjectContext of the MyDocument instance: it's the File's owner of the myDocument.xib Nib file.
    It's not the case in your Nib File where the Managed Object Context is bound to the invoiceID of the Invoice Controller.
    It's difficult to help you without an overall knowledge of your application, perhaps could you create an InvoiceItem Controller and bind its Content Set to the relationship of your invoice.

  • How-To Microsoft Keyboard Elite for Bluetooth in Solaris 10 x86 10/08

    Dear all,
    I have a MS keyboard elite for bluetooth install in XP and it's working fine.
    But how can i configure and use this keyboard in my Solaris environment?
    My Setup:
    - Dell Optiplex GX270 PC.
    - Solaris 10 x86 10/08
    - MS keyboard elite for bluetooth
    Thanks in advance for any help.
    Regards,
    Alisampras

    Assuming you have enabled the solaris volume manager (man vold), you should be able to simply pop the pen drive in and find it mounted on /vol

  • How to Implement Screen Exits for MK01...

    Hi All,
    I have to implement screen exits for Tcode MK01.
    There is a BADI namely VENDOR_ADD_DATA_CS for Mk01.
    Please guide me on how to implement a screen exit..
    If possible send me the steps to be followed.
    Regards,
    Vidya.

    Hi,
      Check this:
    http://wiki.ittoolbox.com/index.php/HOWTO:Implement_a_screen_exit_to_a_standard_SAP_transaction
    Have a look at this thread:
    your working with BADI Then do as follows....
    you follow the SPRO way and do everything they say.
    1.you make an own z program with your subscreens
    2.by VENDOR_ADD_DATA you put something like this to method CHECK_ADD_ON_ACTIVE:
    Aktivierung Zusatzfelder für ZDB
    if i_screen_group = 'Z1'.
    e_add_on_active = 'X'.
    endif.
    3.by VENDOR_ADD_DATA_CS you put something like this to get_taxi_screen
    CASE i_taxi_fcode.
    Premier
    WHEN 'Z1_SRCE1'.
    e_screen = '0100'.
    e_program = 'ZPM_SCREENEXIT_MK02'. " your own program
    e_headerscreen_layout = ' '.
    Deuxiem
    WHEN 'Z1_SRCE2'.
    e_screen = '0110'.
    e_program = 'ZPM_SCREENEXIT_MK02'.
    e_headerscreen_layout = ' '.
    ENDCASE.
    4. you make sure, that everything is active
    Regards
    Kiran
    Edited by: Kiran Sure(skk) on Apr 11, 2008 3:42 PM

Maybe you are looking for

  • Create security profile based on different payroll

    we have two payrolls, I want to assign different responsibilities based on the two apyrolls. I tried to do that by creating a new security profile but it is not working. can anubody tell me in detail steps what to do, please..

  • Thread Process is exiting without completing the process in SharePoint 2010 webpart

    We have implemented simple thread to process to excel upload into SharePoint 2010 custom list. Thread process running in local SharePoint 2010 environment (OS -Windows 7). Once we deployed in SharePoint server, Thread process is exiting without compl

  • Super Bom

    Hi, Can any one give all the details like how to mainatin the BoM for the configuration material & other setting like creation of character type currency ,class, cration profile & info record so the price flow automatically in the po depending upon s

  • Do we need to create two different home for UCM and WC?

    Hi All, I am trying to create Webcenter VM(oracle linux 5) with ECM I used 11.1.1.5.0 version for all installable.for creating this VM. here do we need to create separate Home for webcenter and UCM installations. any one give me some proper direction

  • Can ATT unlock an iPhone 5 that is currently being used on Consumer Cellular?

    Hello, I currently have an ATT iPhone 5 that is being used on Consumer Cellular. I want to unlock my iPhone so that I can use it on a different carrier. I was wondering if ATT can unlock my iPhone, since Consumer Cellular is a MVNO of ATT.