Skip to content

Commit

Permalink
added sample bots
Browse files Browse the repository at this point in the history
	new file:   lib/MyTankBotMad.js
	new file:   lib/MyTankBotScared.js
	modified:   lib/MyTankBotStill.js
	modified:   lib/jsbattle.js
	modified:   www/dashboard/dashboard.js
	modified:   www/index.html
  • Loading branch information
jeromeetienne committed Mar 30, 2011
1 parent 54a06e9 commit a81bfe3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
17 changes: 17 additions & 0 deletions lib/MyTankBotMad.js
@@ -0,0 +1,17 @@
/**
* This is a definition of a user bot
* aka this is to be written by user
*/

var TankBot = require('./TankBot')
var util = require('./util')

var bot = TankBot.Bot.extend({
tick : function(){
if( Math.random() < 0.02) this.setSpeed(Math.random()*3-1.5);
if( Math.random() < 0.02) this.turn(Math.PI);
this._super();
},
});

module.exports = bot;
28 changes: 28 additions & 0 deletions lib/MyTankBotScared.js
@@ -0,0 +1,28 @@
/**
* This is a definition of a user bot
* aka this is to be written by user
*/

var TankBot = require('./TankBot')
var util = require('./util')

var bot = TankBot.Bot.extend({
tick : function(){
this.setSpeed(1);
this._super();
},
/**
* Handle collision with a wall
*/
onHitWall : function(eventType, eventArgs){
this.turn(util.deg2rad(180));
},
/**
* Handle collision with a bot
*/
onHitBot : function(){
this.turn(util.deg2rad(40-80*Math.random()));
}
});

module.exports = bot;
17 changes: 4 additions & 13 deletions lib/MyTankBotStill.js
@@ -1,18 +1,9 @@
/**
* This is a definition of a user bot
* aka this is to be written by user
*/

var TankBot = require('./TankBot')

var bot = TankBot.Bot.extend({
tick : function(){
// TODO move this _super() at the begining of the function
this._super();
}
/**
* The simplest bot
*/
var botStill = TankBot.Bot.extend({
});

// to mixin TankBotPlugin into bot
require('./TankBotPlugin').mixin(bot)

module.exports = bot;
2 changes: 1 addition & 1 deletion lib/jsbattle.js
Expand Up @@ -20,7 +20,7 @@ var Renderer = Class.extend({
*/
var World = Class.extend({
minPosition : {x: 0, y: 0},
maxPosition : {x: 600, y: 400},
maxPosition : {x: 450, y: 400},
bodies : [],
width : function(){
return this.maxPosition.x - this.minPosition.x;
Expand Down
4 changes: 2 additions & 2 deletions www/dashboard/dashboard.js
Expand Up @@ -24,7 +24,7 @@ Dashboard.prototype.editorCtor = function()
{
// build editor
this.acewidget = jQuery('#editor').acewidget({
width : "400px",
width : "450px",
height : "400px",
});
// setTabSize to 8
Expand Down Expand Up @@ -79,7 +79,7 @@ Dashboard.prototype.viewerReset = function()
jQuery('<iframe>').attr({
id : "viewerIframe",
src : '../viewer/',
width : '400px',
width : '450px',
height : '400px'
})
);
Expand Down
1 change: 1 addition & 0 deletions www/index.html
Expand Up @@ -8,6 +8,7 @@
<li><a href="viewer">viewer</a></li>
<li><a href="dashboard">dashboard plain</a></li>
<li><a href='dashboard/#{"bot1":"http://localhost/~jerome/webwork/arenajs/lib/MyTankBot.js","bot2":"http://localhost/~jerome/webwork/arenajs/lib/MyTankBot.js"}'>dashboard with 2 players</a></li>
<li><a href='dashboard/#{"bot1":"http://localhost/~jerome/webwork/arenajs/lib/MyTankBot.js","bot2":"http://localhost/~jerome/webwork/arenajs/lib/MyTankBotScared.js","bot3":"http://localhost/~jerome/webwork/arenajs/lib/MyTankBotMad.js"}'>dashboard with 3 players</a></li>
<li><a href='dashboard/#{"bot1":"http://arenajs.jetienne.com/lib/MyTankBot.js","bot2":"http://arenajs.jetienne.com/lib/MyTankBot.js"}'>dashboard with 2 players on server</a></li>
</ul>
</body>
Expand Down

0 comments on commit a81bfe3

Please sign in to comment.