Monday, 8 July 2013

Dynamic/Static typing, a single observation

It is fair to say I have written more lines of code in statically typed rather than dynamically type ones.

This is in part due to my day job and also having written a fair amount of Java in my spare time. It is also fair to say I have written a reasonable amount of code in dynamically typed languages. Primarily in CoffeeScript and Python with some JavaScript and other less popular languages (read as Lisp).

At home I tend to flip between the two every six months or so and dream of a languages the lets me add type information when I start to need it. That is as the code base grow bigger.

Well bigger is a bit of a subjective word. With my most recent return to dynamically typed languages I have observed that the definition of bigger can be put of by being really intolerant to bad or messy code. Constantly asking myself things like "is this a simple as can be?" or "can I improve this code?" and then acting on it really helps.

Statically typed languages lets you get a way with a little bit more, because the compiler can capture some of the errors for you and the better IDE tools let you manage it better.

I would say coding in a dynamically typed language helps my statically typed programming just because it reminds to to focus on simplicity, not adding complexity if not needed and on having an interface that can be guessed (consistency is very important here).

I am currently taking a look at Typescript, it adds a statically typed layer to JavaScript. You don't have to use the typing a the start meaning you can start to add types when you need to. Well it adds a whole lot more like classes and modules but the statically type part is the attractive bit.


Tuesday, 28 May 2013

Simple Event Manager In CoffeeScript

Over the past few days I have been messing with CoffeeScript and web stuff. It is really just for fun to get myself back into programming at home after nearly a month off. Bashing together some parts of  a simple 2D game platform in CoffeeScript sure is fun.

Today I wrote a simple EventSystem where you can add/remove listeners and fire/dispatch events. It is not complicated. The contrast between the code here and what you would have to do in say Java is pretty striking. Each language has it's own trade offs and CoffeeScript (read as dynamic languages) shines quite well here.

class EventManager
  constructor:() ->
    @listeners = {}

  fire:(name, data)->
    console.log 'firing'
    for lis in @listeners[name]
      lis(data)
    this

  dispatch:(name, data) -> fire(name, data)

  add:(name, listener) ->
    if name of @listeners
      @listeners[name].push(listener)
    else
      @listeners[name] = [listener]
    this

  remove:(listener)->
    for name,lis of @listeners
      idx = lis.indexOf(listener)
      if idx != -1
        lis.splice(idx, 1)

  removeAll:() ->
    @listeners = {}

This use case is pretty much this

$ ->
  em = new EventManager()

  listener = (d)->
    console.log "event lis", d

  em.add "test", listener
  em.fire('test', 100)
  em.remove listener
  em.fire('test', 'this should not be printed')


I appreciate I could remove a lot more brackets in my code shown. I am still dabbling with how many brackets I like to see in my code. Sometimes having them there makes it feel more readable to my tried brain. Years of coding C/C++/Java take their toll.

Friday, 24 May 2013

Pixel Perfect Hit Testing.

One of the fun things I have been messing with this month is CoffeeScript and the HTML5 canvas element. I regularly return to these two topics.

I took a bit of a look around at some of the gaming/rendering libraries but then realized the urge I had was to actually knock one together. Perhaps using some open source for things like tweening.

Anyway I was quite impressed with easelJS part of the createJS collection of tools for interactive graphics. If I was not just messing with code and had something I wanted to achieve I would use it.

However I have been looking through the code just to learn some of the ideas they use and one fun one stands out.

It is for pixel perfect hit testing they use for shapes they are going to render. The idea is to test whether the mouse pointer is over a shape or not.

It works for both bitmap shapes and vector based images. I like they way they solved the problem mostly because it is really simple.

The create an internal canvas that is 1 pixel by 1 pixel. Then if you want to hit test at position x,y then simply draw the graphic to this canvas but with a translation set to -x,-y in the context. Finally read single pixel on the canvas. If that pixel has color then the position x,y overlaps the shape otherwise it does not.

You need to be clear about using world or local co-ordinates and remember to clear out the pixel when you are done.

Obviously is does not handle collision between arbitrary shapes bit it is such a simple idea and not one I had thought of doing myself. I really like reading code that lets me learn new idea even if they are really obvious once you have come across them.

Tuesday, 14 May 2013

A shell/dos style input in HTML


