2 players - 8 direction movement?

This forum is currently in read-only mode.
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • can seem to figure out how to assign2 seperate sets of keys for 2 players each having 8 direction movement..

    thanks, as always

  • Short answer: You'll need to code your own custom movement.

    Long answer:

    Since using the default controls will control both players if they have 8Dir movement, and you'll have to write custom control events for player 2 anyway, just ditch 8Dir movement and give each player Bullet movement.

    Now set up your player 2 controls and call them "p2 Up" and "p2 Down" and such. Then start writing custom control events:

    +Mouse&Keyboard "Move Up" is down
    [ul]
    	[li]p1Sprite: Set angle to 270 degrees[/li]
    	[li]p1Sprite: Bullet: Set speed to 200[/li]
    [/ul]
    +Mouse&Keyboard "p2 Up" is down
    [ul]
    	[li]p2Sprite: Set angle to 270 degrees[/li]
    	[li]p2Sprite: Bullet: Set speed to 200[/li]
    [/ul][/code:81fd07a7]
    
    This is a very basic way of setting it up.  You'll have to get more complicated for multiple keypresses:
    
    [code:81fd07a7]
    +Mouse&Keyboard "p2 Up" is down
    +Mouse&Keyboard "p2 Right" is down
    [ul]
    	[li]p2Sprite: Set angle to 315 degrees[/li]
    	[li]p2Sprite: Bullet: Set speed to 200[/li]
    [/ul][/code:81fd07a7]
    
    You'll also need conditions that compensate for conflicting keypresses.  Obviously, if the player is holding [i]both[/i] the left and right keys at the same time, you don't want to be setting the angle for both of them:
    
    [code:81fd07a7]
    +Mouse&Keyboard "p2 Right" is down
    +[Inverted] Mouse&Keyboard "p2 Left" is down
    [ul]
    	[li]p2Sprite: Set angle to 0 degrees[/li]
    	[li]p2Sprite: Bullet: Set speed to 200[/li]
    [/ul][/code:81fd07a7]
    
    You'll also have to take into account stopping:
    
    [code:81fd07a7]
    +[Inverted] Mouse&Keyboard "p2 Up" is down
    +[Inverted] Mouse&Keyboard "p2 Down" is down
    +[Inverted] Mouse&Keyboard "p2 Right" is down
    +[Inverted] Mouse&Keyboard "p2 Left" is down
    [ul]
    	[li]p2Sprite: Bullet: Set speed to 0[/li]
    [/ul][/code:81fd07a7]
    
    Again, this is a very basic example, and doing it this way would mean you have to code events for all possible keypress combinations to avoid being buggy.
    
    A more advanced (and more efficient) technique would be to use the control keys to perform a series of checks to see if the inputted movement is logically valid, and move the player in a secondary event based on the results of those checks.  For instance, holding left and right makes no sense playwise.  So if the player is holding left, right, and up then your control engine would discard the input for left/right and give the result of "up."  Then the movement engine would pick up that result and the player would just move up.
    
    It gets even more complicated if you want to take into consideration things like acceleration/deceleration or the way the 8Dir movement gradually turns the sprite toward the new direction.  It is possible to replicate all of this, but it would take a lot more work.
    
    Good luck!
  • ahhh deadeye, you rock!!

    lordy - complex stuff indeed - I was hoping I there was some kind of p2 flag somewhere.. ah well..

  • I was hoping I there was some kind of p2 flag somewhere.. ah well..

    Now that's a feature worth suggesting.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Is there a way to retrieve last key pressed, in order to store it on a variable and so allow the player to configure the keys?

  • Is there a way to retrieve last key pressed, in order to store it on a variable and so allow the player to configure the keys?

    It's the very first item on Ashley's to-do list:

    http://scirra.com/phpBB2/viewtopic.php?t=422

    ...and apparently it's right next to this:

    allow two movements to use separate controls

    Which I'm guessing is another way of saying:

    some kind of p2 flag

    And I totally missed it

    So work3, I suppose you could just wait until Ashley has the 2nd player control thingum set up, unless you're really itching to write your own custom controls.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)