View.Set ("position:centre;centre,graphics:640;500,offscreenonly")
colorback (black)
cls
var score1 : int := 0
var score2 : int := 0
var time2 := 0
var chars : array char of boolean
type projectile_t :
record
startx, starty, x, xp, y, yp, angle, weight, velocity : real
end record
type player_t :
record
x, y, w, v, t : real
end record
var projectile_1 : projectile_t
var player_1 : player_t
var player_2 : player_t
player_1.x := 100
player_1.y := 100
player_1.v := 50
player_1.w := 10
player_1.t := 0
player_2.x := maxx - 100
player_2.y := 100
player_2.v := 50
player_2.w := 10
player_2.t := 0
projectile_1.startx := 100
projectile_1.starty := 140
projectile_1.x := 100
projectile_1.y := 140
projectile_1.velocity := 90
projectile_1.angle := 90
projectile_1.weight := 15
var time1 := 0.0
var bjump_1 := false
var bjump_2 := false
var currentangle : real
var slope : real
var bounceangle : real
procedure Projectile (var obj : projectile_t, t : real)
obj.x := (obj.velocity * cosd (obj.angle) * t) + obj.startx
obj.y := (obj.velocity * sind (obj.angle) * t - (obj.weight) * t ** 2 / 2) + obj.starty
end Projectile
procedure Jump (var obj : player_t)
obj.y := (obj.v * sind (90) * obj.t - (obj.w) * obj.t ** 2 / 2) + 100
obj.t += .1
end Jump
procedure ResetP (var obj : projectile_t, sx, sy, v, a, w : real)
projectile_1.startx := sx
projectile_1.starty := sy
projectile_1.velocity := v
projectile_1.angle := a
projectile_1.weight := w
end ResetP
color (10)
loop
%if round (projectile_1.velocity) > 1 then
if projectile_1.starty > 110 then
time1 += .105
else
if projectile_1.x < 320 then
score2 += 1
elsif projectile_1.x > 320 then
score1 += 1
end if
player_1.x := 100
player_1.y := 100
player_1.v := 50
player_1.w := 10
player_1.t := 0
player_2.x := maxx - 100
player_2.y := 100
player_2.v := 50
player_2.w := 10
player_2.t := 0
projectile_1.startx := 100
projectile_1.starty := 140
projectile_1.velocity := 90
projectile_1.angle := 90
projectile_1.weight := 15
time1 := 0.0
delay (200)
end if
%end if
projectile_1.xp := projectile_1.x
projectile_1.yp := projectile_1.y
Projectile (projectile_1, time1)
if projectile_1.y not= projectile_1.yp and projectile_1.x not= projectile_1.xp then
slope := (projectile_1.y - projectile_1.yp) / (projectile_1.x - projectile_1.xp)
currentangle := arctand (slope)
bounceangle := -currentangle
locate (3, 2)
put "Angle : ", currentangle
end if
if projectile_1.y < 105 then %Ball hits ground
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 2), projectile_1.angle, projectile_1.weight)
time1 := 0
end if
if projectile_1.x < 1 then %Ball hits left wall
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 1.3), bounceangle, projectile_1.weight)
time1 := 0
end if
if projectile_1.x > 639 then %Ball hits right wall
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity / 1.3), bounceangle, projectile_1.weight)
projectile_1.angle += 180
time1 := 0
end if
if projectile_1.y < 160 then %ball lower than top of net
if projectile_1.x > 310 and projectile_1.x < 320 then %Ball hits left side of net
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), bounceangle, projectile_1.weight)
time1 := 0
end if
if projectile_1.x < 330 and projectile_1.x > 320 then %Ball hits right side of net
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), bounceangle, projectile_1.weight)
projectile_1.angle += 180
time1 := 0
end if
end if
if Math.Distance (player_1.x, player_1.y, projectile_1.x, projectile_1.y) < 40 then %Bouncing ball off Player 1
if projectile_1.x not= player_1.x then
locate (1, 1)
if arctand ((projectile_1.y - player_1.y) / (projectile_1.x - player_1.x)) < 0 then
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), 180 + arctand ((projectile_1.y - player_1.y) / (projectile_1.x - player_1.x)),
projectile_1.weight)
else
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), arctand ((projectile_1.y - player_1.y) / (projectile_1.x - player_1.x)), projectile_1.weight)
end if
else
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), 90, projectile_1.weight)
end if
time1 := 0
end if
if Math.Distance (player_2.x, player_2.y, projectile_1.x, projectile_1.y) < 40 then %Bouncing ball off Player 2
if projectile_1.x not= player_2.x then
locate (1, 1)
if arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)) < 0 then
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), 180 + arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)),
projectile_1.weight)
else
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), arctand ((projectile_1.y - player_2.y) / (projectile_1.x - player_2.x)), projectile_1.weight)
end if
else
ResetP (projectile_1, projectile_1.x, projectile_1.y, round (projectile_1.velocity), 90, projectile_1.weight)
end if
time1 := 0
end if
%%%%Player Boundaries%%%
if player_1.x < 30 then %Player 1 Wall
player_1.x := 30
end if
if player_1.x > 290 then %Player 1 Net
player_1.x := 290
end if
if player_2.x < 350 then %Player 2 Net
player_2.x := 350
end if
if player_2.x > 610 then %Player 2 Wall
player_2.x := 610
end if
if bjump_1 then %Jumping of Player 1
Jump (player_1)
if player_1.y < 100 then
bjump_1 := false
player_1.t := 0
player_1.y := 100
end if
end if
if bjump_2 then %Jumping of Player 2
Jump (player_2)
if player_2.y < 100 then
bjump_2 := false
player_2.t := 0
player_2.y := 100
end if
end if
Input.KeyDown (chars)
%Player1 Controls
if chars ('w') then
bjump_1 := true
end if
if chars ('a') then
player_1.x -= 3
end if
if chars ('d') then
player_1.x += 3
end if
%Player2 Controls
if chars (KEY_UP_ARROW) then
bjump_2 := true
end if
if chars (KEY_LEFT_ARROW) then
player_2.x -= 3
end if
if chars (KEY_RIGHT_ARROW) then
player_2.x += 3
end if
drawline (320, 100, 320, 150, yellow) % net
drawfilloval (round (player_1.x), round (player_1.y), 30, 30, 9) % player 1
drawfilloval (round (player_2.x), round (player_2.y), 30, 30, 42) % player 2
drawfillbox (0, 0, 640, 100, 10) %ground
drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, 12) %ball
View.Update
delay (10)
drawfilloval (round (player_1.x), round (player_1.y), 30, 30, black) %Player 1 Previously
drawfilloval (round (player_2.x), round (player_2.y), 30, 30, black) %Player 2 Previously
drawfilloval (round (projectile_1.x), round (projectile_1.y), 10, 10, black) % Ball Previously
drawline (320, 100, 320, 150, brightred) %Bright red of net
/*var mx, my, mbutton : int
Mouse.Where (mx, my, mbutton)
locate (1, 1)
put mx, " - ", my*/
locate (1, 2)
put "Score : ", score1
locate (1, maxcol - 10)
put "Score : ", score2
end loop |