After a good three months of droning on (and on) about stuff that has very little to do with Yaroze programming, I suddenly realised that these diary entries were getting a bit random. So, finally finishing C for Dummies: Volume 2 (whoopee!), I decided to sit and pore over the numerous pages of Yaroze source code I had printed out and relate the C I knew to what was going on in other Yarozers code. I can tell you that this was the most depressing experience Ive had since getting the machine, and for a little while (about a day or two) I suddenly felt like the biggest dope in the world. How could I possibly expect to write for this machine, with my cheesy programming ability (self-rated as 2/10, according to my profile on Dennis Brinkhuis page) and lack of any mathematical background past GCSE? As I stared at the squiggles and strangely-familiar-but-still-unfathomable C, I was confronted by numerous functions, loops and weirdness (bitshifts? What the..?) that - hey! - they never told me about in C for Dummies. Which, by the way, was seeming an awfully ironic title for that book.
Never give in! Over the next few days (and after about 10 readings of Ira Raineys and Scott Campbells most basic sprite tutorials) it gradually began to make sense. I have to admit, the turning point came when I was sitting typing this stuff into the computer myself - blatant word-for-word imitation, but I did get a vague sense of where the program was at, and I realised that if I could just hold onto that, then as I gradually looked up the functions, read other code etc etc I could work out what was going on and get it all straight in my head. After 3 hours or so on a Saturday night, I ended up with a picture of the Final Fantasy VIII logo displayed on my Yaroze screen - and even better I was about 50% certain of how it got there.
The other thing I did was write something that displayed, in text, which button was being pressed on pad 1. Like, "CIRCLE" or "PAD UP" - nothing fancy. I even made a loop so you could hold "SELECT" and "START" together to quit. Well, it made me happy. Pad input - dont ya just love it?
Every bit of advice Ive heard from people, directly or indirectly, has stated that you should aim to get a sprite onscreen, then get it moving about, then add another sprite, then add some animation, rotation scaling, a background, collision detection, scrolling and gradually build up into something basic that might even be passable as a game! Whew! I guess thats my goal - so I decided to try and get a program written that displayed 2 sprites on the screen, and then build it up from there.
Believe it or not, I had a bit of trouble working out how I should go about putting up 2 sprites. Do you need 2 GsSprite things? 2 GsImage structures? How do you go about getting them initialised, etc? Basic questions, I know, but still a bit daunting when there isnt too much in plain English to help you. The sprite tutorials were very helpful, but they didnt seem to say anything about 2 sprites. Oh. Well, I just muddled about and eventually got it sort-of working (AFAIK, you DO need 2 GsSprite structures - and 2 GsImage things is playing it safe). Except something was wrong - the colours were totally messed-up. It was ugly. Now, earlier in my programming endeavours I had discovered that my TIMs (graphics files) were being overwritten by the actual program code when that loaded up (doh) but this wasnt the case here. Hmmm.
I tried a lot of things - shifting TIMs around in memory using TIMtool and swearing at the computer being two of them - but it wasnt until a chance (honest, guv!) visit from fellow Edinburgh Yarozer James "Mr Frosty" Rutherford that the problem was solved. Amusingly enough, the mistake was one of such blind stupidity that it took even the creator of Snowball Fight (were not worthy, were not worthy) a good half hour to suss it: my TIMs were fine, but my CLUTs were still lurking in the video memory display area. Dur! Duh-duh-duh-durrrr! I knew what a Colour Look-Up Table was, but I had rather forgotten about sorting it out in memory before running the program. Ahem. Another foolish newbie error, but we all have to learn, right?
This problem solved, I was left with my beautiful 8-bit creations, resplendent in their naked, brazen glory. The job was done for the day, but my next task was to add a bit of movement. Wahey! With what Id sussed from reading the pad, this shouldnt have proven too tricky. And it didnt! Using the dire and pathetically inadequate default Sony "pad.h" header, I soon had the 2 sprites zooming over the screen (albeit with no regard for the screens boundaries, or each other). I also added a bit of code to show (gasp) the X and Y co-ordinates of the two sprites. After another quick (ahem) glance at the tutorials, I added scaling and rotation to the sprites, just for a laugh. With my "goal for the day" (good idea, that) completed, I felt it would be a doddle to add some collision detection next. Wrong!!!
Is it just me, or is there no collision detection function in the Yaroze libraries? Does this mean (shudder!) that Im going to have to write.. my... own? Apparently. Cue bit of graph paper, 2 cut-out shapes and a lot of thinking hard about an equation for when two rectangles (bounding-box method ahoy!) overlap. This hurts my (largely arts-and-literature filled) head a lot. I resort to cheating, and plummet into the source code for Snowball Fight (not available to the public, but I have a copy for my own enjoyment from the benevolent and generous Mr Frosty) to look at how it was done there. I am aghast to discover that I was on the right track, and only my inability to wrap my head around the concept failed me. Another "Doh!" on the long and dangerous road to gaming greatness...
Now, out of respect for Mr Frostys entrusted SBF source - and not wanting to incur the wrath of a buddy and mentor - I do not perform a straight cut-and-paste. Oh no! I have "adapted" this basic idea into my code, and Im fairly pleased with the result. Send off the co-ordinates to a collision function, and if the movement just performed results in a collision, then undo it. Pretty basic stuff, all handled in the pad reading routine. Phew! Actually, the first thing I did was to create a variable which was "1" if the sprites were overlapping in some way and "0" if there was no collision, just to check the function worked OK. Then I wrote a quick fix to stop the sprites going off-screen (learning a bit about that PAL display bug - 240 vs 256 lines - in the process) before putting motion checks on the sprites. It worked. Time for bed.
Finally, I decided to add a background and change the sprites to something a bit cooler. With the vague idea of a crappy arena-based shooter occurring to me (remember Battle City on the NES?) I figure some funky ships are in order. Numerous experiments in Photoshop later, and I come up with what I was aiming for - simple, sleek, sexy and distinctly retro in appearance, but with a modern feel as well. Yes, look at the picture below and youll see exactly what Im being so pretentious about!!!
Well, not bad for 30 minutes work. I spend a bit longer coming up with some "cool" background for these epic battles to take place on, and eventually I have a screen-sized 16-bit sprite ready to stick in the background, with 2 dinky spaceships roaming about on it, rotating and scaling and sliding away...
What went wrong? I dealt with the background as Ira Rainey suggested (and it works fine), but now my sprites are mutated (much as they were when the CLUTs were stuck in the display area). Grrr! I subsequently try everything I can think of to get the damn code to work, including (for no really obvious reason):
Changing the player sprites to 4, 8 and 16-bit.
Ditto for the background. Doesnt look pretty at 4-bit, I can assure you.
Moving TIMs and CLUTs about in memory. Many, many times. Oh, that gets old quick, dunnit?
Read through my (no sir, not buggy at all!) code. I cant see anything, but that doesnt prove anything does it?
The gods MUST be crazy. Eventually, the combination of 8-bit background and sprites, pretty TIM arrangements in memory etc works. To this day, Im not sure why this is so, and I reckon I should make a bit more of an effort to understand how the Playstations memory works, and how to go about loading things into it. Oo-er, missus.
(Starts off in husky movie-trailer guy voice) Thats where my story ends. Two weeks ago. Since then, nothing. Not a sign. Ive been a bit busy with "other commitments", although Id better get my arse in gear sharpish if I want to get some code in for the Game Design UK competition. Hmmm. I have reneged on my summer pledges to NOT WORK and CODE. Rather, my old job wanted me back for MORE MONEY and as I am a sell-out slut when it comes to cash, I accepted. The only reason I have a shred of cred remaining is that I refused to work a full day, so I get away with 5 hours a day - which is all I can stand, processing the results of the British Survey of Fertiliser Practice (yes, really), anyway... At least this means I can now afford to get Banjo-Kazooie, Zelda, F-Zero, Metal Gear Solid, Parasite Eve, Colour Gameboy etc when they come out.
A few quick things that I feel the need to share. First of all, I went to an Iain Banks book signing at Waterstones in Edinburgh on Saturday and was first-in-line (sad man that I am) to get my old-and-battered copy of Consider Phlebus signed by the great man himself! Cool, huh? Also, I went home a few weekends ago (not to Hong Kong - my parents are back in the UK for a month) and whipped my brother at Street Fighter II on the SNES. Heh heh heh. You see, usually he could DESTROY me with Guile (his character), even when I used Ryu (my best character). Maybe my improved coding skills have somehow made me a better gamer, too..? Or perhaps not. I also got a hold of my aunts shiny (and awesome) Fuji digital camera (it gets 5/5 in this months T3 magazine) and got some very cheesy pictures of myself. These were taken in the bathroom and have been digitally altered to remove any semblance of "taken in a bog"-ness (the removal of a loo-roll holder by my arm, and a row of toothbrushes up behind my head). Vanity, eh? Its a terrible thing.
(You can get your own slice of the cheese by clicking here...)
Or return home?