Thursday, January 10, 2008

Shattow

Ok, so I ended up scrapping the entire collision based block placement idea after a few more iterations of merking with it. Instead I decided to go with a basic grid placement system, that I will hopefully have finished by the end of the weekend. I just keep track of the space available, how many blocks of various sizes I have to place and update that information after each block placement. It's more of a simple system and actually makes sense, unlike my mad scientist ideas previously ventured. More later.

Wednesday, January 09, 2008

Oh yeah!

I was doing some more reading and I had a side thought about the last suggested block placement logic. The way it is currently set up the loop exits upon first collision, meaning that if the block were to intersect on the x axis while it was being placed, it would simply be projected away from the object it was colliding with and then the loop would exit leaving it possibly suspended in mid air, if the block was now no longer colliding with an object.











OOps, not what we want to happen. This is an easy fix though, we just have to
continue to move the object through the main do loop until both an x and y collision has happened, so that the Object is at rest. So, this will change the logic structure too..







int collide=0 //Change collide to an integer value
do
{
if(collide==0)
{
Move block along negative x and y axises by -0.005
}

else
{
Move block along negative y axis by -0.005
}

if( collision with block placement area)
{
determine the projection by seeing which axis is the shortest distant to
non collision
move block to new position.
collide +=1; //ADD ONE TO COLLIDE
if(collide==2)
{
break; //(SIMPLE IF ENCLOSER OF BREAK STATEMENT)
}


}

else
{
do
{
subtract a number from the current block to work down the list of previously
generated blocks

if(the current block to check is out of bounds)
{
subtract one from the current row of blocks to check and make the last
block in the row the first to check
}

if(the row is out of bounds)
{
no collision happened, so break this loop
}
if(collision with current block to check)
{
determine the projection by seeing which axis is the shortest distant to
non collision
move block to new position.
collide +=2
break;
}

}
while(there's still blocks to check)
}



}while( collide<2)>





This seems to fix our problem, but upon closer inspection we run across one more.
Using the current structure of logic the blocks at some point will begin to leave spaces due to the inability of the blocks to know about spaces between each other. This problem occurs no matter what point of origin is used for placing the blocks into the Block Placement area. This is due to the different sizes of the blocks and the random nature of their creation.














So.. Now what??

Well one solution is that through the use of reference counting, the blocks keeping track of the order in which they are created, that they should be able to share information with a management system. It will be the job of this management system to keep track of available space that needs to be filled as the blocks are generated.

For example :


The first row of blocks can be generated by keeping track of the translations of the blocks before them without running into the space problem. By simply knowing the boundaries of the block before it and knowing it's own boundaries the right origin for placing the block can be determined. Once the first row is filled, if we continued to rely on this system alone, the same problem would occur so an added element is needed.

Because of the nature of the growing complexity of placing these blocks, this is where a quad tree does indeed come in handy. By Subdividing the space we can know which blocks the next block placed in the new row can come into contact with, without having to cycle through all of the blocks.

It will be up to blocks to keep track of what sectors or branches of the subdivided space they are in so that when an initial collision occurs on the new row, by comparing sizes of the blocks, and knowing the dimensions of the each sizes bounding blocks, we can determine where the new block will fit without wasting space.




This sounds well and dandy in theory, and I'm glad that I took the time really analyze the problem before attempting to really code the solution again, even though this analysis took me a couple of hours, it probably ended up saving me a couple of days time. Following this model I will be structuring a new system for block placement. I will post screenshots of this implementation, even if it ends up that it doesn't work out. That will be available sometime later today.

Further analysis will be required as well if this implementation fails.

Mid-week update

I'm trying to get into a habit of continuously blogging with good content. Hopefully I make that become a reality. It has been a somewhat progressive week.
With the addition to the implementation of the bounding boxes for objects in the game engine, I also managed to add some simple AABB type collision to the system.
I'm still struggling with how I'm going to actually handle the collisions for the initial block placement in the game barricade however. So, because of this, tonight, I'm taking some time dedicated solely to research in that area.

Yesterday, I experimented with writing some simple functionality that took a block and moved it from the center of the world origin down the negative y axis and the negative x axis until it either came into contact with the block placement volume or another block. Once a collision happened, a test would take place to make sure that the block was not outside of the block placement area, if it was, we iterated small movements until it no longer was testing both the X and Y half-vectors of the bounding volumes. ( I realized that this wasn't the best approach as it eats up some time, but seeing as how there are only a maximum of 60 blocks currently being created, I figured it was at least worth experimenting with.) If it was intersecting with another block we did the same thing. Now feasibly this should work, except that you either A) have to at least divide areas into sub regions and check every block in that region, or B) check every single block in that has already been generated and placed. Seeing as how the game works with such a small number of objects, for simple block placement it didn't seem to make much sense to write a system to check for subdivision organization. My opinion on this may eventually change as I do some additional research this evening.

My problem with the sample implementation yesterday simply was a lack of accurate checking on the x axis for all boxes. I was simply trying to write something fast and was some what disoriented as I've been sick for the last week or so, again.. damn winter, At any rate, I only checked for a collision on the previously generated and placed block instead of with all
blocks. Essentially what I was supposed to have written was two separate main bodies of code for collision, one that checked for block 2 block collision and one that checked for block
to placement bounds collision. Inside each one I was supposed to have checks to see what the shortest path of projection for the objects to no longer be intersecting was and then move the objects appropriately to their resting places. But as I said I didn't check for every block on the x axis, and I didn't get the new translation position from projection, instead, I did small moving increments, which looking back caused extra checks to be made afterwards.

Writing this out has really allowed me to see where I went wrong with things yesterday. I had the right idea, but my actual implementation was wrong. My new structure should look something like the following.


bool collide=false
do
{
Move block along negative x and y axises by -0.005

if( collision with block placement area)
{
determine the projection by seeing which axis is the shortest distant to
non collision
move block to new position.
break;
}

else
{
do
{
subtract a number from the current block to work down the list of previously
generated blocks

if(the current block to check is out of bounds)
{
subtract one from the current row of blocks to check and make the last
block in the row the first to check
}

if(the row is out of bounds)
{
no collision happened, so break this loop
}
if(collision with current block to check)
{
determine the projection by seeing which axis is the shortest distant to
non collision
move block to new position.
collide = true
break;
}

}
while(there's still blocks to check)
}



}while( collide == false)



That should be all the code I need for proper placement of the blocks, at least that's what I'm thinking right now. Yesterdays implementation was something like 273 lines of code,
so, if this works, it should speed the block placement up drastically. I'm still going to do some additional reading before trying to implement this in the actual game and make sure that there isn't a better approach to take that I haven't thought of yet. Hopefully, my next entry will include some screen shots of some neatly placed blocks.

Monday, January 07, 2008

Hitting the right spot

Well, I spent the last few hours working on implementing bounding box collision detection. I would have gotten farther today, but I spent a lot of time looking for a simple bug in the wrong places, which sometimes happens. Essentially for the game barricade, I have it setup so that I can see the bounding boxes in debug mode for the game. Or, at least that was what I was trying to do. All I could get it to do was draw three boxes in the center of the screen though, one for each of the different sizes of blocks in the game. So, I went hunting to see if I could find the problem. I thought maybe I wasn't drawing it right, and tried different variations of using offsets from the quads the sprites are drawn on. It didn't work.

I then realized, after setting some break points, that the data stored in the structures for the sprites bounding boxes was still set to zero. You see, I had placed setting the bounding boxes translations in the same function that generated the sizes of the blocks. This wouldn't have been a problem, except that the bounding boxes are determined by an offset based on the dimensions of the textures and the translations of the quads for the sprites themselves. So, of course the size of the blocks would need to be generated before the placement of the blocks, so the data wasn't getting set correctly. I finally figured this out after looking around for a while. Simple, simple things can cause such chaos in a system.

So, I ended up re-building the system within it's own function and had it updated after the placement of every block. This worked out great. Here's a picture of it in action.





Clicky for bigger View


Next up tomorrow will be writing the actual collision detection for block to block collision. Then it will be on to finishing the bullets class, followed by bullet to block collision. Then bot to powerup collision.

After that the only things left to do will be to code the powerup effects, the scoring system, add sound effects, and the demo will be finished. I'm aiming to get this done by the end of the month.