A return to text input.

It could be said I have had a little bit of a hobby in attempting to get a satisfying command line input for text entry for a html page. This is probably quite simple for some one with more html/css/jquery skills than me.

The history of this is at some point in the past I wanted to create a very simple web based text adventure. Just for fun. I think I spent more time working on the text input than I did on any other component.

I think I have arrived at a fairly minimal solution that works on Firefox, chrome and IE9 (and probably above). It is very simple and that make me happy.

Ok lets loot at the html code for it

<!doctype html>
<html>
  <head>
    <script src='jquery-2.0.0.min.js' ></script>
    <script src='main.js' ></script>
    <style>
      .main-area {
        width:25em;
        height:500px;
        background-color:#333;
        color:#ccc;
        margin: auto;
        overflow-y:hidden;

      }
      .main-area .line {
        margin-left:1em;
      }
      .main-area .input {
        margin-left:0.3em;
        margin-bottom:0.1em;
      }
      .main-area .input div {
        display:inline;
      }
      .main-area .input .prompt {
        width:1em;
      }
      .main-area .input input {
        background-color:#333;
        color:#ccc;
        border:none;
        width:24em;
      }
    </style>
  </head>
  <body>
    <div class='main-area'>
      <div class='input' > <div class='prompt'>&gt</div> <div class='input-area'><input type=text></input></div> </div>
    </div>    
  </body>
</html>

I am using JQuery 2, you can probably use an earlier version but I have not tested it.

In a real application you tend to not inline your css but I was just playing so found it easier. Most of the css is just setting up some colors and nice margins along with getting stuff centered on the page.

The actual html just specifies a main-area where the text will be output and inside that the input area, the bit where you type.

The input area just has a > symbol to hint this is where you type and a text input box.

We power this very simple html code using Coffeescript. Here it is.

# Coffee file

# Handles user input
class TextInput
  constructor: (@callback) ->
    @input = $('.main-area .input input')
    @focus()
    scrollToBottom()
    @input.keydown (evt) =>
      if evt.keyCode == 13 #return pressed
        callback @input.val()
        @input.val("")

  focus: () ->
    @input.focus()

scrollToBottom = () ->
  $(".main-area").animate({ scrollTop: $('.main-area')[0].scrollHeight}, 1000)

$ ->
  echo = (enteredText) ->
    output = "
You typed: #{enteredText}
" $('.main-area .input').before output scrollToBottom() input = new TextInput(echo) # Refocus if user click on play area. $('.main-area').click () => input.focus()


About 30 lines including comments. The TextInput class monitors your keystrokes on the input line and calls a callback when you press return. My example callback just adds a line the text output and triggers a scroll to the bottom of the dislay area. This is important to keep the text input line shown.

Finally whenever the user clicks in the main-area the text input gets focus. This makes it look more like a single window like a shell/dos prompt and is handled in the last two lines of code.

I quite like this solution mostly because it is very simple and I really like simple. It does keep on adding elements into the main-area div tag so if you spent all week typing away in it it would use a lot of memory. Remove the first div tag  contain a line when you add a new line if you have say over 200 of them is pretty simple.

There are no scroll bars and that may be a show killer. I am pretty sure something like iscroll would sort you out here.

Finally some people prefer to keep the text input at the bottom of the main-area. I kind of like it moving down the screen as it fills with input but my views change from week to week.

Hopefully you might find this useful.

Friday, 3 May 2013

What Next For May



The other day I released my fourth game on android under the banner of voyaging mind. I am actually pretty happy with this. At the beginning of the year I decided my main goal of the year was to push my game dev skills a little bit. Since then 3 little games have been produced.

Ok, none have been met with any success from the metric of people actually playing them but they have push my knowledge of LibGdx and let me explore Entity/Component orientated programming. All good fun if you are a programmer type like me.

So what next, well I could continue to pump out small games for the rest of the year. I have plenty of ideas.  I want to push my game dev skills this year and pumping out small games usually means I focus on the code. To become a better game developer I need to push my other skills as well. The major one I am lacking in is my art skills, it is not easy to make progress in the practice of art while at the same time producing a game, so for the next few weeks I am going to attempt to draw as much as possible. If possible everyday but I know some days this will just not happen.

