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........

Wednesday, September 28, 2011

Doubly Link List in Objective-C

I spent most of my weekend working on the doubly link list in objective-c. To be honest this project got me going as far as link lists are concern. I did the delete node function, i got done with that then, i started working on the sorting aspect of the list which i finished yesterday. At first I started imagining how i wanted to code this in my head and then tried to code it, and it did not work so well. So i decided to go back to the basics, by basics i mean drawing the link list on the paper and try to simulate the deletion of a node. I came up with 4 scenarios that could happen when trying to delete a node from a list. Then i followed the same procedures i drew on the paper and lord and behold there it was, and i know every programmer knows the feeling when you get stuff to work.

The four scenarios i check for of what could happen when deleting a node are:
1: if we found the node and it is in the middle of two nodes.
2: if we found the node and it is at the beginning of the list.
3: if we found the node and it is at the end of the list.
4: if we found the node and it is the only node in the list.

I don't know maybe there are more scenarios but these are the only ones i could possibly think of when i was doing my drawing simulation of a doubly link list. Overall this project taught me a lot of things on the aspect of a Link List and when you get stuck is is always good o go back to basics.

Till next time, so long stay tuned and thirst my friends.



Thursday, September 22, 2011

Objective-C LinkList

I have spent sometime testing my small chunks of code in Objective-C following some sample code from the book, just to get familiar with the language. After gaining a little bit of knowledge but a little bit enough, i started working on the Double Linked list in Objective-C. So far i have gotten all my classes set up and finally after hours of struggle i had a breakthrough inserting Nodes to the front of the list and printing it out. I first started with just inserting integers from 1 to 5, then after that worked then i added a char data type to the Node for the letter alphabet.

I am taking every precaution with this, it may seem simple to others but i got to take turtle steps (type one line of code compile and run just to make sure it is not broken). So far things are sinking in and i am hopping to get used to the syntax of Objective-C in no time, as they say if you practice you are perfecting your skills. I am hoping by weekend to get all the insert functions (insertAtBack, insertInMiddle) done and the delete function done.

so-long and stay thirst my friends..

Wednesday, September 14, 2011

Iphone Apps dev

With the mobile Apps on demand i thought to myself why not learn how to develop one for myself or develop for those in need of mobile Apps, maybe a combination of both. I believe possibilities are endless and steaks are high, you have to create cutting edge Apps that everyone would like to have, so i am willing to learn from anyone.

So with that said, i am currently working getting the basics of Objective-C and the working environment of X-code just to get familiar with the development process in a simplest way. I have been following small examples from the book "Programming in Objective-C" just to get familiar with the syntax.

It took me sometime to get the environment setup and getting it to work correctly and setting up the workspace in P4 correctly looks easy but somewhat challenging if you don't follow the steps correctly, as far as i am concern, it looked even harder than creating my first iphone App. The bottom line is it is part of learning and that is why there is those who knows to teach things they know to those who don't like myself, and all i did is ask and the answer was right there. Thanks to those who helped me to get this to work, but there will be more questions to come. To those who are afraid of asking, my advice to you is there is no such things as stupid question(s). And to those who knows the answer to the question(s) please help, the more you help the more you become better understanding of the subject involved.

I will keep everyone posted on my progress, stay tuned.