[squeakland] How to create a multi-player game

Scott Wallace scott.wallace at squeakland.org
Tue Feb 2 00:09:31 EST 2010

On Feb 1, 2010, at 7:35 PM, CherryW wrote:

> Hello, 
> My students are asking if it's possible to have multiple players in their games. They've programmed ObjectA and ObjectB to each have different sets of keyboard inputs. The problem is pressing keyboard inputs for ObjectA stops the movement of ObjectB and vice versa. Anyway to do bypass this problem? 
> Thank you!
> ---Cherry

Hi, Cherry,

One way is to have each an object's behavior governed not directly by "world's last keystroke" but rather by its own private variable telling it what "state" it is in, and hence what it should do.  This can be accomplished by devoting one ticking script in each object to maintaing the object's "state"; this script can "watch" the world's last keystroke, and when it sees a keystroke that means something to it, it sets the corresponding state in the object's state variable, whereas when it sees keystrokes intended to control different objects, it ignores them; and devoting a second, separate, ticking script in each object to carrying out the action represented by the current "state".

The attached project provides a simple illustration of this.  It allows two objects to be navigated from the keyboard.  Each object is looking for a different set of keys.

A diamond-shaped cluster of four keys at the left edge of the keyboard is used to control Red:

a	rotate counterclockwise
s	rotate clockwise
w	go forward
z	go backward

A second diamond-shaped cluster of four keys further to the right is used to control Blue:

j	rotate counterclockwise
k	rotate clockwise
i	go forward
m	go backward 


  -- Scott

-------------- next part --------------
A non-text attachment was scrubbed...
Name: twoPlayerGame-sw.001.pr
Type: application/octet-stream
Size: 142056 bytes
Desc: not available
Url : http://lists.squeakland.org/pipermail/squeakland/attachments/20100201/98638dd2/twoPlayerGame-sw.001-0001.obj

More information about the squeakland mailing list