Whenever I have taken the effort to practice drawing I improve, it is just I am starting at such a low skill level it will take many hours of practice to get anywhere descent. While the initial plan is to just use pencil and paper I have a slight urge to do some 3D modelling probably using blender. I am realistic about this and don't expect to get good with just a few weeks practice but any improvement helps - right!

This argument to improve my art skills is also motivated by a quote from Einstein (I think) "Insanity is doing the same things again and again and expecting different results". If I keep on churning out small games at the current polished level then I should not expect things to change. So onto drawing as my primary purpose for a while.

There are some distractions. I have a book on natural language processing book that I want to devour and the voyaging mind website certainly needs a bit of an update.

Wednesday, 1 May 2013

Percy Grower Released.


Well I have finally finished another game. Yes it is pretty simple and I have low expectations on download numbers. Still it has been fun to produce and I got to grips with more of LibGdx.

I don't yet have a link to it as I have only just published it and it can take a some time for it to go active on the play store. It should turn up here at some point.

The idea of the game is for you to navigate Percy and escape the maze. Spiky things are out to stop you.

Well this is my fourth game using libgdx and I am starting to feel like I know the system quite well now. While all of it is not resident in my head I have used it enough that learning new bits of it don't take too long.

The small Entity/Component based system I have built on top seems to be standing up to my simple usage and makes adding new stuff really easy. It would be fascinating to see how it held up to larger projects. Being implemented in Java means it is not quite as sweet as one written in a dynamic language like JavaScript but it is still pretty nice to use.

Next up is a couple of days planing to decide what to do next.  

Thursday, 28 February 2013

End Feb 2013 Update



Just in time for the end of the month I published the little chain reaction game I had been working on. It is not exactly the best work I have done. The aim was to get my brain back into libgdx which it has done.

I am not expert yet!

While I was in publish APK mood I also took the advertising off of Onions Vs Wheelies. The game has not exactly been downloaded many times so I figure why should i let it interfere with the game play.

I have also taken the same approach with my latest game, aptly named Circle Explosion by the way, the popularity of these simple games just does not warrant adding adverts to them.

In fact I am starting to think ads are not great when it comes to games on android, a better approach would be to do an in app purchase to unlock the whole game.

There is not much else to report really. February has not been the most productive when it comes to code. I am looking forward to picking up some momentum in march.

The fun thing is I am probably going to start training for a marathon this week making march quite a busy month.

Tuesday, 19 February 2013

Mid Feb '13 Update


Yep, it is another one of those rambling posts about what is going on in my programming life.

First up I decided to flip to a different simpler game. Why well not having used libgdx for a while I thought it would be nice to do something simpler to get a feel for it again  I am now working on a simple "chain reaction" game. Yep it is another clone :)

If I am being totally honest there is another reason for flipping. The game I was designing would be a lot easier to make if the Tiled support in libgdx was a lot better, This is being worked on at this very moment. It sort of makes sense to delay making that game until it lands in the code base. It is not like I am short of ideas for games.

I have been trying Eclim a little bit. I really wanted it to work out as I like living inside vim. It is almost there for me. It makes me a little sad to say it but it is not as smooth as using the default editor in eclipse.

I wrote a couple more paragraphs of complaints but sort of realised as I wrote them it is more likely that it is me who is at fault. I just don't know enough about vim/Eclim to have a rant about it.

I was sort of hoping it would work out of the box and have some commands like RunLastProject to make it really easy to use. Alas not what I could find. I am probably going to keep chipping away at it on and off and see if I can get something that resembles and good work flow.

There are stability problems with the embed vim in eclipse so I may wait for a newer version of Eclim. For now when I code in Java it will be in pure Eclipse, just as someone on google plus suggested to me when I mentioned Eclim.

I am still happily working on a little html5 sprite editor. I got to the stage of actually being able to draw on the screen. It is a fun little project and a nice distraction, when needed, from anything else going one :) Progress is very slow.

I also signed up to BitBucket. It is something I have been meaning to do for ages. No longer will my home projects be dumped on dropbox with not version control. BitBucket is free to individuals even for private repositories. My very limited use gives it five stars.

Friday, 15 February 2013

Wow it has been a little while since I posted.


To be honest it has been a bit of a slow period in terms of getting stuff done. Some family stuff popped up that derailed my productivity and I have not quite got back into the rhythm of things.

