// HTML ELEMENT GLOBALS var canvas; // CREATEJS GLOBALS var stage; var preloader; var loader; // CREATINE GLOBALS var director; var display; var device; // GAME GLOBALS var registry; var preloadManifest = [ // Keep the minumum necessary here! {id:'logo_creatine', src:'assets/powered_creatine.png'}, ] var loadManifest = [ {id:'bmp_buttonstart', src:'assets/button_start.png'}, {id:'bmp_buttoncredits', src:'assets/button_credits.png'}, {id:'bmp_buttonmenu', src:'assets/button_menu.png'}, {id:'bmp_buttonback', src:'assets/button_back.png'}, {id:'bmp_buttonlevel', src:'assets/button_level.png'}, {id:'img_bg', src:'assets/img/bg.png'}, {id:'img_credits', src:'assets/img/credits.png'}, {id:'img_logo', src:'assets/img/logo.png'}, {id:'img_boxbg', src:'assets/img/boxbg.png'}, {id:'img_button', src:'assets/img/button.png'}, {id:'img_button_pause', src:'assets/img/button_pause.png'}, {id:'img_button_sound', src:'assets/img/button_sound.png'}, {id:'img_sheep', src:'assets/img/medsheep.png'}, {id:'img_wolf', src:'assets/img/medwolf.png'}, {id:'img_fluffy', src:'assets/img/fluffy.png'}, {id:'', src:'assets/img/level01_tutorial.png'}, {id:'', src:'assets/img/level02_tutorial.png'}, {id:'', src:'assets/img/medtileset2.png'}, {id:'map_level01', src:'assets/maps/level01.json'}, {id:'map_level02', src:'assets/maps/level02.json'}, {id:'map_level03', src:'assets/maps/level03.json'}, {id:'map_level04', src:'assets/maps/level04.json'}, {id:'map_level05', src:'assets/maps/level05.json'}, ] var dist = function(x1, y1, x2, y2) { return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2)); } var v2dist = function(vec1, vec2) { return Math.sqrt(Math.pow(vec1.x-vec2.x, 2) + Math.pow(vec1.y-vec2.y, 2)); } var norm2d = function(x, y) { return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) } var v2norm = function(vec) { return Math.sqrt(Math.pow(vec.x, 2) + Math.pow(vec.y, 2)) } var getTile = function(layer, x, y) { return layer.data[(layer.width*y + x)] } var toCoordX = function(x) { return Math.floor(x/registry.map.tileWidth); } var toCoordY = function(y) { return Math.floor(y/registry.map.tileHeight); } function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function easeInOut(t) { return t<.5 ? 2*t*t : -1+(4-2*t)*t } String.prototype.toTime = function () { var sec_num = parseInt(this, 10); // don't forget the second param var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num - (hours * 3600)) / 60); var seconds = sec_num - (hours * 3600) - (minutes * 60); if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} var time = minutes+':'+seconds; return time; } function start() { verifyDependences(); preloadAssets(); } function verifyDependences() { try { !!localStorage.getItem; } catch (error) { window.localStorage = {} } if (typeof(localStorage['ismuted']) === 'undefined') { localStorage['ismuted'] = false; } } function preloadAssets() { preloader = new createjs.LoadQueue(true); preloader.on('complete', onPreloadComplete); preloader.loadManifest(preloadManifest); } function onPreloadComplete(event) { /** Get the canvas element **/ canvas = document.getElementById('canvas'); /** Create and initialize the CreateJS objects **/ stage = new createjs.Stage(canvas); loader = new createjs.LoadQueue(true); /** Create and initialize the Creatine objects **/ director = new creatine.Director(stage); display = new creatine.Display(canvas); device = new creatine.Device(canvas); loader.installPlugin(createjs.Sound); createjs.Sound.alternateExtensions = ['ogg', 'mp3']; if (device.firefox||device.chrome||device.opera) { loadManifest.push({id:'music', src:'assets/music/happy.ogg'}); loadManifest.push({id:'sfx_sheep01', src:'assets/sfx/sheep01.ogg'}); loadManifest.push({id:'sfx_sheep02', src:'assets/sfx/sheep02.ogg'}); loadManifest.push({id:'sfx_sheep03', src:'assets/sfx/sheep03.ogg'}); loadManifest.push({id:'sfx_sheep04', src:'assets/sfx/sheep04.ogg'}); loadManifest.push({id:'sfx_sheep05', src:'assets/sfx/sheep05.ogg'}); loadManifest.push({id:'sfx_sheep06', src:'assets/sfx/sheep06.ogg'}); loadManifest.push({id:'sfx_sheep07', src:'assets/sfx/sheep07.ogg'}); loadManifest.push({id:'sfx_sheep08', src:'assets/sfx/sheep08.ogg'}); loadManifest.push({id:'sfx_sheep09', src:'assets/sfx/sheep09.ogg'}); loadManifest.push({id:'sfx_sheep10', src:'assets/sfx/sheep10.ogg'}); loadManifest.push({id:'sfx_wolf01', src:'assets/sfx/wolf01.ogg'}); loadManifest.push({id:'sfx_wolf02', src:'assets/sfx/wolf02.ogg'}); loadManifest.push({id:'sfx_wolf03', src:'assets/sfx/wolf03.ogg'}); loadManifest.push({id:'sfx_wolf04', src:'assets/sfx/wolf04.ogg'}); loadManifest.push({id:'sfx_wolf05', src:'assets/sfx/wolf05.ogg'}); loadManifest.push({id:'sfx_wolf06', src:'assets/sfx/wolf06.ogg'}); loadManifest.push({id:'sfx_wolf07', src:'assets/sfx/wolf07.ogg'}); loadManifest.push({id:'sfx_wolf08', src:'assets/sfx/wolf08.ogg'}); loadManifest.push({id:'sfx_wolf09', src:'assets/sfx/wolf09.ogg'}); loadManifest.push({id:'sfx_wolf10', src:'assets/sfx/wolf10.ogg'}); loadManifest.push({id:'sfx_win', src:'assets/sfx/win.ogg'}); loadManifest.push({id:'sfx_dead', src:'assets/sfx/dead.ogg'}); } else { loadManifest.push({id:'music', src:'assets/music/happy.mp3'}); loadManifest.push({id:'sfx_sheep01', src:'assets/sfx/sheep01.mp3'}); loadManifest.push({id:'sfx_sheep02', src:'assets/sfx/sheep02.mp3'}); loadManifest.push({id:'sfx_sheep03', src:'assets/sfx/sheep03.mp3'}); loadManifest.push({id:'sfx_sheep04', src:'assets/sfx/sheep04.mp3'}); loadManifest.push({id:'sfx_sheep05', src:'assets/sfx/sheep05.mp3'}); loadManifest.push({id:'sfx_sheep06', src:'assets/sfx/sheep06.mp3'}); loadManifest.push({id:'sfx_sheep07', src:'assets/sfx/sheep07.mp3'}); loadManifest.push({id:'sfx_sheep08', src:'assets/sfx/sheep08.mp3'}); loadManifest.push({id:'sfx_sheep09', src:'assets/sfx/sheep09.mp3'}); loadManifest.push({id:'sfx_sheep10', src:'assets/sfx/sheep10.mp3'}); loadManifest.push({id:'sfx_wolf01', src:'assets/sfx/wolf01.mp3'}); loadManifest.push({id:'sfx_wolf02', src:'assets/sfx/wolf02.mp3'}); loadManifest.push({id:'sfx_wolf03', src:'assets/sfx/wolf03.mp3'}); loadManifest.push({id:'sfx_wolf04', src:'assets/sfx/wolf04.mp3'}); loadManifest.push({id:'sfx_wolf05', src:'assets/sfx/wolf05.mp3'}); loadManifest.push({id:'sfx_wolf06', src:'assets/sfx/wolf06.mp3'}); loadManifest.push({id:'sfx_wolf07', src:'assets/sfx/wolf07.mp3'}); loadManifest.push({id:'sfx_wolf08', src:'assets/sfx/wolf08.mp3'}); loadManifest.push({id:'sfx_wolf09', src:'assets/sfx/wolf09.mp3'}); loadManifest.push({id:'sfx_wolf10', src:'assets/sfx/wolf10.mp3'}); loadManifest.push({id:'sfx_win', src:'assets/sfx/win.mp3'}); loadManifest.push({id:'sfx_dead', src:'assets/sfx/dead.mp3'}); } /** Create and initialize the Game objects **/ registry = {}; /** Display settings **/ display.setUserSelect(false); display.setTouchAction(false); // display.setSmoothingEnabled(true); stage.snapToPixelEnabled = true; /** Ticker settings **/ createjs.Ticker.setFPS(60); createjs.Ticker.addEventListener('tick', onUpdate); /** Create the preload scene **/ var preloadScene = new PreloadScene(); director.push(preloadScene); /** Initialize the asset loading **/ loader.loadManifest(loadManifest); } function onUpdate(event) { event.fdelta = event.delta/1000.; if (director.scene) { director.scene.onUpdate(event) } stage.update(); }