Multiple players with same sprites

Get help using Construct 2

Post » Sun Feb 03, 2013 8:20 pm

I'm looking to create a game similar to Super Smash Bros, where four players fight in an arena setting. The issue I'm wrestling with at the moment, however, is how to streamline the addition of new characters for up to four players.

Ideally, there's a character select screen with a number of characters available and four players (using gamepads) can select whichever one they like (even the same one multiple times). The problem I'm having with this is I don't know how to create four copies of the player sprite that can each be controlled and animated separately by each controller.

I could do this by copying the basic control/animation functions four times for every single character, but that seems insanely time consuming and terribly inefficient (I'll have to repeat the process each time I add another player). Is there a better way?

The way it works in my head is that the number of the controls would be relative to which number player sprite is moving. I can set this for the controller movements by giving each of the four player sprites a "Controller" variable numbered 0-3 and then making a function referencing the "Player.Controller" variable (so one event works for all four controllers), however, I don't know how to make it figure out which player to move.

As it stands, it seems like I can only pick a single object to create the action from, rather than making it use "Player(Controller.Player)" or something to that effect (so Player0 is moved when controller 0 is pressed, Player1 is moved when controller 1 is pressed, etc).

Sorry if I didn't explain my issue well, I'm still pretty new to Construct. Can anyone understand my problem and maybe help me find a solution? It would be greatly appreciated, especially since I don't want to get too deep into working on other aspects of this game if I find out that local multiplayer isn't feasible. D:
B
5
S
1
Posts: 37
Reputation: 549

Post » Sun Feb 03, 2013 8:24 pm

EDIT: My topic name might be a bit misleading...I actually worked out half of the problem while typing that post...here's some clarification:

I've created four Player sprites (Player0, Player1, Player2, Player4) on a blank layout, made them global, and I create them as needed on the start of a stage. Each one has a "Controller" variable with the same number as in their names. I want to use a single block of actions for all four player characters by matching the gamepad number with the "Controller" variable from the corresponding Player sprite.
B
5
S
1
Posts: 37
Reputation: 549

Post » Mon Feb 04, 2013 4:45 pm

You can spawn 4 instances of the same Object (player sprite) which have instance variable: playerNumber which you make sure is distinct for each player.

You can then assign control to the instance of an Object that has playerNumber x.

B
5
Posts: 39
Reputation: 678

Post » Mon Feb 04, 2013 4:48 pm

Sorry, if they need to be 4 different sprites then that wont work. When you say controller? Is this 4 people with control pads on the same computer or over a network?
B
5
Posts: 39
Reputation: 678

Post » Mon Feb 04, 2013 8:49 pm

One thing that will really help you down the road is to create one player as a container object and add all of their health/score/UI info to the container as well. It will simplify things greatly down the road for you.

Then each player will have different different animations based on which player they are actually playing eg: if you choose the red guy, you'd play the red guy set of animations. All animations would be stored in one player object.

Then as you guessed, assign each player a variable that would equal which player they were on the keyboard/gamepad etc.

Only the buttons associated with the particular player would trigger the appropriate player in the game.

now if you want to get a bit fancy and save yourself programming duplicate version of the same code over and over you can use a function to do all the work for you.

create a function and call it "punch" lets say.

When you Call the function, you would tell it which player send the command,

eg: call function "punch" (1) *<--player's controller name

This number will be used as a parameter for the function to tell construct which player should initiate the punch animation

On function "punch" (parameter)
if function.param(0) = 1 then
-> player 1 play animation punch
if function.param(0) = 2 then
-> player 2 play animation punch
etc.


its kinda complicated, so lemme know if you have any questions

use @justifun to notify me that there's a reply
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Mon Feb 04, 2013 10:15 pm

@aceofpack
Four controllers on one computer.

@justifun
Alright, I think Functions were exactly what I was looking for. I'm still not 100% sure how to use them properly, though. Here's a (hopefully) clearer version of what I have set up:

I have four blank player sprites (named Player0, Player1, Player2, Player3) placed on a layer by themselves. Each one has a "Controller" variable to match their number (0-3).

When a stage starts, it spawns as many of these player sprites as needed (Player0 for one player, Player0 and Player1 for two players, etc) and pins the selected character animation sprite to each (this might be another issue entirely, but I'm also not sure how to handle two players choosing the same character sprite).

Now, I have events created for controls and animations, all referencing Player0. What I'd like to do, as opposed to copying these events for each player, is to have a single set that is smart enough to pick up on which controller is sending inputs and move the matching player sprite. I'll also have to set this up for animations and a dozen other things, but I think if I understand how to set it up for controllers, the knowledge will apply elsewhere.

I'm going to play around with Functions a bit and see if I can get the desired result, but I thought I'd at least take a moment to clarify and thank you both for being so helpful. :D
B
5
S
1
Posts: 37
Reputation: 549

Post » Wed Feb 06, 2013 1:01 am

Alright, I took a swing at functions...I'm not sure if I'm following your example correctly, but I don't know if this is going to save me all that much as far as copying events goes. Here's an example of what I've done so far:

http://i47.photobucket.com/albums/f173/kitsune37/functions_zpsb74e5e22.png

Is there a nicer way to clean this up? Otherwise it doesn't seem much more efficient than what I was doing already.
B
5
S
1
Posts: 37
Reputation: 549

Post » Wed Feb 06, 2013 1:23 am

It would be great if you could use a string in Simulate Platform pressing " " ...

You can make your Player0, Player1, Player2 and Player3 into a family "Players".


then
left arrow is down - > Function: Call "Move" (Left)
...
right arrow is down - > Function: Call "Move" (Right)
...


Function: On "Move" -> Players: Set Facing to function.param(0)
                    -> Players: Set Movement to function.param(0)


Only thing left is way to pick players, but it depends on your code.


edit: you could use same function to controll everything - I change code above a littleshinkan2013-02-06 01:25:40
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Wed Feb 06, 2013 6:14 am

Oh, okay. I think I'm starting to understand the usefulness of functions now. Passing Left/Right/etc to a Move function really cleans things up.

As for referencing all players...Families are only available in the paid version, correct? I might have to invest. I think that's exactly what I'm looking for.
B
5
S
1
Posts: 37
Reputation: 549

Post » Thu Feb 07, 2013 11:04 pm

Hey Noisetank, check your inbox, we might be able to help each other
B
32
S
4
Posts: 406
Reputation: 3,221

Next

Return to How do I....?

Who is online

Users browsing this forum: makkancs and 28 guests