There has been a bit of progress but not much. For my next game I decided to jump ship in terms of technology and return to Java. Using Libgdx and Java will let me target a wider range of android devices and still partially target the web. I say partially as it uses webGL and there is a browser that holds out from implementing it.

The game has not progressed very far. The time I have had has gone mostly towards re-learning the api's that Libgdx provides. I admit some geekery as I have experimented with eclim, a sort of vim-eclipse bridge. I am not sure if I am that productive with it yet although I think this is more down to my vim set up not have had time to evolve to where I would like it to be.

I have not even installed NerdTree and that will probably be quite a nice thing to have installed when attempting use use eclim.

My other, usually lunchtime, project is I have sort of returned to the idea of an online sprite editor/pixel editor. When I say returned it really just started out as me trying to figure out how to get a simple application style layout working in html. That is a header, main display and a panel on the right. When the window is re-sized the main display absorbs the extra area.

Perhaps my brain is not working too well but that actually took a while to get right. I also wanted the side panel to be able to slide in and out. It now all looks quite smooth and before I knew it I was adding a canvas layer and thinking about making a pixel editor - again.

I attempted something similar last year but decided it was not worth the hassle when I realized I was going to have to transport the image up to a server just so you could download it. At that time I was not that interested in dealing with servers but now I suspect it would not be a big deal. Plus I think chrome and Firefox support a downloadable tag of some kind where you can specify the name of the file to be save without having to do a round trip.

For now this is kind of my part time project that is really just a learning exercise in trying to push as much as possible into css and html rather than relying of CoffeeScript and JQuery.

As an aside I have noticed that the more I blog the more productive I am. Is it causal or is it just a case of when I get productive I want to write about it? Either way I am starting to attach more importance to blogging as a tool to productivity. I guess this is the reason many people write a diary.

Wednesday, 30 January 2013

Postmortum


While I have blogged about my latest game Onion Vs Wheeles  a number of times I figured it was time to do a bit of a postmortem on it.

Onions Vs Wheelies is a very simple 'Dalek' clone straight out of the eighties.The goal was not to produce an outstanding game but to iterate on my slowly growing gaming library, get a better grip on whether I like the
entity/component style of programming and go through the process of actually releasing a little game on to the web as it had been a while.

I decided to have a go at porting the game to android.

What when right:

As it was a clone there was no need for a design so to speak. Initially I just opened up Inkscape and drew some art, The I started coding. It is a small game and I wanted to see if the entity/component architecture would hold up to me just coding on the fly.

The whole game was coded in CoffeeScript and my editor was GVim that had been tweaked a bit to compile CoffeeScript on saving and report any errors.

CoffeeScript is pretty concise meaning when I created a component they looked pretty good without any. Components lend themselves to only doing one thing almost by design. This keeps them simple although it may shift complexity upwards in the way they interact with each other. I didn't experience this but could imagine it on a larger code base.

I am still in the process of learning vim (does it ever stop) but have attained enough skill in it that it now keeps out of my way. The CoffeeScript compiled quickly resulting in very fast iterations. Perhaps not as fast as using LibGdx and Hot swapping but Coffeescript is less verbose compared with Java. Trade off
are always fun and one of the reason I flip between technologies.

My engine grew a little bit in terms of functionality and hit "no oh dear I am going to have to rewrite the engine" moments.

What went wrong:

Given it was a fairly small game done over a short period of time that is not much that can go wrong in a big extent.

The biggest issue I had was porting to android. I took the route of wrapping the generated JavaScript and html code in a WebView and then producing an android APK that could be put on the play market. This was is my first experience in doing this sort of thing for games.

I hit a number of problems that were trivial to fix but revealed my lack of experience with my tools. I had no idea how to remotely debug websites being displayed on chrome. Discovering the desktop Chrome can simulate touch event was new to me as well. Next time round I will be a lot better prepared.

While the game appeared snappy on my Nexus 7 it crawled on my HTC One V. The One V is a lower spec-ed phone running android 4.0. Given the simplicity of the game it is looking like just simply wrapping up the game is really really a good approach if I actually want people to play it.

I am pretty sure the WebView in 4.2 is powered by chrome whereas in 4.0 it is the older WebView. This may be the reason for the slowness of the game as the hardware in the HTC One V is not that bad.

