Thursday, November 10, 2011

SlingShot Direction

This week i have been trying to figure out what i considered to be the hardest part of my project, so i decided to go back to basics, "vector math" thats right. I was trying to figure out the shooting direction of a slingshot based on the player start touch and end touch point. What I did was to get the start point for the bubble that is been dragged at the beginning of the touch and then get the last position of this bubble at the end of the touch. Then take the start position subtract the last position, then take the difference and calculate the magnitude. Divide the difference position with the magnitude that gives me the direction I which the bubble should go after it is released. Since I plan on using constant velocity, then take this constant velocity value and multiply it with the direction in which that bubble should go, and add it to the current position of the bubble that will make it move in that direction. This is the simplest physics, because initial I wanted to use Chipmunk but it come with a lot of files and this came is simple and I wanted to be as simple as possible but at the same time make the game functional and fun. I know this may sound easy to do others but hey i am learning this stuff. If this not the right way please give me a better advice.

-(void) setShotDirection

{

CGPoint v;

float xm;

float ym;

float magnitude;

v.x = startBlockLastPos.x - endBlockLastPos.x;

v.y = startBlockLastPos.y - endBlockLastPos.y;

xm = v.x*v.x;

ym = v.y*v.y;

magnitude = sqrt((xm+ym));

if (magnitude != 0)

{

shotDirection.x = (v.x/magnitude);

shotDirection.y = (v.y/magnitude);

NSLog(@"mag: %f shotdirection(%f,%f)\n", magnitude, shotDirection.x, shotDirection.y);

}

}

So long and stay thirst my friends


Thursday, November 3, 2011

UnBlock Me Game

This is the function I wrote that is doing the snapping
The endFoundBlockPos position is set when the touchEnds and the
startFoundBlockPos is set when we start the touch and we found the
block before you move the block get the starting position.
Also these values should be assigned according to the direction in
which the block is moving. If the block is moving verticaly for
example startFoundBlockPos = FoundBlock.y and when the touch ends
endFoundBlockPos = FoundBlockPos.y; then I get the difference of the
two. The take the difference divide it with 50, since we know that the
the field is 300 by 300 and out blocks are have the maximum width and
height of 150. So if I divide the difference by 50 and there is no
remeinder I know that the block has been moved by 50 or 100 or 150
then I just need to add the difference to the startFoundBlockPos
andset the block pos to that depending on the direction it is moving.
If there is a remender I have to check how much is the remeinder if
the remeinder is less than 24 I just ignore it if it is greater than
24 I take the difference divide by 50 muiltiply by 50 then add
startFoundBlockPos plus 50. Any way go through the code and try to
understand it.. This function is called as soon as the touchends in
the touchends function and after you set endFoundBlockPos but before
you set the FoundBlock = 0;

Like this:
endFoundBlockPos = FoundBlock.x or y depending on direction.
[self.snapBlock: FoundBlock];
FoundBlock = 0;
endFoundBlockPos = 0;
startFoundBlockPos = 0;

