Skip to content

gumuz/robojs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RoboJS - Robocode in Javascript

About

This is a fork of Robojs, which is a clone of Robocode. Built using Javascript & CoffeeScript using HTML5 Canvas and Web workers.

Demo

You can check out how it works on http://murilopolese.github.io/robojs/

Build your own bot

Create a folder called bots on the root of this repo and create your custom bots there. You can check some examples of bots like the Scan Bot.

After that, open the index.html and search for this part of the code:

BattleManager.init(ctx, [
	"js/scan-bot.js",
	"js/scan-bot.js",
	"js/scan-bot.js",
	"js/scan-bot.js"
]);
BattleManager.run();

Add, change or remove the lines where it says js/scan-bot.js for bots/yourbot.js.

How does it work?

Every Robot runs in it's own Web Worker thread. A robot sub-classes a base robot which handles the worker/event-loop communication and event propagation. The new robot just has to implement behaviour using call-backs, reacting on possible events:

importScripts('base-robot.js');

ScanBot = BaseRobot;

ScanBot.run = function() {
	var robot = this;
	robot.shoot();

	robot.turn_turret_right(45);
	robot.move_forward(Math.random()*400, {
		DONE: function() {
			robot.shoot();
			robot.turn_right(Math.random()*90, {
				DONE: function() {
					robot.shoot();
					robot._run();
				}
			});
		},
		ENEMY_COLLIDE: function() {
			robot.shoot();
			robot.move_backward(100, {
				DONE: function() {
					robot._run();
				},
				WALL_COLLIDE: function() {
					robot._run();
				}
			});
		},
		WALL_COLLIDE: function() {
			robot.turn_left(180, {
				DONE: function() {
					robot.shoot();
					robot._run();
				}
			});
		}
	});
}

About

robocode javascript clone

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published