It would certainly be a shame to limit my ports to 4.2 or above, well at least for the next year or so.

A lack of promotion.
I decided early to not promote this game but it did occur to me that I should be learning about the preferred size of displays and at least generating a list of HTML5 portals to submit to. While just coding games and putting them on my website is fun learning the whole process is what I really want to do. Making
an effort early on and learning from my attempts is very important. Deciding to not promote other than blogging is not really a good start to this. Not promoting is a mistake.

Art Skills
Not being able to draw is a limiting factor and something I should work on


Conclusions
Overall I am happy with my results looking at it from a technology stand point. Obviously the game is quite limited. As my goal is to iterate through a few games to learn more it is a good start particularly given it has been quite a while.

Having written this postmortem has given me clarity on what I need to do next in terms of improving things. Given most improvements are outside my comfort zone if should mean I am in for a period of growth.


Wednesday, 23 January 2013

Webgen is Now Being Used


Tonight I ported marblemice.com over to use webgen. webgen is a static site generator that while not that actively developed seems to fit all my requirements. marblemice is now a little bit more maintainable.

Given the number of pages that marblemice has this was really just a bit of geek-ing around for an evening or two. I did this on the pretense that I would write some articles and that marblemice will grow over the coming months into some sort of large website.

Obviously this is not really going to happen, it is only going to grow slowly but hey it gave me a reason to mess around with it a bit and get it out of my system.

I am not sure what to think of webgen to be honest. It does what it sets out to with a minimum fuss and does it in a snappy way, for a website of my size.

Tuesday, 22 January 2013

Onion Vs Wheelies Ported to Android


Over the last couple of days I have had my head down coding. Well that and and doing some sledging and we get our yearly couple of inches of snow.

For the most part I have been fixing up posting to facebook in the app. I can not see on the developer section of facebook people are using my app. Of course I can't see what people are posting just that people are using my app.

This is a good things as it means I fixed the issues.

I also found another bug in Onion Vs Wheelies that was making the title screen slow down to a crawl when using it on android and playing through a few games. I put a fix into the online web version as well.

I am guilty of not having promoted my web version at all. I really should if I want to build up the number of visitors to marblemice.com.

I finally feel like I have cleared some of the back log that has been lingering in my mind.

What next?

Well starting work on the next game is a good idea. I also have a simple web app I created with JQueryMobile that I would like to publish and get it up on the chrome web store. It is really simple and consists of less than a 100 lines of CoffeeScript.

Having also recently moved marblemice.com to a different host I sort of come to the conclusion it really needs a bit of an overhaul  I kind of like the design but it is not really maintainable. I prefer to keep it as a static site so will probably look at nanoc as a way of making it more maintainable.

All this will be done in dead time when I am either in need of a break from coding or just outright tired.

Sunday, 20 January 2013

Side tracked into android app update

I have been a little side tracked into updating on of my apps I have for android. Posting to Facebook has not been working.

As Facebook recently published version 3 of their library I thought it was time to upgrade to that. It does look like that have put quite a bit of work into it which is nice. However for someone who just wants to send a bit of text to the user wall it is a bit of an overkill. If only they support the share some text intent.

The SDK is very much geared up to having the user log in and use that as their id in the app. If that is the sort of thing you want then the SDK is a huge improvement.

Anyway I eventually arrived at a solution that I was happy with and so will be putting out an update fairly soon. The funny thing is I think I had mis-configured something server side and with that fixed I think users will be able to post without the update. I am not 100% hence deciding to continue to do the update.

Dropping back into eclipse was a bit of an experience. When I was flipping between the debugger and the Java work-spaces I seemed to end up in .class files. Eclipse displays them as source files so you don't realise until you try to type and nothing happen as they are read only. I got caught by this a few times.

My eclipse Fu had definitely gone backwards in the past few months although some of the speed drop should be attributed to my new laptop with its slightly eclipse un-friendly keyboard layout. It is of course fine with vim. There is a vim plug in that uses a headless version of eclipse that I very nearly downloaded.

I am hoping get the updates published this week so I can refocus on releasing my latest little game to android. The porting part is done I just need to sit down draw some art and produce the APK.

My expectation is I start game 2 just before February. I am pretty much have the outline of the game sorted.

