2 players - 8 direction movement?

For questions about using Classic.

Post » Fri Feb 08, 2008 12:10 am

can seem to figure out how to assign2 seperate sets of keys for 2 players each having 8 direction movement..

thanks, as always
B
4
S
2
G
5
Posts: 149
Reputation: 2,025

Post » Fri Feb 08, 2008 1:15 am

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:

[code:81fd07a7]
+Mouse&Keyboard "Move Up" is down
-p1Sprite: Set angle to 270 degrees
-p1Sprite: Bullet: Set speed to 200

+Mouse&Keyboard "p2 Up" is down
-p2Sprite: Set angle to 270 degrees
-p2Sprite: Bullet: Set speed to 200
[/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
-p2Sprite: Set angle to 315 degrees
-p2Sprite: Bullet: Set speed to 200
[/code:81fd07a7]

You'll also need conditions that compensate for conflicting keypresses. Obviously, if the player is holding both 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
-p2Sprite: Set angle to 0 degrees
-p2Sprite: Bullet: Set speed to 200
[/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
-p2Sprite: Bullet: Set speed to 0
[/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!
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Feb 08, 2008 1:24 am

ahhh deadeye, you rock!!

lordy - complex stuff indeed - I was hoping I there was some kind of p2 flag somewhere.. ah well..
B
4
S
2
G
5
Posts: 149
Reputation: 2,025

Post » Fri Feb 08, 2008 1:28 am

[quote="work3":1wzkvkz7]I was hoping I there was some kind of p2 flag somewhere.. ah well..[/quote:1wzkvkz7]

Now that's a feature worth suggesting.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Feb 08, 2008 10:06 am

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?
B
2
S
1
G
5
Posts: 70
Reputation: 1,540

Post » Fri Feb 08, 2008 11:50 am

[quote="Snakesoft":3fbbhhaa]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?[/quote:3fbbhhaa]

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:

[quote="Ashley":3fbbhhaa]allow two movements to use separate controls[/quote:3fbbhhaa]

Which I'm guessing is another way of saying:

[quote="work3":3fbbhhaa]some kind of p2 flag[/quote:3fbbhhaa]

And I totally missed it :oops:

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests