Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Breakout (wip)

Author
Message
Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 4th Apr 2006 15:52 Edited at: 9th Apr 2006 10:18
Made in Dbc
Hi again. This is my new thread about my breakout game. Now that the code actually works i won't be posting in the one that says "breakout won't get started" well because it is. Thanks to X_MEN and Darkcoder#5 for helping me so far. I changed the name to breakers by the way.

Bugs
1. Ball can go through the two blocks on left side if you do it right

Improvments
1. Put in the stupid bitmap fonts
2. try to make the ball correctly bounce off the side(right now it just bounces up or down)
3. Make level 3
4. Put in music and sound effects

Controls:
left and right arrow keys to move paddle
space to start next ball(you have 5 balls)
1 to restart when you die and 2 to exit when you die


Updated Code:


code with level 1 and 2 (buggy):
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 4th Apr 2006 18:02
The print, and text commands are really 2D commands, and you have a 3D game here. That's why they dissapear. You need to make a bitmap font, that's a font made from graphics. You put a black background around them to make them transparent. The set Object command has an option for transparent black 0,0,0. You put the font on some plains, and postion the plains by using a program to convert strings into the correct plains.

I'm not sure why you can pass through the blocks at the moment. I think it is due to 2 collisions taking place at the same time.

Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 5th Apr 2006 13:03
ok... i'll try to do it but i'm not totally sure how
thanks though
Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 5th Apr 2006 15:28
i'm going to add another row in sometime but i'm too tired right now
Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 7th Apr 2006 13:13
uggh triple post

OK a few updates.
1. Title screen
2. New row

Improvements to make
1. Put in the stupid bitmap fonts
2. try to make the ball correctly bounce off the side(right now it just bounces up or down)
3. Make more levels(maybe)

A question : Can i reset the screen to 2d after you lose or win?

no new code now
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 7th Apr 2006 13:31
Quote: "A question : Can i reset the screen to 2d after you lose or win? "


Yes.
Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 7th Apr 2006 13:37 Edited at: 7th Apr 2006 13:37
another question: How?
lol try to find on my own first
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 7th Apr 2006 15:00 Edited at: 7th Apr 2006 15:03
'Backdrop Off' ,delete 3D objects, copy/paste bitmap.., , sends you back to 2D. It can create odd problems though. Like the game might only work properly on its second run. That's the bug that I had in one of my games that did what you are doing.

Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 8th Apr 2006 06:24
thanks pincho! it works now
musty
18
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Istanbul
Posted: 8th Apr 2006 20:29
Hi. I tried to run your code but it didn't work properly. First of all I'll try to help you about the "2 bricks destroyed at a time" problem.Do you know whether the ball hits the wall from the sides or from the upper or lower surface while performing the collision detection? You need to determine this to properly bounce the ball. If you don't do this then the ball will pass through multiple blocks before bouncing. Of course this will happen when you hit the bricks from the sides. You probably check the collision and reverse the y movement direction of the ball. That won't be enough. One method to overcome this problem is to calculate the next x and y positions seperately and do the checks to determine the direction of the ball when the collision happens. For example if you determine that the collision happens after the x position update of the ball then you'll know that the ball has hit the brick from the side. And only this way you can decide the proper ball response. I hope this unorganized and badly written paragraph helps you in tackling the ball movement in your game. MUSTY
Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 9th Apr 2006 10:14
Thanks musty. I didn't get what you meant at first but now i do. I'll do that after i finish a few of the other bugs that i'm having.

I finished level 2!... Kind of. Here are the problems:
1. When you lose a life the text for you to press space does the disappearing trick
2. I'm getting the "Specified angle must be 0 to 360" error on level 2 only. I have the wrapvalue code in there but i still get the problem.

Here is the bugged code with level 1 and 2:
musty
18
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Istanbul
Posted: 9th Apr 2006 10:56
Hi. I retryed your code and made a few minor revisions. To be able to see the text in your restart routine etc. You should place a sync after the text commands. Otherwise the screen won't be refreshed until the game enters the main loop again. Hope this helps.
musty
18
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Istanbul
Posted: 9th Apr 2006 15:49
Hi. I retried your code and made a few minor revisions. To be able to see the text in your restart routine etc. You should place a sync after the text commands. Otherwise the screen won\'t be refreshed until the game enters the main loop again. Hope this helps.