Sunday, 13 January 2013

Link To Game 1.



The weekend has turned out quite well, I got to the bottom of my of my problems in game one and I called it Onion Vs Wheelies. A simple clone of the game Dalek clone that involves an onion that is being chased by wheelie bins!

I am glad I started back with a small project as going through the whole process of design to release in a very short period of time has let me spot lots of things that need streamlining and also spot bugs in my slowly developing game library. The game does play reasonably well on my nexus 7 this means I will probably try to embed it into a simple java wrapper and see how it runs there. That's on the to-do list for this week, There will be a number of art assets I have to create if the game does embed well so it will take a little while before I get it published. Thankfully the controls seem ok so I probably won't need to do further work with them.

Spare moments I get tend to be spent on the design ideas for the next game. I am starting prefer one game idea over all the rest, It will be slightly larger in concept and design than "game 1" of the year but still draws on old 8/16 bit game ideas. I will probably stick with CoffeeScript again. However first things first, an android port of Onions Vs Wheelies.

Friday, 11 January 2013

Onions are Escaping


Well I have been fairly busy over the past few days. I have published a game on my website. So yay! I will link to it in a while but for now you have to find your way there.

Why? Well there are couple of issues that make it not ready for prime time. First there is an issue of loading images. It is a case of me being a little bit stupid and forgetting to wait until the images are loaded. Sort of thing you only catch when you are pulling images off a server rather than you hard drive. I wondered what was going on and this morning as heading out to work the answer just appeared in my head. I am pretty sure it is correct.

Also I have not turned of the ability to select things, again a silly mistake on my part.

Finally there should be some google ads that don't appear to be there...

The first two are pretty important to me and I want to fix as soon as possible. Alas that means sometime over the weekend as it won't be happening tonight.

All this smacks of little mistakes as I get be into the groove of web stuff so to speak. I am glad I produced something small to get my brain back into it.

In other news I shifted my web hosting over to Small Orange rather than using google app-engine. Marblemice.com is just a static site so hosting it on the app-engine was kind of a strange thing to do although it was free. Small Orange is not the cheapest place but for a website with as few visitors as mine I only need their lowest tier which in absolute price is cheap, compared with others it is not for what you get. Their reputation on the web is what sold them to me. I don't mind paying a small amount in absolute terms to avoid hassle. Should I ever get to transferring more then 5Gb per month then that is a good problem to have.

The transfer went smoothly as you would expect for a site that consists of static pages.

My mind is slowly turning to the next game and I am beginning to jot down ideas and see what I can come up with. Well I have lots of idea but they need fleshing out and importantly they have to fit within the constraints of my artistic talent.

So my TODO list over the next week is
    1. Fix issues with game 1
    2. Do a pass over my engine to improve it
    3. Sketch out and decide on next game
    4. Investigate putting current game onto android.

I may have mentioned I returned to vim as my text editor. Well it is going really well, I miss a few things from emacs but work flow in gvim is really starting to grow on me. That is for CoffeeScript, I will be rushing to proper IDEs when I do C++ or Java. One of the reasons I started to use emacs is it feels so different from my day job and that makes it fun, GVim retains this feel. Not that my day job is bad but changing environments when at home is a good thing.

Title of this post refers to the name of the game I am just in the process of finishing. Just in case you are wondering.

Sunday, 6 January 2013

Odds and Ends (Current Game and JQueryMobile)



Over the past couple of days I have been busy. I have downloaded the android sdk again and am starting to get my android dev system set up. This is motivated by the fact I have been getting some reports that some of my apps are not posting to facebook anymore. I have had a little bit of a rant about facebook in the past so shall not cast stones until I have investigated the problems other than to say it would be really nice if facebook started to support intents. Perhaps they do as I have not checked in a while.

I was looking at JQueryMobile for a while again. All the transitions now work quite smoothing on my nexus 7 in chrome, that is pretty nice. I once entertained the idea of writing a few apps with JQueryMobile and then embedding them in an java wrapper so I could release them on the android market. I am left wondering with the WebView component provided by the java api build on top of the chrome renderer or is it still based on a pre-chrome port?