-(void) snapBlock:(Block *) inBlock
{
int diff;
float foundBlockNewPos;

diff = (endFoundBlockPos - startFoundBlockPos);

if(diff % 50 == 0)
{
foundBlockNewPos = (startFoundBlockPos + (endFoundBlockPos -
startFoundBlockPos));
NSLog(@" No remeinder");
}
else if(diff % 50 !=0 )
{
if (diff % 50 <= 24 && diff % 50 > 0)
{
if ((diff % 50) > 24)
{
foundBlockNewPos = (((diff/50)*50) + startFoundBlockPos + 50);
}
else
{
foundBlockNewPos = (((diff/50)*50) + startFoundBlockPos);
}

NSLog(@" remeinder inside less not less 0: %i\n", diff % 50);

}
else if (diff % 50 <= 24 && diff % 50 < 0)
{

if ((-(diff % 50)) > 24)
{
foundBlockNewPos = (((diff/50)*50) + startFoundBlockPos - 50);
}
else
{
foundBlockNewPos = (((diff/50)*50) + startFoundBlockPos);
}

NSLog(@" remeinder inside less 0: %i\n", diff % 50);

}
else if (diff % 50 > 24) {

foundBlockNewPos = (((diff/50)*50) + startFoundBlockPos + 50);
NSLog(@" remeinder inside greater");

}

}

if (inBlock.dir == Horiz_BLK)
{
NSLog(@" MOVING IN X");
inBlock.x = foundBlockNewPos;
}

if (inBlock.dir == Vert_BLK)
{
NSLog(@" MOVING IN Y");
inBlock.y = foundBlockNewPos;
}

Thursday, October 27, 2011

Doubly Link List in Objective-C For PA4

For this Project I used doubly Linked List, to me it makes things easier. I have a Block class, BlockList class, then i have views for level1, level2 and level3. In the Block class i have all the data for a block and a function to initialize the Block values. Then in the BlockList class i have functions to draw Blocks in a list, find a block, add block to the list, clamp blocks in a list, reDraw the blocks in the list, memory clean up. So when i load up level1 view i just initialize the list with a number of blocks i want, then call specific functions from the list class. For example to draw blocks in the list, redraw the blocks this function is called in the level1 view gameLoop function, and when i move from one level to another i call the memory cleanup function.

I figure this way i have all the functions in one place then when i initialize levels i just initialize the list and call specific function. I just thought of sharing this cause it makes things easier.

so long and stay thirst my friends.

Thursday, October 20, 2011

Taps, Touches, Gestures

For the past few days i have been going over Chapter 15, on Taps, Touches, and Gestures. Also went over Chapter 14 on drawing Quartz. It is very interesting, i never thought will be some how easy to draw stuff like polygons. I played a lot with taps, touches and gestures because i am planning on using those when developing my final project. I am planning on creating a simple game for the final project hopefully i get to pull that off, it will be simple but it will be playable and fun that's my goal. I think it will be do-able and i am hoping to start setting up the views for the game as soon as possible so i can concentrate on the developing simple mechanics for the game.

Hoping to have a simple game at the end of the quarter for you guys to play.

so long and stay thirst my friends.

Thursday, October 13, 2011

Multiview Apps

After some hours of struggling getting the Multiview App to work right i finally got it to work right and that struggle made me understand how the whole Multiview shenanigan work. Victory for me and sad news for this whole thing. After wards i felt like doing everything to display a new view from a slider, button, to a label you name it, i just wanted to get everything to display the view. It to me a while to understand, but hey i got the job done at least.

During this process i encounter a problem with the Interface Builder that is worth mentioning to those Iphone/Ipad developers. The problem was that whenever i double clicked an XIB file in xcode, the Interface builder would not show up and this was just happening on my laptop. So i thought of just searching for Interface Builder from the Mac "Spotlight" and try and run it from there. I ran it and it showed up then i closed it, and try double clicking on the XIB file from xcode, lord and behold there it was it showed up. To those who might encounter this problem try what i did it might help. The crazy thing is that it was working before but all the sudden it stop.. What a day in a life of a developer..

So long and stay thirst my friends..

Thursday, October 6, 2011

Iphone Dev UI

This week i have just been going through the tutorials from the iPhone 4 Development book. I have been trying to get as much as better understand of the UI coding from the as simple as pressing a button and getting a simple feed back like yes you pressed me i know that simple is always better and easy does the job.

I also started working on the Multiview Application from the book trying to understand how to transition from one view to another. I know every iPhone Application as far as i know has multiview transitions, not even one but many. But for now i am just trying to get it were if i press a button i transition to another view. I know it will take a while but, i will get there slow but sure.

Hopping by the end of this week i will have a better knowledge of Multiview apps for iPhone dev.

So long and stay thirst my friend.

Thursday, September 29, 2011

Memory Clean Up for Link List in Objective-C

I have been working on trying to get the memory leaks vanish in for this
project and this is the approach i took, i don't know if it is
the right way to go or not. I created another function that traverse
through the list and delete all the remaining node before i delete the
actual List object. I know we have another function that searches the
list for a specified node to delete, but this other function i created
doesn't care what type of a node is in the List it wipes out every
node remaining in the list. But the tricky is you have to store the
current node into a temporary node, so that when you move on to the
next node thats when you delete whats behind, otherwise if you don't
do that then you will be trying to delete the current node causing the
current iteration of the List to break.

-(void) gabageCollector
{
Loop (through the while p is not == null)
save p into a temporary pointer;
assign p to the next pointer;
then release the temporary pointer;

}

The after setting up the function, then i call it like this in main

//go through the list and delete all remaining nodes
[newList gabageCollector];
//delete the List object
[newList release];

I don't know whether this is the right way to go but
thats the approach i took..

So long and stay thirst my friends........