http://wiki.squeak.org/squeak/488

On Oct 27, 2007, at 15:29 , Bill Kerr wrote:

> I can't see any capability for keyboard commands
> (important requirement for serious game making)

In the World's viewer you can find the "last keystroke" tile.

- Bert -


thanks bert, karl
but still can't get the functionality I want with only a global
lastKeyStroke

eg. to make a simple shooter
I have one script to move the shooter right and left - using right and left
keys
Another script to prime the bullet, so it starts in the same position as the
shooter - I have arbitarily used the z key for this
Another script to shoot the bullet - I have used space bar for this

But if I shoot the bullet and then move the shooter then the bullet suddenly
stops
And I want to make a sound once only when the bullet fires, can't see how to
do that because the script to fire the bullet has to tick continually

Converting my visual scripts to text:

move

World1 getLastKeystroke =3D '' ~~ false
ifTrue: [self setHeading: 90.
self forward: 5].
World1 getLastKeystroke =3D '' ~~ false
ifTrue: [self setHeading: -90.0.
self forward: 5]

prime

World1 getLastKeystroke =3D 'z' ~~ false
ifTrue: [Bullet setY: self getY.
Bullet setX: self getX]

shoot

World1 getLastKeystroke =3D ' ' ~~ false
ifTrue: [self setHeading: 0.0.
self forward: 10]

By comparison it's much easier using GameMaker, which has localised (to
objects) keyboard and keypress events and distinct movement and speed
actions

Information about object: objBear

Keyboard Event for Key:
move relative to position (-4,0)

Keyboard Event for Key:
move relative to position (4,0)

Key Press Event for Key:
create instance of object objBullet at position (objBear.x,objBear.y)
__________________________________________________

Information about object: objBullet

Create Event:
start moving in directions 000000010 with speed set to 10
play sound sndShot; looping: false

I see making a shooter, eg. a space invaders simulation, as a nice first
game activity for children, one that many find highly motivating

-- =

Bill Kerr
http://billkerr2.blogspot.com/

On 10/28/07, karl wrote:
>
> Bill Kerr wrote:
> > I can't see any capability for keyboard commands
> > (important requirement for serious game making)
> Key input is a property of the world. Make a viewer on the world and one
> of the categories has keyboard input.
>
> Karl


Hi Bill,

the Etoys version wouldn't actually be too different from the Game
Maker one. You wrote:

> start moving in directions 000000010 with speed set to 10
> play sound sndShot

"start moving" is not the same as "move" obviously. So make a
"moving" script for the bullet that ticks and moves it one step each
time, and on space key press "start moving", that is, call "bullet
startScript: #moving" from the "scripting" category.

An alternative to this would be introducing a "moving" variable that
would be set to true when the space key is hit, and testing this in
each step to move the bullet.

- Bert -


Page Information

  • 6 months ago [history]
  • View page source
  • You're not logged in
  • No tags yet learn more

Wiki Information

Recent PBwiki Blog Posts