Giter Site home page Giter Site logo

tanks's Introduction

tanks

This is an educational programming game. You write some code for your remote controlled tank and hit "Run"!

Pew pew pew

Getting started

Before you start, install and run the app.

Now the fun begins. We'll first create an empty bot. Copy the following code into the editor on the left:

// You can rename the bot!
class MyBot extends Bot {
  create() {}

  update() {}
}

module.exports = MyBot;

Now hit "Run", you should see your tank appear in the game view on the right. Now we can make it do things!

Tank lifecycle

You can see there 2 functions on your tank already. These will be called during the lifecycle of a game.

  1. create() is called when your tank is first created at the start of each game. This is useful for initialising your bot. You can also call commands (explained below) here.
  2. update() is called each "tick" of the game. A "tick" is each frame when the game engine updates the world. It will move all objects and do things like resolve collisions. This is a good place to put any code that you want to run throughout the game (e.g. scanning for changes in the world).

Commands

So what can I do with my tank? Here are the built in Bot functions you can call that will make your tank do things.

// It wouldn't legally be a tank if it couldn't move!
// Use this function to set drive speed between 1 (forward) and -1 (backwards)
// driveSpeed will be clamped at magnitude of 1, no speeding for you!
this.drive(driveSpeed);

// Rotation is as straightforward as specifying a clockwise rotational speed.
// Set `rotationSpeed` to -1 to turn left and 1 to turn right.
this.rotate(rotationSpeed);

// Very similar to tank rotation but will only move your turret.
this.rotateTurret(rotationSpeed);

// Shoots a bullet in the direction your turret is facing.
// Note: there is a reload time for bullets.
this.shoot();

// Scans the worlds and provides a list of objects and their locations
// Use this to find and shoot your enemies. Remember enemies move, so
// you may want to keep scanning to track them
this.scan();

// You can add/remove a marker in the world, it doesn't do anything just looks cool.
// This is useful for debugging if to highlight positions on the map.
// E.g. you can see where you're aiming, or create visual waypoints.
this.setMarker({ x, y });
this.clearMarker();

Modules

There are a few small modules that will help you build your tank logic. And you can add your own!

  • Nav: Sick of writing logic for navigating to things? This is the module for you
  • Bearing: Utility function to make it easier to work with directions. Handles radians + degrees.
  • Point: Measure distances and angles between points.

Modules are accessible at lib.ModuleName

Tips

  • You can log to console from your bot. Open your browser dev tools to see them
  • As long as you have a Bot class that is exported, with implementations for create() and update() you can add whatever code you want! This means storing state in your bot, more bot functions, more classes etc. Go wild!
  • Have fun!

Example

Installation

The game isn't currently hosted but you can run it yourself easily:

yarn
yarn watch
yarn serve

tanks's People

Contributors

haack avatar

Watchers

 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.