----------------------------------- rollerdude Wed Jun 01, 2005 8:59 am ckeck out my cool game ----------------------------------- try this.... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % MISSILE.T % % % % % % This is a simple video game featuring an ever increasing % % number of missiles tha must be avoided. The seeking % % algorithm of the missiles is rather simplistic and is open % % to modification and refinement by anyone. Suggested changes % % are having the missiles trail disappear, different launching % % times for each missile and having missiles last different % % amounts of time. % % % % All of the constants defined at the top of the program can % % be changed in order to experiment with different environments % % and factors. Feel free to tinker, doctor and change this % % program to your hearts content. That's what it's here for! % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Constants % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% const groundColour := 1 const missileColour1 := 2 const missileColour2 := 1 const explosionColour := 2 const playerColour := 3 const playerSpeed := 4 const turnDelay := 100 const outOfPlay := - 1 const maxMissiles := 20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Global Variables % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% var numMissiles : int := 1 % the number of missiles in play var evadedMissiles : int := 0 % total number of missiles evaded var tx : int := maxx div 2 % the x position of the player in pixels var ty : int := maxy div 2 % the y position of the player in pixels var turns, prevTime, timer, dist : int /************************************************************** * This procedure gives the instructions for the game. * **************************************************************/ procedure Instructions setscreen ("text,screen,noecho,nocursor") locate (1, 30) put "MISSILE" put skip color (2) put "You are a pilot over Zornastria. Unfortunately, the missile" put "defence system has been activated and is now turned against" put "you! Even worse, the missiles are heat seeking missiles and" put "head straight for you. Luckily if you manuever carefully," put "you can dodge them until they run out of fuel." put skip put "To pilot your airplane, use the arrow keys. THe missiles start" put "out coloured " .. colour (13) put "purple" .. colour (2) put " and turn " .. colour (11) put "blue" .. colour (2) put " when they run out of fuel. You" put "must attempt to survive as long as you can. After surviving each" put "wave, the next wave will be launched." put skip put "Good Luck! You'll need it." put skip put "Hit any key to start the game..." var ch : string (1) getch (ch) setscreen ("graphics,noecho") end Instructions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This procedure draws the player. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% procedure DrawPlayer (clr : int) drawline (tx - 1, ty - 1, tx + 1, ty - 1, clr) drawline (tx - 1, ty, tx + 1, ty, clr) drawline (tx - 1, ty + 1, tx + 1, ty + 1, clr) end DrawPlayer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This procedure handles any key strokes by reading any char % % from the keyboard and moving the player in response to it. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% procedure ControlPlayer % Blank out the old player by drawing it in colour 0 (black) DrawPlayer (0) % Read in a character var c : string (1) getch (c) case ord (c (1)) of % The 7 key (on the numeric keypad) label 199 : tx -= playerSpeed ty += playerSpeed % The 8 key (on the numeric keypad) label 200 : ty += playerSpeed % The 9 key (on the numeric keypad) label 201 : tx += playerSpeed ty += playerSpeed % The 4 key (on the numeric keypad) label 203 : tx -= playerSpeed % The 6 key (on the numeric keypad) label 205 : tx += playerSpeed % The 1 key (on the numeric keypad) label 207 : tx -= playerSpeed ty -= playerSpeed % The 2 key (on the numeric keypad) label 208 : ty -= playerSpeed % The 3 key (on the numeric keypad) label 209 : tx += playerSpeed ty -= playerSpeed % The 'q' key (this quits the game) label ord ("q") : tx := - 1 return label : end case % Make certain the player doesn't go off the screen. if tx < 10 then tx := 10 elsif tx > maxx - 10 then tx := maxx - 10 end if if ty < 10 then ty := 10 elsif ty > maxy - 10 then ty := maxy - 10 end if % This empties the buffer loop exit when not hasch getch (c) end loop % Draw the player in its new position DrawPlayer (playerColour) end ControlPlayer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This function determines whether the player was hit by checking to % % see if any pixels of the player's piece are not of the appropriate % % colour. (i.e. a missile track was drawn over top of the player) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function PlayerHit : boolean var hit : boolean := false var dot : int for i : tx - 1 .. tx + 1 for j : ty - 1 .. ty + 1 dot := whatdotcolour (i, j) if dot not= playerColour then hit := true end if end for end for result (hit) end PlayerHit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Main Body % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% var px, py : array 1 .. maxMissiles of int % The position array for the missiles var vx, vy : array 1 .. maxMissiles of int % The velocity array for the missiles randomize setscreen ("graphics,noecho") Instructions loop % Initialize the missile array. for i : 1 .. numMissiles randint (px (i), 0, maxx) py (i) := 0 vx (i) := 0 randint (vy (i), 1, 5) end for % Draw the screen cls drawline (0, 0, maxx, 0, 1) DrawPlayer (playerColour) % Set the clock and number of elapsed turns clock (prevTime) turns := 0 % The main loop loop turns += 1 % For each missile: determine the new x velocity % determine the new y velocity % set the new missile position % draw a travel line % check to see if it hit the ground % check to see if it hit the player for i : 1 .. numMissiles const ox : int := px (i) const oy : int := py (i) if ox not= outOfPlay then % Determine the x velocity dist := abs (vx (i)) * (abs (vx (i)) + 1) div 2 if vx (i) < 0 and ox - dist < 0 then vx (i) += 2 elsif vx (i) > 0 and ox + dist > maxx then vx (i) -= 2 elsif turns > 100 then if turns mod 10 = 0 then if vx (i) < 0 then vx (i) += 1 elsif vx (i) > 0 then vx (i) -= 1 end if end if elsif ox < tx then vx (i) += 1 elsif ox > tx then vx (i) -= 1 end if % Determine the y velocity dist := abs (vy (i)) * (abs (vy (i)) + 1) div 2 if vy (i) > 0 and oy + dist > maxy then vy (i) -= 2 elsif turns > 100 then if turns mod 4 = 0 then vy (i) -= 1 end if elsif vy (i) < 0 and oy - dist < - turns div 15 then vy (i) += 2 elsif oy < ty then vy (i) += 1 elsif oy > ty then vy (i) -= 1 end if % Set the new missile position px (i) += vx (i) py (i) += vy (i) % Draw a travel line if turns > 100 then drawline (ox, oy, px (i), py (i), missileColour2) else drawline (ox, oy, px (i), py (i), missileColour1) end if % Check to see if it hit the ground if py (i) prevTime + turnDelay end loop prevTime := timer % This will leave the loop when all the missiles have crashed. var endNow : boolean := true for i : 1 .. numMissiles if px (i) not= outOfPlay then endNow := false end if end for exit when endNow end loop % After each time all the missiles have crashed, add 1 to the number % of missiles with a maximum of maxMissiles. numMissiles += 1 if numMissiles > maxMissiles then numMissiles := maxMissiles end if end loop have fun.... ----------------------------------- aussilia Thu Jun 30, 2005 1:43 pm ----------------------------------- i dont know why everybody gave you the cold shoulder but your program is great :D good job man ----------------------------------- Cervantes Thu Jun 30, 2005 2:04 pm ----------------------------------- Gah, these things are still around? aussilia: It's because it's not his game. locked.