Showing posts with label Unity. Show all posts
Showing posts with label Unity. Show all posts

Thursday, 6 November 2014

A Day of Shuffleboard King

Today I intend to blog more but less. A few short posts that nobody reads rather than one that nobody reads. I think it will suit my brain since today I'll be pulled in every direction, when my mind only wants to work on the game.

WScreenshot_2ednesday was a rare day which I managed to entirely devote to improving things on Shuffleboard King. I coded all day and night but, looking back, it doesn't feel like I added a great deal. It's odd but adding things that are small and user friendly can take much longer than implementing things that are big and game changing. The game runs on a loop, which means that the same code executes every fraction of a second. Adding features that don't interrupt the running of that loop are easy. Adding a dialog box to help the user means bringing everything to a halt and that can be tedious. Saying that, I added a shot counter message, which works well and was a good suggestion by a player.

I've also added a few other features that people have been suggested and, late on, I started work on a new game mode, which proves my point about the differences of big and small since I got it working about 2AM. My intention now is to have features which are enabled on a version of the game which people can buy for a paltry sum. There'll be no micro transitions or in-app purchases. Just an old fashioned choice on the Play Store of either playing the free version or pay a little and getting a lot more.

Having said all that, after yesterday's hard work, I've also broken a different part of the game than I was working on. How it happened, I have no idea since these things are mean to be isolated from each other. However, it has happened and I'll probably spend the entire day figuring out why.

 

Monday, 3 November 2014

And It's Goodnight From Me...

It's 3AM and I'm about finished for the night. It's been a long day.

The game should be back on the Play Store and I'm hoping that tomorrow will see fewer dramatic bugs.

I'm still not sure what caused the physics glitches except there appears to be a difference in how screen touches are handled between Android devices. I increased the sensitivity of the throws and that allowed the pucks to fly at the maximum speed. However, this caused a very rare situation to occur on the Dutch Shuffleboard, in which the pucks could bounce back towards the front of the board. I'd written code that caught them and destroyed them (putting them 'out of play', as the rules of Sjoelen dictate). However, the code had a loophole I hadn't spotted and it allowed some of the pucks bounce back, escape the board, and cause all manner of hell with the game logic, which didn't expect pucks to be rattling around the floor.

But this is the nature of computer programming. One small change (the sensitivity control) caused a bigger bug to reveal itself. And this is why I never believe any leader who announces that new computer systems will improve the NHS or any branch of the government. The complexity of computer systems increases enormously the bigger they get.

In addition, I fixed about nine or ten smaller things. Or I hope I fixed them. I'll be playing the game tomorrow and hunting out more bugs. I'm sure there are plenty.

If anybody reads this blog and has an Android device, please give the game a try. Perhaps drop me a line to say it seems stable because now I'm now going to bed and I know I'll be dreaming of pucks flying out of the screen, causing all kinds of havoc as they break noses and glasses, chip tooth enamel, go flying out the window, damaging cars, nuns, and policemen...

Under The Rock

Woke up dreading the coming day. Not that I have anything out of the ordinary to do but the game being live makes me uneasy. I had a restless night, wondering about how it's performed. I always feel like this when something I've poured my heart into is suddenly out there. I just want to crawl under a rock and not look how my work is faring. I guess I'm not really suited to the harsh reality of internet life. I appreciate the good people enormously and it's why I do this. I feel lifted by every generous comment and email.

Good people make me feel better about the world and I know there are plenty of good people out there. I've been very blessed in my time as a blogger to have contact with many bright, encouraging, enthusiastic, and generous souls. I've also had the misfortune of attracting the scorn of a few whose vengeful ugliness really breaks my spirits. There really are too many Welsh Rottweilers in the world.

The outcome of yesterday was my releasing version 1.0.1 of the game. I'm taking an ambitious approach to my version numbers. The first 1 represents major alterations to the game. So, if I add a new big exciting feature, such as a new game mode, that number will increase to 2. The 0 will only increase when I add smaller but key features, such as new menu options or I fix some large bug. Last night I increased the last number, from a 0 to a 1 since I fixed a small but dumb mistake I'd made, positioning an important button in the space occupied by the ads. That last number represents everyday bug fixes. I expect it to get into double figures very quickly, possibly by early afternoon...

The other outcome of day 1 was my first look at my advertising stats. The numbers were higher than expected (due entirely to Tim Worstall, many thanks Tim)  but the income depressingly oval shaped. I don't understand it but I hope it will increase in the coming days and weeks. I never did this to make a fortune. It's more about achieving a goal and raising my competence as a programmer. However, I'd like to think that I'd get money for allowing people to paste their ads on my game. At the moment, if feels like I'm providing a charitable service to billionaires.

I'm honestly at a loss as to what to do next. I had a report from Barman who says that it's too difficult to throw the pucks the length of the board. I now have to go through my code very carefully, trying to figure out if I've overlooked anything that would make the throw power device dependent. The two main things that change from device to device are screen resolution and processor speed. But since neither should affect my calculations, I can't see what it could be. I could increase the power of the throws by any amount I like but I've spent weeks carefully tuning them to a point which doesn't break the game's physics. Time in computer games is not linear but discrete. A moving object doesn't have every moment of its path calculated to an almost atomic scale. Like slowing down a movie, objects leap through space. In a physics simulation, the objects also leap through space (but, theoretically, the gaps are much smaller) and if they're moving quickly, they can simply leap through other objects because the computer never examined the time-frame where the two objects would have collided. Of course, there are ways to calculate these things more carefully but it requires so much more computer power that, in the context of a simple game, it's unworkable.

