Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 missle game 2
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rollerdude




PostPosted: Wed Jun 01, 2005 9:05 am   Post subject: missle game 2

to get the first part of the program, look for "check out my cool game"

this is lines 121-341(end)


code.....

% 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) <= 0 then
drawline (px (i), 0, px (i) - 4, 4, explosionColour)
drawline (px (i), 0, px (i), 6, explosionColour)
drawline (px (i), 0, px (i) + 4, 4, explosionColour)
px (i) := outOfPlay
evadedMissiles += 1
end if

% Check to see if it hit the player
if PlayerHit then
drawline (tx - 5, ty - 5, tx + 5, ty + 5, playerColour)
drawline (tx + 5, ty - 5, tx - 5, ty + 5, playerColour)
drawline (tx - 5, ty, tx + 5, ty, playerColour)
locate (10, 5)
put "You evaded ", evadedMissiles, " missiles!"
locate (1, 1)
delay (500)
return
end if
end if
end for

% If a key has been pressed, control the player
if hasch then
ControlPlayer

% If 'q' was pressed, tx will be -1 and the game should end.
if tx = - 1 then
return
end if
end if

% This is a timer delay loop to make sure that each turn takes
% the same length of time to execute, regardless of the number
% of missiles on the screen
loop
clock (timer)
exit when timer > 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






there you have it, combine the two program peices and have fun!!!!
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Wed Jun 01, 2005 8:12 pm   Post subject: (No subject)

Ok ok, first of all, who's going to want to look up another half to the program, somewhere on the site? Put it all together, or upload it in a .t file, which isn't very hard.

Secondly, use code tags, such as:

code:

[code]Your code goes here.[/code]


Only makes sense man Confused
rollerdude




PostPosted: Wed Jun 01, 2005 9:38 pm   Post subject: (No subject)

ok, but when i tried that, the internet errored and timed out

i also tried doing the whole program at once, but it was too large
decon1985




PostPosted: Tue Jun 07, 2005 2:22 pm   Post subject: Whatever...

Well I guess Ill say something good then. I really liked it even though I had to find the other part. Very cool, keep it up! Wink
Drake




PostPosted: Wed Jun 22, 2005 12:50 pm   Post subject: (No subject)

This is just a copy of the missile game that Turing comes with. He did no actual work to come up with this game, just looked around through the files that Turing comes with and pasted it onto here. I'm pretty sure that there was a post somewhere on this forum about plagarism. This is exactly what they were talking about.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: