[squeakland] How to create a multi-player game

Karl Ramberg karlramberg at gmail.com
Tue Feb 2 12:14:34 EST 2010


On 2010-02-02 06:09, Scott Wallace wrote:
> 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
>
> HTH...
>
>    -- Scott
>    

Nice project, Scott :-)

One thing I often do is to add a last line to my ticking watchKeystrokes 
script:
world last keystroke <- ''
This blanks out the world last keystroke so scripts don't trigger 
multiple times.
Specially when I make a 'shooter' game.

How would you make a 'shooter' game using state ?

Karl




More information about the squeakland mailing list