Stay hungry, stay foolish, don’t settle.
Lessons in life.
RIP Steve Jobs.
IOS, Box2D and OpenGL.
Looking through the top selling IOS apps (well, the games section), it seems like having realistic physics is the place to be. (Angry Birds of course, but also others like Cover Orange, Cut The Rope, and the new number one app Tiny Wings).
Tiny Wings (excellent by the way) credits Box2D on one of it’s screens – this got me thinking how easy it would be to get something up and running that uses the Box2D library.
There’s a lot of stuff out there regarding Box2D on IOS, but most of it is related to cocos2d, and that’s not really my thing. Fortunately for me, I found an excellent blog post on Cocoanetics which walks you through how to quickly get Box2D working in a simple app.
My code is based largely on their excellent work (and of course the equally impressive Box2D library itself) – the changes I’ve made are purely to get something working using Open GL.
The code here generates a universal app (ipad or iphone/ipod touch). All the blocks are generated at random (size, colour, linear and angular velocity). Touching the screen restarts the process (or waiting for the blocks to all stop moving…).
Change the MAX_RECTS define in the ViewController.h file to change how many blocks are generated – size and colour info is done in Rectangle.m. Here’s the project:
Side note – the project is called nibfree as I was originally trying to get a universal opengl app working with no nib file (done!).
I’m not sure why, but it’s quite mesmerising watching how the blocks fall.
Big thanks to the Cocoanetics guys for their original blog.
As usual, any feedback at all is welcomed.
Starquake on iPhone
…with buttons on…
Thanks to Nay for doing some buttons. There’s a selection of buttons in the Graphics folder to have a look at (code changes in player.m and button.m, plus a few other nips and tucks here and there).
I’ve left the old alpha buttons on too – you can comment these out in the button.m class (draw method).
Here’s the updated project:
(project removed)
Back in the saddle again – iSpacies2
Blimey, almost 8 months since my last post.
I’ve finally got back on to doing some iPhone coding – spending some time away from this and coming back, it felt like I’d forgotten a lot of stuff. After checking my old projects (iSpacies, Ant Attack) it appeared that maybe I didn’t know as much as I’d thought…
So, with that in mind, I decided to do iSpacies from scratch, giving myself only a couple of weeks, and to focus on what I didn’t like last time.
Here’s what’s better than before:
- The graphics (same sprites, but a nicer background with a parallax starfield)
- The sound (it’s got some)
- The code (much more object based this time)
- Collision code on the bases (much improved)
When I started this I wasn’t sure that revisiting an old project was going to be beneficial – but now I’ve done it, I’d recommend it to anyone. I’m much happier with the way this one has turned out, and it’s giving me some momentum to carry on with new stuff.
Left box controls left/right movement, right box to fire (anybody got any nice button graphics I can use?)
Here’s the project, would really appreciate some feedback on this (good or bad):
(project removed)
There are ants lol
Following my last update, and fortunately for me (and the project), someone has come forward to help out with the graphics – Colin Wren is his name (see his site here), and he’s a top man.
The graphics Colin supplies are in .dae format, and with a lot of help from this site (Tipu’s iTiger) and an XML parser (TBXML), and much head scratching, we got the models going nicely.
At the moment they’re not animated, but they will be soon…
Other things now in there are bombs and collisions. To aid testing on the simulator I’ve added an auto-jump feature on the player – a collision in the x or y plane makes him/her jump. This also works quite nicely when testing on hardware so I may keep it (maybe as an option). I’ve also updated to the latest version of the 71Squared Sound Manager.
The button top left flicks between the male and female model – other controls as before (bomb button now works of course).
So, still plenty of things to be done, but slowly and surely it’s coming together.
Here’s the latest project folder:
(removed)
Happy New Year – Ant Attack project source
Here’s the latest version of the Ant Attack project – I’ve not had much time to spend on this over the last month or so, so I’ve decided to release it as is (unfinished of course).
The map data used in here is ripped directly from the spectrum original – see this website for an explanation of how the data is stored:
Inside the map class I read in this data and parse it into discrete blocks (total of 2650 of them) and then render the ones closest to the current camera position – this system isn’t great by any means, but does provide a simple enough algorithm and reasonable frame rate. (Would appreciate it if someone could test this on a 3GS device and let me know the frame rates achieved).
At the moment, the ‘ants’ in the map just run around at random, colliding with the map and making occasional direction changes.
The large button on the left is used to move, right button to jump – the button next to it currently does nothing (other than stop the jump sound playing). The red buttons allow zooming in and out – if you touch the middle of the screen (where your player block is) you can change the camera angle…
The sound code is basically taken from the 71Squared guys, the glu functions were found on Iphone Development (amongst others).
All opinions / comments / questions are welcomed…
(project removed)
Moving into the 3rd dimension
I’ve spent the last couple of months playing around with things in 3d (OpenGL) on the iPhone. I find it easier to stick with and learn something if there’s a definite end goal, and so after thinking about it for a while, I decided to do a version of the classic ZX Spectrum game 3d Ant Attack by Sandy White (see his page here: Sandy Whites Ant Attack page).
The main difference between the original and this one is that my version will be ‘proper’ 3d, compared to the isometric original (not to disrespect that version, it’s an absolute classic). This also means we can get nice things happening, like zooming and panning the camera, lights, textures and other bits and pieces.
Here’s a screenshot of how it’s coming along – all graphics (quite clearly) are programmer art. Hopefully I can find someone to help me out with something a little bit prettier.
The green squares overlaid are the control buttons (left big box for movement, right smaller box for jump). I’m finding the hardest thing to get right is the control method on the iPhone, and am still not happy with how I’ve got it at the moment. The small brightly coloured cube is your player (I did mention it was programmer art).
So far I’ve got the map in, along with a camera system allowing zooming and switching angles. You can move the player box, jumping and general map collision are working well. I’ve also got 5 ants (well, brightly coloured boxes) running around and colliding with the walls. Current frame rate (on a 1st gen iPod touch) is between 40 and 60fps.
Still to be done then, in no particular order:
A.I. for the ants
People to rescue
Sound
Better graphics (any volunteers?)
Lighting
User interface tweaks
Bombs
Menu screens
Sounds like a lot of stuff, but after getting all the 3d stuff going I’m hoping I’ve got the hard bits done….source code will follow when it’s finished if anyone’s interested.
iSpacies 1.1 – bugfixes and small changes.
Just a quick update to the project to fix a few things and change bits and pieces.
First up I’ve moved away from using an NSTimer update method, and gone to just spinning round the main loop. (Thanks once again to 71squared for that). One effect of doing this is that on the simulator it now runs almost too fast – on hardware it’s fine though. To be honest I’m not sure why – I’ve also made a few changes around using the timeDelta (time elapsed between cycles of the main loop) to help smooth things out a bit.
Other things fixed / changed:
The game now ends if the invaders land.
Improvements to the key controls – I’ve discovered you can get a hash value for a particular touch which makes the input logic work much nicer.
Fixed a bug whereby the number of bombs on level 2 and beyond decreased.
Changed it so that if you lock the iPhone/iTouch it doesn’t still run around the main loop / render.
Bit of a tidy up.
Here’s the latest project: (removed)