However, that's my day. Solving a problem which I'm not entirely sure how to solve.

I drew some cartoons last night but they're lousy.

I'm going to hide back under my rock.

Sunday, 2 November 2014

A Cartoon About Poppies

My body just gave out last night and I slept most of the evening. I'm not feeling particularly better this morning, though there's definitely a fretful edge about me as I now worry about possible bugs in the game. As I've said previously, we live in a strange age where the consumer is God and I now feel utterly obliged to fix everything and anything that might be wrong with my code.

It's a odd place to be. On the one hand, I feel like I've come to the end of a journey of many months, when every day I've had to figure out another problem or learn to do something new and often difficult. The reality is that I'm now judged by strangers with the power of clicking on a star rating which can either destroy me or build me up. Yet I also understand that there's no way of knowing the real value of that rating. In the internet age, we're used to rating things and people sometimes rate out of sheer spite or malicious intent. We're also in throwaway age, when people try and discard with equal indifference. For me, however, all of that is plumbed directly into my central nervous system and strangers now have the power to make me feel sick and faint, buzzing or glad, miserable or elated. Never look at the reviews has always been a motto I live by. With Google, you can't avoid it. It's there, visible and unavoidable, when you need to examine the bug reports for your code.

But that's for tomorrow. For me, today , I just feel so damn happy that I wrote 10,000 lines of code which made a kind of logical sense.

All of the above was rattling around in my head, last night, when I fell asleep. When I awoke I tried to relax by drawing a cartoon. Taking the encouragement of Ben as my starting point, I thought I'd try to change my style. I can't honestly say I followed any example, though I was looking at some cartoons by Bill Stott earlier in the evening and had I realised how much I enjoy lines which aren't straight. So I tried to draw this with a deliberately unsteady hand. After a couple of less successful attempts, I began to settle into a style and I drew three cartoons in rapid succession and I was surprised that I liked the results.


Saturday, 1 November 2014

Shuffleboard King: Your New Must-Have Android Game



Well, here it is, the efforts of the past few months which I've given the catchy name: Shuffleboard King.

I'll probably regret this in the morning but I've now released my first game onto the Play Store (hopefully, it should appear here in the coming hours). I might have delayed more but I'm mentally and physically exhausted and this is a somewhat daunting moment and I just wanted out of the way so I can move on and improve the game.

What is Shuffleboard King? Well, it's the version of shuffleboard I wanted to make for myself and for my friends who regularly play shuffleboard on their tablets. The problem with current shuffleboard games is that they feel quite artificial to play. Their physics tend to feel and look quite scripted in that you throw a puck and the damn thing flies out of your hand in a perfect straight line. Even the best shuffleboard game out there feels like the computer is playing the game for you.

So, I thought I'd try to make a shuffleboard game myself and this is the result.
I'd like to say it was 'easy' but, in truth, there are many hundreds of hours of work in this and it's probably thousands of hours if I take into account the many months before I started, just to learn Unity and all the other packages I used in this game's creation.

The part I'm most proud about, I guess, is the version of Sjoelen included in the game.
I nearly released this a few weeks ago but at the last moment, I discovered Dutch Shuffle (called Sjoelen on the continent). I watched a few videos and got hooked on the gameplay. I also realised that I could add my own Sjoelen mode to Shuffleboard Kings using the code I'd already written and, an extra month of work later, I'd expanded my original three game modes to include a fourth.

Those 4 games are the traditional shuffleboard, Sjoelden (Dutch Shuffle), as well as two games of my own creation: Angleboard and Crossboard, which do pretty much as described. On Angleboard, you bounce your shuffle off a rail so you have to play around a 90 degree bend in the table . In Crossboard, you can throw your puck from one of four sides toward a target in the centre of the table.

There's a tournament mode, in which you play opponents who are increasingly difficult to beat. There's also a challenge mode in which you have to beat 50+ challenges, such as throwing the winning puck on a board already dominated by your opponent.

I know there'll be bugs, typos, and probably even the occasional glitch. Some I can't fix but are part of the Unity engine. Others, I'll work hard to eradicate in the coming months, should enough people actually play the game.

I hope you will take a chance and play the game and perhaps, if you do, you could tell me what you think in kind, even patronising, words.

Friday, 31 October 2014

Ready For The Play Store

Today might be the day. I've now played my game through from the beginning to the end so I know all the achievements are winnable. The major bugs are (hopefully) fixed, though I don't delude myself into believing that it's now completely bug free. Bug-free computer code is theoretically impossible. In fact, I'm pretty sure serious research goes into that very subject and nobody has yet established a way of ensuring that the almost infinite number of inputs going into a system will produce a finite set of predictable results. So, although the game plays okay, there's probably going to be some person who comes along and jams a thumb in a place where I never expected somebody to jam a thumb, producing some crazy results. If a company like Bungee can produce a million dollar game like Destiny, release it to the public, and then face the problems they've faced recently with people exploiting cheats to boost their statistics or, as one particularly clever soul did, discover a way of jumping up a cliff face in order to explore an area of the game that Bungee had yet to unlock, then I'm pretty sure I'm going to face a few headaches over the coming weeks as people tell me that my game throws a fit whenever they do X,Y, or Z.