These things only took a small part of my time. Most of it has been spent working on a little game I am making, It is a clone of the old 8-bit game called Daleks. So far it consits of about 800 lines of code about 400 of which form my slowly evolving gaming library. Most of the game mechanics are in place other than the player dying, I usually add this last in simple games as it make development easier. There is a bit of refactoring needed to support in play states but otherwise I am happy with the progress of the game.

While the graphics need has consisted on only a few icons I have taken the approach of drawing on pencil and paper and then taking a picture of them. This is then imported into inkscape so I can manually trace and then color the image. It seems to be working fairly well. My paper drawing skills exceed my inkscape skills but both are very poor.

I continue to learn some of the corner cases of CoffeeScript, like how to get the index of the item in an array with using CoffeeScripts' for loop. The approach I am taking is one where I tolerate messy code in the game code but not in the library code. In a months time I probably won't touch the game code again while the library code will be being used in a different game. The game code is limited in scope and size and I doubt the whole game will get much above 1000 lines so I don't expect the complexity to kill me.

The entity/component system is really easy to work with and certainly separates concerns very well. I am not really using the power it gives in composing together different components on such a simple game. The C++ programmer in me really struggle to not "fix" my very inefficient implements of the entity system but for now I resist. For a laugh I may take a few days after releasing it and see if I can get it working on an android device but that is a little way off.

Thursday, 3 January 2013

Setting Goals For The Next Six Months


Yep it is going to be another rambling post.

As you may have guessed from my previous post I like to do some thinking as a new year starts. I usually set some goals for the year coming ahead. Well actually rather than goals I have found it better to set topics. Things like this year I will focus on android app and so on.

My focus usually only last about 6 months before I do something else but I usually end up learning a lot. So for the next six months I plan to focus on producing games. Any platform/language is allowed although I can only really see myself coding for either android or HTML5.

This does mean I probably will not work on the sprite editor I was working on. While I have some nice ideas that have not really been done anywhere I have look the whole idea of a web based editor put tension on the work flow that mean it would be frustrating to use.

I briefly looked at using JavaFx to create a desktop version but in the decided to put it on the at some point it would be good list. JavaFx seems quite nice by the way.

I am starting small when it comes to games and tonight go some initial code and art put together for the first game I am producing.

Sunday, 30 December 2012

Nearly end of year - Rambling Post


So I have been pretty quiet the past few weeks. As you can imagine Christmas means I am pretty busy with family stuff and plenty of eating. For Christmas I got a new laptop. A dell XPS 15 and it is pretty nice. For now I have stuck with window 8 rather than installing Linux on it as most of the tools I use are cross platform and I would like to spend some time with window 8 just to get used to it.

It does mean I have spent some time setting up my tool chain again. Eclipse and android are not yet installed but I spent some time with emacs. Then strangely enough I spend some time setting up vim. Sort of  to compare both environments for coding CoffeeScript in. For now vim seems to be winning even though there is a lot the I like in emacs. I seem to find the navigation around a buffer easier in vim compared with emacs. Also getting vim set up for coding in CoffeeScript took quite a bit less time than getting emacs set up. In the long run not a big deal. Now being fairly familiar with both I imagine I will flip between the two of them on a whim. OrgMode is still great.

My mind is turning to projects I wish to develop. Yes I am planning again and that never works out that well. It usually means I take on too much.

First of all the past month or so has been fun just coding up what I want so I don't want that to stop but flipping between things and running with every crazy idea I have means I never actually get anything done. I like to complete things.

In previous posts I mention feeling a bit burned out. That culminated with a flu like cold just before Christmas. I was hit much worse than my family and spend 3 days pretty much asleep and quite a few days after that sleeping 10-12 hours a day. I think it is fair to say I caught up with any sleep deprivation I may have had. A bonus is when I am ill I can't face coffee. Even now my caffeine intake is greatly reduced meaning I now sleep like a baby.

So with all this in mind I am feeling recovered and wanting to take on some projects that I will actually release. Looking at where I am at it seem I am enjoying the whole HTML5 thing so may as well continue that for a while and return to android later in the year.

I would like to continue with my little sprite editor. I am enjoying creating it and learning quite a bit. I am not sure it is going to be super useful to anyone but if it is fun I will continue. I may gradually it to CoffeeScript just so I only have to think about one language.

