PDA

View Full Version : Help With Game!!


Smokey
05-20-2003, 02:09 PM
alot of people have been very helpfull on here lately and hopefully i can get the same assistance here. i am creating a breakout style game trying to learn more about flash. i have the game itself created but i am having trouble with the following.

1.getting the ballcounter to work to show remaining balls.

2.designing the levels. all i have is the tile layout.( the level
storyboards are included in the zip file.)

3.the ball takes out alot of tiles on collision.

the main issue would be the design of the levels. i hope somone can help me. i have tapped all my resources and this project has 2 weeks till completion is a must. thanks for your help as well as all your past help.

Smokey
05-20-2003, 02:23 PM
here are the files

Smokey
05-20-2003, 02:38 PM
and the level storyboard

CyanBlue
05-20-2003, 08:05 PM
This is what I have so far...

I think number 1 is kinda done with this file... But I see that the hitTest() is not working properly... I guess you'd have to work on it some more before you implement the level stuff... See if you can do anything while I get some nap, and upload any progress... I'll take over when I get up... ;) Oh... Just for your information, this is my full time non paying job... :D

Are you on F5 or FMX???

Smokey
05-20-2003, 08:31 PM
i am using fmx. im real new to this. thanx for helping out!!

agent81
05-21-2003, 02:06 AM
Hey Smokey. I had similar issues with breakout recently. trouble is hitTest is a pretty bad way of doing it, not only do you have to chack every single tile, but there's no eal way of measuring an accurate angle for the bounce (if you have, then there is no use for hitTest in the first place).

its pretty hard to find a starting point to explain this, i took me a while to work out myself,

the replacement for hitTest is these two lines, where 'this' is referring to your ball

var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((this.y-this.stageTop)/blockHeight)-1;

if you have laid out your blocks along a grid, then you now know which block the ball is over with two lines rather than a massive loop of hitTests.

next, you check to see if a block is there.

i do this by constructing a two dimensional array, at the same time as adding my blocks to the stage. put a variable is that says amHere = true

so you just need to say now

if (blockArray[cell_x][cell_y].true){
this["block" + cell_x + "_" + cell_y].removeMovieClip()
blockArray[cell_x][cell_y] = false

}

hope that makes sense to you.
the next thing is to work out the angle the ball has to bounce at depending on which side of the block it has hit. I'll include the code that i used here, you would have to modify it for your own movie. but if you can make sense of it, it works a heap better than the method you are using at the moment.

var path = this._parent.blockStore[cell_x][cell_y].path;
var ylength = (this.y-this._y);
var ymov = this.yspeed/Math.abs(this.yspeed);
var tileY = path._y+(ymov*path._height);
var pcnt = ylength/(tileY-this._y);
var ballX_pcnt = (this._x-this.x)*pcnt;
if (ballX_pcnt<0) {
if (this._x+ballX_pcnt<path._x-(path._width/2)) {
this.xspeed *= -1;
this.x += this.xspeed;
} else {
this.yspeed *= -1;
this.y += this.yspeed;
}
} else {
if (this._x+ballX_pcnt>path._x+(path._width/2)) {
this.xspeed *= -1;
this.x += this.xspeed;

} else {
this.yspeed *= -1;
this.y += this.yspeed;
}
}


if you have any questions then post them and I'll answer. Hope i havent just confused matters.

CyanBlue
05-21-2003, 03:22 AM
Very thorough, agent81... Thanks... ;)

Hey, Smokey...

Why not try what agent81 said and let us know how it go??? ;)

Smokey
05-21-2003, 05:01 PM
i'll give it a shot. im pretty quick but also very new!! hopefully i can figure it out. thanx

Smokey
05-22-2003, 01:22 PM
having trouble transferring the code into my application. also the levels are still giving me hell.

CyanBlue
05-22-2003, 02:24 PM
Um... You need to be abit more specific and precise than that... Show us where you are having problems with, at least...

Smokey
05-22-2003, 05:09 PM
basically the initial problems remain. the hittest is acting up and the level construction has had no progress. i am having no luck integrating the code example that was posted here into the game. also i dont even know where to begin with the level construction.

agent81
05-23-2003, 12:00 AM
to make a game like this, you need to understand multi-dimensional arrays, which are alot easier than they sound. basically this is a graphical representation of an array, which is a data representation of your graphics

where 1 equals a brick, and 0 equals an empty space

