commit 70870939d9be818c55dee8aa2f265f91412fd3d3 Author: Valeriano A.R Date: Wed Sep 9 19:03:36 2015 +0200 Basic GameLib and ball image resources diff --git a/code/CandyFucker.js b/code/CandyFucker.js new file mode 100644 index 0000000..0d5e86a --- /dev/null +++ b/code/CandyFucker.js @@ -0,0 +1,74 @@ + +window.Images = new ImageLoader(); + +///////////////////////////////////////// +// +// CandyEntity +// +var CandyEntity = function(game, position, type){ + this.Game = game; + this.GameEntity = new GameEntity( + game.GameScreen, + position, + {X: 32, Y: 32}, + Images.GetImage(type), + type + ); +}; +CandyEntity.prototype = { + Update: function(){ }, + Debug: false +}; + + +///////////////////////////////////////// +// +// CandyFucker +// +var CandyFucker = function(idScreen){ + var self = this; + this.GameScreen = new GameScreen(idScreen, + this.Init.bind(this), + this.Proc.bind(this), + this.End.bind(this) + ); + this.Grid = null; + this.GridOffset = {} + + window.Images.LoadImages( + [ + {Name: "Red", Url: "gfx/Red.png"}, + {Name: "Blue", Url: "gfx/Blue.png"}, + {Name: "Cyan", Url: "gfx/Cyan.png"}, + {Name: "Green", Url: "gfx/Green.png"}, + {Name: "Yellow", Url: "gfx/Yellow.png"}, + ], + function(){ + self.GameScreen.Start(); + } + ); + +}; +CandyFucker.prototype = { + Init: function(gameScreen){ + var test; + test = new CandyEntity(this, {X: 100, Y: 100}, "Red"); + this.GameScreen.AddEntity(test); + test = new CandyEntity(this, {X: 132, Y: 100}, "Blue"); + this.GameScreen.AddEntity(test); + test = new CandyEntity(this, {X: 164, Y: 100}, "Cyan"); + this.GameScreen.AddEntity(test); + test = new CandyEntity(this, {X: 196, Y: 100}, "Green"); + this.GameScreen.AddEntity(test); + test = new CandyEntity(this, {X: 228, Y: 100}, "Yellow"); + this.GameScreen.AddEntity(test); + }, + Proc: function(gameScreen){ + + }, + End: function(gameScreen){ + + }, + Debug: false +}; + diff --git a/code/GameLib.js b/code/GameLib.js new file mode 100644 index 0000000..036babe --- /dev/null +++ b/code/GameLib.js @@ -0,0 +1,189 @@ + +///////////////////////////////////////// +// +// GameScreen +// +var GameScreen = function(idScreen, funcInit, funcProc, funcEnd){ + this.Screen = document.getElementById(idScreen); + this.Ctx = this.Screen.getContext('2d'); + this.Size = {X: this.Screen.width, Y: this.Screen.height}; + this.Entities = []; + this.NewEntities = []; + this.Running = false; + this.FuncInit = funcInit; + this.FuncProc = funcProc; + this.FuncEnd = funcEnd; + + var self = this; + this.Tick = function(){ + if(self.FuncProc){ + self.FuncProc(self); + } + self.CleanDead(); + self.InsertAdded(); + self.Update(); + self.Draw(); + if(self.Running){ + window.requestAnimationFrame(self.Tick); + }else{ + if(self.FuncEnd){ + self.FuncEnd(self); + } + } + } +}; +GameScreen.prototype = { + // For internal use + CleanDead: function(){ + var i = this.Entities.length-1; + while(i>0){ + if(this.Entities[i].GameEntity.Deleted){ + this.Entities.splice(i,1); + } + i--; + } + }, + InsertAdded: function(){ + for(var i=0,n=this.NewEntities.length;i + + + + + Candy Fucker + + + + + + + + +