This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-04-22 21:58:54

mrdance62
New Scratcher
Registered: 2013-04-15
Posts: 13

How to make a multiplayer game

Hi,
I have seen some game where there are two sprites, and if you press the "2" key, the second sprite is playable. How do you program that to happen? Thank you for you help in advance.
Best Regards,
mrdance62

Offline

 

#2 2013-04-22 22:34:56

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to make a multiplayer game

mrdance62 wrote:

Hi,
I have seen some game where there are two sprites, and if you press the "2" key, the second sprite is playable. How do you program that to happen? Thank you for you help in advance.
Best Regards,
mrdance62

You mean having two people able to play on the same computer, right?

Well, that is very easy, you just assign the player two sprite to have movement, just like the player one sprite, except with different keys. A popular second set is W, up, S, down, A, left, and D, right.

Regards,

CAA14

Offline

 

#3 2013-04-22 22:41:56

mrdance62
New Scratcher
Registered: 2013-04-15
Posts: 13

Re: How to make a multiplayer game

CAA14 wrote:

mrdance62 wrote:

Hi,
I have seen some game where there are two sprites, and if you press the "2" key, the second sprite is playable. How do you program that to happen? Thank you for you help in advance.
Best Regards,
mrdance62

You mean having two people able to play on the same computer, right?

Well, that is very easy, you just assign the player two sprite to have movement, just like the player one sprite, except with different keys. A popular second set is W, up, S, down, A, left, and D, right.

Regards,

CAA14

That's exactly what I mean, yet what about the part where you press the "2 key? Is that automatic?

Offline

 

#4 2013-04-23 13:36:04

CAA14-NL
Scratcher
Registered: 2013-02-28
Posts: 16

Re: How to make a multiplayer game

mrdance62 wrote:

CAA14 wrote:

mrdance62 wrote:

Hi,
I have seen some game where there are two sprites, and if you press the "2" key, the second sprite is playable. How do you program that to happen? Thank you for you help in advance.
Best Regards,
mrdance62

You mean having two people able to play on the same computer, right?

Well, that is very easy, you just assign the player two sprite to have movement, just like the player one sprite, except with different keys. A popular second set is W, up, S, down, A, left, and D, right.

Regards,

CAA14

That's exactly what I mean, yet what about the part where you press the "2 key? Is that automatic?

The "2 key"? You mean the player two keys? If so, then yes, that's all you need to do to have the second sprite controlled by a second player. Of course, you would have a lot of other scripts that, for example, tell the sprites when they can and cannot be controlled(like on a menu), but yeah, that will work.

Here's the scripts you could use:

set [gamePlaying? v] to [yes]
when i receive [game start v]
repeat until <(gamePlaying?) = [no]>
if <key [up arrow v] pressed?>
change y by [3]
end
if <key [down arrow v] pressed?>
change y by [-3]
end
if <key [left arrow v] pressed?>
change x by [-3]
end
if <key [right arrow v] pressed?>
change x by [3]
end
end
when i receive [game start v]
repeat until <(gamePlaying?) = [no]>
if <key [w v] pressed?>
change y by [3]
end
if <key [s v] pressed?>
change y by [-3]
end
if <key [a v] pressed?>
change x by [-3]
end
if <key [d v] pressed?>
change x by [3]
end
end

You see?

Or, are you asking how to make it so that it can be one or two player?

Regards,

CAA14

Last edited by CAA14-NL (2013-04-23 13:36:57)


Mind Blowing Math! Challenge yourself!
http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i45.tinypic.com/292oakk.png&amp;link2=http://i.imgur.com/t9kiBfd.png

Offline

 

Board footer