The moment I stick it on the Play store, I'll be on here talking about it and no doubt boring you with videos about how I made it and things I've learned about Unity in the approximately two months (and two days) it's taken me to build it since I started coding on the 28th August.

My final jobs today are to do with the marketing. I've recorded some gameplay footage which I now have to edit into a short video to include with my Play Store listing and on the website I've built to advertise the game and provide contact details for all the complaints I expect to receive. Then I need to double check all my text for typos.

One final coding job might remain but that's based on a last minute decision I've yet to make. How much I want to annoy players to encourage them to buy the ad-free version? At the moment, I have ads at the top of the screen but I'm wondering if I should add some interstitials ads, which are the full screen ads that occasionally pop up during gameplay. I don't like them, I don't want to add them, but the game as it currently stands is perfectly playable with banner ads. In fact, it might be too playable with banner ads and banner ads are going to earn me so little that they might as well not be there. Interstitials would earn me more but, more importantly, would give people a reason for upgrading.

The alternative is to carry on coding once the free version is built. Once that's launched, I could branch off a paid-for version of the game and start adding features to it. Other game modes might make it more attractive. I don't know. Any thoughts or advice are, as always, very welcome.

 

Tuesday, 21 October 2014

Testing... Testing...

A week last Sunday, I was sitting in the Accident & Emergency room at Whiston Hospital. It was my first visit to an A&E but my sister was really unwell and we'd thought it important to have her checked out. Though that's not the reason I write this, I would like to say how amazed I was at the whole experience. We walked in to learn that waiting times were up to 5 hours. I was shocked but we sat down, feeling that we had no choice. My sister was feeling really unwell but in the waiting room, they were showing Formula One. We moved away and sat in a small room to the side. Soon after, some fool put X Factor on and the horrendous music was blaring out, making my sister feel worse. To be honest, I was feeling pretty shabby because there are few things I hate more than the X Factor. However, after about three and a half hours, we did see a young Scottish doctor who, without exaggerating, was simply amazing. My faith is the NHS was (partially) restored that day and my sympathy for A&E staff went up enormously after seeing people arrive with a wide variety of conditions. Most, I'd harbour to guess, could have been sorted by their local GP. There seems to be far too many people holding a thumb (no visible damage) or limping on mildly twisted ankles. However, I'm the wrong kind of doctor to diagnose such things but it didn't surprise me that A&E is struggling when there's such a disparity between those who looked really ill (and I notice most of those were admitted) and those that were given a painkiller and politely shown the door.

The reason I mention this: we'd been sat down for about half an hour when a young boy came and sat in the seat opposite. He was with his father and was busy playing on his iPad. I glanced casually at he game he was playing and felt my stomach sink as I realised he was playing a version of my game. A *much* better version of my game. Well, I say much better but only because it looked glitzy. It didn't seem to have good gameplay or much skill but it was definitely the product of a team of programmers/sound engineers/graphic artists. It put into context the mediocrity of my own achievement.

Yet when I look back on the past few months of constant distractions, I'm amazed that I've managed to finish a project. I'm now in the process of getting every small wrinkle worked out ahead of my publishing 'the game' on the Google Play store. It's miserable work. The beginning is always the enjoyable part of any project, whether it's writing a blog, a book, drawing a cartoon or comic, or writing an app or computer game. Writing new code is wonderfully exhilarating as you shape the hardware to do what you want. You face problems along the way but nothing beats that moment that all the problems fall away and you have a result that's pleasing to you.

At the other end of the project, life becomes a bit of a toil. You simply think that nothing you've done is worthwhile. You get hung up on small things which are often beyond your power to fix. For example, my game occasionally displays a glitch caused by the physics engine. I've done everything in my power to fix it but I know that there will be rare cases when the glitch will happen. I hate settling for 'the best I can do' but, really, I know this is the best I can do without actually writing a new physics engine to suit my purposes. Even if that were within my powers, it wouldn't be worth the months of work.

So, instead, I'm constantly playing my game. A friend asked me the other day what I was doing. I said I was debugging. Then they saw I was playing a game. 'Oh, is that what programmers mean whey they say they're mean by debugging? Are they actually playing games all day?'

In a way, I suppose they're right but it's not really 'play'. There's no fun in sitting here trying to break a game or making it glitch because I'm deliberately playing it the wrong way. And the more I do sit here testing it, the more I despise so many little things about it. They might be things I come back and fix if I release an update. I suppose it will depend on the number of people who play it and if anybody actually gives me any positive feedback. This is my second proper game I've finished but the first I'll actually publish. As I sit here writing this, I find myself wishing it out of the door and gone. I want to do something new and interesting. It's been two long hard months and I want to do something that will stretch me again.

 

***