11111111111111111111111
11111111111111111111111
11111111111111111111111
11111111111111111111111
11111111111111111111111


this is a full stage of bricks, everytime a brick is hit, you swap the 1 for a zero, also if you want to make a new level, you need a new array, with a different order, e.g level 2 might look like this

11111111111111111111111
11100011111111110001111
11100011111111110001111
11111111111111111111111
10101010101010101010101
10101010101010101010101

to create these arrays in actionscript, you can use a few different formats. the easiest for you might be;

level2 = new Array()
level2[0] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
level2[1] = [1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
level2[2] = [1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
//etc


when you set up the game (and I am assuming the you are using mx here, your loop that creates the blocks, checks against this array, if there is a 1, then it puts a block there3, if its a 0, then don't. you also use this array, for determining whether or not there is a block in the space, using the code i listed earlier.

so your setupFinction goes more like this

function setUp(level){
for (var (i=0;i<=this["level" + level].length;i++){
for (var(j=0;j<=this["level" + level][0].length;j++){
if (this["level" + level][i][j] == 1){
//place a block here(using the code you are using now
}
}
}


so you can call this function to re-populate your screen at the start of each level, just make sure it corresponds with your naming for your arrays.

e.g

setUp(1)

will set up level1

also try to incorporate the code i gave you earlier, mostly this bit

var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((this.y-this.stageTop)/blockHeight)-1;

you can use this in the same way as above, checking if that entry (which is the spot that the ball is currently in) is a 1, if so then, you know the ball is hitting a block, and you know which block it is.

turn the entry for that block in the array to 0, and remove the block.

alot of this depends on you using a good naming convention, so you can easily target the movieclips dynamically, and setting up your stage co-ordinates properly.

I would reccomend that you take a step bac, and start trying to get these two things working properly, before worrying about everything else. once you undertand this, it'll make alot more sense as to what you need to do next.

CyanBlue
05-23-2003, 12:11 AM
Great... I was going to go over how I did tetris clone long time ago, but being lazy actually pays off... Great explanation, agent81... ;)

agent81
05-23-2003, 12:42 AM
no probs cyan, i spent the first half of this year writing tile based games, and if i remember rightly, you helped me i a tricky situation back then....

CyanBlue
05-23-2003, 12:44 AM
Oh, really??? Honored to help you... ;) Got anything you can show us??? I need some inspiration... :)

agent81
05-23-2003, 12:51 AM
you mean a link??

if so yes, my latest creation is in testing stages, and i need user feedback... as to playability, or points of confusion.

STA Travel, Round The World (http://www.koanproductions.com/rtw2)

long live Carmen Sandiago.....

CyanBlue
05-23-2003, 01:28 AM
Geez... Great one, agent81... ;)

I think it is abit hard for me to set the travel route when I don't know where those clue cities might be... But if you give out too much time to select them, people will probably google out where they need to go to see those...

I'm on 18th day and I now got one city down... I was keep trying to go do the sightseeing, but the screen says that I need to have more credibilities... That's fine, but I think you need to tell me how much I need to do certain act... Know what I mean???

Hm... At the third city, I am stuck... That guy is not letting me work to generate the credibility because I do not have enough credibility... And, due to that, I cannot do the sightseeing to see what I need to see... What's up with that??? :D

And, I see that sometimes, I have to click on those four round buttons twice to get it working... I mean those buttons that says sightseeing, travel, chill and work...

Phew... How long did it take to get this one working??? Half a year you said??? Great... Good job... ;)

The only thing is that I am on PII 300 with 196 ram... It kinda slows my computer alot... :(

agent81
05-23-2003, 01:46 AM
Hey Cyan, no this took about a month, with probably a month before that of creative and planning, though i havent been able to do it full time, as I've had all my other work on...

Yeah I'm trying to get a balance, where it's hard, but not too hard. Most peoples feedback has originally been that it's too hard, but then they have become addicted.

My plan is that you should be able to make just enough cities on your first round, before getting stuck. That way it becomes a challenge, rather than just a brick wall. Hence the user testing. as i know where everything is, its pretty hard for me to gauge the correct difficulty, I reckon this will be the difference between it being a valuable promotion tool for STA, or just a nice piece of fluff in my folio.


As for getting stuck, where was it? the concept that i have at the moment, is that you need to earn enough cred in Asia, before going to Europe (where cred is alot scarcer), then you need to get cash in Europe before heading to the Americas, as distances are greater. I think i do need to make this easier...

as for slowing your computer, damn it, the graphics are so complicated, and some of the code routines are pretty complex....

I've tried all the tricks i know for optimisation.

good point on the buttons, I'm initialising their functions at the end, I'll need to re-think that one.


cheers Cyan, your comments are appreciated...

CyanBlue
05-23-2003, 01:58 AM
Where??? Well... To be honest, it was all brick walls to me... :D

The second try... I went to see the Ankor Wat... and the place didn't let me work... so, I did the sightseeing... and went to the Rome... Did a sightseeing again, but the place didn't let me do the work in that place either... At that point, I had not enough money to go to the next city or the credibility to work there... :(

At the first try... I am not sure... The thing is that I don't know how much credibility I need to get something done... Um... What about this??? Have a bar or something that displays percentages of the credibility, and have it decreased at a certain act, and have it increased after the work, and have it turn to blue or some recognizible color when I can do something with the credibility??? Just a suggestion... :)

Oh... Once I land on a city, you show me th edescription of the city, and there is another graphic screen where I have to click to go on, right??? I wasn't really knowing what I should do in the beginning because the click to continue text was not so visible to me... and, maybe show me the city / country name at the bottom of each city??? Like status bar at the bottom maybe or one more link in the camcorder screen with that information???

Good job to pull all that in two month... :)

agent81
05-23-2003, 02:42 AM
Yeah you are right. Although I think,that it shouldn't be too obvious whether you have enough cred. but that it should be easier to get cred in the start...

I'll take the cred requirements for all volunteer work in Asia down to 0 (except Delhi, cos i spent 5 months teaching there, and i could never bring myself to tell anyone that you don't need a certain amount of preparation for that :D )

i'll have a think on how to make someones lack of cred more intuitive. I don't want people to know exactly how much cred they need for each option. but it does definately need to be easier, so you don't get tuck so easily.

cheers Cyan

CyanBlue
05-23-2003, 03:08 AM
Yup... Good luck and let me know how it goes... ;)

No Korea??? Sad... :(

Add one if you can and if you don't mind... :D

agent81
05-23-2003, 03:40 AM
Yeah, it was so hard to narrow down the countries, there are heaps more that i wanted to do (although I've made it very australaisian centric, so that if its a success, and other countries want it, I'll get the chance to extend it and add more. I'd like to do sound as well, but at this point budget doesn't allow)...

Anyway, I've added a hint box in the no-cred animation. giving you a verbal clue as to how far off you are. i want people to not know the cred thay need before trying something, I like the way the guy comes up, i think it adds alot, but it is a fine line before people start to get frustrated)

if you've got five, have a look, and tell if you think this help's, or if i still need to go further.......

cheers Cyan.

CyanBlue
05-23-2003, 08:37 AM
Finally made it working to the goal... :D

I have visited cairo to see the pyramid, but it didn't really check it, I think... I had to go back to Egypt to see the pyramids again... :(

Smokey
05-26-2003, 06:00 PM
I think I may have gotten in over my head here with this game. When I selected this project I did not expect this level of difficulty. I cannot get these new codes to work. The only thing lacking is the level construction and the hittest. For some reason I cannot make this work and it needs to be completed today. Can some one help?

CyanBlue
05-26-2003, 11:05 PM
Can you upload whatever you have???

I cannot guarantee it, but I can at least take a look at it... ;)

Smokey
05-26-2003, 11:13 PM
here's wut i have so far. thanx for any help!!

agent81
05-26-2003, 11:40 PM
Hey Smokey, that zip file is empty.

How have you gone?? it can be quite difficult to get games working first time round. send me what you've got. I'm not going to do it for you, but I'll get you started with the best ways to start writing it.

CyanBlue
05-26-2003, 11:41 PM
That's what you have so far??? You've been a bad boy, huh??? :mad:

There is no file in that zip file... :p Check out the file and post it again...

Smokey
05-26-2003, 11:48 PM
try this one

Smokey
05-27-2003, 02:38 AM
i tried to integrate agents code, but i cant get past these errors.

agent81
05-27-2003, 04:08 AM
Hey Smokey, i've made a start at integrating the code for you. Have a look, if you can make sense of how this is working, and how to use functions properly, then you should be able to do the rest.

yell if you get confused

Smokey
05-27-2003, 04:32 AM
i understand now i think, but i am not sure about what i need to change. could you be more specific?

agent81
05-27-2003, 04:39 AM
keep working through the code until you get stuck. there should be enough there to get you started...

sorry, I've got to get back to my work, its opening a whole can of worms to try to explain the fundamentals of game programming.

CyanBlue
05-27-2003, 04:45 AM
Nice one, agent81... ;)

