Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
MauMaGau committed Dec 6, 2015
0 parents commit 7fb7c89
Show file tree
Hide file tree
Showing 26 changed files with 26,986 additions and 0 deletions.
48 changes: 48 additions & 0 deletions game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<title>Less is more</title>

<script data-main="js/main-built" src="js/require.js"></script>
<!--<script data-main="js/game/main" src="js/require.js"></script>-->

<!-- For debug only! -->
<!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>-->

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-10955279-6']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

<style type="text/css" media="screen">
body{
background-color: #222;
}
*{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body>

<canvas style="background-color:#fff;" id='map_canvas'></canvas>
<canvas style=";" id='game_canvas'></canvas>
<canvas style=";" id='debug_canvas'></canvas>
<canvas style=";" id='info_canvas'></canvas>

</body>
</html>
49 changes: 49 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>Less is more</title>

<!-- For debug only! -->
<!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>-->

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-10955279-6']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

window.addEventListener("keydown", function(e){console.log(e)}, true);

</script>

<style type="text/css" media="screen">
body{
background-color: #222;
}
</style>

<link href="http:////netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>

<div class="container">
<div class="row">
<div class="hero-unit">
<h1>Less is more</h1>
<p><i>The less you shoot, the more your health regenerates</i>,
<i>The less you move, the more your ammo regenerates</i>.</p>
<p>Use wasd, mouse, and left-click</p>
<p>Compatible with Chrome and Firefox (and probably Safari). IE9 no likey.</p>
<a href="game.html" class="btn btn-success btn-large btn-block">Play</a>
<p><i class="muted">I recommend hitting F11 to full-screen and the F5 to refresh page</i> To restart the game, hit F5 to reload the page</p>
</div>
</div>
</div>
</body>
</html>
5 changes: 5 additions & 0 deletions js/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
({
baseUrl: "./game",
name: "main",
out: "main-built.js"
})
114 changes: 114 additions & 0 deletions js/game/agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
define(["collision", "trig"], function(Collision, Trig){
var Agent = {
Collision: Collision,
Trig: Trig,

type: 'Agent',
color: 'black',

lastPos: {x: 0, y: 0, w: 0, h: 0},
toPos: {x: 0, y: 0, w: 0, h: 0},
pos: {x: 0, y: 0, w: 0, h: 0},

dir: 0,
xSpeed: 0,
ySpeed: 0,

alive: 0,
lastHit: 0, // time last hit by projectile

target: null,
lastShot: 0,

health: 2,
maxHealth: 2,
ammo: 0,
maxSpeed: 0,
reloadSpeed: 0,

init: function(pos){
this.pos = pos;
this.lastPos = pos;

require('game').agents.push(this);
},

update: function(){
this.move(this.toPos)

this.lastPos = {x:this.pos.x, y:this.pos.y, w:this.pos.w, h:this.pos.h};
this.toPos = {x:0, y:0, w:0, h:0};
},

draw: function(){
if(this.lastHit > require('game').loopCounter - 5){
require('game').ctx.game.fillStyle = 'blue';
}else{
require('game').ctx.game.fillStyle = this.color;
}

require("game").ctx.game.fillRect(
this.pos.x - ( (this.pos.w)/2 ),
this.pos.y - ( (this.pos.h)/2 ),
this.pos.w,
this.pos.h
);

require('game').ctx.game.fillStyle = require('game').defaultFillStyle;
},

// amount is {x, y, w, h} to move
setMove: function(amount){
this.toPos.x += amount.x;
this.toPos.y += amount.y;
},

// amount is {x, y, w, h} coords
move: function(amount){
if(
! Collision.grid(this.pos.x+amount.x, this.pos.y+amount.y)
){
this.pos.x += amount.x;
this.pos.y += amount.y;
}
},

setTarget: function(agent){

},

shoot: function(dir, Projectile, maxSpeed, damage){
var projectile1 = Object.create(Projectile);
projectile1.init(
{
x: this.pos.x,
y: this.pos.y,
w: 5,
h: 5
},
dir,
'todo',
this, // firedBy
maxSpeed, // projectile speed
damage
);
delete projectile1;
},

hit: function(damage){
this.health -= damage;
this.lastHit = require('game').loopCounter;
if(this.health <= 0){
this.die();
}
},

die: function(){
var i = require('game').agents.indexOf(this);
require('game').agents.splice(i, 1);
}

}

return Agent;
})
86 changes: 86 additions & 0 deletions js/game/circle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
define(["agent", "projectile"],
function(Agent, Projectile){

// define the Circle class as a copy of Agent
var Circle = Object.create(Agent);


Circle.init = function(pos){
this.dir = Math.random() * (0 - 6.28); // 6.28 is 2 PI, a full circle (ish)
this.maxSpeed = 3;
this.type = 'Circle';
this.health = 2;
this.target = require('game').Player;
this.reloadSpeed = this.Trig.randomFromTo(50, 70);
//this.color = this.color;
Agent.init.call(this, pos);

require('game').mobs.push(this);
}

Circle.update = function(){
Agent.update.call(this);
if(this.lastShot < require('game').loopCounter - this.reloadSpeed){
this.shoot();
}
}

// Update setMove method to wander aimlessly
Circle.setMove = function(amount){
Agent.setMove.call(this, amount);
}

// Extend move method to update dir based on dir to player
Circle.move = function(pos){
// Set this.dir
this.dir = this.Trig.radTo(this.pos.x, this.pos.y, this.target.pos.x, this.target.pos.y)

var toMoveX = ( Math.cos(this.dir) * (this.maxSpeed) );
var toMoveY = ( Math.sin(this.dir) * (this.maxSpeed) );

if(
! this.Collision.grid(this.pos.x + toMoveX, this.pos.y + toMoveY)
){
this.toPos.x += toMoveX;
this.toPos.y += toMoveY
}else{
// get dir by moving negative toPos and calcing dir from that (hackey hackey)
if(this.Collision.grid(this.pos.x, this.pos.y + toMoveY)){
this.dir = this.Trig.radTo(this.pos.x, this.pos.y, this.pos.x+toMoveX, this.pos.y-toMoveY);
}
if(this.Collision.grid(this.pos.x + toMoveX, this.pos.y)){
this.dir = this.Trig.radTo(this.pos.x, this.pos.y, this.pos.x-toMoveX, this.pos.y+toMoveY);
}
this.toPos.x += ( Math.cos(this.dir) * (this.maxSpeed) );
this.toPos.y += ( Math.sin(this.dir) * (this.maxSpeed) );
}
Agent.move.call(this, pos);
}

Circle.draw = function(){
if(this.lastHit > require('game').loopCounter - 5){
require('game').ctx.game.fillStyle = 'blue';
}else{
require('game').ctx.game.fillStyle = this.color;
}
require('game').ctx.game.beginPath();
require('game').ctx.game.arc(this.pos.x, this.pos.y, this.pos.w/2, 0, Math.PI*2, true);
require('game').ctx.game.fill();

require('game').ctx.game.fillStyle = require('game').defaultFillStyle;
}

Circle.shoot = function(){
var dir = this.Trig.radTo(this.pos.x, this.pos.y, this.target.pos.x, this.target.pos.y); // too hard
Agent.shoot.call(this, dir, Projectile, 20, 4);
this.lastShot = require('game').loopCounter;
}

Circle.die = function(){
var i = require('game').mobs.indexOf(this);
require('game').mobs.splice(i, 1);
Agent.die.call(this);
}

return Circle;
});
Loading

0 comments on commit 7fb7c89

Please sign in to comment.