Breakout game, need advice
Author |
Message |
reckless
|
Posted: Fri May 06, 2005 12:07 pm Post subject: Breakout game, need advice |
|
|
well this is my first year of turing, coming from C++ it is quite an odd change...
but yeah, im being forced to basically work on it for a mark so i can get my credit so im not complaining
basically ive tried to make a breakout game to hand in for my end of the year project so i need advice for how to make it better because there is alot of glitches in it right now heres the coding
code: | setscreen ("offscreenonly")
var key : array char of boolean
var power1, power2, paddlex, paddley, xmod, ymod, ballx, bally, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8, x9, y9, x10, y10, x11, y11, x12, y12, x13, y13, x14, y14, x15, y15 : int
paddlex := 200
paddley := 10
power1 := 200
power2 := 10
xmod := 1
ymod := 1
ballx := Rand.Int (0, 180)
bally := Rand.Int (0, 180)
x1 := 400
y1 := 200
x2 := 300
y2 := 200
x3 := 200
y3 := 200
x4 := 100
y4 := 200
x5 := 400
y5 := 300
x6 := 300
y6 := 300
x7 := 200
y7 := 300
x8 := 100
y8 := 300
x9 := 400
y9 := 400
x10 := 300
y10 := 400
x11 := 200
y11 := 400
x12 := 100
y12 := 400
x13 := 300
y13 := 400
x14 := 200
y14 := 400
x15 := 100
y15 := 400
loop
Draw.FillBox (0, 0, maxx, maxy, 0)
Draw.FillBox (paddlex, paddley, paddlex - 100, paddley - 5, 12)
Draw.FillOval (ballx, bally, 10, 10, 16)
Input.KeyDown (key)
ballx += xmod
bally += ymod
if ballx >= maxx then
xmod := -xmod
elsif ballx <= 0 then
xmod := -xmod
end if
if bally >= maxy then
ymod := -ymod
elsif bally <= 0 then
ymod := -ymod
end if
if ballx = paddlex then
bally := bally + 1
end if
if ballx < paddlex and ballx > paddlex - 100 and bally < paddley - 5 and bally < paddley then
ymod *= -1
end if
Draw.FillBox (x1 - 10, y1 - 10, x1 + 80, y1 - 3, Rand.Int (1, 16))
if ballx > x1 - 10 and ballx < x1 + 80 and bally > y1 - 10 and bally < y1 - 3 then
ymod *= -1
x1 := 0
y1 := 0
end if
Draw.FillBox (x2 - 10, y2 - 10, x2 + 80, y2 - 3, Rand.Int (1, 16))
if ballx > x2 - 10 and ballx < x2 + 80 and bally > y2 - 10 and bally < y2 - 3 then
ymod *= -1
x2 := 0
y2 := 0
end if
Draw.FillBox (x3 - 10, y3 - 10, x3 + 80, y3 - 3, Rand.Int (1, 16))
if ballx > x3 - 10 and ballx < x3 + 80 and bally > y3 - 10 and bally < y3 - 3 then
ymod *= -1
x3 := 0
y3 := 0
end if
Draw.FillBox (x4 - 10, y4 - 10, x4 + 80, y4 - 3, Rand.Int (1, 16))
if ballx > x4 - 10 and ballx < x4 + 80 and bally > y4 - 10 and bally < y4 - 3 then
ymod *= -1
x4 := 0
y4 := 0
end if
Draw.FillBox (x5 - 10, y5 - 10, x5 + 80, y5 - 3, Rand.Int (1, 16))
if ballx > x5 - 10 and ballx < x5 + 80 and bally > y5 - 10 and bally < y5 - 3 then
ymod *= -1
x5 := 0
y5 := 0
end if
Draw.FillBox (x6 - 10, y6 - 10, x6 + 80, y6 - 3, Rand.Int (1, 16))
if ballx > x6 - 10 and ballx < x6 + 80 and bally > y6 - 10 and bally < y6 - 3 then
ymod *= -1
x6 := 0
y6 := 0
end if
Draw.FillBox (x7 - 10, y7 - 10, x7 + 80, y7 - 3, Rand.Int (1, 16))
if ballx > x7 - 10 and ballx < x7 + 80 and bally > y7 - 10 and bally < y7 - 3 then
ymod *= -1
x7 := 0
y7 := 0
end if
Draw.FillBox (x8 - 10, y8 - 10, x8 + 80, y8 - 3, Rand.Int (1, 16))
if ballx > x8 - 10 and ballx < x8 + 80 and bally > y8 - 10 and bally < y8 - 3 then
ymod *= -1
x8 := 0
y8 := 0
end if
Draw.FillBox (x9 - 10, y9 - 10, x9 + 80, y9 - 3, Rand.Int (1, 16))
if ballx > x9 - 10 and ballx < x9 + 80 and bally > y9 - 10 and bally < y9 - 3 then
ymod *= -1
x9 := 0
y9 := 0
end if
Draw.FillBox (x10 - 10, y10 - 10, x10 + 80, y10 - 3, Rand.Int (1, 16))
if ballx > x10 - 10 and ballx < x10 + 80 and bally > y10 - 10 and bally < y10 - 3 then
ymod *= -1
x10 := 0
y10 := 0
end if
Draw.FillBox (x11 - 10, y11 - 10, x11 + 80, y11 - 3, Rand.Int (1, 16))
if ballx > x11 - 10 and ballx < x11 + 80 and bally > y11 - 10 and bally < y11 - 3 then
ymod *= -1
x11 := 0
y11 := 0
end if
Draw.FillBox (x12 - 10, y12 - 10, x12 + 80, y12 - 3, Rand.Int (1, 16))
if ballx > x12 - 10 and ballx < x12 + 80 and bally > y12 - 10 and bally < y12 - 3 then
ymod *= -1
x12 := 1
y12 := 1
end if
Draw.FillBox (x13 - 10, y13 - 10, x13 + 80, y13 - 3, Rand.Int (1, 16))
if ballx > x13 - 10 and ballx < x13 + 80 and bally > y13 - 10 and bally < y13 - 3 then
ymod *= -1
x13 := 0
y13 := 0
end if
Draw.FillBox (x14 - 10, y14 - 10, x14 + 80, y14 - 3, Rand.Int (1, 16))
if ballx > x14 - 10 and ballx < x14 + 80 and bally > y14 - 10 and bally < y14 - 3 then
ymod *= -1
x14 := 0
y14 := 0
end if
Draw.FillBox (x15 - 10, y15 - 10, x15 + 80, y15 - 3, Rand.Int (1, 16))
if ballx > x15 - 10 and ballx < x15 + 80 and bally > y15 - 10 and bally < y15 - 3 then
ymod *= -1
x15 := 0
y15 := 0
end if
if whatdotcolour (ballx + 12, bally + 12) = 24 or whatdotcolour (ballx - 12, bally - 12) = -24 then
xmod := -xmod
end if
if paddlex >= maxx - 7 then
paddlex := paddlex - 1
elsif paddlex <= 100 then
paddlex := paddlex + 1
else
if key (KEY_RIGHT_ARROW) then
View.Update
paddlex := paddlex + 1
elsif key (KEY_LEFT_ARROW) then
View.Update
paddlex := paddlex - 1
end if
end if
View.Update
delay (2)
if bally = 0 then
locate (10, 35)
put "Game Over"
return
end if
end loop
|
help would be appreciated thanks alot |
|
|
|
|
|
Sponsor Sponsor
|
|
|
jamonathin
|
Posted: Fri May 06, 2005 12:20 pm Post subject: (No subject) |
|
|
ARRAY! its a mess without it.
code: | var x,y:array 1 .. 15 of int
%then use
x(1):=
y(1):=
...
x(15) :=
y(15):= |
There too much wrong with this (setup wise), and I've already assisted with one of these, (therefore I dont feel like repeating), so ake a look at this topic, and read through it.
http://www.compsci.ca/v2/viewtopic.php?t=8585 |
|
|
|
|
|
mike200015
|
Posted: Fri May 06, 2005 3:15 pm Post subject: (No subject) |
|
|
hey.. yea.. thats wat game im making also.. u should defenitely use arrays.. u can chek it out in jamonothins link to my posts. |
|
|
|
|
|
Paul
|
|
|
|
|
reckless
|
Posted: Thu May 12, 2005 11:56 am Post subject: (No subject) |
|
|
well thanks for the help but im lost again lol i tried doing the whole array thing and this is why i didnt do it in the first place
code: | setscreen ("offscreenonly")
var key : array char of boolean
var x, y : array 1 .. 15 of int
var power1, power2, paddlex, paddley, xmod, ymod, ballx, bally : int
paddlex := 200
paddley := 10
power1 := 200
power2 := 10
xmod := 1
ymod := 1
ballx := Rand.Int (0, 180)
bally := Rand.Int (0, 180)
x (1) := 400
y (1) := 200
y (2) := 200
x (2) := 300
y (2) := 200
x (3) := 200
y (3) := 200
x (4) := 100
y (4) := 200
x (5) := 400
y (5) := 300
x (6) := 300
y (6) := 300
x (7) := 200
y (7) := 300
x (8) := 100
y (8) := 300
x (9) := 400
y (9) := 400
x (10) := 300
y (10) := 400
x (11) := 200
y (11) := 400
x (12) := 100
y (12) := 400
x (13) := 400
y (13) := 500
x (14) := 300
y (14) := 500
x (15) := 200
y (15) := 500
loop
Draw.FillBox (0, 0, maxx, maxy, 0)
Draw.FillBox (paddlex, paddley, paddlex - 100, paddley - 5, 12)
Draw.FillOval (ballx, bally, 10, 10, 16)
Input.KeyDown (key)
ballx += xmod
bally += ymod
if ballx >= maxx then
xmod := -xmod
elsif ballx <= 0 then
xmod := -xmod
end if
if bally >= maxy then
ymod := -ymod
elsif bally <= 0 then
ymod := -ymod
end if
if ballx = paddlex then
bally := bally + 1
end if
if ballx < paddlex and ballx > paddlex - 100 and bally < paddley - 5 and bally < paddley then
ymod *= -1
end if
Draw.FillBox (x (1) - 10, y (1) - 10, x (1) + 80, y (1) - 3, Rand.Int (1, 16))
if ballx > x (1) - 10 and ballx < x (1) + 80 and bally > y (1) - 10 and bally < y (1) - 3 then
ymod *= -1
x (1) := 0
y (1) := 0
end if
Draw.FillBox (x (2) - 10, y (2) - 10, x (2) + 80, y (2) - 3, Rand.Int (1, 16))
if ballx > x (2) - 10 and ballx < x (2) + 80 and bally > y (2) - 10 and bally < y (2) - 3 then
ymod *= -1
x (2) := 0
y (2) := 0
end if
Draw.FillBox (x (3) - 10, y (3) - 10, x (3) + 80, y (3) - 3, Rand.Int (1, 16))
if ballx > x (3) - 10 and ballx < x (3) + 80 and bally > y (3) - 10 and bally < y (3) - 3 then
ymod *= -1
x (3) := 0
y (3) := 0
end if
Draw.FillBox (x (4) - 10, y (4) - 10, x (4) + 80, y (4) - 3, Rand.Int (1, 16))
if ballx > x (4) - 10 and ballx < x (4) + 80 and bally > y (4) - 10 and bally < y (4) - 3 then
ymod *= -1
x (4) := 0
y (4) := 0
end if
Draw.FillBox (x (5) - 10, y (5) - 10, x (5) + 80, y (5) - 3, Rand.Int (1, 16))
if ballx > x (5) - 10 and ballx < x (5) + 80 and bally > y (5) - 10 and bally < y (5) - 3 then
ymod *= -1
x (5) := 0
y (5) := 0
end if
Draw.FillBox (x (6) - 10, y (6) - 10, x (6) + 80, y (6) - 3, Rand.Int (1, 16))
if ballx > x (6) - 10 and ballx < x (6) + 80 and bally > y (6) - 10 and bally < y (6) - 3 then
ymod *= -1
x (6) := 0
y (6) := 0
end if
Draw.FillBox (x (7) - 10, y (7) - 10, x (7) + 80, y (7) - 3, Rand.Int (1, 16))
if ballx > x (7) - 10 and ballx < x (7) + 80 and bally > y (7) - 10 and bally < y (7) - 3 then
ymod *= -1
x (7) := 0
y (7) := 0
end if
Draw.FillBox (x (8) - 10, y (8) - 10, x (8) + 80, y (8) - 3, Rand.Int (1, 16))
if ballx > x (8) - 10 and ballx < x (8) + 80 and bally > y (8) - 10 and bally < y (8) - 3 then
ymod *= -1
x (8) := 0
y (8) := 0
end if
Draw.FillBox (x (9) - 10, y (9) - 10, x (9) + 80, y (9) - 3, Rand.Int (1, 16))
if ballx > x (9) - 10 and ballx < x (9) + 80 and bally > y (9) - 10 and bally < y (9) - 3 then
ymod *= -1
x (9) := 0
y (9) := 0
end if
Draw.FillBox (x (10) - 10, y (10) - 10, x (10) + 80, y (10) - 3, Rand.Int (1, 16))
if ballx > x (10) - 10 and ballx < x (10) + 80 and bally > y (10) - 10 and bally < y (10) - 3 then
ymod *= -1
x (10) := 0
y (10) := 0
end if
Draw.FillBox (x (11) - 10, y (11) - 10, x (11) + 80, y (11) - 3, Rand.Int (1, 16))
if ballx > x (11) - 10 and ballx < x (11) + 80 and bally > y (11) - 10 and bally < y (11) - 3 then
ymod *= -1
x (11) := 0
y (11) := 0
end if
Draw.FillBox (x (12) - 10, y (12) - 10, x (12) + 80, y (12) - 3, Rand.Int (1, 16))
if ballx > x (12) - 10 and ballx < x (12) + 80 and bally > y (12) - 10 and bally < y (12) - 3 then
ymod *= -1
x (12) := 1
y (12) := 1
end if
Draw.FillBox (x (13) - 10, y (13) - 10, x (13) + 80, y (13) - 3, Rand.Int (1, 16))
if ballx > x (13) - 10 and ballx < x (13) + 80 and bally > y (13) - 10 and bally < y (13) - 3 then
ymod *= -1
x (13) := 0
y (13) := 0
end if
Draw.FillBox (x (14) - 10, y (14) - 10, x (14) + 80, y (14) - 3, Rand.Int (1, 16))
if ballx > x (14) - 10 and ballx < x (14) + 80 and bally > y (14) - 10 and bally < y (14) - 3 then
ymod *= -1
x (14) := 0
y (14) := 0
end if
Draw.FillBox (x (15) - 10, y (15) - 10, x (15) + 80, y (15) - 3, Rand.Int (1, 16))
if ballx > x (15) - 10 and ballx < x (15) + 80 and bally > y (15) - 10 and bally < y (15) - 3 then
ymod *= -1
x (15) := 0
y (15) := 0
end if
if whatdotcolour (ballx + 12, bally + 12) = 24 or whatdotcolour (ballx - 12, bally - 12) = -24 then
xmod := -xmod
end if
if paddlex >= maxx - 7 then
paddlex := paddlex - 2
elsif paddlex <= 100 then
paddlex := paddlex + 2
else
if key (KEY_RIGHT_ARROW) then
View.Update
paddlex := paddlex + 1
elsif key (KEY_LEFT_ARROW) then
View.Update
paddlex := paddlex - 1
elsif key (KEY_UP_ARROW) then
View.Update
elsif key (KEY_DOWN_ARROW) then
View.Update
end if
end if
View.Update
delay (2)
if x (15) = 0 then
end if
if bally = 0 then
locate (10, 35)
put "Game Over"
return
end if
end loop
|
[EDIT] nevermind i got it working but is this what you meant to use arrays or can i still shorten it? |
|
|
|
|
|
Xuman
|
Posted: Mon May 16, 2005 4:26 pm Post subject: "for" |
|
|
The whole point of using arrays is so that you can shorten the code and make it neat.
This still does the same thing but is way shorter.
Use "for" !!!
code: | setscreen ("offscreenonly")
var key : array char of boolean
var x, y : array 1 .. 15 of int
var power1, power2, paddlex, paddley, xmod, ymod, ballx, bally : int
paddlex := 200
paddley := 10
power1 := 200
power2 := 10
xmod := 1
ymod := 1
ballx := Rand.Int (0, 180)
bally := Rand.Int (0, 180)
for i : 1 .. 15
x (i) := 100 + (i mod 4) * 100
y (i) := 200 + (i mod 3) * 100
end for
loop
Draw.FillBox (0, 0, maxx, maxy, 0)
Draw.FillBox (paddlex, paddley, paddlex - 100, paddley - 5, 12)
Draw.FillOval (ballx, bally, 10, 10, 16)
Input.KeyDown (key)
ballx += xmod
bally += ymod
if ballx >= maxx or ballx <= 0 then
xmod := -xmod
end if
if bally >= maxy or bally <= 0 then
ymod := -ymod
end if
if ballx = paddlex then
bally := bally + 1
end if
if ballx < paddlex and ballx > paddlex - 100 and bally < paddley - 5 and bally < paddley then
ymod *= -1
end if
for i : 1 .. 15
Draw.FillBox (x (i) - 10, y (i) - 10, x (i) + 80, y (i) - 3, Rand.Int (1, 16))
if ballx > x (i) - 10 and ballx < x (i) + 80 and bally > y (i) - 10 and bally < y (i) - 3 then
ymod *= -1
x (i) := 0
y (i) := 0
end if
end for
if whatdotcolour (ballx + 12, bally + 12) = 24 or whatdotcolour (ballx - 12, bally - 12) = -24 then
xmod := -xmod
end if
if paddlex >= maxx - 7 then
paddlex := paddlex - 2
elsif paddlex <= 100 then
paddlex := paddlex + 2
else
if key (KEY_RIGHT_ARROW) then
View.Update
paddlex := paddlex + 1
elsif key (KEY_LEFT_ARROW) then
View.Update
paddlex := paddlex - 1
elsif key (KEY_UP_ARROW) then
View.Update
elsif key (KEY_DOWN_ARROW) then
View.Update
end if
end if
View.Update
delay (2)
if x (15) = 0 then
end if
if bally = 0 then
locate (10, 35)
put "Game Over"
return
end if
end loop
|
btw, sometimes the ball doesnt bounce off the blocks... |
|
|
|
|
|
|
|