PDA

Click to See Complete Forum and Search --> : Arkanoid... PLEASE HELP!


BLiNDPiG
Dec 18th, 2000, 12:29 AM
Hello. I'm writing Arkanoid for my final project in Computer 1. I know this is VB-world, but it may be helpful for you to know that I'm writing it in True Basic... The problem I'm having is with a concept identical as it would be in Visual Basic.

I have the mechanics of the ball and the paddle working, and I figured out how to draw the boxes as the top. The only problem I'm having is when the ball collides with the block. I set up an array for the following:

dim blockx1(80) !block(count) xmin
dim blockx2(80) !block(count) xmax
dim blocky1(80) !block(count) ymin
dim glocky2(80) !block(count) ymax
dim block$(80)
dim blockval(80) !block value [1=on, 0=off]
!There are 80 blocks
!I set window as follows:
set window 0,100,0,100 !xmin,xmax,ymin,ymax

---

This is the code I used to draw the blocks:

FOR a=0 to 3 !4 rows of blocks
FOR b=0 to 19 !19 columns of blocks
LET count=count+1
LET blockx1(count)=(b*5) !block xmin
LET blockx2(count)=(b*5)+5 !block xmax
LET blocky2(count)=65-(a*2) !block ymax
LET blocky1(count)=blocky2(count)-2 !block ymin
SET COLOR rnd*16
BOX AREA blockx1(count),blockx2(count),blocky1(count),blocky2(count)
BOX KEEP blockx1(count),blockx2(count),blocky1(count),blocky2(count) in block$(count)
LET blockval(count)=1 !block(count) is visible
NEXT b
NEXT a


---

That draws 4 rows of 20 blocks each, and each block is a random color. I'm having problems checking which block the ball is boucing off of. Here is the code I'm using:

!finds which block ball is hitting
LET count=0
LET sbloop=1 !just a simple variable to start/stop following loop
IF (by1+2)>56 then !checks if ball is in block area
DO
LET count=count+1
IF (by1+2)>=(blocky1(count)-1) then
IF (bx1+2)>=blockx1(count) and (bx1+2)<blockx1(count+1) then
LET by1=blocky1(count)-2.1
LET by=by*(-1)
LET sbloop=0
BOX HIDE block$(count)
LET blockval(count)=0
END IF
END IF
LOOP until sbloop=0
END IF

---

The ball will make it up to 56, then the ball and paddle will disappear. I've been working at this, trying to make a loop to determine which block the ball is hitting, instead of making 80 separate if else statements to check which block the ball it hitting. Could anyone help me out? I'd really appreciate it. I'll even put you in the credits.

Hope my directions and desires were clear. If there are any questions, post a reply. I can clear them up for you. ***REMEMBER- this is being done in TRUE BASIC. I would have posted this problem on a TB forum, but I haven't found any as of yet.

Thanks for any help I may receive in solving my predicament.

-BLiNDPiG

BLiNDPiG
Dec 18th, 2000, 05:52 PM
Okay... I got the program to determine which block the ball collides with, but once it hits a ball in the bottom row, and you try to hit the block that is above it, it says subscript is out of bounds... Here is the code I use to determine which block the ball hits:


!finds which block ball is hitting
IF by1>55 then !ball is above where blocks start
LET count2=80
LET sbloop=1
DO
LET count2=count2-1
IF (bx1+1)>=blockx1(count2) and (bx1+1)<=blockx2(count2) and blockval(count2)=1 then
IF (by1+2)>blocky1(count2)-1 then
LET by1=blocky1(count2)-2.1
LET by=by*(-1)
LET sbloop=0
LET score=score+10
CALL ballhit
BOX CLEAR blockx1(count2),blockx2(count2),blocky1(count2),blocky2(count2)
LET blockval(count2)=0
END IF
END IF
LOOP until sbloop=0
END IF

--

I can't seem to figure out why this doesn't work. Anyone have ANY suggetions as to how I can make this work? My code sucks, I know... Please, somebody gimme some help. This is for my final project, and I need to finish it.

Thanks

-BLiNDPiG

Jotaf98
Dec 20th, 2000, 05:30 PM
Hum... it seems to me that you're getting no replies because True Basic is veeeery different from Visual Basic.

I'm trying to help because it's your final project (at school I guess?) and I know how important it is to you :p

I'd do it this way: you set up a 2-dimensions array that would hold the blocks' colors (I hope you know what I'm talking about!). It would be an array of numbers, being 0 that this block doesn't exist, and all other numbers, the block's color. Then it would be easy to set up a routine to draw them based on their color!

Try to move the ball as you know, and to detect if it's on top of a block, check the array like this: Blocks(BallX * 30, BallY * 20) , where 30 is the blocks' width and 20 their height.

Also, check if (very important) the NEXT POSITION (not current position) of the ball is on top of a block, if it has reached a wall and if it has touched the player's "bar" before moving it any further (changing its coordinates and then drawing it in the drawing routine). If any of these conditions is met, change its direction but don't move it.

Yes, your code is a bit messy, but that's not the reason I didn't try to understand it: True Basic is much different than Visual Basic.

This is usually the best thing you can do if you can't figure out the error: start your game again, but FROM SCRATCH! Don't copy even a single line from your other version, because it might be what's causing the error!

I hope that helped! Look for a True Basic forum for more detailed answers.