Apropos of nothing: I recently launched a new blog. Not that I'm advertising it here. It was one of my stupid ideas to which I wouldn't want to attach my name. It was something to do whilst I was coding and since it took very little time to create it, I had fun. It amused me. Until, that is, I thought I should try to attract readers. The blog has been live three weeks and so far it has had zero visitors. The Googlebot has dropped by a few times and my pages are indexed on Google. But real visitors: none. I suppose I should be disappointed but I'm just resigned to the fact that Google is no longer really relevant. Unless my blog gets picked up and passed around via Facebook or Twitter (and I really cannot be arsed getting 'social'), it might as well not exist. Such is the way of the world which moves on towards the next big thing quickly and without compassion. Like Facebook was usurped by Twitter, and Youtube was suddenly the old folk's version of Vine, blogging is already a thing of the distant past. As relevant today as poetry, novels, and film in cameras.

 

Friday, 10 October 2014

So, I've Finished Building My Second Game

It began weeks ago with a moment of idle distraction.

If you read this blog, you might remember that I'd been playing around with Unity, building my procedural city and generally trying to be too ambitious. I had an idea that wasn't working or, if it was working, it was simply too big. These months of self-educating myself in the world of Unity had led me to realise that the difference between good and bad game design isn't a matter of coming up with 'content'. There are terrible games which have almost unlimited content (think any failed RPG) and then there are great games that have almost no content at all (think Minecraft). Of course, there are games which combine the two. I recently finished playing 'The Last of Us', which has a really strong game mechanic tied to the best world-building I think I've seen in a video game. The new 'Alien Isolation', by comparison, brilliantly realises the world of the first Alien movie, though the game mechanic is somewhat mundane. I guess it's why I'm so interested in Indie games, where the limitations of small teams mean that more effort is placed in game design. I guess it's something of Peter Molyneux's forte and why I always have enjoy listening to listen to him get enthusiastic about his next project, even when he sometimes over promises and under delivers, which as the tree he promised we'd be able to plant and watch grow in the original Fable...

In computer games, content is not always king and the fact was made more obvious when I recently spent a weekend watching all the presentations at the EGX in London. It wasn't 'Dragon Age', 'The Witcher' or even 'Alien Isolation' that excited me. It was seeing an early version of a small independent game called 'Heat Signature'. I think what excited me the most was that this was a  game entirely built around a quite novel mechanic. It reinforced something I'd already realised about big game companies who equate next-generation gaming with their making their vast object database available in different guises. These mega budget game titles appear to be little more than a chance to wander through a huge repository of virtual mugs, cars, dustbins, street lights, barricades, walls, fraying sofas, industrial pipe work... Change a flag and recompile the code and Assassin's Creed becomes Watchdogs becomes the next Call of Duty.

But I digress...

So, I was tired of my ambition, the hours I was putting into something I hadn't probably thought through. I'd launched into creating something without actually thinking about the game design. I was doing something that I recognised in so many people who inhabit the Unity forums. They usually introduce themselves with a post that follows the same format:
Hi guys. I'm just starting out on creating my own game in Unity and I wonder how I'd go about creating a massive MMORPG.

An MMORPG, should you not be entirely immersed in this world, is a Massively Multiplayer Online Role-Playing Game. It's something I constantly notice as I read the Unity forums. So many people with very little programming experience wants to build the next Warcraft, which was built by a team of hundreds, each one an expert in their field.

What annoyed me was that I realised that I'd been making the same mistake. My procedural city looked okay but there was no real gameplay and, even if there was, there was no way I could fill that city myself. I was also generally tired and wanted to do something different. So I decided I'd spend an afternoon playing around with something new. I wanted to do something that wasn't ambitious and I'd be able to finish in a day, maybe two. I wasn't going to create anything that hadn't been seem before but I just wanted to create something small and playable.

So, I started making a really simple game; so simple, in fact, that anybody could play it. So simple, in fact, that I'd already played it a hundred times in different guises. However, none of the games I'd played were quite right so I thought I'd make my own version...

After a day, I had a prototype working and I thought it was finished. However, the next day, I stupidly carried on working on few hundred lines of code and my labours continued for a third and then a fourth day. Soon I'd been working on it for a week and I was thinking of new ways to tweak it. A week became two weeks but the game had become a bit of a prop. Life has been complicated because there had been countless visits with my sister to see a range of consultants or have various tests and scans... My small game project was perfect, since I could just code a little in between all the trips and distractions.

I started working on this game on the 28th August and today it's the 11th October. It's 1.31AM and, except for some writing and some final testing, the game is finished. It has okay graphics, mostly culled from drawings I did sitting in hospital waiting rooms. I even wrote a little title music, which doesn't sound too bad on the ear, mainly thanks to some amp effects I used on my old batter Fender.  It looks quite good, played quite well, and has a few things that make it unique in the marketplace. I'm quietly pleased with it because it's really nothing different. It feels right in the middle of the mainstream, not at all like my books (all of which were clearly too left of centre to find a mass audience).

I'm now going to spend a couple of days trying to beat the game's levels and each one of its 50+ challenges. If I can do that and find it reasonably challenging, I'll publish it to the Google Store. If it gets downloaded 100 time (my ambitions are very humble), I'll begin to work on a version for Apple iOS, not least because I want to know how to do that.