Just to give you better idea, add this right below the level1 data array and play until you get to finish the level1... I think you will know what agent81 means by that time... ;)level2 = new Array();
level2[0] = [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0];
level2[1] = [1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1];
level2[2] = [1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1];
level2[3] = [1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1];
level2[4] = [1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1];
level2[5] = [1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1];
level2[6] = [1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1];
level2[7] = [1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1];
level2[8] = [1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1];
level2[9] = [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0];I guess you called agent81 up so that he could help you... I think he did a great job... :)

Just out of curiosity... Is this some sort of school homework by any chance??? :D

spriggan
05-27-2003, 05:20 AM
Just noticed this thread. I'm currently working on this type of game and have a realy nice level editor that lets you create a level then save it to an XML file.

The Zip is here (http://www.timewastersguide.com/VG/NickelCade/arcanoid.zip) The level generator only works when you run it in the flash compiler itself then traces it in XML code. Copy the code and paste it to a text file. Then save that as an XML. The code is kida messy, but hopefully it will help.

I don't want to double post this problem (I've posted this in"Memory Problems" (http://www.actionscripts.org/forums/showthread.php3?s=&threadid=28590) in the general forum) but since this is a topic about this type of game if anyone can help out there's a memory problem with the game. Or so I think. It will slow down on the second level. I'm also planning on adding a frame independent hittest for the ball and bricks.

CyanBlue
05-27-2003, 05:21 AM
Hm... So, it actually is a school homework??? Isn't there some sort of honesty code or something??? :D What kind of school do you go to??? Your teacher will kill you if you don't do your homework??? Don't worry... We'll pray for you... :D

Smokey
05-27-2003, 01:08 PM
none of the admin. know anything around here. thats why i have to find help from people like you and agent who are actually educated in this area.

Smokey
05-27-2003, 01:26 PM
i tried to get the new hittest working. i thought i had the code right but i guess not. can anyone see the prob??


stop();
this.onEnterFrame = function() {
for (var i = 0; i<=brick.length; i++) {
//Collision Detection
var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((this.y-this.stageTop)/blockHeight)-1;
if (block[cell_x][cell_y].true) {
this["block"+cell_x+"_"+cell_y].removeMovieClip();
block[cell_x][cell_y] = false;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// pause needed
}
}
}
}

spriggan
05-27-2003, 07:58 PM
ok I looked at your code in the FLA and from what I can tell you never define some varables, when I traced them I got undefined.
var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((this.y-this.stageTop)/blockHeight)-1;

stageLeft
Blockwidth
this.stageTop
blockheight

also I'm assumeing that this is supposed to be the Ball MC so:
var cell_x = Math.ceil((ball._x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((ball._y-stageTop)/blockHeight)-1;


should work once you define those varables. also I don't know why you where useing this.stagetop. so i took the this off.

Also you've got a problem I had when I first tried to make this game. You've got so may actions going on each frame (your code is checking the call against every brick) so it's slowing down big time. How it works at the moment in mine is that it only checks the grid position that the ball is in. I would take the for loop out. you'd have to change the way that the game would check to see if a level is cleared, but the game would run faster.

agent81
05-27-2003, 11:40 PM
Yeah exactly, that code

var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;

was copied out of a game that I made, working in a very different situation, its not the code that you need, but the concept, that will tell you which brick (if any) that the ball is hitting, So you don't have to do all of those hitTests, in fact you don't have to do any.

You need to work out what it's doing, so you can apply it to your own script.

Smokey
05-28-2003, 02:38 AM
how do i place that script?? i must be retarded cuz I cant get it to work.


stop();
this.onEnterFrame = function() {
for (var i = 0; i<=brick.length; i++) {
//Collision Detection
var cell_x = Math.ceil((ball._x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((ball._y-stageTop)/blockHeight)-1;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// you need to put something in here that will pause the game, until the user is ready to restart.
}
}
};

spriggan
05-28-2003, 03:18 AM
Ok you've got it in the right place. Did you place values in these varables:
stageLeft
Blockwidth
stageTop
blockheight

if you haven't (ie StageLeft=44; ) then flash auto places 0's in them and that will screw up the code.

Smokey
05-28-2003, 03:20 AM
not sure wut you mean. i know how to define them but i dont know wut values to use

spriggan
05-28-2003, 03:30 AM
block width is the width of the block MC
block height is the height of the block MC

so go check the MC you're useing and look under the properties section and it will tell you what those values are.

then Stage left and top are values of where your grid begins. so the top left corner of the first brick in the top left corner is that value.

Smokey
05-28-2003, 03:35 AM
stop();
this.onEnterFrame = function() {
stageLeft = 120
stageTop = 37
blockWidth = 24
blockHeight = 8

for (var i = 0; i<=brick.length; i++) {
//Collision Detection
var cell_x = Math.ceil((ball._x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((ball._y-stageTop)/blockHeight)-1;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// need the game to stop here!!!
}
}
}


this seems like wut your talking about but it does not work

spriggan
05-28-2003, 03:37 AM
remove the stop(); at the top and the this infront of the function and see if that helps

Smokey
05-28-2003, 03:46 AM
i dunno, maybe if you take a look at the game

Smokey
05-28-2003, 03:51 AM
also there will be some different bricks. some wont break

spriggan
05-28-2003, 03:52 AM
Ya i'll dubble check your code on the file. I probaly wont get to it for a while. I was pretty sure that was the only problem.

How much do you know about how to debug a program?

agent81
05-28-2003, 03:53 AM
Smokey, you are using this in entirely the wrong place. stop and think about what it is doing, rather than trying to find the right place to put it. when you understand what it does, it'll become more obvious.

I'll go through it

var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((this.y-this.stageTop)/blockHeight)-1;


cell_x is a variable, that you will tell you where in the bricks array to access (i.e. which row vertically the ball is over.
cell_y is the same, once you have found these variables, you can now say

bricks[call_x][cell_y]

which is a reference to where the ball currently is.

to find these variables you need to do a simple calculation (have a good look at it, it really is very simple)

(this.x-stageLeft)/blockWidth

'this' means the ball. you need to reference the ball here,
the balls x position minus the left side of the stage is how far away the ball is from the left side of the stage. Yes?? simple.

then
divide this by the width of your blocks.

which means how many blocks accross from the side of the stage am i?

do this for up and down, find the block you are on in the array. if its a 1 then get rid of the block (from the stage, and the array), and bounce.

if its a 0, then there is no block. continue as before.

there is no need for a loop, you don't need to check every single block. hence why you program the game this way.

The code that i gave you was never intended to be cut and pasted (I have said that a few times now), but for you to understand how the game of breakout is made.

work out where the correct variables are and write the code yourself.

Sorry if this sounds a little scathing. I am really more than happy to help, and i'm sorry, i probably jumped a little far ahead of you at the start.

but now, you work it out....




:)

Smokey
05-28-2003, 04:08 AM
do i need to have it in an "if" statement. i swear i have it right but it wont work.


stop();
this.onEnterFrame = function() {
blockWidth = 24;
blockHeigth = 8;
stageTop = 37;
stageLeft = 120;
for (var i = 0; i<=brick.length; i++) {
//Collision Detection
var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((this.y-this.stageTop)/blockHeight)-1;
if (block[cell_x][cell_y].true) {
this["block"+cell_x+"_"+cell_y].removeMovieClip();
block[cell_x][cell_y] = false;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// pause needed
}
}
}
}

agent81
05-28-2003, 05:19 AM
no, get rid of your for statement, and change the this, reference to the name of your ball movieclip.

Smokey
05-28-2003, 05:39 AM
still no luck

stop();
this.onEnterFrame = function() {
blockWidth = 24;
blockHeigth = 8;
stageTop = 37;
stageLeft = 120;
//Collision Detection
var cell_x = Math.ceil((_root.ball.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((_root.ball.y-stageTop)/blockHeight)-1;
if (block[cell_x][cell_y].true) {
this["block"+cell_x+"_"+cell_y].removeMovieClip();
block[cell_x][cell_y] = false;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// pause needed
}
}
}

agent81
05-28-2003, 06:03 AM
set up a trace statement, and use this to watch the variables that you are getting, go through, until you find one that looks broken....

e.g. add

trace(cell_x)

see if its returning a legal value

Smokey
05-28-2003, 06:28 AM
cells are not defined?? where did i miss that?

Smokey
05-28-2003, 05:39 PM
all other var are defined. i thought the equation was to define the cells. where else do i need to do it at?

agent81
05-28-2003, 11:40 PM
this.x, refered to a variable in an object for me.

for you there is no object or variable, so you need to say ball._x

etc

Smokey
05-28-2003, 11:45 PM
i already changed that. its saying that var cell is not defined???

Smokey
05-30-2003, 01:24 AM
having trouble with my game here. the collision detection is'nt workin, im having trouble with some of the buttons and other misc. things. i would appreciate any help you guys provide. i am very new to all this. thanx

Smokey
05-30-2003, 01:46 AM
agent81, im real close with this but i do not understand why the var. is returned undefined?? what am i missing?


stop();
this.onEnterFrame = function() {
trace(cell_x);
brickWidth = 24;
brickHeigth = 8;
stageTop = 37;
stageLeft = 120;
//Collision Detection
var cell_x = Math.ceil((_root.ball.x-stageLeft)/brickWidth)-1;
var cell_y = Math.ceil((_root.ball.y-stageTop)/brickHeight)-1;
if (_root.ball[cell_x][cell_y].true) {
_root.ball["brick"+cell_x+"_"+cell_y].removeMovieClip();
brick[cell_x][cell_y] = false;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// pause needed
}
}
};

agent81
05-30-2003, 02:52 AM
stop();
this.onEnterFrame = function() {
trace(cell_x);
brickWidth = 24;
brickHeigth = 8;
stageTop = 37;
stageLeft = 120;
//Collision Detection
var cell_x = Math.ceil((_root.ball._x-stageLeft)/brickWidth)-1;
var cell_y = Math.ceil((_root.ball._y-stageTop)/brickHeight)-1;
if (_root.ball[cell_x][cell_y].true) {
_root.ball["brick"+cell_x+"_"+cell_y].removeMovieClip();
brick[cell_x][cell_y] = false;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// pause needed
}
}
};


_x, not x
_y, not y

Smokey
05-30-2003, 04:03 AM
that still does not work. i rewally dont undserstand. im sorry to be a pest but i really need some help here!!!!


stop();
this.onEnterFrame = function() {
trace(cell_x);
brickWidth = 24;
brickHeigth = 8;
stageTop = 37;
stageLeft = 120;
//Collision Detection
var cell_x = Math.ceil((_root.ball._x-stageLeft)/brickWidth)-1;
var cell_y = Math.ceil((_root.ball._y-stageTop)/brickHeight)-1;
if (_root.ball[cell_x][cell_y].true) {
_root.ball["brick"+cell_x+"_"+cell_y].removeMovieClip();
brick[cell_x][cell_y] = false;
_root.score += 10;
_root.ball.by_speed = -_root.ball.by_speed;
// break brick
brick.splice(i, 1);
//remove associated element from array
//Is Game Over?
if (brick.length == 0) {
nextLevel();
// pause needed
}
}
};

spriggan
06-02-2003, 09:30 AM
if we trace cell_x and cell_y as follows:

var cell_x = Math.ceil((_root.ball._x-stageLeft)/brickWidth)-1;
trace (cell_x);
var cell_y = Math.ceil((_root.ball._y-stageTop)/brickHeight)-1;
trace (cell_y);


we get numbers from -10 to 10 for x and infinity for y. So that shows you that you've got a problem with your math. so lets look at the math and break it down ok.

you've got a grid that's X by y so how do you find your position in the X position? We'll use a 5x5 grid with cells that are 20 pixels it makes the math easier.

cellsize=20;
xposition=75;
cell_x=math.ceil(xposition/cellsize);


Math.ceil rounds the number so we get an intager. It's a realy simple math trick that devides the X position by the height to get the cell #. It's the same for finding the Y position. OK then remove the var from infront of both of the equaions.

The next problem is your if statement that checks the hittest. It's wont work because of the way you copied and pasted it. To get something that will work you'll have to go through your program and recode it.

one thing to look at is that if statement: if (brick[cell_x][cell_y].true);

why dosen't that work? If you check where you create the grid you'll notice that all your bricks are based off a single array not a multi-dimensional array. ie brick[counter]. This is what hapenes when you mix match code that 1) dosen't goto gether and 2) you don't understand. I'd try and fixt the brick[counter] so the set up matched the hittest

I'm not going to give you the answer but I've pointed you in the right direction.