microsoft / pxt-arcade

Arcade game editor based on Microsoft MakeCode
https://arcade.makecode.com
MIT License
479 stars 207 forks source link

api for setting current controller in multiplayer mode #5780

Open felixtsu opened 1 year ago

felixtsu commented 1 year ago

Is your feature request related to a problem? Please describe. Current controller.A/B/menu/pauseUntil() etc. are default to player1, while multiplayer mode is introduced, is it possible to add an API to set the current controller to player2 / 3 / 4 ?

During make a multiplayer turn base game, like pokemon battle, 2 players choose their actions in turns. Currently all the legacy implementation of menu (story-telling / customMenu / ... ) use controller.A.isPressed() or some alike to catch user input, and this is not the case after multiplayer mode is introduced. The proposal is to expose an api in controller module for setting the current player, masking all the details of whether the game is in multiplayer or not in one place other than leaking to other module

Describe the solution you'd like controller.setCurrentPlayerTo(2) story.showPlayerChoice("","") // player 2's turn controller.setCurrentPlayerTo(1) story.showPlayerChoice("","") // player 1's turn

Describe alternatives you've considered

Additional context

abchatra commented 1 year ago

@felixtsu have you tried the new extension :

image
felixtsu commented 1 year ago

Yeah, but the multiplayer extension dose not keep the information of the current active controller inside controller / mp module, therefore extensions and games have to write code like:

if (currentPlayerIndex == 0) {
    if (controller.A.isPressed()) {
       // ... 
    } 
} else if (currentPlayerIndex == 1) {
    if (controller.player2.A.isPressed()) {
      // ...
    } 
}

or

if (controller.players()[currentPlayerIndex].A.isPressed()) {
    // ...
}

https://arcade.makecode.com/S06156-47069-95107-71336

abchatra commented 1 year ago

@eanders-ms ?

eanders-ms commented 1 year ago

Hey @felixtsu, I actually like this suggestion. We still have some design thinking to do around how to better support prompts in multiplayer, and make sure they work well with the notion of per-player cameras (another feature we want to implement). I don't think your suggestion would be in conflict with that future system. @jwunderl, thoughts?

jwunderl commented 1 year ago

It's pretty easy change on our end (change would be basically just going through all the places we have these 'modal like' options and changing lines like [this] from controller.A.isPressed to controller.activeController.A.isPressed)

There's a little weirdness with per players cameras, but that's not really new weirdness / is something we'll have to think about separately anyways, as the approach we use for these of pushing a scene, throwing up a full screen modal, and continuing on after user inputs doesn't really work nicely if the intention is to use it with multiple cameras at once -- these being easy, synchronous apis is nice for the simple case & a way to set the controller might work nice for that, and we can do an extension for the more complicated 'menus / popups that don't block everyone else from doing anything' scenario (which would probably look very similar to arcade-mini-menu)

felixtsu commented 1 year ago

It's pretty easy change on our end (change would be basically just going through all the places we have these 'modal like' options and changing lines like [this] from controller.A.isPressed to controller.activeController.A.isPressed)

There's a little weirdness with per players cameras, but that's not really new weirdness / is something we'll have to think about separately anyways, as the approach we use for these of pushing a scene, throwing up a full screen modal, and continuing on after user inputs doesn't really work nicely if the intention is to use it with multiple cameras at once -- these being easy, synchronous apis is nice for the simple case & a way to set the controller might work nice for that, and we can do an extension for the more complicated 'menus / popups that don't block everyone else from doing anything' scenario (which would probably look very similar to arcade-mini-menu)

Great!~

As of per-player camera, the camera (or higher level of abstraction, a client, which contains camera and controller ) would be able to provide same api, with state synchronization ( ie, only after all player have chosen their action, game move into another stage ) done at server-side maybe?