Of course, there's a lot of work still to do. I've registered a domain for the game, hoping to give the operation a slightly more professional look than the reality of me sitting here, night after night, working to iron out bugs from the mere 7500 lines of code. I still need to build a website. I have to think about a price for the game or if I'm even going to charge. I've integrated Google ads into the game but I probably need to think of ways to make people want to upgrade from the free version, which isn't in my nature since I want to give everything away for free. I always want to go back and fix a local multiplayer element which I thought I had working until I discovered the frightening fact that computers are often non-deterministic and code does not always execute exactly the same way across a network of machines.

However, at this stage, I feel like I've accomplished something and I've only accomplished it because I inadvertently started out small and I've kept my ambitions limited. I think I've learned a valuable lesson. My next game, should there be another, will have a simple game mechanic and I won't write a single line of code until I've figure out what that mechanic will be.

In the meantime, I'm off to play my game which is satisfyingly easy to play but annoyingly hard to master.

Wednesday, 10 September 2014

Two Types of Unity

Unity. Unity. Unity...

Seems ironic that I've been thinking about Unity so much recently without actually giving much thought to the unity of the country, currently threatened by the incompetence of naive wasters in Westminster who gave the Scottish independence movement enough advantages to turn what should have been a straightforward referendum producing a resolute 'NO' into a full blown political crisis lest they decide 'YES'.

Not that I'm unsympathetic to the nationalist cause. It's hard to argue in favour of the status quo when the status quo is as unfashionable as the real Status Quo. I understand why some people's wish to break the Union. Living here in the north of England is (arguably) worse than living in Scotland. It sometimes feels like we're sitting in the middle ground, as political debate flies over our heads. Westminster does actually listen to Scotland whilst ignoring the rest of the country.

Yet clearly something does need to be done to change a situation in which, for example, arts funding for London is £21.90 per head, whilst here in the North West, our arts are funded to the value of £5.06 per head (2012/13 figures). I've joked in the past about Sky News and their paper reviews but, when so many in the media talk about representation, nobody seems to notice how the news agenda is often directed (and commented upon) by small coteries of people who all sound the same. Simply too much of our national identity is tied into a London identity. Being British is too often seen as being a Londoner, in the same way, I suppose, those of us who live close to the Mersey are assumed to be Scouse, instead of being part of the surrounding areas, such as Lancashire, Cheshire, Manchester, or even Wales.

I should imagine that many of us have some Scottish blood. My own grandmother was Scottish. Yet even if there isn't a blood tie, Scotland has given us so much of what we should collectively feel proud. It's hard to pick apart our country without cutting deep into ancestral flesh. Many of my favourite writers are Scottish, so I suppose my thought processes are deeply influenced by that culture. Are we suddenly meant to feel less proud of Andy Murray or Sean Connery because they're suddenly from foreign soil? None of this makes sense. We're being led into an unnecessary quagmire by people making decisions that might last centuries based on fads, cults of personality, and acts of sheer bloody-mindedness.

I genuinely think it will be disastrous for Scotland to vote yes but it's especially sad to see people voting for their own ruin simply because Alex Salmond has managed to turn this debate into a chance to give Tories a bloody nose. It seems as dumb (or perhaps even as profound) as the reason one guy gave for voting 'no' on Newsnight  last night, which was he didn't want to lose 'Match of the Day'.

Simply put, so much of our identity is tied up with the Union that I hate to think of this country divided after centuries of productive harmony. There'll be no more chances to wave the 'red, white, and blue' once we've stripped the blue from our flags.

 

newunionjack

***

Meanwhile, Unity in PC land still means that I'm teaching myself more C#.

About a week ago, I thought it would be a cheerful thing to quickly create a simple game I could play with a friend. It started out as a joke, a minor distraction from my procedural city project which had been exhausting me. Last week was also dominated by long days travelling with my sister so she could see consultants, so I wasn't going to get much concentrated time at my PC.

Now that simple game is almost finished, I've run up against a huge problem.

I wrote the game because I wanted to do something involving multiplayer, which means I had to learn how to get machines talking to each other over the network. That's relatively easy to do in Unity and it took only an hour before my PC was moving objects around on my Android tablet via Wi-Fi.

Without going into too much detail, the game is a very simple game not entirely unlike snooker, moving objects using Unity's physics engine. It looked pretty good until I noticed that the game's progress being played out on one machine gradually began to look quite different to the game's state as seen on the other machine.

It was then that I began to understand the non-deterministic nature of modern computers.

It's probably dumb of me not to realise this earlier but I've never done network coding before. I would assume (not so much naively but idealistically) that one set of input fed into code running on one machine would produce exactly the same result as the same input fed into the very same come running on a different machine. Common sense dictates that it would be true. 1 plus 1 always equals 2...

Except, that isn't always entirely true.

One of the bigger bugs I struggled with a few months ago (unrelated to networks but simple maths) involved a problem I saw with floating point numbers. Some numbers were getting calculated wrong for no obvious reason.

