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 = '<right>' ~~ false
ifTrue: [self setHeading: 90.
self forward: 5].
World1 getLastKeystroke = '<left>' ~~ false
ifTrue: [self setHeading: -90.0.
self forward: 5]
prime
World1 getLastKeystroke = 'z' ~~ false
ifTrue: [Bullet setY: self getY.
Bullet setX: self getX]
shoot
World1 getLastKeystroke = ' ' ~~ 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 <Left> Key:
move relative to position (-4,0)
Keyboard Event for <Right> Key:
move relative to position (4,0)
Key Press Event for <Space> 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/
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