I also have a very incomplete gaming library and when I say incomplete I really mean it. So I am thinking that I will develop a few simple games to flesh it out. Game development is nice as it forces me out of my comfort zone of coding into the world of attempting to draw (usually badly) and thinking on making sure it is fun.

Ok this post is a bit of thinking while I write so I may decide on something else. Either way I want to have decided my course of my coding over the next few months by the time the new year starts.

Do excuse the slightly rambling post but I usually post a few thinking out loud blogs around this time of year.




Monday, 10 December 2012

Are too many units tests bad for your project?




Perhaps to some this might sound like heresy and to others it my seem like common sense.

I am a fan of unit testing but have recently been thinking about the right number of tests prompted from observing an over zealous attempt at creating unit tests.

During this time I was reminded that tests are not free, they take time to create, maintain and run. The idea is this time is recouped during development by catching errors early and acting as a sanity check. This kind of works out quite well most of the time.

There are times when it can be a drag.

The first of these is small prototype projects. The sort of ones I talk about on this blog. Things that are knocked out on a weekend or at most a month. They are mostly for personal consumption, occasional I do do unit tests but often only start adding unit tests after the first release. If I start on a second iteration it probably means I will work on it on and off for an extended period and unit tests will pay for themselves. I doubt people will disagree with this one as it is not exactly controversial.

The point of this post is I recently observed someone create many hundreds of unit tests that were all permutations of each other. It took him quite a while. All these permutation represent  different options that can be given to a system. The code is programmed such that there are many similar functions (this part of the code if old and by that I mean decades) so he used that as the reasoning for writing the test while altering the code.

The trouble is the possible combinations is so large even this guys herculean attempt could not cover everything and general testing revealed more bugs.

This led me to thinking someone sitting down and attempting to write lots of unit tests should trigger warning alarms. Personally I felt it is more appropriate to spend time going over the code to reducing the number of branches/functions in the system meaning we could cover the code with less unit test.

To answer the obvious re-action. there are many layers of testing so it is possible to refactor code fairly safely without unit tests in place.

TL/DR Sometimes it is better to simplify code rather then write unit test for complex code.

Wednesday, 5 December 2012

Early Dec 2012 JavaScript Adventures


My JavaScript adventures continue. I have sort of started a separate little game project but more on that in a minute.

The little sprite editor that can't continues. I added a tiny bit of polish to it in the way of a title bar across the top. Suddenly is has started to look like a web app.

Currently it sits are about 750 lines of JavaScript but that probably needs a bit of a going over. Thankfully I am not starting to feel it is getting to complex just yet. This must mean my skills in JavaScript are improving  I look forward to how the app feels when I trundle past a 1000 lines.

As I wrote this it felt weird. talking about handling complexity of a 1000 lines. I regularly write code in Java or C++ in code bases that get close to 500k lines of code and do not struggle (and I do not know the full system obviously just a mental model) but in the past when playing with JavaScript I have noticed the fun starts to disappear when I get in the 500-1000 line mark.

I suspect it is because I am used to statically typed languages and dynamically typed languages need a slightly different approach. Also I am less familiar with dynamic languages so may make poor choices in terms coding idioms. I have noticed this in JavaScript and re-factor my work often as I learn more tips and tricks. Either way I feel I am rapidly improving in terms of skill in JavaScript.

One area I have to keep correcting myself on is generating html code in JavaScript. This makes the JavaScript verbose and I don't like it from a separation of things point of view. Having effectively made a few UI components it does give me an appreciation of the approach the say JQueryMobile have taken. Perhaps "What would JQueryMobile do?" would be a good question to keep asking myself.

So my approach to developing this little app is if I can do it somewhere other than JavaScript I should. Another example of this is the used of the animate function in JQuery where I should really be using css transition. All the browsers I plan on supporting have this implemented.

Enough pixel editing talk. My second project on the go is a very small game. I wanted to get a better feel for using entity systems inside game dev. It is a HTML5 canvas game and currently consists of a square that moves around. I am thinking of producing a space invaders clone. Yep small scale and not innovative but it should give me a good feel for entity systems.

That pretty much sums up my coding life. Quite enjoying it and it is nice going with the flow and coding up stuff I am enjoying. I am sure post Christmas new year I will get the urge to try to progress on to stuff that will be more useful for people but for now I am hacking code for fun.