The reason had to do with floating point errors. Some numbers are impossible to accurately store insider a computer's memory. Numbers which have extremely long (or sometimes infinitely long) mantissa (the fractional part after the decimal point) cannot be stored given the finite number of bits available. Irrational numbers, for example, can't even be stored as a ratio. The value of Pi is often written as 22/7 but that's an approximation, and it's certainly impossible to write the entire value since it (probably) goes on forever. One of my favourite parts of science fiction occurs in Carl Sagan's novel, Contact, where Pi is calculated to such a length that they reach a point where our original creators had hidden a message.

But I digress.

Because floating maths require some degree of approximation, different processors (and, by extension, difference compilers that create the machine code ready by processors) have different ways of approximating those numbers.

Usually, we don't notice this but when a physics engine starts to do thousands of calculations, those small fluctuations begin to produce big differences. So, for example, the way my PC calculates the friction of an object moving across a surface might produce a different velocity than that calculated by my Android tablet's processor running the very same code. The values differ by very small amounts but it's enough to make large changes. I suppose it's the old simile of the butterfly flapping its wings in New York and producing a storm in Tokyo. My PC might show a ball rolling into a pocket whereas on the Android it just clips the edge and fails to roll in. Since the game is multiplayer and both players are meant to be playing the same game in the same virtual space, this causes big problems.

So, this is where I am today, with a nearly functioning game that I'll have to re-engineer to ensure that only one machine does the calculations whilst the other produces movements in all the game objects based on a hell of a load of numbers I'll have to send over the network.

I suppose, if I had time, I might explain how this is all an apt metaphor for the problems of devolution, nationalism, and our Westminster elite. However, I hope that my floating point errors will be much easier to fix.

Monday, 28 July 2014

Beginning A Procedural City in Unity



The title pretty much sums up the point of this post, though it doesn't really explain why I'm posting it. I suppose I retain a sense of wanting to be a good guy in a world that is increasingly choked by the smoke of the pillaging hordes and rampant whores. My blog - this blog - is daily swamped by a deluge of spam and unwanted emails from web marketers who would destroy it and everything I create in the search for the last grimy penny. I now rarely check my emails, not that many people email. All accounts bar the one I keep private for friends and family have become inundated with the electronic effluent of a thousand installations of MailChimp, which must surely rank alongside the Channel 5 and landmines as one of the world's most terrible inventions.

It's the way of the world, I suppose. This is a world run by men and women who would shoot down airliners full of people to make some baseless political point or lob missiles across borders simply to further their warped ideology.

My last week was somehow symbolised by a woman I saw walking across our local down square. She had a large tattoo of Audrey Hepburn on the back of her calf. Had Audrey Hepburn been alive today, she might have approved. I don't know. It's not that I dislike tattoos because I like rebellion and I identify strongly with outsider culture. But their ubiquity has ruined that. It just sometimes feels like I possess the last untattooed flesh in town, which makes me the outsider and that's sometimes a lonely place to be. I find myself living for the next PJ Harvey album, news of Spark's next tour, or an utterance from Stewart Lee.

I ramble but I've not written prose in so long. They're ideas I'd like to address in the game I'm currently building but I don't suppose I will. I'm aiming to cast current 'big idea' at the heart of the mainstream. I'm about a month or so into the project and I have the basics of the game in place. This video details just the last two days of hard work, learning to create a procedural city in Unity. It probably won't entertain or seem remotely interesting to anybody but this is the stuff that excites me as I walk around my town, inhaling the 'vape' of electronic and real cigarettes, amid the boorish bald circus strongmen, with their tribal tattoos vining their way up their veining necks. Yes, my thinking is reductive and I reach easily for the stereotype. But from killers to politicians, this is a time of stereotypes and very little originality. It's a world that makes shiteaters of us all.

Monday, 2 June 2014

Thinking Alpha

My intention this week (yes, I know it won’t happen) is to have a build of the game ready to give friends and family to play and report back any bugs / ideas / impossible to complete levels. I also hope to get access to a Mac to see if I can build a version to test on iPads and iPhones, though that’s less important given that I can’t see myself spending the £100 to buy an Apple developer’s license anytime in the near future. However, I’ve discovered that there’s a way for developers to send apps over the web to Apple devices, which will at least allow me to see how the game works in that alien environment.

Today I have two jobs. The first is to throw myself into writing the game text. I’ve (somewhat foolishly) created a game with plenty of places to insert funny stuff. The only point of the game is to make the player laugh and so there are dozens of arrays to fill with as many witty one-liners as I can fashion. They’ll get served dynamically as you play the game, hopefully meaning that it shouldn’t get too stale too quickly.

The second job is to get the app’s size down. Last night it stood at a whopping 47mb, which was worryingly close to the Google’s stores 50mb limit. It’s a problem of textures. Many of graphics are still the size they came of my Samsung tablet, which is where I’ve drawn everything for the game. A megabyte for a pair of underpants definitely seems like overkill. I’ve started to tinker with the texture settings within Unity, brining many of the textures that were 2048x2048 to 1024x1024, those that were 1024 down to 512, and taking icons down much further. I can barely see a quality difference on the screen and the app is already down to about 33mb.

