CLS PRINT " +------------------------------------------+ " PRINT " | | " PRINT " | GRAND CANYON RACER | " PRINT " | | " PRINT " | A game of skill and cunning | " PRINT " | for one player. | " PRINT " | | " PRINT " +------------------------------------------+ "' setup_constants REPEAT PRINT '"Press any key to start a new game..." any_key := GET CLS setup_game REPEAT draw_stuff collision_test update_player update_canyon UNTIL player_killed% do_explosion UNTIL FALSE //// ------------------------------ /// Procedures // -------------------------------- PROC setup_constants // NOTE - different keyboards may have different key codes // The key codes below work with _my_ keyboard... left_key% := 45 // '<' key right_key% := 41 // '>' key space_bar% := 55 // Space bar screen_width% := 64 canyon_width% := 20 spaces$ := "" FOR n := 1 TO screen_width% DO spaces$ := spaces$ + " " ENDPROC setup_constants PROC setup_game CLS canyon_pos% := screen_width% / 2 canyon_lhs% := canyon_pos% - canyon_width% / 2 canyon_rhs% := canyon_pos% + canyon_width% / 2 player_pos% := canyon_pos% player_killed% := FALSE ENDPROC setup_game PROC draw_stuff stuff$ := spaces$ stuff$ (1) := "|" stuff$ (screen_width%) := "|" stuff$ (canyon_lhs%) := "*" stuff$ (canyon_rhs%) := "*" stuff$ (player_pos%) := "V" PRINT stuff$ SYNC ENDPROC draw_stuff PROC update_player IF KEY_DOWN left_key% THEN player_pos% := player_pos% - 1 IF KEY_DOWN right_key% THEN player_pos% := player_pos% + 1 ENDPROC update_player PROC update_canyon CASE RND 3 OF WHEN 1 move% := -1 WHEN 2 move% := 1 OTHERWISE move% := SGN (canyon_pos% - player_pos%) ENDCASE IF canyon_rhs% + move% > screen_width% THEN move% := 0 IF canyon_lhs% + move% < 1 THEN move% := 0 canyon_pos% := canyon_pos% + move% canyon_lhs% := canyon_lhs% + move% canyon_rhs% := canyon_rhs% + move% ENDPROC update_canyon PROC collision_test IF player_pos% <= canyon_lhs% THEN player_killed% := TRUE IF player_pos% >= canyon_rhs% THEN player_killed% := TRUE ENDPROC collision_test PROC do_explosion BEEP PRINT '" BOOM!" PRINT '" *** You have died ***"' SYNC ENDPROC do_explosion