/* Not eXactly C Code for NXT Ultra Pinball Machine III.
Idea for putting this NXC program in the NXT-G information box from m1n1f1g. Thanks.
Coded by NatoNX. ><> */
#define lights1on HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_A, PF_PWM_FWD7) //define macros
#define lights1off HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_A, PF_PWM_FLOAT)
#define lights2on HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_B, PF_PWM_FWD7)
#define lights2off HTPFSingleOutputPWM(S4, PF_CHANNEL_1, PF_OUT_B, PF_PWM_FLOAT)
int balls; //initiate variables
int score;
int threshold1;
int threshold2;
string display;
task main ()
{
SetSensorTouch(IN_1); //set sensors
SetSensorType(IN_2, IN_TYPE_REFLECTION);
SetSensorLight(IN_3);
SetSensorLowspeed(IN_4);
while (true)
{
OnFwd(OUT_BC, 100); //light up lights powered off of NXT
ClearScreen();
TextOut(20, LCD_LINE2, "NXT Ultra"); //beginning screen
TextOut(5, LCD_LINE3, "Pinball Machine");
TextOut(36, LCD_LINE4, "III");
TextOut(15, LCD_LINE6, "Press Orange");
TextOut(24, LCD_LINE7, "to Start");
while (ButtonPressed(BTNCENTER, true) == TRUE) //wait for orange button to be pressed...
{
}
while (ButtonPressed(BTNCENTER, true) == FALSE) //...and released
{
}
ClearScreen();
TextOut(0, LCD_LINE1, "Use the flippers"); //instructions
TextOut(0, LCD_LINE2, "to get the ball");
TextOut(0, LCD_LINE3, "to hit the black");
TextOut(0, LCD_LINE4, "part at the top");
TextOut(0, LCD_LINE5, "and into the box");
TextOut(0, LCD_LINE6, "on the left. You");
TextOut(0, LCD_LINE7, "have 3 launches.");
TextOut(0, LCD_LINE8, "Press orange.....");
while (ButtonPressed(BTNCENTER, true) == TRUE) //wait for orange button to be pressed...
{
}
while (ButtonPressed(BTNCENTER, true) == FALSE) //...and released
{
}
ClearScreen();
threshold1 = Sensor(IN_3) + 3; //sets thresholds for light sensors
threshold2 = Sensor(IN_2) - 50;
balls = 2;
score = 0;
while (balls > -1)
{
display = "Score: "; //score and ball display
strcat(display, NumToStr(score));
TextOut(0, LCD_LINE2, display);
display = "Balls Left: ";
strcat(display, NumToStr(balls));
TextOut(0, LCD_LINE5, display);
if (Sensor(IN_1)) //if bumper is pressed, add to score...
{
score += 100;
PlayTone(440, 500);
lights1on; //...and flash touch sensor lights
Wait(200);
lights1off;
}
if (Sensor(IN_3) > threshold1) //if score light sensor detects something, add to score...
{
score += 500;
PlayTone(640, 500);
lights2on; //...and flash light sensor lights
Wait(200);
lights2off;
}
if (Sensor(IN_2) < threshold2) //if drain light sensor detects something...
{
balls -= 1; //subtracts from ball count...
PlayFile("! Attention.rso"); //...and plays a sound
Wait(1000);
}
}
ClearScreen(); //if ball count reaches -1, the the game ends. Screen clears
PlayFile("! Startup.rso"); //ending display and sequence
TextOut(17, LCD_LINE2, "Final Score");
TextOut(0, LCD_LINE4, NumToStr(score));
TextOut(23, LCD_LINE6, "Thanks for");
TextOut(0, LCD_LINE7, "playing! Please");
TextOut(12, LCD_LINE8, "press orange.");
while (ButtonPressed(BTNCENTER, true) == FALSE)
{
}
}
}