My biggest breakthrough of the weekend was to get my game objects flipping across the x-axis. I’d read last week’s Unity changelog and noticed they had claimed to have fixed the bug which broke the physics engine when scaling negatively. However, when I sat down and tested this claim, scaling the objects by -1 on x, any physics attached to the objects immediately failed. I either had characters looking one way but their bodies acting as though they were facing the other or I had characters falling in a heap of body parts on the floor. Clearly, the Unity bug hasn’t been fixed.

After a little work, I realised that the problem seemed linked to having objects in a hierarchy. If, for example, I had a human figure with arms and legs and I created the usual hierarchy of hand attached to lower arm, lower arm to upper arm, upper arm to torso, etc, then the physics would fail when scaled by -1. However, removed from the hierarchy, they would work.

My solution was to recalculate the object’s physics settings and apply them on the fly as objects changed direction. Since the problem only occurs when objects moved out of the kinematic state (that is, went from being unaffected by the game’s physics engine to having all forced acting upon it) I would also only keep them in the hierarchy when the object is kinematic and then dynamically flatten the structure when I needed them to work under physics.

Christ, all of this must sound so very boring. Is there anything duller than tech talk to anybody other than a very smaller number of people who enjoying reading tech talk? Is it a sad confession to say that I actually visit the Unity forums just to read about this stuff?

Okay. I have writing to do including as many insulting put-downs as I can manage for my ‘failure’ screen.

Saturday, 31 May 2014

Rain! Beautiful Virtual Rain...

Two dull programming-related blog updates within two days? What am I thinking? Does anybody read this stuff?

But I guess I’m excited because it’s raining. In my game, I mean.

I keep saying it’s all about the small details but I genuinely think it’s half the battle. Being able to add little touches without impacting too severely on the performance is one of the ways that Unity never fails to amaze me. When I set out programming this game, I assumed that my lazy techniques would soon punish the game’s performance. I’m not by training an Object Orientated programmer, so it’s taking time for me to come around to not writing things in a very linear fashion. I’m also writing this game for tablets and (I hope) mobile phones, which means I haven’t got huge resources to play with. Each time I add a feature, I think the frame rate will be impacted hugely.

Last night I added rain. Unity barely flinched.

[Sidenote: the way I added rain was to create a long sprite, fading towards the upper end, a slight tear on the other. I then display about 20 or 30 of them (random intervals and timings on each) inside the camera bounds (don’t waste precious CPU cycles drawing rain you can’t see), and then I move them down as I very quickly stretch them. I also apply a gradual fade by adjusting the alpha values. Add a random angle of slant and with the right timing, they look just like rain. I keep reusing the same GameObjects to save time, repositioning/re-angling/retiming the line of rain as soon as it has faded from view. I also animated a few drops of rain splashing on the ground which I also randomly display. ]

game1

The effect isn’t bad, as I hope you can see from this deliberately empty and uninspiring shot of my game. And, yes, it’s mainly in black and white but it does have splashes of colour. The lack of objects on the screen accounts for the framerate nearly hitting 70fps, as you can see in the top left corner. I added that frame rate display to show me the average performance and the numbers are surprising. On the PC, the framerate is effectively about 450 frames a second (though, of course, my screen doesn’t update that quickly). It means that the code could update the screen over four hundred times per second if called upon. In reality, 30 frames a second is what most games run at. Some of the newer games run at 60 frames a second, which is something of a gold standard for 3D games, and accounts for much of the current bickering between XBone and PS4 owners.

My game is 2D so it’s not quite so impressive to be hitting around 60fps on my tablet but that’s (apparently) it what it’s doing. It drops a little on my phone to somewhere in the 40-50fps but that hopefully means that I’m in a sweet spot given that my phone is neither the most recent nor the powerful. The more people can play this game, the more my efforts are worth it.

Today it’s about fixing more bugs, adding more content which I drew last night, playing and replaying each level to see if it feels right. I’m thinking about ripping out all the music since I also need to start to reduce the final size of the final app. It’s compiling into a 45mb package, which is just under the Play Store’s limit of 50mb (I believe you can go much higher but it involves breaking the app into different resource files, which is something I don’t want to do). 45mb seems far too big for this game, even if it is packed with hand draw graphics which don’t lend themselves to tight compression. The main problem seems to be five or six very large graphic files, which I’ll need to reduce in quality. Hopefully there’ll be no obvious visual impact on the game.

Hmm… I push on.

Monday, 19 May 2014

The Angel of High Satire

I seem to spend my life between identities.

What do I mean by that beyond trying to sound profound? I suppose I mean: I don’t know what I am. So many people seem to define themselves by their jobs or their religion or their marital status and number of children. I don’t really have any identity in those respects. I don’t think of myself as ‘a writer’ and even when I had a book in bookshops, to say ‘I’m a writer’ felt hollow and not entirely truthful. I never say 'I’m a cartoonist’ because I haven’t had any cartoons published and I refuse to spend the rest of my life being Private Eye’s least successful would-be cartoonist. I’m not an illustrator, though I occasionally provide people with illustrations. I’m not a web designer though I sometimes build websites. Nor am I an animator, though I’ve made a few animated shorts. I can’t even say that I’m an academic because my PhD never led me into any academic post of significance. Now that I’m programming again, I am reluctant to call myself a programmer because the programming is only serving an end as far as another of my non-descriptors, that is, the cartoonist part of me.

