for my summative project i was going to do ddr but it was to hard for me so, now im trying to make a space, shooting game. but im having problems with it. i cant make the random objects come up, ti tried many things but as usual they dont work for me.
Turing: | var camx, camy, camz : real
var done, hit : boolean := false
var x, y : int
var h, v, button : int := 0
var rand_x, rand_y, z, count : int := 0
var width, height : int := 20
function Pt_In_Rect (x, y, x1, y1, x2, y2 : int) : boolean
result (x > x1 ) and (x < x2 ) and (y > y1 ) and (y < y2 )
end Pt_In_Rect
%sparkle.........................................................................
camx := maxx / 2
camy := maxy / 2
camz := 0
class Drop
import camx, camy, camz
export init_, move, draw, delete
var x, y, z, zv, z2, screen_x, screen_y, screen_x2, screen_y2, zl : real
proc init_ (x_, y_, z_, zl_ : real)
x := x_
y := y_
z := z_
zv := 0. 2
zl := zl_
end init_
proc move
z + = zv
z2 := z + zl
screen_x := (x - camx ) * 5 / (z - camz + 1e- 3) + camx
screen_y := (y - camy ) * 5 / (z - camz + 1e- 3) + camy
screen_x2 := (x - camx ) * 5 / (z2 - camz + 1e- 3) + camx
screen_y2 := (y - camy ) * 5 / (z2 - camz + 1e- 3) + camy
end move
proc draw
Draw.Line (round (screen_x ), round (screen_y ), round (screen_x2 ), round (screen_y2 ), brightblue)
end draw
fcn delete () : boolean
result z > 9
end delete
end Drop
View.Set ("position:center;center,offscreenonly")
setscreen ("graphics: 1000,500")
var drops : flexible array 1 .. 0 of ^Drop
colourback (7)
cls
process sparkle
loop
for n : 1 .. 4
new drops, upper (drops ) + 1
new Drop, drops (upper (drops ))
drops (upper (drops )) -> init_ (Rand.Int (0, maxx), Rand.Int (0, maxy), 0, 0. 3)
end for
for i : 1 .. upper (drops )
exit when i > upper (drops )
if drops (i ) -> delete () then
free drops (i )
drops (i ) := drops (upper (drops ))
new drops, upper (drops ) - 1
else
drops (i ) -> move
drops (i ) -> draw
end if
end for
View.Update
delay (15)
cls
end loop
end sparkle
fork sparkle
%fork target
loop
Mouse.Where (h, v, button )
Pic.ScreenLoad ("target.bmp", h - 31, v - 30, picMerge)
%Pic.ScreenLoad ("pit2.jpg", 0,0, picMerge)
drawfilloval (maxx div 2, maxy div 205, 18, 18, red)
%drawoval (maxx div 2, maxy div 205, 16, 16, brightred)
drawoval (maxx div 2, maxy div 205, 22, 22, brightred)
drawline (maxx div 2, maxy div 205, h, v, 89)
%y -= 1
View.Update
delay (10)
%exit when x = 50
cls
end loop
%end loop
%random objects
%snake game ???????
%skyscraper thing
%animations read form another file
%random objects..........................................................
loop
Mouse.Where (h, v, button )
hit := false % reset hit at the beginning of each turn
randint (rand_x, 0, maxx)
randint (rand_y, 0, maxy)
drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, yellow)
drawfilloval (maxx div 2, 2, 18, 18, red)
drawoval (maxx div 2, 2, 22, 22, brightred)
%draw box in randon location
loop
buttonwait ("down", h, v, z, z ) % user must click on box to exit this loop
if Pt_In_Rect (h, v, rand_x, rand_y, rand_x + width, rand_y + height ) then
hit := true
end if
exit when hit
end loop
drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, black)
count := count + 1
if count = 6 then % count the number of hits
done := true
end if
end loop
%target..........................................................
loop
Mouse.Where (h, v, button )
hit := false % reset hit at the beginning of each turn
randint (rand_x, 0, maxx)
randint (rand_y, 0, maxy)
drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, yellow)
drawfilloval (maxx div 2, 2, 18, 18, red)
drawoval (maxx div 2, 2, 22, 22, brightred)
%draw box in randon location
loop
buttonwait ("down", h, v, z, z ) % user must click on box to exit this loop
if Pt_In_Rect (h, v, rand_x, rand_y, rand_x + width, rand_y + height ) then
hit := true
end if
exit when hit
end loop
drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, black)
count := count + 1
if count = 6 then % count the number of hits
done := true
end if
end loop |
[Mod edit: Lets use syntax tags and the edit button] |