What is it you are trying to achieve?
deleting the brick when the ball hits it, with the ball coming back to the user (brickbreaker)
What is the problem you are having?
cant seem to delete the brick it keeps coming back
Describe what you have tried to solve this problem
i would die before naming all that i tried
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
import GUI
View.Set ("graphics:638;690")
%_______Global Variables_______%
var wholescreen : array 1 .. sizepic (0, 0, maxx, maxy) of int
var arrowKeys : array char of boolean
var colorchanger1 : int
var PicID, PicID1 : int
var replay : string
var x1, y1, x2, y2 : int
var ball_x1, ball_x2, ball_y1, ball_y2 : int
var ball_directionx1 : int := 1
var ball_directiony1 : int := 1
var ball_directiony2 : int := 1
var ball_directionx2 : int := 1
var fontS : int
var x, y : int
var ball_speed, ball_speed1 : int
var continueGame : string
var lives : int
var score : int
var timeElapsed1, timeElapsed2 : int
var block_x1, block_y1, block_x2, block_y2 : int
var x1_ 1, y1_ 1, x2_ 2, y2_ 2 : int
var debugger : boolean := false
var ball_Radius : int := 15
var xb1, yb1, xb2, yb2 : int
var alive : array 1 .. 16 of boolean
var rc1, rc2, rc3, rc4 : int
type BrickData :
record
xCord, yCord, width, height : int
alive : boolean
end record
var brick : array 1 .. 6 of BrickData
xb1 := 50
yb1 := maxy div 2
x := 50
y := maxy div 2 + 50
randint (rc1, 2, 6)
randint (rc2, 2, 6)
randint (rc3, 2, 6)
randint (rc4, 2, 6)
proc initialValues
% Ball
ball_speed := 10
ball_speed1 := 8
ball_x1 := 512
ball_y1 := 200
ball_x2 := 900
ball_y2 := 200
% Paddle (Player)
x1 := 250
y1 := 25
x2 := 350
y2 := 50
% lives and score
lives := 2
score := 0
% blocks
x1_ 1 := 850
y1_ 1 := 25
x2_ 2 := 950
y2_ 2 := 50
block_x1 := 25
block_y1 := 200
block_x2 := 75
block_y2 := 250
% font
fontS := Font.New ("Verdana:20")
% splash screen
timeElapsed1 := Time.Elapsed div 1000
Pic.Draw (PicID, maxx div 2 - (638 div 2), maxy div 2 - (690 div 2), picCopy)
end initialValues
%_______Procedures_______%
procedure TheGame2
initialValues
setscreen ("graphics:1000;650,title:The BrickBreaker Game")
View.Set ("offscreenonly")
colorback (16)
const SnowFlakesFalling := 600
var SnowFlakeX : array 1 .. SnowFlakesFalling of int
var SnowFlakeY : array 1 .. SnowFlakesFalling of int
for SnowFlake : 1 .. SnowFlakesFalling
SnowFlakeX (SnowFlake ) := Rand.Int (0, maxx)
SnowFlakeY (SnowFlake ) := Rand.Int (0, maxy)
end for
lives + = 1
timeElapsed1 := Time.Elapsed div 1000
loop
randint (colorchanger1, 1, 101)
delay (1)
drawfillbox (x1, y1, x2, y2, colorchanger1 )
delay (5)
drawbox (20, 20, maxx - 20, maxy - 20, 51)
drawbox (5, 5, maxx - 5, maxy - 10, 51)
drawfillbox (250, 900, 350, 925, 101)
drawfillbox (maxx div 2 + 20, 20, maxx div 2 + 25, maxy - 20, 51)
drawfilloval (ball_x1, ball_y1, ball_Radius, ball_Radius, 48)
drawfill (maxx - 15, maxy - 15, 71, 51)
drawfilloval (ball_x2, ball_y2, 15, 15, 61)
drawfillbox (x1_ 1, y1_ 1, x2_ 2, y2_ 2, 31)
for SnowFlake : 1 .. SnowFlakesFalling
SnowFlakeY (SnowFlake ) - = Rand.Int (1, 5)
if SnowFlakeY (SnowFlake ) < 0 then
SnowFlakeY (SnowFlake ) := maxy
SnowFlakeY (SnowFlake ) := Rand.Int (0, maxx)
end if
Draw.FillOval (SnowFlakeX (SnowFlake ), SnowFlakeY (SnowFlake ), 1, 1, white)
end for
Input.KeyDown (arrowKeys )
if arrowKeys (KEY_RIGHT_ARROW) then
x1 + = 10
x2 + = 10
end if
if arrowKeys (KEY_LEFT_ARROW) then
x2 - = 10
x1 - = 10
end if
if x1 <= 25 and x2 <= 125 then
x1 := 30
x2 := 130
end if
if x1 >= maxx div 2 - 85 and x2 >= maxx div 2 + 10 then
x1 := maxx div 2 - 90
x2 := maxx div 2 + 10
end if
if arrowKeys (KEY_ESC) then
cls
break
end if
if ball_y1 >= maxy - 50 then
ball_directiony1 * = - 1
end if
if ball_x1 >= maxx div 2 + 5 then
ball_directionx1 * = - 1
end if
if ball_x1 <= 45 then
ball_directionx1 * = - 1
end if
var direction : int
ball_x1 + = (ball_directionx1 * ball_speed )
ball_y1 + = (ball_directiony1 * ball_speed )
if ball_x1 <= x2 and ball_y1 <= y2 and ball_x1 >= x1 and ball_y1 >= y1 then
ball_directiony1 * = - 1
ball_directionx1 * = - 1
end if
for i : 1 .. 6
brick (i ).xCord := 50 + ((i - 1) * 75)
brick (i ).yCord := maxy div 2
brick (i ).width := 50
brick (i ).height := 25
brick (i ).alive := true
end for
for i : 1 .. 6
if brick (i ).alive = true then
drawfillbox (brick (i ).xCord, brick (i ).yCord, brick (i ).xCord + brick (i ).width, brick (i ).yCord + brick (i ).height, 8 + i )
elsif brick (i ).alive = false then
end if
if ball_x1 >= 50 and ball_x1 <= 100 and ball_y1 <= maxy div 2 + 25 and ball_y1 >= maxy div 2 then
drawfillbox (50, maxy div 2, 100, maxy div 2 + 25, black)
ball_directiony1 * = - 1
end if
end for
for k : 1 .. 6
brick (k ).xCord := 50 + ((k - 1) * 75)
brick (k ).yCord := maxy div 2 + 50
brick (k ).width := 50
brick (k ).height := 25
brick (k ).alive := true
end for
for k : 1 .. 6
if brick (k ).alive = true then
drawfillbox (brick (k ).xCord, brick (k ).yCord, brick (k ).xCord + brick (k ).width, brick (k ).yCord + brick (k ).height, 8 + k )
elsif brick (k ).alive = false then
end if
if ball_x1 >= brick (k ).xCord and ball_y1 >= brick (k ).yCord and ball_x1 >= brick (k ).width and ball_y1 >= brick (k ).height then
drawfillbox (brick (k ).xCord, brick (k ).yCord, brick (k ).xCord + brick (k ).width, brick (k ).yCord + brick (k ).height, black)
ball_directiony1 * = - 1
exit when brick (k ).alive = false
end if
end for
for s : 1 .. 6
brick (s ).xCord := 50 + ((s - 1) * 75)
brick (s ).yCord := maxy div 2 + 100
brick (s ).width := 50
brick (s ).height := 25
brick (s ).alive := true
end for
for s : 1 .. 6
if brick (s ).alive = true then
drawfillbox (brick (s ).xCord, brick (s ).yCord, brick (s ).xCord + brick (s ).width, brick (s ).yCord + brick (s ).height, 8 + s )
elsif brick (s ).alive = false then
end if
if ball_x1 >= brick (s ).xCord and ball_y1 >= brick (s ).yCord and ball_x1 >= brick (s ).width and ball_y1 >= brick (s ).height then
drawfillbox (brick (s ).xCord, brick (s ).yCord, brick (s ).xCord + brick (s ).width, brick (s ).yCord + brick (s ).height, black)
ball_directiony1 * = - 1
exit when brick (s ).alive = false
end if
end for
for p : 1 .. 6
brick (p ).xCord := 50 + ((p - 1) * 75)
brick (p ).yCord := maxy div 2 + 150
brick (p ).width := 50
brick (p ).height := 25
brick (p ).alive := true
end for
for p : 1 .. 6
if brick (p ).alive = true then
drawfillbox (brick (p ).xCord, brick (p ).yCord, brick (p ).xCord + brick (p ).width, brick (p ).yCord + brick (p ).height, 8 + p )
elsif brick (p ).alive = false then
end if
if ball_x1 >= brick (p ).xCord and ball_y1 >= brick (p ).yCord and ball_x1 >= brick (p ).width and ball_y1 >= brick (p ).height then
drawfillbox (brick (p ).xCord, brick (p ).yCord, brick (p ).xCord + brick (p ).width, brick (p ).yCord + brick (p ).height, black)
ball_directiony1 * = - 1
exit when brick (p ).alive = false
end if
end for
for o : 1 .. 6
brick (o ).xCord := 50 + ((o - 1) * 75)
brick (o ).yCord := maxy div 2 + 200
brick (o ).width := 50
brick (o ).height := 25
brick (o ).alive := true
end for
for o : 1 .. 6
if brick (o ).alive = true then
drawfillbox (brick (o ).xCord, brick (o ).yCord, brick (o ).xCord + brick (o ).width, brick (o ).yCord + brick (o ).height, 8 + o )
elsif brick (o ).alive = false then
end if
if ball_x1 >= brick (o ).xCord and ball_y1 >= brick (o ).yCord and ball_x1 >= brick (o ).width and ball_y1 >= brick (o ).height then
drawfillbox (brick (o ).xCord, brick (o ).yCord, brick (o ).xCord + brick (o ).width, brick (o ).yCord + brick (o ).height, black)
ball_directiony1 * = - 1
exit when brick (o ).alive = false
end if
end for
for m : 1 .. 6
brick (m ).xCord := 50 + ((m - 1) * 75)
brick (m ).yCord := maxy div 2 + 250
brick (m ).width := 50
brick (m ).height := 25
brick (m ).alive := true
end for
for m : 1 .. 6
if brick (m ).alive = true then
drawfillbox (brick (m ).xCord, brick (m ).yCord, brick (m ).xCord + brick (m ).width, brick (m ).yCord + brick (m ).height, 8 + m )
elsif brick (m ).alive = false then
end if
if ball_x1 >= brick (m ).xCord and ball_y1 >= brick (m ).yCord and ball_x1 >= brick (m ).width and ball_y1 >= brick (m ).height then
drawfillbox (brick (m ).xCord, brick (m ).yCord, brick (m ).xCord + brick (m ).width, brick (m ).yCord + brick (m ).height, black)
ball_directiony1 * = - 1
exit when brick (m ).alive = false
end if
end for
%% ______________ (AI + Paddle + ball)_______________%%
if ball_y2 >= maxy - 30 then
ball_directiony2 * = - 1
end if
if ball_x2 >= maxx div 2 + 40 then
ball_directionx2 * = - 1
end if
if ball_x2 <= maxx - 40 then
ball_directionx2 * = - 1
end if
var direction1 : int
ball_x2 + = (ball_directionx2 * ball_speed1 )
ball_y2 + = (ball_directiony2 * ball_speed1 )
if ball_x2 <= x2_ 2 and ball_y2 <= y2_ 2 + 15 and ball_x2 >= x1_ 1 and ball_y2 >= y1_ 1 + 15 then
ball_directiony2 * = - 1
end if
if ball_x2 > x1_ 1 + 35 then
x2_ 2 + = 10
x1_ 1 + = 10
elsif ball_x2 < x1_ 1 + 35 then
x2_ 2 - = 10
x1_ 1 - = 10
end if
if x2_ 2 >= maxx - 30 and x1_ 1 >= maxx - 130 then
x1_ 1 := maxx - 130
x2_ 2 := maxx - 30
end if
if x1_ 1 <= maxx div 2 + 30 and x2_ 2 <= maxx div 2 + 130 then
x1_ 1 := maxx div 2 + 30
x2_ 2 := maxx div 2 + 130
end if
%%_________________________________________________%%
color (91)
put "Lives: ", lives
locate (1, 20)
put "Score: ", score
locate (1, 40)
timeElapsed2 := Time.Elapsed div 1000 - timeElapsed1
put "Game Time: ", timeElapsed2
if ball_y1 < 35 then
cls
lives - = 1
ball_x1 := 512
ball_y1 := 200
ball_x2 := 650
ball_y2 := 200
ball_directionx1 := 1
ball_directiony1 := 1
ball_directiony2 := 1
ball_directionx2 := 1
if lives = - 1 then
cls
Font.Draw ("You Have Lost :(", 50, 50, fontS, green)
put "You have acquired a total score of: ", score
loop
put "Would you like to play again?"
get replay
if replay = "Yes" or replay = "yes" or replay = "y" then
put "Your game will replay shortly..."
put "Get READY!"
Time.Delay (3000)
timeElapsed1 := 0
lives := 4
TheGame2
timeElapsed1 := Time.Elapsed div 1000
elsif replay = "No" or replay = "no" or replay = "n" then
put "Good bye, and thanks for playing!"
Time.Delay (2500)
cls
break
else
put "Invalid answer"
cls
end if
end loop
end if
end if
delay (10)
View.Update
delay (1)
cls
end loop
end TheGame2
procedure Instructions
colorback (16)
color (48)
cls
locate (4, 1)
put "The objective of the game is..."
locate (7, 1)
color (58)
put "to destroy all of the blocks on your side of the screen (left)"
locate (10, 1)
color (73)
put "Before the computer destroys all of his blocks on his side of the screen (right)"
locate (13, 1)
color (81)
put "You will use the 'Left' and 'Right' Arrow keys to move left and right"
locate (16, 1)
color (67)
put "If you press the 'ESC' key on your keyboard the game will exit."
locate (19, 1)
color (96)
put "Good Luck and go smash some blocks. HINT : You only have 3 Lives!"
var game_Button : int := GUI.CreateButton (265, 275, 0, "Click To Play!", TheGame2 )
end Instructions
procedure returnBack
var go_back : char := " "
loop
put "Please enter 'y' to go back"
get go_back
if go_back = "y" then
Pic.Draw (PicID, maxx div 2 - (638 div 2), maxy div 2 - (690 div 2), picCopy)
var game_Button : int := GUI.CreateButton (265, 275, 0, "Click To Play!", TheGame2 )
var instructions : int := GUI.CreateButton (265, 225, 0, "Instructions", Instructions )
exit
end if
end loop
end returnBack
PicID := Pic.FileNew ("ball02.jpg")
Pic.Draw (PicID, maxx div 2 - (638 div 2), maxy div 2 - (690 div 2), picCopy)
var fontS1 : int := Font.New ("Verdana:12")
Font.Draw ("Please click 'instructions' to view the instructions then 'Click To Play'.", 35, 500, fontS1, red)
assert fontS1 > 0
Font.Free (fontS1 )
var instructions : int := GUI.CreateButton (265, 225, 0, "Instructions", Instructions )
loop
loop
exit when GUI.ProcessEvent
end loop
end loop
proc Debugger (debugger_ : boolean)
if debugger_ = true then
var mx, my, mb : int
Mouse.Where (mx, my, mb )
if mb = 1 then
loop
cls
Mouse.Where (mx, my, mb )
put "X: ", mx, " Y:", my
exit when mb not= 1
View.Update
Time.DelaySinceLast (25)
end loop
end if
end if
end Debugger
|
Please specify what version of Turing you are using
4.1.1a
run the program to see where it goes wrong and help me fix it |