Remote collision detection (for games)

Hello all, so I have been pretty active on the “create games” front but not so much for blogging, sorry about that… So I come to you now with a Pen that razed over 1500+ views on codepen and 14 hearts so far…

It’s my implementation of a remote collision detection system that uses degrees instead of bounding boxes. This works well for games where you want to calculate the position of the shoot but the “cannon/lazer/fazer/tower” is not near the target, so instead of creating long bounding-boxes. We just calculate the degrees between the source (cannon) and the target(enemy). And when the cannon is rotated on those degrees it can fire.

Here I will show how a tank can “detect” the enemy. Here’s a quick example and the code will follow:

See the Pen Remote collision detection by Michael Dobekidis (@netgfx) on CodePen.

Continue reading

Secret Word, (a hangman game with a twist)

I have launched yet another game. This time is a classic hangman game build with HTML5 Canvas and Javascript.

Features

Classic hangman game with a plot twist

Game Features:

Dictionary with over 1800 words
Supports themes, and theme creation
Includes two themes ( blackboard and notepad )
Adaptive design that manages size in different devices
Included video help file for changing Theme

Check how easy it is to change themes:

Particles with KineticJS and collision detection

Hello once again, this time I will show a nice technique to create exploding particles with KineticJS.

First of all we setup the stage and the canvas objects.

DEMO:

http://cdpn.io/IwAoc

See the Pen kineticjs collision detection by Michael Dobekidis (@netgfx) on CodePen.

Continue reading

Quick Tip: Parse single object from unknown key-values JSON.

Sometimes we need to read data from JSON but we are not sure which value corresponds to a key or we need to parse a really large object. So here’s a tip about how to read key names and their corresponding values from a JSON object.

Let’s assume the following JSON structure:

var gameOps = {"tanks":[
{
    "type":"T1",
    "velocity":"800",
    "speed":"100",
    "bulletType":"t1Ammo",
    "damagePerHit":"0.25",
    "tankWidth":"74",
    "tankHeight":"128",
    "bulletWidth":"7",
    "bulletHeight":"15"
},
{
    "type":"T2",
    "velocity":"800",
    "speed":"100",
    "bulletType":"t1Ammo",
    "damagePerHit":"0.25"
},
{
    "type":"",
    "velocity":"",
    "speed":"",
    "bulletType":"",
    "damagePerHit":""
}

]};

In this object we notice how the first object has values that the others do not, if we tried to parse it based on the first object the code would halt on error because it would be unable to find the rest of the keys.

So what if we only wanted one of the objects but we did not know what properties it has?

Let’s consider the following snippet:

var myObj = getOptions(gameOps);

function getOptions(type, opts){
        var counter = 0;
        var obj = {};
           
        for(var i = 0; i<opts.tanks.length; i++){
            var temp = opts.tanks[counter];
            var keys = Object.keys( temp );
           
            if( temp.type == type){
               
                for(var j=0; j<keys.length; j++){
                   
                    obj[ keys[ j ] ] = temp[ keys[ j ] ];
               
                        }
                     }
           
            counter += 1;
        }
       
        return obj;
    }

Here we check if the desired “type” is among the object properties, if it is we read the available “keys” that the object has, and then we construct another object with those keys and values.

Browser compatibility:
This solution is compatible with
Firefox (Gecko) – 4 (2.0)
Chrome – 5
Internet Explorer – 9
Opera – 12
Safari – 5

Because it uses: Object.keys(obj)

Read more here: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys

My game template on Codecanyon!

Finally I have had some free time and thought to try my luck with Codecanyon, which is a place were authors and coders get to monetize their works and for people to get some high-quality code/themes/templates/apps build-in and ready to go.

So I managed to “transform” my game of Easter-egg-hunting into a framework for gathering games (games where items drop and the player has to collect them) I added some code, removed much, and generalized the core to actually adapt and be manageable through a JS file that the user can alter to create his own game.

The template offers:

  • mobile and modern browser support
  • media-queries baked inside
  • responsive gameplay
  • auto pause when the player changes tab or browser loses focus
  • highly customizable options like: background, items, gathering image, score, etc…
  • High performace even on mobile devices, by using multiple canvases
  • And per frame collision detection
So check it out, and buy if you also want to create your own gathering game…

http://codecanyon.net/item/gathering-items-game-template-jquery-tweenmax/4525985

Note: The template uses jQuery, jQueryUI for dragging, and GSAP to manage animation and update functions per frame.

HTML5 Video on Canvas + pixel manipulation

One of my latest experiments was to create a fullscreen background with a video, for this I used HTML5 video tag and loaded it on a canvas element.
Although it worked it somehow felt incomplete because it was simply a video as background, it needed some edge add to it, for this I decided to use Pixelate library http://close-pixelate.desandro.com/ and extend it so it supported video as well as images.
Github extension can be found also here:

https://github.com/netgfx/close-pixelate

** Note This example is best viewed with latest Chrome or Webkit browser. **

DEMO

Continue reading

Text Effects with TimelineMax

Text is one of the most important aspects of web-development, someone may have great pictures, effects, and complex animations but if there is no content in text, chances are that the viewer will start looking elsewhere. So since text is such a great aspect of the website or application why not try and make it a little more appealing and exciting, after all it’s not only what you say (write) but how you present it.

So I thought to create a series of effects and animations that modify and give text a “Wow factor”.

[[code]]czowOlwiXCI7e1smKiZdfQ==[[/code]]<a href="http://codepen.io/netgfx/pen/DpbIy">Check out this Pen!</a>

Continue reading

ThreeJS camera control with TweenMax

Recently I started exploring the world of 3D, I mostly wanted to work in a familiar environment so I chose ThreeJS an excellent framework for 3D construction/animation with javascript. And of course I wanted to inject my favorite tool for javascript animation TweenMax.
So after a few examples and documentation reading I came up with a very simple example/tutorial of how to control various aspects of the camera in 3D space using TweenMax to animate properties and end-values.
For this example I also used the extremely helpful threejs boilerplate

You can view a DEMO here

Continue reading

Image Slideshow with PreloadJS, JQuery and TweenMax

This is a tutorial about how to create a simple slideshow element with dynamicaly loaded images and some cool animations.
PreloadJS is a rather new JS library that aims to help with the loading of various assets, in our case it will provide us with the info of when the images are fully loaded and a value of percentage completion of this task.

DEMO

Continue reading