Skip to main content

My Game: Canon Defense


If you know about #js13kgames contest you might be interested in my small game created for it.



I called it Cannon Defense, but the sole purpose of creating it was to learn in practice how to create a game. You can say that it looks ugly, or is small, but for me it was great co create it.

My submission is not yet online so if you want, play it at: http://krzychukula.github.io/js13k/

Code is on github: https://github.com/krzychukula/js13k

What I have learned:

User constructor and prototype inheritance for game objects.

function Bullet(x, y){
   this.x = x;
   this.y = y;
}
Bullet.prototype.draw = function(ctx){
   ctx.drawRect(x, y, 10, 10);
}

It will be more memory efficient.

Do not use translations to move objects
For me it was hard to manage bullets flying at various angles and the first idea was to translate all bullets to cannon position, then add some offset variable and just move bullet on one X or Y angle using offset.
It worked :)
Until I had to check for enemy/bullet collisions...
I had to refactor the whole thing to have my version of velocityX and velocityY and just draw bullets without transformations.
But I still use scale for red blood ovals after enemy dies. I think it is ok.

I don't have it in my game but I should:


Object Pools
I don't have this in my game for for all objects like bullets and enemies. However, it would be much wiser to use some pool that could manage them and prevent from running GC all the time (in next game I will use it).

Time Diff
I should have used time diff in calculations of movements, when running on slower device the whole thing feels slow... With time diff it will move bullets at one speed on all devices (maybe will introduce "teleportation" of bullets but it's hard to say).

Interval/Timeout
I use them for many purposes and I think that they can cause problems. At this point I think that it would be better to add enemies after certain count of requestAnimationFrame instead of fixed time, but I don't know how it would work in lower than 60FPS environment...




Comments

Popular posts from this blog

Course Review: The Bitfountain iOS 8 with Swift Immersive

This is second big iOS learning project. For first one read iOS Programming book review. As I only have two of them done I have to compare them somehow.

I am mindful that it took me a really long time to finish it (since last autumn). For a couple of months this year I didn't even have the internet to learn it, so it could not be helped. But last half of the June I've spent watching the videos every day and managed to finish it before any new internet problems.

So how was it?
In my opinion, it's great if you're starting out. There are a lot of basics, and seeing how to do things in XCode just makes your learning much easier than looking at the photos in the book. On the other hand, learning is more shallow and it is much easier to just follow the videos and learn only the basics without bigger picture about iOS SDK. I somehow missed more challenging exercises (even though I don't like to do them ;)

Length:
Course it pretty long but many videos are quite short (1-2…

How to Learn when Life is Short

I haven't really think this through but I have read really interesting articles recently and I just wanted to write for myself later.

Life is Short by Paul Graham

It's just that, learn from people older that you what is most important, and that life actually is short...

Instead of Goals or Resolutions, Try Creating Rules by Leo Babuta

In the time of New Year Resolutions, it's good to read something that is proposing different way of achieving things. Still I see much more value in habits than setting goals. But...

The Easy Way To Learn Hard Stuff by Per Harald Borgen
It's something that I read from time to time and I know it works sometimes for me. The things I learn then are really learned and something Jakub Wasilewski  has told me many times to do. Still it's uncomfortable and for some reason, I have failed to use this method more than once or twice. Writing it here so maybe I can think about it more and figure out how to do that more often.

Towards an understandin…