The transpose function is available since version 1.20, and the inverse function is available since version 1.40, so we can’t use it. Instead we have two options. A. Calculate the normalMatrix from the C++ code and pass it as a uniform to the frag shader. B. Write our own transpose and inverse functions.
Although, with option B, we shall have consistent code, but since the code in frag shader is called for each pixel on the screen, I think it would be inefficient. Also, we can not ignore the fact that we already have a time tested maths library, which would be better than our own code.
In RenderInstance, I’ve added this line to use glm compute the normalMatrix for us
With version 1.0 we don’t have implicit conversions, so instead of 0 and 1, we have to explicitly say 0.0 and 1.0.
And, now we should be able to run our code.
Next big change is with gestures. If you run the Desktop app, you can observe that after moving the camera around and pressing the ’1′ key updates the light position to current camera position.
With the 05_asset_instance we used gestures as direct mapping with keyboard, but from this sample code I’ve tried to utilize the touch based gestures more, and also made them more natural to the touch based gestures.
2.1 Long press WASD
The WASD gestures are now not directly mapped with the desktop version. Instead, W, A, S, and D when tapped for a longer duration now move the camera Up, Left, Down and Right respectively.
This movie requires Flash Player 9
2.2 Short press WASD
When tapped on WASD zones for a quick duration, launches a different action. In current case W, A, S, D maps to Update the light to current position; Change light to red; Change light to white; Change light to Green.
This movie requires Flash Player 9
2.3 Pinch to zoom
The zooming gesture, that were previously mapped to W and S key are now mapped to pinch gestures.
This movie requires Flash Player 9
The mouse movement is mapped to dragging on the screen.
Even though I tried to keep things as consistent as possible, but for some reasons I had to change the code at few places, here I’m listing the thoughts behind that. I think it would help someone following the above tutorial for iOS, or for OpenGLES. The original main.cpp has been renamed to iOS_main.
1. The Loop:
The loop should be the most striking change. The main reason being that Apps on iDevices run in their own loop. We don’t have control over the loop, the system kind of passes the control to us when ever an event occurs. So, Update and Render are called directly from WLViewController.
2. Touch Events:
A new type eGesture is declared in iOS_main. For any kind of touch gesture, the RegisterGesture is called and the gesture state is saved. The gesture is then used in the Update.
Gesture include tapping on the four areas and tilting device up and down.
3. Linking glm:
I assume that you’ve installed glm using macports, as suggested by Tom in the first article. In any case you still have to go to Build Settings > Search Paths and provide glm’s location.
4. Code change:
All the code from original source remains the same, except when something doesn’t works for OpenGLES.
For example, in Program.cpp the MACRO hack for ATTRIB_N_UNIFORM_SETTERS is split into ATTRIB_SETTERS and UNIFORM_SETTERS.
Other than that, I think the articles can be easily followed. The code should work for iPhone and iPad in every orientation.
Next thing was gathering the data from Xcode to Grapher. To start with, I wrote this small C code to format the data from the Xcode’s console to some plain txt, that I could be parsed and generate 3 other files.
These 3 files were supposed to be feed into the Grapher, for each of the Menu > Equation > New Point Set by doing Edit Points > Import
Every thing was working fine. This is some data I visualized:
The Blue line is the Bullet firing and the two Red circles (one almost out of border) are the Sprite’s A and D points.
But, as you can guess, doing this every time was no fun. I had to:
Copy the data from Xcode’s console.
Paste it into “cd.txt”
Run the C program.
Import 3 files (W.txt, A.txt, D.txt) to Grapher.app
and see the data visualized.
That’s when I decided to try out Gnuplot. I spend literally 2 mins reading this quick tutorial. 2 mins to download and install Gnuplot. And, 2 mins to get it running!
The best part is, since gnuplot is scriptable and runnable from command-line, I can even run it from the Xcode automatically (Using Xcode Menu > Behaviors > Running > Completes > Run Script).
For now, this one line in Terminal is good enough:
gnuplot> plot "cd.txt" using 1:2 title 'Weapon', "cd.txt" using 3:4 title 'A', "cd.txt" using 5:6 title 'D'
I like to think of every programming experience as going from point A to B. A language is just a vehicle we pick for the journey. The effort while covering distance between A and B is the total amount of effort we’ve to put in development or maintenance wise.
At the basic is Assembly type languages. They’re like walking. You’ve extreme control over it. When you fall you can instantly guess what caused it, and can easily get up and move forward. You can also easily guess how much time it should take if you’re walking on such-n-such surface from point A to B. The drawbacks are that, you can not walk over large distance, it’s not impossible, but impractical. And, every time you’ve to walk on a new kind of surface (like Moon or water), you’ve to literally relearn walking.
Next in line you have C type languages, which can be thought of as like riding a bicycle. The beauty to appreciate is, how transparent the whole machinery is when compared to walking, and still you can go miles. In cases when something breaks on the way, the fault isn’t as instantaneous as walking, but still you can pretty quickly figure out the faults. The drawback is that you can still get tired when covering even larger distances. But, when the mood is set, nothing feels as pleasurable as riding a bike.
Then we have the C++ type languages. They’re like riding a motorcycle. Remember the feeling when you rode a motorcycle for the first time? It’s like woah! The machinery isn’t as transparent as a bicycle, but the thing is awesome. You’re like, I want to go places on this thing. And, every now and then you keep hearing new trick that people are applying on their motorcycle rides. What traffic, what roads, you just don’t care! It’s exactly what it sound like; a bicycle with a motor. Nothing can beat that. The downside is, when you fall on the ground, it hurts bad. Can even make you go crazy, even make to think, “I’m never going to pick this thing again, where are my car keys?”. But, again and again you can’t resist riding it.
Next in range are Java type languages. They are like cars. The vehicles get more complex with respect to the inner machinery, and the rides get smoother. A lot of things are done by the machine for you. The roof over head, windshields, air-conditioning, safety-belts, air-bags. They severely try to reduce the chances of your collision, and the engines are well tested. Best thing for traveling a long distance, or with your family/friends. Just plug in your favorite music and get riding. The downside is that they are bulky objects, and that comes with reduced mobility when traffic is heavy, but still you’ve the control. But, still most of the people are riding cars for usual jobs.
So, what should I pick for my next adventure? Smart people like Batman, use a top-down approach. They use public transportation when in the Bruce Wayne mode, and when the time strikes, they bring out the car from the garage. And, in extreme cases when even the car is broken they transform it into the motorcycle, or even use two feet. Get the job done, that’s how they save the day. Be the Batman.
Before I even begin, here’s the disclaimer: I’m already an iOS developer from 2008, so coding is nothing new to me. But, as I realized sometime in the journey, programming for a game is entirely different that for other apps I had been doing. For example, the game runs at around 60 frames per second, usually in a tight loop. So, all the resources, the data, processing, memory are very expensive.
All in all it was relatively new experience for me.
I could have used many freely available game engines, but since this was my first attempt, I wanted to go as deep as possible. The other perspective of making a game was to understand all the inner mechanics. So, I started studying OpenGL ES.
I started out by simple tutorials available on the web. And soon I was able to draw triangles, squares of all colors and sizes. I then moved to 3D, drawing cubes, icosahedron and what not. Next step was Texture mapping, and GLSL shading. It all took months.
Since, I started out so late and the technology has advanced severely. After a while, everything became very confusing for my little brain. So, I took a step backwards and started with the 1990s, and started learning the OpenGL 1.x, the fixed function pipeline with GLUT on desktop.
I used the glut methods as minimum as possible, because learning glut wasn’t my objective. Mostly, just to handle the window and inputs. But, at times like I was learning about manipulating the view or projection matrix, it was much quicker to use glutSolidCube.
During that time I bought at least dozen of books on Computer Graphics. During my book purchasing rage, I even bought the Computer Graphics by Hearn and Baker book twice, one using OpenGL the other C version. My daily routine had almost become reading and coding. The best book I would recommend for the basics is the Interactive Computer Graphics by Edward Angel.
On, the parallel side I was also reading iPhone 3D by Philip Rideout. The best thing about this rarely mentioned book is that, it covers both GLES 1.0 as well as 2.0, which was a huge win for me as I was able to look at how to implement the same thing with GLSL shaders, and what’s the real deal about the programmable pipeline.
So, after months of rendering triangles and cubes I was confident enough to write a simple 2D or 2.5D game.
As far as the OpenGL developer’s standards go, I’m still a noob. But, as the time passes by hopefully I’ll get more mature. And, I think now I’m in a situation to peek at some real OpenGL based game engine.
2. Programming Language
Looking back, this shouldn’t had been discussed, but it was. The main discussion was always centred around three things:
i – Performance: C > C++ > ObjectiveC
ii – Recognition: C++ > C > ObjectiveC
iii – Ease of use: ObjectiveC > C > C++
The OpenGL is usually implemented in C, and that was not a problem, because I’m moderately good at C. The game dev community uses C++, which is a easy to use but hard to master. And, ObjectiveC is the language Apple prefers.
My first choice obviously was C, but sooner I realized that C was never designed for bigger project. I know many game devs have been using C from centuries, and many are still actively doing amazing things with it. But, maybe I wasn’t experienced enough to use C at such a huge scale, or maybe working with ObjectiveC for so many years spoiled me permanently. At one point I bought Expert C Programming by Peter Van Der Linden and read it from cover to cover. It really helped boosting my confidence, maybe someday I’ll use C, but that day isn’t today.
So, that brought me down to ObjectiveC. I’m already using it at my day job, and I’m really confident with it. For the good parts, with ObjC it becomes easier to use all the Apple’s Cocoa API, and the game can use the latest the Apple has to offer with no problem. The only downside is the runtime overhead, and that’s the second complain I’ve heard from other game devs, the first one being that it just lives in the Apple’s environment. But, for my little board game I assumed that shouldn’t be a problem, and I wasn’t even targeting any other platforms than iOS. And, frankly speaking I never found any runtime issues.
3. Project Management.
As Bismark once said, “The secret of politics? Make a good treaty with Russia“, and by politics he meant Coding, and by Russia he meant Design Patterns.
I have been working on iOS projects since late 2008, and I never felt the need to improve something in my coding pattern. My intuitions always almost predicted correctly like when a new class is required, or a new method or a new variable. I just used the ‘Don’t repeat yourself’ philosophy. This was the core guideline I created for myself as I evolved:
a. If some code is getting repeated, put that in a loop.
b. If some almost similar code is getting executed in different places, put that in a a function, and resolve the differences with function arguments.
c. If some code looks likely to being used in the next project, put that in a class. And again if some code is never going to be used again, quarantine it in a class.
And, so far the philosophy worked great. But game programming is a little different. You don’t just need a good solutions, you need the best way possible. At some point of time I read the GoF Design Patterns. It had an epic impact on me. Now sometimes, I find myself spending hours drawing UML diagrams of how my classes are going to be structured, the entire flow. I feel like some commander in his tent with a map, planning out the attack strategy. It’s great!
The next lesson, I learned during the whole thing was using some kind of revision control system, like Git or svn. It’s a comfortable feeling knowing that you can jump around the time, it’s like you own the DeLorean time machine. The only negative side is, you have one more TODO thing to remember.
I started out with Inkscape, it’s a great software for creating artwork. I started with these awesome tutorials, there are more than 100 tutorials and I yet have to see around 40 of them
The only thing I can say about graphics is that, there is the hard way or the highway. When I started out, I soon started to get the feeling that the colors are very limited thing. What ever palate I picked the colors never seemed to be enough. Sometime I just gazed at the stuff people were doing at dribbble, and the colors they were using.
Some time later I realized that the real thing about colors was their use in perspective of each other. I tried to study some of the awesome paintings and see how they were making use of the colors. I now know that it’s a big big world there within the colors.
One day I found colorschemedesigner, and I used it extensively to understand what colors feels nice to the human eye. Turns out, there’s a total science involved in it.
The problem with colors, as with all the other core basic things that define the nature, is that it can never be defined by any theory, in the end everyone is a equally capable critique; everyone has eyes. So, in the end, I just went on with my basic human intuitions.
For the little effect I used bfxr. Although, I understand that it isn’t good for polished games, but for this game I didn’t had many effects. The one that anyone was going to hear most of the time was the error buzz, like when you make any illegal move.
For the game music, I tried GarageBand on OS X. And, its really good software. I was able to make nice music quickly.
First, I created this
And it looked awesome to me. But, when I played it on the real device, there was a lot of noise. So, I updated it with the current music it has now.
In the initial stage I did all the testing myself. When, the game became a little stable, I gave it to few of my friends. Their honest feedbacks were very valuable.
When, I got more confident, I added the testflight library. It’s easier than you imagine, in fact, I don’t think it could be any more easier to add and use. I posted on twitter looking for beta testers. And within few hours I got almost 10 requests. I sincerely thank them all for taking time for testing my game.
I wasn’t looking for feedbacks from the users, it was more like the usablity testing. Like how many of them use the tutorial screen, which was zero, so I changed that, and things like that.
I did minimum marketing. Just posting in toucharcade forums.
As this was my first game, I wanted to see how many downloads I get with zero reviews.
Maybe from the next game onwards, when I do things in proper order, I’ll request journalists to review the game.
8. What now?
Now, I’m working on my next game. I’m feeling better about myself
Also, I’ve realized my weaknesses, I need to brush up my 3D geometry, and C++. I also need to practice some more on algorithms part. My usual day job, doesn’t requires me to do any smart job with algorithms. Like if there is sorting, I can use bubble sort all the time.
I also need to practice more on the art side, if I’m going to do the next game all by myself again. And, there is a whole segment of marketing that I skipped with the Capture Path.
In near future, I’m also planning to do a post-mortem about my sale figures and more lessons I learned.
For now, if you’ve read so far, you would probably like to even try the game, it’s free
But, that’s was good, because the main motive behind the Jam wasn’t the success, but to boost myself up, and today I’m a more better developer than I was yesterday.
Today, I’ve decided to clean up the mess I created yesterday. The code right now lives in just a single monolithic class, and even I didn’t wrote that class, that’s the class that comes with the template. Plus, I’ll add more reliability to the code, and more animation.
If I’ve learned anything from yesterday, is to challenge the task by making it time bound. So, I’ll doing all this in 2 hours.
Here’s the list of some of the main things I intend to cover:
Clean up the code, make it more Object oriented.
Add animations for sliding objects on the screen.
More images for handling selection, awake and sleeping states.
Add exception handling, to avoid unnecessary crashes.
Day 1 :: 03:53 hours – Let begin
05:39 hours – Update
Holy crap, it more than one and a half hour, and I’m still adding more and more classes!
Converting a structured program into OOP based is horrifying, but I guess at the end it would pay off, with lesser maintenance and easy debugging.
This is the Class Inheritance structure I’m trying to build:
Here, each GameObject can hold many child GameObjects. This should help me render things easily using Painter’s Algorithm, because I’m not using any crazy OpenGL things here so far, so this approach fits best. I think this design pattern has a name, the Composite Design Pattern
Now, I’ll be taking a break. Some stupid task has came over me, should be able to finish that up in half an hour.
DAY 2 :: 22:10 hours
I’ve planned to finish up the pending tasks today. I’d already mentioned in my other rant, that I’m doing this silly little game because I’m unable to deliver things on target, so the other purpose of this thing was to evaluate my performance: Like how much time do I take in doing X thing, and so on. So, I’m not as much feeling bad on how I’m doing well below my own expectation, than I’m building my own expectation. I’m hoping that for my other projects I would be able to work out more accurately on my timelines.
Since, today it’s Sunday night and I don’t have anything else to do, I’m hoping to finish this game in total. Let’s dive in the game.
One other thing I’ve learned from this development is, that I’m never leaving the code in broken state. Good thing with that is, I don’t have a single starting point. I already have a perfectly working game, I need to improve it over some bits, so I can start from anywhere. This is one of the most important lesson I’ve learned so far – Never leave the project in a broken state.
I think the basic code is almost working, just need to fix some images, right now the ‘blue selected’ and ‘blue awake’ don’t seem so much different.
The middle Blue selected isn't good
OK, finally the game seems to be in a better state, with a small slide animation and better selection sprites.
Next, I’m planning to add some computer assistance, that guides you for all the illegal moves you make and displays alerts when you win or loose. But, before that I’m taking a break, as all this coding has made me really hungry, so going to omnomnom on something.
Day 3 :: 23:45 hours
My strategy with never leaving the game in broken state is really helping me a lot.
Today, there’s something different with the environment, first of all I’m working on the game when I can get easily distracted by some other work that I’ve to do on the first priority, but since I’ve started to love this game so much recently, I’m unable to get over it. Secondly, I’m listening to music, though I read somewhere that working unplugged is more awesome, and I’d been working unplugged, and it was awesome. Just experimenting.
For today I’m keeping a small target: Just to finish state change after the animation is over, rather than a quick as the touch events are received. I’m hoping to finish it up by 01:00 AM. Let’s begin.
This is how it looks right now, notice the colors of the selected army going to sleep even before the moving trooper is not done.
This movie requires Flash Player 9
I tried too many weird approaches, and sooner i realized I was making the code more complex by adding more ‘Generalization’ and ‘Abstraction’. I really hate it when my mind works like, like even for a ultra-simple problem, I start coding like I’m going to reuse this class for ever and ever. So, in the end the Abstract class is doing everything except solving the real problem.
Finally, about 3 minutes ago I decided to cut the crap and solve the real problem in hand and it’s working now.
This movie requires Flash Player 9
I deserve a coffee break, as an achievement for overcoming my stupidness.
I’m excited to announce that, the game is ready to play, with whole logic to replay and check who wins.
Next, I’m planning to add some AI, as I’m pretty sick of playing against myself. I mean, I might be a lonely guy, but I’m not schizophrenic.
One more milestone achieved: The dumb AI is now complete, so now you can either play human vs human, human vs machine, or machine vs machine. Just for fun, as a human I find pleasures when machines fight against machines.
Dumb AI at work
I think that’s enough for the day, I’ll test how the rules are being violated, and fix them in the next iteration.
Day 4 :: 08:04 hours
Today, I’m going to fix the AI. Right now the AI is very dumb, it’s like playing with a 4 year old. It just pick one of the piece at random and places it down at one of the unoccupied positions.
So, today I’m planning to make it more smarter, at least do the right moves. In short, to grow the AI from a 4 year old 10 year old.
The AI is now playing with rules, it’s still playing like a 4 year old though, but with rules.
Day 5 :: 00:51 hours
I’ve been messing with the AI, and so far it looks good, and it’s becoming better and better. Watching the computer against computer is becoming more fun.
For all this time I was building the AI with the sense like look at the occupied slots, the opponents’ slots and the vacant slot and guess the best move. But slowly it has started to take all space in my code.
I know it works fine now, and even though I’ve been documenting the code all fine at all mandatory places, but still I’m afraid that if I’ve an amnesia for a nanosecond, I might lose all the track.
Just to illustrate, here’s a code snippet:
So, I’ve thought of an alternate route: Calculating the weight of each path, and proceed to the path with highest rank.
Let me explain. Let’s say for now we just consider the 8 paths we have; 3 row-wise + 3 column-wise + 2 diagonal. As, these are the most important paths
Most important 8 paths
Another, important class of paths that I’m ignoring now can be of following form, where the opponent can set up pieces such that the danger isn’t in the straight line:
Another important path sample that is not necessarily in straight line
I did some maths, to calculate the number of combinations possible, when at least one of the node on the path is not occupied
Total possible cases with at least one node vacant
This is the ranks, I’ve decided to give them according to their importance.
For the figure, I’m assuming I’m blue player and the opponent is red. The red background represents Attacking mode and blue background represents Defensive mode move.
Ranks for each possible paths
I’m still confused about paths with ranks 1 and 2. If I place the one with single enemy piece above the one with all places vacant, then maybe I’m going to waste one opportunity into something that might not be even an attack, and anyways if the opponent is really planning to build it as an attack, I should become priority #4 in the next move, so it should be taken care of.
That’s enough inside story, let’s dive in the code. At one point I was scared to write my algorithm in this rant, because at some point you might see this and cheat on the AI, but still I’m most certain this is just the basic structure, I would improve a lot on the AI that will go to death bed with me And secondly, I’m hoping that the players are going to play more human vs human matches, I’m not assuming people are as lonely as me ;D
04:48 hours – Update
The logic I explained above is working! Now the AI is much smarter, the only problem is now the computer vs computer game is quite boring. Or, even in Computer vs Human, if you learn a pattern to beat the AI, you are assured to get a win by that every time. I blame the ever so expected for loops.
I need to devise a way to write a for loop in such a fashion that it isn’t the same every time; starting from 0 to n. I want the order to be random.
05:33 hours – Random for loop
Wow, adding that random for loop has added a lot of randomness to the game. The Human vs Computer is now I think at the top of the awesomeness! But, since the AI has gotten so super smart, the game between Computer vs Computer often leads to stalemate situations. There are three possibilities I’m thinking:
Once in while let the AI play a dumb move. Like, when you do a shake gesture the AI goes dumb for a move
Pick anything at random from 1 and 2, when playing for ranks 1 and 2, as they both seem equal.
Add a stalemate condition, like say if the game isn’t over by X amount of moves, or X amount of time, it turns into draw.
I think at some point I need to add point 3, that’s the nature of this game.
Day 6 :: 05:02 hours
I tried my two AI algorithms against each other. I call the older approach as Alice and the newer with all the Path Ranking system as Bob. Right now, the Bob is much stronger than Alice, but still Alice is much random, so it creates a lot of confusion for Bob. Also, since Bob is so perfectly programmed, it isn’t fun watching Bob’s moves. I would like to try an algorithm that is midway Alice and Bob, maybe a child of Alice and Bob, who randomly either plays like Alice or plays like Bob. And, further in the settings panel a user can adjust difficulty level, that would basically adjust the randomness factor.
I know there is a lot to fix in both Alice and Bob at the moment, but today I’m thinking of fixing the UI part a bit. I would try to create some better images or try to add more screens.
Day 7 :: 06:37 hours
Holy mother of code, my eyes are burning. I don’t remember, how long I’ve been working on my AI, but finally it beat me 5 times in a row. So, either the AI is perfect or I badly need a sleep.
I’ve greatly modified my AI algo. Now, there’s a bizarre concept that I’ve copied shamelessly from the Inception movie. There are dreams with dreams of the AI, right now I’ve been playing with 2 levels of inception, but I’ve tested with 5 levels of inception. I’m not sure, how the levels of inception are impacting the AI, but I’m happy with the AI.
Now, going to looooong sleep.
Day 8 :: 08:38 hours
I’ve been working for many hours now. The AI is fixed, I’ve added a Main Menu screen, a pause button in the game that brings to the Main Menu.
The Main Menu
Now, I’m working on the biggest thing: the GameCenter. So, that players can play this game with their friends or random people on the Internet.
Day 9 :: 14:01 hours
I worked on the background. The motivation is to do some crazy particle effect in the background, like some galaxy or something. Other than that I also worked on the images. I think they are improved right now, but I’m not satisfied. I need to work more on things and faster.
Right now I don’t have anything charming to show, the background particle effect is very random, not how we’re used to gazing at the universe. I’ll probably post some snapshots after the particle effect is done.
Ladies and gentlemen, here’s the first draft of your night sky with 50 stars:
This movie requires Flash Player 9
I tried everything from simple coherent noise patterns, to spirals. But in the end a simple random function did the job in the easiest way. The key to twinkling stars is that each star is decaying at some rate, and that rate is inversely proportional to its current brightness or energy.
14:49 hours – Background Universe
And here’s the almost final product. I’m toooo tired to write any more, so as they say one swf is greater than a thousand words:
This movie requires Flash Player 9
Day 11 :: 09:57 hours – Electricity
This is the first draft, I’m looking to improve something. But, before that there is a huge lesson to be learned, never use srand() each frame. It delays the calculation so slow that your game will start to run at something like 10 fps, and I was rendering a couple of GL_LINES, no polygons nothing. I wasted hours with Instruments to look for bottlenecks, I was anticipating something fishy in GL calls. I learned the lesson the hard way, but it was worth it in a way, now my code is 10 times more optimized in some places I would’ve never optimized it earlier. There are some extra for loops removed and some smart ways to move data around all due to that srand(time(NULL)).
Next stop, the Main Menu.
Day ‘Don’t remember when’
I haven’t been updating this log for a long time now. The first reason for that was, my mind playing dirty games with me. And the more I tried to work on this log, the more I felt the need to change something in the game.
So, I took a step back, and stopped logging things, and today I can say the game is done. It’s in the AppStore review process.
So, it’s 6:51 AM, and I really want to test my balls. I’m doing a quckie to check can I really make a game in 3 hours. I will start at 7:00 and end at 10:00.
I’m doing this less for the sake of making money or getting recognition and more for the moral boost, because for past few months I’m just struggling to finish my deadlines, and I’m kinda loosing my faith in me, which is pretty sad thing. So, here is the ultimate test.
First the background, I’ve been working all night on some project that earns my food and cost on earth, so I’m somewhat pretty tired. I’ve planned to not mix any Caffeine in my blood as I’ve to sleep at 10, and Caffeine makes me go crazy for hours.
I’ll doing the game on iOS platform, as I’m best in it, I’ll be using Inkscape for graphics, and probably sfxr for sound, if there are any. Most probably I’ll use OpenGL ES 2.0 for rendering and that’s all I can think of right now.
7:00: Let the time roll!!
7:22: The Big Plan
The game I’ve thought is a game I played as a kid with one of my friend, it’s pretty popular concept, every one must have played a version of it.
Here’s the artwork I’ve done so far:
You are either the Red Army or the Blue Army and capture the positions in a straight line. That’s pretty simple right!
8:59: Basic Setup
I know it’s a lot of time since I posted last update, but I’m finally able to setup the basic code. Here’s a snapshot of the above graphic in the simulator:
I know it’s not very exciting to see that, but I hope the next update is something awesome.
10:11: Time Over Update
Time’s up, I could just create the basic structure of the game. There’s no main gameplay logics, this is how it looks:
Since, I’m not as sleepy as I’d imagined, so I’m going forward and see how much time do I actually take to finish up a thing like this.
11:26 Final update
Good news is the game is working at the basic level, bad news is I’m logging off. I think the task is done for today, I’ve achieved what I wanted. I don’t know what I’m going to do with this game, release Open Source, or publish on AppStore.
But, still the game is not 100% done, there are many exception handlings to be implemented, right now I’ve no idea when it might just crash.
I loved the idea because I’m already working on my first iOS game, but at times for a change my focus moves to some other place, so I think for that #NaGaDeMo is a awesome idea
Today I found this awesome art work at DeviantArt, that I think I’m going to use for my prototyping.
If you don’t know it yet, I’ll be working on some platformer game, and will keep this page updated.
Update 2: Rotating Squares
And for size, you just pass x not like sizeof(GLfloat) * x!
So, with two rotating colorful squares I’m taking a break, next task is going to load textures
PS: I’ve an amazing game idea, for which I’m 100% sure Nintendo will sue me, but since I’m planning to use the Super Mario artwork I’ve linked above (for which I’m assuming the artist will sue me too), so the game is going to set up in the Mario’s world, and I’m calling the game as Super Goomba! Details later
Update 3: Textures!
Most of the time I just kept switching IDEs, from Aptana Studios to TextWrangler, to Unitron, each comes with its pros and cons. Maybe in future I’ll purchase TextMate as everybody on Internet seems to be recommending it, but I’m more like waiting for an IDE that supports WebGL syntax highlighting.
And to blame more the GLES 2.0 for iOS also spoiled me a bit, after three days of brainstorming I realized that my textures weren’t loading because they were not in POT(power of two), and as soon I realized that long forgotten fact my textures started working again
I don’t know how many people know that a sort of very intelligent Multiple inheritance is available with Objective-C.
What is multiple inheritance?
Multiple inheritance is a controversial concept where a class can derive from one or more classes. It is widely appreciated by lazy programmers who don’t like to code same thing twice, don’t even care to copy paste as they reason that it would increase the code maintenance overhead. Also, they add that while replicating some real world scenario into code, multiple inheritance is very helpful.
Since the discussion is about ObjC, let’s consider a scenario. We’re working on a universal project, (targeting both iPhone and iPad with single code)
For iPad we have a class called iPadStylingTableViewController, this inherits from UITableViewController, and every controller on iPad inherits from iPadStylingTableViewController. Let’s say iPadStylingTableViewController adds a cool looking background image.
But, then for iPhone in the settings screen you don’t need all the effects coming from iPadStylingTableViewController, you just want to keep it the default way, so this is how your code should look like
You must have noticed we’ve two different interface declarations for SettingsTableViewController class.
One ugly solution I’ve seen is that you create two classes SettingsTableViewController_iPad and SettingsTableViewController_iPhone, and it somehow works, but you need to maintain the same code two places.
If Java has been in your head for too long, you might do something creating an @protocol like:
This will solve the code duplicacy issue, as now we just have the real implementation of showSettings method in single class.
But, what if some other day you want to extend the functionality for the settings screen, let's say you want to add a new -(void)toggleAds method.
You would add the implementation to SettingsTableViewController_iPhone:
So, after a while you will realize that still upgrading the code is a real pain in the ass, as for each time you add some new functionality you still have to upgrade at more than one place. Now here is where we bring the awesome Message Forwarding into play.
Objective C has one awesome NSInvocation class that handles message forwarding very smartly.
All you need is to do is to implement these three methods, and it automatically redirects the messages to the classes that are capable to handle it, without you writing any extra lines
-(void)forwardInvocation:(NSInvocation *)anInvocation method is called everytime a message to passed to an object, we simply extended it’s implementation by checking that if our delegate controller, that is in this case the SettingsTableViewController_iPhone, implements the method being called in the message recieved. If yes, let it handle the message, otherwise do what it was originally meant to do (most probably crash the app).
The - (NSMethodSignature*)methodSignatureForSelector:(SEL)selector method matches the signature of the selector is also internally called each time to resolve the selector.
For further info check out the Apple’s documentation, it’s a great read.