GithubHelp home page GithubHelp logo

jaimejorge / robojs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gumuz/robojs

0.0 1.0 0.0 1.34 MB

robocode javascript clone

License: MIT License

CoffeeScript 30.98% JavaScript 62.62% HTML 6.41%

robojs's Introduction

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();
				}
			});
		}
	});
}

robojs's People

Contributors

murilopolese avatar gumuz avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.