Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rodikh committed Jan 27, 2014
1 parent 3dc3e8d commit c82fcc7
Show file tree
Hide file tree
Showing 23 changed files with 1,192 additions and 0 deletions.
Binary file added images/bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bg_new.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bg_old.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bg_small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bullet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cell.psd
Binary file not shown.
Binary file added images/cell_old.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/selection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/triangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/units.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/units.psd
Binary file not shown.
Binary file added images/world-map-background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<section class="page">
<canvas id="main_canvas" width="800" height="600" oncontextmenu="return false;"></canvas>
</section>
<section class="console">
</section>
<footer>wallpaper taken from http://onlyhdwallpapers.com/</footer>
<script language="JavaScript" src="../../../lib/jquery.js" type="text/javascript"></script>
<script language="JavaScript" src="js/easeljs-0.4.2.min.js" type="text/javascript"></script>
<script language="JavaScript" src="js/easeljs-colorfilter.js" type="text/javascript"></script>
<script language="JavaScript" src="js/class.js" type="text/javascript"></script>
<script language="JavaScript" src="js/script.js" type="text/javascript"></script>
<script language="JavaScript" src="js/map.js" type="text/javascript"></script>
<script language="JavaScript" src="js/unit.js" type="text/javascript"></script>
<script language="JavaScript" src="js/bullet.js" type="text/javascript"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions js/bullet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(function(window){
var bulletImg = new Image();
bulletImg.src = "images/bullet.png";

bulletCont = new Container(canvas);
var BulletC = Class.extend({
init: function(shooter, trajectory, shooterId){
this.body = new Bitmap(bulletImg);
this.body.x = shooter.x;
this.body.y = shooter.y;
this.body.rotation = trajectory;
this.body.regX = 2;
this.body.regY = 2;
this.originX = shooter.x;
this.originY = shooter.y;
this.velocity = 4;
this.trajectory = trajectory;
this.status = "shooting";

bulletCont.addChild(this.body);
this.shooter = shooter;
this.shooterId = shooterId;
this.body.parentId = bullets.push(this)-1;

},
tick: function(){
var dx = this.velocity * Math.cos(this.trajectory * (Math.PI/180));
this.body.x += dx;
var dy = this.velocity * Math.sin(this.trajectory * (Math.PI/180));
this.body.y += dy;
if (distance(this.body.x,this.body.y,this.originX,this.originY)> 200){
this.destroy();
}
bullet_collisionDetector(this);
return true;
},
destroy: function(){
bulletCont.removeChild(this.body);
delete(bullets[this.body.parentId]);
}
});
function bullet_collisionDetector(bullet){
for(i in units){
var unit = units[i];
if(unit.name != bullet.shooterId && !unit.dead){
if (distance(unit.body.x,unit.body.y,bullet.body.x,bullet.body.y)<5){
// TODO: also check if owner is same as shooter's owner.
bullet.destroy();
unit.health--;
break;
}
}
}
}

window.BulletC = BulletC;
})(window);
63 changes: 63 additions & 0 deletions js/class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};

// Create a new Class that inherits from this class
Class.extend = function(prop) {
var _super = this.prototype;

// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
initializing = false;

// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() {
var tmp = this._super;

// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];

// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;

return ret;
};
})(name, prop[name]) :
prop[name];
}

// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if ( !initializing && this.init )
this.init.apply(this, arguments);
}

// Populate our constructed prototype object
Class.prototype = prototype;

// Enforce the constructor to be what we expect
Class.prototype.constructor = Class;

// And make this class extendable
Class.extend = arguments.callee;

return Class;
};
})();
Loading

0 comments on commit c82fcc7

Please sign in to comment.