Subject:
|
RCX games.
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Wed, 27 Dec 2000 07:30:17 GMT
|
Original-From:
|
Steve Baker <sjbaker1@STOPSPAMMERSairmail.net>
|
Reply-To:
|
sjbaker1@airmail.=avoidspam=net
|
Viewed:
|
687 times
|
| |
| |
Someone asked about games requiring 2 RCX's - I don't have one - but here
is my humble submission of a game for *one* RCX that's a lot of fun for the
children. Extending it to work with two RCX's (or in my case, an RCX and
3 scouts) will be left as an exercise for the reader.
You need a rotation sensor, two bump sensors, a Lego Lamp and an RCX - plus
NQC and the version 2.0 RCX firmware. It'll take you all of 3 minutes to build
and is so simple that you don't need pictures to explain it.
If you've seen the kid's game 'BopIt' - this game will be kinda familiar.
Take a large base plate and mount on it the following components in
any location you fancy (be creative - you don't *have* to use a baseplate!):
1) A motor, geared down 5:1 using an 8t gear feeding into a 40t, connected
that to OUT_A on the RCX.
2) Get some Lego lights and connect a couple of them onto OUT_B.
3) Connect a rotation sensor to SENSOR_1 with some way to easily rotate
it using your fingers (I just used a 40t gear wheel and an axle stuffed
directly into the sensor).
4) Connect a switch (aka Bump Sensor) to SENSOR_2 and and another to SENSOR_3
I connected two of the stripy 4x4 'umbrella' parts onto the two 40t gears
for prettyness.
Run the NQC program at the end of this email to bring it all to life...
The idea is that the RCX randomly either lights the lamps, makes a sound or
spins the motor (either clockwise or anticlockwise) - and you (the human) have
to copy it's actions by pressing the switch in SENSOR_2 (to extinguish the light),
pressing the switch in SENSOR_3 (to make a sound) or spin the rotation sensor in
the same direction that the motor is turning the 40t gear.
If you do that within a couple of seconds, the RCX beeps twice and you score a
point...if you don't (or if you do the WRONG action) - you lose...game over.
This happens over and over - with the time between actions and the time you have
to respond getting shorter and shorter.
Your score is displayed on the LCD of the RCX. When you lose, the RCX makes a
low beeping noise over and over. To play again, stop the program and restart
it by pressing the RUN button twice.
Here is the NQC program:
----------------- CUT HERE ---------------------
/*
LEGGO-IT - a simple RCX game.
by Steve Baker.
*/
int score ; /* Has to be global to be displayed on the LCD */
task main ()
{
int pick ;
int action ;
int speed ;
int rot ;
int lig ;
int snd ;
int i ;
score = 0 ;
speed = 300 ; /* You may want to reduce this number for shorter games */
SetSensorType(SENSOR_1, SENSOR_TYPE_ROTATION ) ;
SetSensorMode(SENSOR_1, SENSOR_MODE_ROTATION ) ;
SetSensorType(SENSOR_2, SENSOR_TYPE_TOUCH ) ;
SetSensorMode(SENSOR_2, SENSOR_MODE_BOOL ) ;
SetSensorType(SENSOR_3, SENSOR_TYPE_TOUCH ) ;
SetSensorMode(SENSOR_3, SENSOR_MODE_BOOL ) ;
SetPower ( OUT_A, 7 ) ; Off ( OUT_A ) ;
SetPower ( OUT_B, 7 ) ; Off ( OUT_B ) ;
SelectDisplay ( DISPLAY_USER ) ;
SetUserDisplay ( score, 0 ) ;
while ( true )
{
action = Random ( 3 ) + 1 ;
pick = 0 ;
ClearSensor ( SENSOR_1 ) ; /* Zero the rotation sensor */
/* Start the action */
switch ( action )
{
case 1 : /* Motor clockwise */
OnFwd ( OUT_A ) ;
break ;
case 2 : /* Motor anticlockwise */
OnRev ( OUT_A ) ;
break ;
case 3 : /* Light */
OnFwd ( OUT_B ) ;
break ;
case 4 : /* Sound */
PlaySound ( SOUND_UP ) ;
break ;
}
/* Look for a response */
for ( i = 0 ; i < speed ; i++ )
{
rot = SENSOR_1 ;
lig = SENSOR_2 ;
snd = SENSOR_3 ;
if ( rot > 4 ) { pick = 1 ; break ; }
if ( rot < -4 ) { pick = 2 ; break ; }
if ( lig == 1 ) { pick = 3 ; break ; }
if ( snd == 1 ) { pick = 4 ; Off ( OUT_A ) ; Off ( OUT_B ) ;
PlaySound ( SOUND_DOWN ) ;
Wait ( 100 ) ; break ; }
Wait ( 1 ) ;
}
if ( pick == action )
{
/* YOU WIN A POINT!! */
score++ ;
Off ( OUT_A ) ;
Off ( OUT_B ) ;
PlaySound ( SOUND_DOUBLE_BEEP ) ;
Wait ( speed ) ;
}
else
{
/* YOU SNOOZE - YOU LOSE!! */
while ( true )
{
Wait ( 100 ) ;
PlaySound ( SOUND_LOW_BEEP ) ;
}
}
/* Make it a little harder to get the next point! */
if ( speed > 100 )
speed -= 10 ;
else
if ( speed > 20 )
speed -= 5 ;
else
if ( speed > 1 )
speed -= 1 ; /* Yikes! 1/100th second! */
}
}
-----------------------------------------------------------------------------
NOTES:
1) You may find that you have to reverse the direction of the cable to the motor to
make it match the direction of the rotation sensor.
2) Place SENSOR_2 closer to the lights than SENSOR_3 in order to avoid confusion.
3) For a 'rotation' to count, you have to rotate at least a quarter turn in the correct
direction...and STOP rotating before the next action is required.
4) I want to change the program to use a light sensor in place of SENSOR_2 so that you
have to block the light from the lamp with your hand to perform that action. I didn't
have time to make the calibration stuff work automatically though...maybe tomorrow.
5) I was thinking about adding a "Simon Says" feature whereby if it does a low BEEP
whilst showing you the light or spinning the motor - then you must *NOT* do the
action. That'll make it a little harder to play!
Now I have 3 scouts as well as the RCX - so I may well build a more EVIL version with
*many* more actions to perform...watch this space!
-------------------------------------------------------------------------------
Steve Baker HomeEmail: <sjbaker1@airmail.net>
WorkEmail: <sjbaker@link.com>
HomePage : http://web2.airmail.net/sjbaker1
Projects : http://plib.sourceforge.net
http://tuxaqfh.sourceforge.net
http://tuxkart.sourceforge.net
http://prettypoly.sourceforge.net
|
|
Message has 1 Reply: | | Re: RCX games.
|
| "Steve Baker" <lego-robotics@crynwr.com> wrote in message news:3A499A89.709082...ail.net... (...) Hey hey hey... is that what I thikn it is? Showing a variable on the display?! Iain (24 years ago, 27-Dec-00, to lugnet.robotics)
|
4 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|