"Ignorance is bliss." Cypher from the movie The Matrix
musty
18
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Istanbul
Posted: 11th Apr 2006 20:13
Hi. Last time I made a post the code couldn't be uploade so this time I paste it in the message window.

rem breaker!!!!

rem print stuff
hide mouse
set text font "arial"
set text size 15
ink rgb(0,255,0),rgb(0,0,0)
Text 200,200,"Welcome to Breaker by Cagel"
Text 200,230,"Left and right key moves"
Text 200,250,"Press space for next life"
Text 200,270,"Press any key to start"
Suspend for key

rem some stuff
sync on

game:
backdrop on

rem some variables
balla#=170
x=0
lives#=5
score#=0
ballx# = 0
ballz# = 0
pad# = 0

rem clear the screen
cls

rem make first,second, and third rows/ position them
for t = 1 to 10
if object exist(t) = 1 then delete object t
make object cube t,1
color object t,rgb(255,0,0)
make object collision box t,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object t,(t*1.1)-6,0,5
next t

for x = 11 to 20
if object exist(x) = 1 then delete object x
make object cube x,1
color object x,rgb(0,152,255)
make object collision box x,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object x,(x*1.1)-17,0,3.9
next x

for g = 41 to 45
if object exist(g) = 1 then delete object g
make object box g,2,1,1
color object g,rgb(255,115,70)
make object collision box g,-1,-0.5,-0.5,0.5,0.5,0.5,1
position object g,(g*2.2)-94.5,0,6.1
next g

rem make the paddle
if object exist(21) = 1 then delete object 21
make object box 21,2.5,1,0.3
make object collision box 21,-1.25,-0.5,-0.15,1.25,0.5,0.15,1
color object 21,rgb(0,255,0)

rem make the ball
gosub make_ball
make object collision box 22,-0.5,-0.5,-0.5,0.5,0.5,0.5,1

rem make grid
if object exist(26) = 1 then delete object 26
make object box 26,17,0.1,20
color object 26,rgb(100,100,100)
position object 26,0,-3,3

rem make the side boxes, position them
if object exist(23) = 1 then delete object 23
make object box 23,1,1,15
color object 23,rgb(50,50,50)
position object 23,-6,0,1

if object exist(24) = 1 then delete object 24
make object box 24,1,1,15
color object 24,rgb(50,50,50)
position object 24,6.1,0,1

rem make top box
if object exist(25) = 1 then delete object 25
make object box 25,13.1,1,1
color object 25,rgb(50,50,50)
position object 25,0.05,0,9

rem make lives boxes
for z = 31 to 35
if object exist(z) = 1 then delete object z
make object cube z,1
color object z,rgb(150,0,150)
position object z,8,0,((z-30)*1.1)
next z

rem camera position
position camera 0,15,-5:point camera 0,0,0

wait 1000

do
rem pad movement and changing ball angle
if rightkey()=1 and pad#<4 then pad#=pad#+0.5
if leftkey()=1 and pad#>-4 then pad#=pad#-0.5
if rightkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#+8
if leftkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#-8

rem get the ball moving
ballx#=newxvalue(ballx#,balla#,0.3)
ballz#=newzvalue(ballz#,balla#,0.3)

rem bounce off paddle
if ballz#<-4 and ballz#>-4.2 and ABS(pad#-ballx#)<1.5 then balla#=180-balla#

rem bounce off walls and top
if ballx#<-5 or ballx#>5 then balla#=360-balla#
if ballz#>8 then balla#=180-balla#
balla#=wrapvalue(balla#)

rem position ball and rotate ball
position object 22,ballx#,0,ballz#
yrotate object 22,balla#

rem position paddle
position object 21,pad#,0,-4.7

rem restore ball position and delete a life
if ballz#<-5.5:gosub death
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=0 and object exist(35)=1 then delete object 35
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=1 then delete object 34
if object exist(31)=0 and object exist(32)=0 and object exist(33)=1 then delete object 33
if object exist(31)=0 and object exist(32)=1 then delete object 32
if object exist(31)=1 then delete object 31
endif

objcol=object hit(22,0)
rem collision
if objcol>0 and objcol<21 or objcol>39 and objcol<46 then delete object objcol:balla#=180-balla#:score#=score#+10

rem game ending
if lives#=0 then gosub gameover
if score#=250 then gosub win

sync
loop

make_ball:
if object exist(22) = 1 then delete object 22
make object sphere 22,1
color object 22,rgb(150,150,150)
return

