Posted: Mon Apr 25, 2005 10:11 pm Post subject: Blockout Game Help
Ok, so im making a blockout game, and i still cant get the collision detection perfect, i got alot of it to work, but still, when the ball hits the blocks in certain spots, the blocks dont dissapear, can someone please help!!
Heres the code for the whole game:
Turing:
type block : record
x :int
y :int
hits :int endrecord var xvalue :int:= -15 var yvalue :int:=0 var blocks :array1.. 156of block
var colours :array1.. 10ofint:=init(40, 50, 60, 70, 80, 90, 100, 110, 120, 130) var blockcol :array1.. 156ofint var chars :arraycharofboolean var ballx :=maxxdiv2 var bally :=15 var pos :=maxxdiv2 var xmod :=1 var ymod :=1 var tries :=3 var score :=0 %var blockhit := 0 var font3 :=Font.New("Courier New:10:bold")%All other font %var font1 := Font.New ("Courier New:20:bold") %Title font var keyPressed :string(1) setscreen("graphics:640;400,title:Mikes X-Treme Pong Game,nocursor") for i :1.. upper(blocks)
blocks (i).hits :=0 endfor
loop cls for i :1.. 156 randint(blockcol (i),1, 10) endfor setscreen("offscreenonly") loop cls for i :1.. 156 if(i - 1)rem12=0then
xvalue +=45
yvalue :=230 endif
blocks (i).x := xvalue
blocks (i).y := yvalue
if blocks (i).hits ~=1then Draw.FillBox(blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, colours (blockcol (i))) endif
yvalue +=12 endfor Draw.FillBox(pos - 25, 0, pos + 25, 5, 1)%user paddle Draw.FillOval(ballx, bally, 10, 10, 12)%ball Font.Draw("Tries Remaining: " + intstr(tries),2, maxy - 12, font3, blue) Font.Draw("Score: " + intstr(score),maxx - 83, maxy - 12, font3, blue) Draw.Line(0, maxy - 20, maxx, maxy - 20, RGB.AddColor(0.1, 0.1, 0.1))%top boundary line Input.KeyDown(chars) if chars (KEY_LEFT_ARROW)and pos - 25 > 0then%Moves paddle left
pos -=1
ballx -=1 elsif chars (KEY_RIGHT_ARROW)and pos + 30 < maxxthen%Moves paddle right
pos +=1
ballx +=1 elsif chars (KEY_UP_ARROW)then exit endif
xvalue := -15
yvalue :=0 View.Update endloop loop
ballx += xmod
bally += ymod
if ballx >= maxxthen
xmod := -xmod %ball goes in opposite x-direction sound(500, 10) elsif ballx <= 0then
xmod := -xmod %ball goes in opposite x-direction sound(500, 10) endif if bally >= maxy - 30then
ymod := -ymod %ball goes in opposite y-direction sound(500, 10) elsif bally <= 5then
ymod := -ymod
sound(500, 10) endif for i :1.. 156 if(i - 1)rem12=0then
xvalue +=45
yvalue :=230 endif
blocks (i).x := xvalue
blocks (i).y := yvalue
if blocks (i).hits ~=1then Draw.FillBox(blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, colours (blockcol (i))) endif
yvalue +=12 endfor Draw.FillBox(pos - 25, 0, pos + 25, 5, 1)%user paddle Draw.FillOval(ballx, bally, 10, 10, 12)%ball Font.Draw("Tries Remaining: " + intstr(tries),2, maxy - 12, font3, blue) Font.Draw("Score: " + intstr(score),maxx - 83, maxy - 12, font3, blue) Draw.Line(0, maxy - 20, maxx, maxy - 20, RGB.AddColor(0.1, 0.1, 0.1))%top boundary line Input.KeyDown(chars) if chars (KEY_LEFT_ARROW)and pos - 25 > 0then%Moves paddle left
pos -=2 elsif chars (KEY_RIGHT_ARROW)and pos + 25 < maxxthen%Moves paddle right
pos +=2 endif if chars ('x')then exit elsif chars ('p')then%Pauses game setscreen("nooffscreenonly") Font.Draw("GAME PAUSED",maxxdiv2 - 20, maxy - 12, font3, blue) Font.Draw("*Press ENTER To Resume*",maxxdiv2 - Font.Width("*Press ENTER To Resume*", font3) div2, 100, font3, blue) loop getch(keyPressed) exitwhen keyPressed = KEY_ENTER
endloop setscreen("offscreenonly") endif
xvalue := -15
yvalue :=0 /*
for i : 1 .. upper (colours)
if whatdotcolour (ballx + 11, bally) = colours (i) or whatdotcolour (ballx - 11, bally) = colours (i) then
xmod *= -1 % same as xmod := - xmod
end if
if whatdotcolour (ballx, bally + 11) = colours (i) or whatdotcolour (ballx, bally - 11) = colours (i) then
ymod *= -1
end if
end for
*/ casewhatdotcolour(ballx + 11, bally)orwhatdotcolour(ballx - 11, bally)of%if ball hits anything green (2) label40, 50, 60, 70, 80, 90, 100, 110, 120, 130:%it will go in opposite x-direction
xmod *= -1 labelblue, 12, yellow, black, 5, 2:
xmod *= -1 label:
xmod *=1 endcase casewhatdotcolour(ballx, bally + 11)orwhatdotcolour(ballx, bally - 11)of%if ball hits anything green (2) label40, 50, 60, 70, 80, 90, 100, 110, 120, 130:%it will go in opposite y-direction
ymod *= -1 labelblue, 12, yellow, black, 5, 2:
ymod *= -1 label:
ymod *=1 endcase for i :1.. upper(blocks) if ballx - 10 >= blocks (i).x and ballx - 10 <= blocks (i).x + 40and bally + 10 >= blocks (i).y and bally + 10 <= blocks (i).y + 10or
ballx + 10 >= blocks (i).x and ballx + 10 <= blocks (i).x + 40and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10or
ballx - 10 >= blocks (i).x and ballx - 10 <= blocks (i).x + 40and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10or
ballx + 10 >= blocks (i).x and ballx + 10 <= blocks (i).x + 40and bally + 10 >= blocks (i).y and bally + 10 <= blocks (i).y + 10or
ballx >= blocks (i).x and ballx <= blocks (i).x + 40and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10 then
blocks (i).hits :=1 %blockhit += 1 %elsif ballx + 10 >= blocks (i).x and ballx + 10 <= blocks (i).x + 40 and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10 then %blocks (i).hits :=1 endif %OR %if x >= blockx (i) and x <= blockx (i) and blocky (i) - (y + radius) <= 4 then %end if endfor /*
if blockhit = 156 then
setscreen ("nooffscreenonly")
Font.Draw ("You Win!!!", maxx div 2 - Font.Width ("You Win!!!", font1) div 2, maxy div 2, font1, black)
delay (700)
Font.Draw ("*Press ENTER To Resume*", maxx div 2 - Font.Width ("*Press ENTER To Resume*", font3)
div 2, 120, font3, blue)
loop
Input.Flush
getch (keyPressed)
exit when keyPressed = KEY_ENTER
end loop
exit
end if
*/ /*
if whatdotcolour (ballx + 11, bally) = padcol or whatdotcolour (ballx - 11, bally) = padcol or
whatdotcolour (ballx + 11, bally) = blockcol () or whatdotcolour (ballx - 11, bally) = padcol then
xmod := -xmod
end if
if whatdotcolour (ballx, bally + 11) = padcol or whatdotcolour (ballx, bally - 11) = padcol then
ymod := -ymod
end if
*/ View.Update cls endloop if chars ('x')then exit endif endloop
And this is the particular code that is the collision detection, which makes the blocks dissapear, which is the part i need help with:
Turing:
for i :1.. upper(blocks) if ballx - 10 >= blocks (i).x and ballx - 10 <= blocks (i).x + 40and bally + 10 >= blocks (i).y and bally + 10 <= blocks (i).y + 10or
ballx + 10 >= blocks (i).x and ballx + 10 <= blocks (i).x + 40and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10or
ballx - 10 >= blocks (i).x and ballx - 10 <= blocks (i).x + 40and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10or
ballx + 10 >= blocks (i).x and ballx + 10 <= blocks (i).x + 40and bally + 10 >= blocks (i).y and bally + 10 <= blocks (i).y + 10or
ballx >= blocks (i).x and ballx <= blocks (i).x + 40and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10 then
blocks (i).hits :=1 %blockhit += 1 %elsif ballx + 10 >= blocks (i).x and ballx + 10 <= blocks (i).x + 40 and bally - 10 >= blocks (i).y and bally - 10 <= blocks (i).y + 10 then %blocks (i).hits :=1 endif %OR %if x >= blockx (i) and x <= blockx (i) and blocky (i) - (y + radius) <= 4 then %end if endfor
Sponsor Sponsor
mike200015
Posted: Tue Apr 26, 2005 4:47 pm Post subject: (No subject)
anyone
jamonathin
Posted: Tue Apr 26, 2005 5:34 pm Post subject: (No subject)
Here yas go mayte
code:
type block :
record
x : int
y : int
hits : int
end record
var xvalue : int := -15
var yvalue : int := 0
var blocks : array 1 .. 156 of block
var colours : array 1 .. 10 of int := init (40, 50, 60, 70, 80, 90, 100, 110, 120, 130)
var blockcol : array 1 .. 156 of int
var chars : array char of boolean
var ballx := maxx div 2
var bally := 15
var pos := maxx div 2
var xmod := 1
var ymod := 1
var tries := 3
var score := 0
%var blockhit := 0
var font3 := Font.New ("Courier New:10:bold") %All other font
%var font1 := Font.New ("Courier New:20:bold") %Title font
var keyPressed : string (1)
setscreen ("graphics:640;400,title:Mikes X-Treme Pong Game,nocursor")
for i : 1 .. upper (blocks)
blocks (i).hits := 0
end for
loop
cls
for i : 1 .. 156
randint (blockcol (i), 1, 10)
end for
setscreen ("offscreenonly")
loop
cls
for i : 1 .. 156
if (i - 1) rem 12 = 0 then
xvalue += 45
yvalue := 230
end if
blocks (i).x := xvalue
blocks (i).y := yvalue
if blocks (i).hits not= 1 then
Draw.FillBox (blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, colours (blockcol (i)))
end if
yvalue += 12
end for
Draw.FillBox (pos - 25, 0, pos + 25, 5, 1) %user paddle
Draw.FillOval (ballx, bally, 10, 10, 12) %ball
Font.Draw ("Tries Remaining: " + intstr (tries), 2, maxy - 12, font3, blue)
Font.Draw ("Score: " + intstr (score), maxx - 83, maxy - 12, font3, blue)
Draw.Line (0, maxy - 20, maxx, maxy - 20, RGB.AddColor (0.1, 0.1, 0.1)) %top boundary line
Input.KeyDown (chars)
if chars (KEY_LEFT_ARROW) and pos - 25 > 0 then %Moves paddle left
pos -= 1
ballx -= 1
elsif chars (KEY_RIGHT_ARROW) and pos + 30 < maxx then %Moves paddle right
pos += 1
ballx += 1
elsif chars (KEY_UP_ARROW) then
exit
end if
xvalue := -15
yvalue := 0
View.Update
end loop
loop
ballx += xmod
bally += ymod
if ballx >= maxx then
xmod := -xmod %ball goes in opposite x-direction
sound (500, 10)
elsif ballx <= 0 then
xmod := -xmod %ball goes in opposite x-direction
sound (500, 10)
end if
if bally >= maxy - 30 then
ymod := -ymod %ball goes in opposite y-direction
sound (500, 10)
elsif bally <= 5 then
ymod := -ymod
sound (500, 10)
end if
for i : 1 .. 156
if (i - 1) rem 12 = 0 then
xvalue += 45
yvalue := 230
end if
blocks (i).x := xvalue
blocks (i).y := yvalue
if blocks (i).hits ~= 1 then
Draw.FillBox (blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, colours (blockcol (i)))
end if
yvalue += 12
end for
Draw.FillBox (pos - 25, 0, pos + 25, 5, 1) %user paddle
Draw.FillOval (ballx, bally, 10, 10, 12) %ball
Font.Draw ("Tries Remaining: " + intstr (tries), 2, maxy - 12, font3, blue)
Font.Draw ("Score: " + intstr (score), maxx - 83, maxy - 12, font3, blue)
Draw.Line (0, maxy - 20, maxx, maxy - 20, RGB.AddColor (0.1, 0.1, 0.1)) %top boundary line
Input.KeyDown (chars)
if chars (KEY_LEFT_ARROW) and pos - 25 > 0 then %Moves paddle left
pos -= 2
elsif chars (KEY_RIGHT_ARROW) and pos + 25 < maxx then %Moves paddle right
pos += 2
end if
if chars ('x') then
exit
elsif chars ('p') then %Pauses game
setscreen ("nooffscreenonly")
Font.Draw ("GAME PAUSED", maxx div 2 - 20, maxy - 12, font3, blue)
Font.Draw ("*Press ENTER To Resume*", maxx div 2 - Font.Width ("*Press ENTER To Resume*", font3)
div 2, 100, font3, blue)
loop
getch (keyPressed)
exit when keyPressed = KEY_ENTER
end loop
setscreen ("offscreenonly")
end if
xvalue := -15
yvalue := 0
for i : 1 .. upper (blocks)
if blocks (i).hits not= 1 then
if ballx - 10 <= blocks (i).x + 40 and ballx >= blocks (i).x + 40 and bally >= blocks (i).y and bally <= blocks (i).y + 10
or ballx + 10 >= blocks (i).x and ballx <= blocks (i).x and bally >= blocks (i).y and bally <= blocks (i).y + 10 then
xmod *= -1
blocks (i).hits := 1
elsif bally + 10 >= blocks (i).y and bally <= blocks (i).y and ballx >= blocks (i).x and ballx <= blocks (i).x + 40
or bally - 10 <= blocks (i).y + 10 and bally >= blocks (i).y + 10 and ballx >= blocks (i).x and ballx <= blocks (i).x + 40 then
ymod *= -1
blocks (i).hits := 1
end if
end if
end for
View.Update
cls
end loop
if chars ('x') then
exit
end if
end loop
Your if statements were a little off, and you were making the ymod's and xmods change at the wrong time, therefore the ball would just plow through everything.
What I changed was, I put the detection of the ball hitting the side of a block in one if statement (both sides of block), and the top and bottom hit dection in another if statement. When those blocks were hit, it was then that I changed the direction of the ball, and told the program not to draw those balls again. I also put another if statement around that, so that it would only check detection if the block (i).hits not=1. If you need any more explanation, juss ask away.
mike200015
Posted: Tue Apr 26, 2005 7:35 pm Post subject: (No subject)
wow!! thnx so much! i was workin on that part for soo long and couldnt get it right. +5 Bits for your help!
Can you just explain the collision part that u changed, like which part is for the side detection and which part is for the top/bottom, and how it works sorta.
jamonathin
Posted: Tue Apr 26, 2005 7:49 pm Post subject: (No subject)
This is all i used for dection, I got rid of everything else.
Turing:
for i :1.. upper(blocks) if blocks (i).hits not= 1then if ballx - 10 <= blocks (i).x + 40and ballx >= blocks (i).x + 40and bally >= blocks (i).y and bally <= blocks (i).y + 10 or ballx + 10 >= blocks (i).x and ballx <= blocks (i).x and bally >= blocks (i).y and bally <= blocks (i).y + 10then
xmod *= -1
blocks (i).hits :=1 elsif bally + 10 >= blocks (i).y and bally <= blocks (i).y and ballx >= blocks (i).x and ballx <= blocks (i).x + 40 or bally - 10 <= blocks (i).y + 10and bally >= blocks (i).y + 10and ballx >= blocks (i).x and ballx <= blocks (i).x + 40then
ymod *= -1
blocks (i).hits :=1 endif endif endfor
Now this is for the horizontal checking:
Turing:
if ballx - 10 <= blocks (i).x + 40and ballx >= blocks (i).x + 40and bally >= blocks (i).y and bally <= blocks (i).y + 10 or ballx + 10 >= blocks (i).x and ballx <= blocks (i).x and bally >= blocks (i).y and bally <= blocks (i).y + 10then
xmod *= -1
blocks (i).hits :=1
The first chunk (before the or) checks if the left side of the ball hits.
Now, you only want to check that tip of the ball, nothing else, so thats why i check with bally, not bally +10 or -10
Now this is for the vertical checking:
Same concept with this. I'm only checking the tip of the ball, and the very bottom.
Ex. I'm Checking these parts of the ball (where the points are)
_.
-- [ I know this is really ugly ]
_'
However, this method can be faulty. For example, if the ball were to hit a corner, the tip, nor the side would hit first, this is where you can do some extra coding, or using whatdotcolor. This is a good start though.
mike200015
Posted: Tue Apr 26, 2005 8:07 pm Post subject: (No subject)
when you say that it only cheks the tips of the ball, do you mean just the top, bottom, right , and left tips of the ball are being checked? And not the parts in between the top/bottom tips and side tips?
And also, how do you do that turing code thing, so it says turing instead of just Code?
jamonathin
Posted: Tue Apr 26, 2005 8:32 pm Post subject: (No subject)
I juss learned it from wtd.
code:
[syntax="turing"][/syntax]
And yeah, i mean juss those tips, not inbetween, just where those ticks were, not the _'s. That's why the method isn't perfect.
mike200015
Posted: Wed Apr 27, 2005 4:12 pm Post subject: (No subject)
k i added sum new stuff to my blockout game, and i need some help with it. I made a ball collision with the paddle, and also added money that falls from certain blocks when you hit them, and if you get the money you get 1 point, and its all randmonly generated.
These are the problems im having:
1. Sometimes when the paddle is moving and ball hits it, it slides with it, or gets stuck.
2. When you it more blocks then the game runs faster and faster the more blocks that are gone.
Please, if anyone can help i'd appreciate it! Thanx!!
Heres the new code:
Turing:
type block : record
x :int
y :int
hits :int endrecord var xvalue :int:= -15 var yvalue :int:=0 var randblocks := Rand.Int (12, 25) var blocks :array1.. 156of block
var colours :array1.. 10ofint:=init(40, 50, 60, 70, 80, 90, 100, 110, 120, 130) var blockcol :array1.. 156ofint var moneyx :array1.. 156ofint var moneyy :array1.. 156ofint var randblocknum :array1.. randblocks ofint var monscore :array1.. 156ofint var chars :arraycharofboolean var ballx :=maxxdiv2 var bally :=15 var pos :=maxxdiv2 var xmod :=1 var ymod :=1 var tries :=3 var score :=0 var blockhit :=0 var font3 :=Font.New("Courier New:10:bold")%All other font var font1 :=Font.New("Courier New:20:bold")%Title font var keyPressed :string(1) setscreen("graphics:640;400,title:Mikes X-Treme Pong Game,nocursor")
loop cls for i :1.. 156% chooses colours for each block randomly randint(blockcol (i),1, 10) endfor for i :1.. upper(blocks)%sets all block hits to 0
blocks (i).hits :=0 endfor for i :1.. upper(randblocknum)%chooses random blocks to have money
randblocknum (i):= Rand.Int (1, 156) endfor setscreen("offscreenonly") loop cls for i :1.. 156%draws each block if(i - 1)rem12=0then
xvalue +=45
yvalue :=190 endif
blocks (i).x := xvalue
blocks (i).y := yvalue
if blocks (i).hits ~=1then% if block hasn't been hit, it's drawn Draw.FillBox(blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, colours (blockcol (i))) else%draws blocks that were hit in white Draw.FillBox(blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, white) endif
yvalue +=12
moneyx (i):= blocks (i).x + 18
moneyy (i):= blocks (i).y
monscore (i):=0 endfor Draw.FillBox(pos - 25, 0, pos + 25, 5, 1)%user paddle Draw.FillOval(ballx, bally, 10, 10, 12)%ball Font.Draw("Tries Remaining: " + intstr(tries),2, maxy - 12, font3, blue) Font.Draw("Score: " + intstr(score),maxx - 83, maxy - 12, font3, blue) Draw.Line(0, maxy - 20, maxx, maxy - 20, RGB.AddColor(0.1, 0.1, 0.1))%top boundary line Input.KeyDown(chars) if chars (KEY_LEFT_ARROW)and pos - 25 > 0then%Moves paddle left
pos -=1
ballx -=1 elsif chars (KEY_RIGHT_ARROW)and pos + 30 < maxxthen%Moves paddle right
pos +=1
ballx +=1 elsif chars (KEY_UP_ARROW)then exit endif
xvalue := -15
yvalue :=0 View.Update endloop loop
ballx += xmod
bally += ymod
if ballx >= maxxthen
xmod := -xmod %ball goes in opposite x-direction sound(500, 10) elsif ballx <= 0then
xmod := -xmod %ball goes in opposite x-direction sound(500, 10) endif if bally >= maxy - 30then
ymod := -ymod %ball goes in opposite y-direction sound(500, 10) elsif bally <= 5then
ymod := -ymod
sound(500, 10) endif for i :1.. 156%draws all blocks, only if they havn't been hit if(i - 1)rem12=0then
xvalue +=45
yvalue :=190 endif
blocks (i).x := xvalue
blocks (i).y := yvalue
if blocks (i).hits ~=1then%draws blocks that haven't been hit Draw.FillBox(blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, colours (blockcol (i))) else%draws blocks that were hit in white Draw.FillBox(blocks (i).x, blocks (i).y + 2, blocks (i).x + 40, blocks (i).y + 10, white) endif
yvalue +=12 endfor Draw.FillBox(pos - 25, 0, pos + 25, 5, 1)%user paddle Draw.FillOval(ballx, bally, 10, 10, 12)%ball Font.Draw("Tries Remaining: " + intstr(tries),2, maxy - 12, font3, blue) Font.Draw("Score: " + intstr(score),maxx - 83, maxy - 12, font3, blue) Draw.Line(0, maxy - 20, maxx, maxy - 20, RGB.AddColor(0.1, 0.1, 0.1))%top boundary line Input.KeyDown(chars) if chars (KEY_LEFT_ARROW)and pos - 25 > 0then%Moves paddle left
pos -=2 elsif chars (KEY_RIGHT_ARROW)and pos + 25 < maxxthen%Moves paddle right
pos +=2 endif if chars ('x')then exit elsif chars ('p')then%Pauses game setscreen("nooffscreenonly") Font.Draw("GAME PAUSED",maxxdiv2 - 20, maxy - 12, font3, blue) Font.Draw("*Press ENTER To Resume*",maxxdiv2 - Font.Width("*Press ENTER To Resume*", font3) div2, 100, font3, blue) loop getch(keyPressed) exitwhen keyPressed = KEY_ENTER
endloop setscreen("offscreenonly") endif
xvalue := -15
yvalue :=0 /*
if blockhit = 15 then %if all blocks are hit then displays You Win!!!
setscreen ("nooffscreenonly")
Font.Draw ("You Win!!!", maxx div 2 - Font.Width ("You Win!!!", font1) div 2, maxy div 2, font1, black)
delay (700)
Font.Draw ("*Press ENTER To Resume*", maxx div 2 - Font.Width ("*Press ENTER To Resume*", font3)
div 2, 120, font3, blue)
loop
Input.Flush
getch (keyPressed)
exit when keyPressed = KEY_ENTER
end loop
exit
end if
*/ for i :1.. randblocks %checks if money block has been hit, if so, 1 point is added to score if blocks (randblocknum (i)).hits =1then Font.Draw("$", moneyx (randblocknum (i)), moneyy (randblocknum (i)), font3, blue) if moneyx (randblocknum (i)) >= pos - 25and moneyx (randblocknum (i)) <= pos + 25and moneyy (randblocknum (i)) >= -6and moneyy (randblocknum (i)) <= 8then
monscore (randblocknum (i)) +=1 endif
moneyy (randblocknum (i)) -=1 endif if monscore (randblocknum (i))=1then
score +=1 endif endfor if ballx - 10 <= pos + 25and ballx >= pos + 25and bally >= 0and bally <= 5%if statement for ball and paddle collision or ballx + 10 >= pos - 25and ballx <= pos - 25and bally >= 0and bally <= 5then
xmod *= -1 elsif bally + 10 >= 0and bally <= 0and ballx >= pos - 25and ballx <= pos + 25 or bally - 10 <= 5and bally >= 5and ballx >= pos - 25and ballx <= pos + 25then
ymod *= -1 endif for i :1.. upper(blocks)%for loop w/if statements to check ball and block collision, and if so, sets the if blocks (i).hits ~=1then% ball #'s hit counter to 1, and ball is not drawn. if ballx - 10 <= blocks (i).x + 40and ballx >= blocks (i).x + 40and bally >= blocks (i).y and bally <= blocks (i).y + 10 or ballx + 10 >= blocks (i).x and ballx <= blocks (i).x and bally >= blocks (i).y and bally <= blocks (i).y + 10then
xmod *= -1
blocks (i).hits :=1
blockhit +=1 elsif bally + 10 >= blocks (i).y and bally <= blocks (i).y and ballx >= blocks (i).x and ballx <= blocks (i).x + 40 or bally - 10 <= blocks (i).y + 10and bally >= blocks (i).y + 10and ballx >= blocks (i).x and ballx <= blocks (i).x + 40then
ymod *= -1
blocks (i).hits :=1
blockhit +=1 endif endif endfor View.Update cls endloop if chars ('x')then%exits game exit endif endloop
Sponsor Sponsor
jamonathin
Posted: Thu Apr 28, 2005 8:12 am Post subject: (No subject)
The reason your game speeds up is because your program is used to drawing a lot of boxes, now it only has to draw a couple, so it's going to do so faster. What you can do, is when you check if the block is hit (that's where you decide whether or not to draw it) you can then draw that block, only in white, or whatever color your background is. Or better yet, you can cheat. Lets say you have some picture you want to import, so redrawing the hit blocks wont work, have the program draw the block at like (5000,5000) or something, you'll never see it, and the speed wont change.
And this is all you need for the paddle. There's no real point and making xmod*=-1 because if the ball does hit the side of the paddle, it still goin down and theres nothing you can do about it.
P.S. I was playin ur game, and one of the times that i got a money thing, my score kept goin, and i got like 7765 score, look into that
mike200015
Posted: Thu Apr 28, 2005 1:41 pm Post subject: (No subject)
haha lol.. yea i know... sum1 else told me that 2.. ill chek that out.. thanx for your help tho
mike200015
Posted: Thu Apr 28, 2005 9:23 pm Post subject: (No subject)
ok.. im adding another new part to my blockout game, im adding a shooting part. You start off with 5 bullets, and then when money falls and you get it you can buy more. I have no clue how to make the shooting part though. I want it so that when you press space, a bullet comes from the middle of wherever the paddle is, and if they hit a block, the blok and bullet dissapear. And when a bullet shoots, it takes 1 off your amo level, and when you hav 0 then you cant shoot. And also, I want it so you can shoot many bullets at a time, with a delay inbetween.
I made the money falling and store to buy bullets, i just need help making bullets shoot from the paddle and the rapid fire etc.
If anyone can help me get started with this part id appreciate it, im working on it in a new file to make it easier, so this is the basic blocks, and paddle part:
Turing:
type block : record
x :int
y :int
hits :int endrecord var xvalue :int:= -15 var yvalue :int:=0 var blocks :array1.. 156of block
var colours :array1.. 10ofint:=init(40, 50, 60, 70, 80, 90, 100, 110, 120, 130) var blockcol :array1.. 156ofint var chars :arraycharofboolean var ballx :=maxxdiv2 var bally :=15 var pos :=maxxdiv2 var xmod :=1 var ymod :=1 var tries :=3 var score :=0 var font3 :=Font.New("Courier New:10:bold")%All other font var keyPressed :string(1) var bulbutton :=chr(ORD_SPACE)%declares space button for shooting setscreen("graphics:640;400,title:Mikes X-Treme Pong Game,nocursor") for i :1.. upper(blocks)
blocks (i).hits :=0 endfor
Posted: Fri May 06, 2005 3:25 pm Post subject: (No subject)
this topic was from sort of a while ago.. but.. i figured out that now i need to check more than just those four points from before, how would i check more than just the 4 points on the ball?
Cervantes
Posted: Fri May 06, 2005 4:02 pm Post subject: (No subject)
Equation of a circle? Didn't I mention that elsewhere?
jamonathin wrote:
The reason your game speeds up is because your program is used to drawing a lot of boxes, now it only has to draw a couple, so it's going to do so faster. What you can do, is when you check if the block is hit (that's where you decide whether or not to draw it) you can then draw that block, only in white, or whatever color your background is. Or better yet, you can cheat. Lets say you have some picture you want to import, so redrawing the hit blocks wont work, have the program draw the block at like (5000,5000) or something, you'll never see it, and the speed wont change.
Why don't we just set a FPS...
jamonathin
Posted: Fri May 06, 2005 8:35 pm Post subject: (No subject)
meh, whatever works
mike200015
Posted: Sat May 07, 2005 3:47 pm Post subject: (No subject)
Yea u mentioned that, but i dont really understand how i would use that equation to chek the circle and block collision
Also, wats a FPS?