cherubI’ve spent two months (or is it now three?), building a game which is little more than a very large satirical sketch or (more accurately) oafish cartoon. It's taken as much efforts drawing the graphics as it has programming the code. I’m part proud of it as I am part ashamed of it. The whole thing is meant to be satire, which is why, over the weekend, I added the following character to the game. At the moment, he flies onto the screen at random moments to add a little difficulty (and some reward) to the challenges. Yet I suppose my ‘Angel of High Satire’ (is the minuscule penis too much?) is a way of my
acknowledging that everything I do is really directed towards satire. I suppose I might call myself ‘a devil of low satire’ because I think it’s always been the closest description I would recognise of myself had I actually achieved anything of note in that field.

I don’t think my game will change that, though I hope it will have a enough edge that people might share it and laugh for all of the few moments they play it before deleting it forever. The humour might not be up to quality demanded by the real High Angel of Satire, on whom I modeled my version, but it has amused me. And that’s the problem. My worry now is that the game contains too many of the things that amuse me such as the thought of a naked Ian Hislop providing the game's hardest challenge. I wish I could have created something playable by somebody other than that person I see in the mirror. Next time, perhaps.

Unity2D: Creating An Explosion Effect



A quick video I put together to show my workaround for the missing AddExplosionForce2D in the Unity engine. It’s probably of interest to nobody out there but it gives a good idea of how Unity works and the very basics of making things move around on the screen.

Saturday, 17 May 2014

Small Details

Writing this feels like I’m coming up for air.

I read an article somewhere the other day which suggested that it takes six months to develop even the simplest game. I’m not entirely sure that can be correct, but, perhaps taken as an average, it’s probably much closer to the truth than the fabled ‘couple of days’ it took the Flappy Bird genius to weave his magic.

At the other end of the genius scale where things don’t come easily and everything is a struggle, it only feels like I get closer to the end as I tick off the increasingly mundane tasks that dominate my ‘To Do ‘list. Beyond that, I spend most of my time fixing bugs and populating my levels with graphics. My problem goes back to the beginning when I didn’t so much design the game as start to play with Unity and a game gradually began to emerge. My game levels are potentially huge, though there are limitations which means not every square inch needs to be populated with landscape. I’m naturally reusing assets all the time but I need to break that up with unique graphics, which is where most of my efforts are not deployed.

The bug fixing takes the longest. A bug earlier in the week took two days to figure out but taught me an important lesson about the difference between Unity’s Awake() and Start() methods. Compared to that, coding new features is an absolute pleasure that rarely takes a very long.

The exception to that rule was the problem I faced creating explosions in my game. Having explosions came pretty late in the process and I thought it would be an easy thing to add. Unity has an AddExplosiveForce method  which you can add to game objects so they act as a bomb, pushing other objects away. However, Unity separates its 3D functionality from the 2D in an obvious way. If a method is designed for 2D games, it will have ‘2D’ appended to the end of the name. So, for example, there’s a RigidBody component, which makes a 3D game object respond to gravity and forces. There’s also a RigidBody2D component with does the same for 2D objects. AddExplosiveForce adds an explosive force to a 3D object and, as you’d guess, AddExplosiveForce2D would do the same for 2D objects.

Except Unity doesn’t currently have AddExplosiveForce2D which meant I had to write my own. It took a day but I solved the problem and my explosions are now working well, with sticks of dynamite even destroying other objects with a nice blast that radiates out. However, it’s an example of how I’m spending my days implementing features which are only a very small fraction of the finished game.

Not everything takes so long. I’d been putting off adding more online leaderboards to the game but I finished that just now, perhaps half an hour’s work to add 30 leaderboards, one for each level I’m currently planning to include in the finished game. I also finished adding the majority of my ‘achievements’ and they now stand around the fifty mark which means I’ll have to spend extra time checking that every one of them works, which means yet another game reset so I can play through it and unlock the achievements myself.

Even at this relatively late stage in the process, I’m learning new things. The surprising thing I’ve recently discovering is that it can be really small things that make a difference. Attention to detail is important. Just as a whim, I added a very small detail to the game about three days ago and it has completely changed the game’s dynamic for the better. It was an addition I made simply to add a little variety to the gameplay but it completely changed the way the game feels. The same is true of sound effects. I still have a few sound effects that don’t fit but those that do really make a difference.

In a way, I suppose all of this is my way of saying that ‘things are coming together’. As it stands, the game is pretty much finished in terms of the gameplay (though I constantly worry that there are times when the player doesn’t have enough to do). I have quite a bit of level design to complete, but that simply comes down to my finding the time to draw custom graphics for the different challenges. On top of that, there are things to write and I have to create some tutorial mode or, at the very least, provide instructions on how to play the game.

Then my final step will be to add some advertising, which I’ll do simply in the vague hope that it might earn me a few bob when others try this game. I don’t expect it to hang around on people’s smartphones and tablets for very long but I’d like to maximise whatever revenue I can generate. All this work should have a point and, I admit, at the moment, I fail to see what that point could be beyond my own amusement.