death:
backdrop off
text 200,200,"Press space to restart!"
suspend for key
ballx# = 0
ballz# = 0
balla# = 170
pad# = 0
lives# = lives#-1
sync on
backdrop on
return

gameover:
backdrop off
cls
print "you lose!"
gosub restart

win:
backdrop off
cls
print "you beat level 1!"
print "loading level 2"
sync
wait 1000
gosub game2

win2:
backdrop off
cls
print "you win!"
gosub restart

restart:
print "press 1 to restart or 2 to exit":sync:input overornot#
if overornot# = 1 then gosub Game
if overornot# = 2 then end

game2:
backdrop on

rem some variables
balla#=170
x=0
ballx# = 0
ballz# = 0
pad# = 0

rem clear the screen
cls

rem make first,second,third, and fourth rows/ position them
for t = 1 to 6
if object exist(t) = 1 then delete object t
make object cube t,1
color object t,rgb(255,0,0)
make object collision box t,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object t,(t*1.95)-6.75,0,7
next t


for x = 7 to 11
if object exist(x) = 1 then delete object x
make object cube x,1
color object x,rgb(0,255,0)
make object collision box x,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object x,(x*1.95)-17.5,0,5.9
next t

for l = 12 to 17
if object exist(l) = 1 then delete object l
make object cube l,1
color object l,rgb(0,0,255)
make object collision box l,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object l,(l*1.95)-28.25,0,4.8
next l

for b = 41 to 45
if object exist(b) = 1 then delete object b
make object cube b,1
color object b,rgb(255,255,0)
make object collision box b,-0.5,-0.5,-0.5,0.5,0.5,0.5,1
position object b,(b*1.95)-83.85,0,3.7
next b

rem camera position
position camera 0,15,-5:point camera 0,0,0

wait 1000

do
rem pad movement and changing ball angle
if rightkey()=1 and pad#<4 then pad#=pad#+0.5
if leftkey()=1 and pad#>-4 then pad#=pad#-0.5
if rightkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#+8
if leftkey()=1 and ballz#<-4 and ballz>-4.5 then balla#=balla#-8

rem get the ball moving
ballx#=newxvalue(ballx#,balla#,0.3)
ballz#=newzvalue(ballz#,balla#,0.3)

rem bounce off paddle
if ballz#<-4 and ballz#>-4.2 and ABS(pad#-ballx#)<1.5 then balla#=180-balla#

rem bounce off walls and top
if ballx#<-5 or ballx#>5 then balla#=360-balla#
if ballz#>8 then balla#=180-balla#
balla#=wrapvalue(balla#)

rem position ball and rotate ball
position object 22,ballx#,0,ballz#
yrotate object 22,balla#

rem position paddle
position object 21,pad#,0,-4.7

rem restore ball position and delete a life
if ballz#<-5.5:gosub death
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=0 and object exist(35)=1 then delete object 35
if object exist(31)=0 and object exist(32)=0 and object exist(33)=0 and object exist(34)=1 then delete object 34
if object exist(31)=0 and object exist(32)=0 and object exist(33)=1 then delete object 33
if object exist(31)=0 and object exist(32)=1 then delete object 32
if object exist(31)=1 then delete object 31
endif

rem collision
objcol=object hit(22,0)
if objcol>0 and objcol<18 or objcol>40 and objcol<46 then delete object objcol:balla#=180-balla#:score#=score#+10

rem game ending
if lives#=0 then gosub gameover
if score#=430 then gosub win2

rem position ball and rotate ball
position object 22,ballx#,0,ballz#
yrotate object 22,balla#

rem position paddle
position object 21,pad#,0,-4.7

sync
loop

"Ignorance is bliss." Cypher from the movie The Matrix
Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 12th Apr 2006 12:24
OK i'm having trouble with the code that bounces off the sides. When i run it if it hits the second row i get the error "object does not exist" Here is the part i'm having trouble with:

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Apr 2006 06:57
There's an EDIT button Musty.


Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 16th Apr 2006 09:18
man that was noobish. can't delete objects twice now can we? I tryed changing it to this but it still doesn't work

something about object number can only be 1 o 63555 or sumthing like that
Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 17th Apr 2006 15:01
mistake #2 also seen. since its not colliding with anything the number is 0 and you can't have an object # as 0. i tried this but now it doesn't do anything.

Login to post a reply

Server time is: 2024-11-26 23:36:55
Your offset time is: 2024-11-26 23:36:55