Skip to main content

Your First Tank

Basics

Clone the template repository of your preferred language.

Language
Python
Rust
Dart
Java
Javascript

You will edit the file within tanks/ to create your tank. You may create as many tanks as you wish, however each tank's code must be in its own file and follow some basic requirements. These are usually the imports at the top of the file, the tank class, the run() and onEvent() tank methods, and the createTank() method that returns a instance of your tank.

spin_bot.py
from codetanks import BaseTank, commands

class MyTank(BaseTank):
"""Simple Python spinning tank
"""

def __init__(self):
super().__init__()

self.direction = 0

print('Running my spinning tank!')

def run(self):
if self.direction % 2 == 0:
self.commands.append(commands.MOVE_BACKWARD | commands.ROTATE_TANK_COUNTER_CLOCKWISE | commands.FIRE)
else:
self.commands.append(commands.MOVE_FORWARD | commands.ROTATE_TANK_CLOCKWISE | commands.FIRE)

def on_event(self, event):
self.direction = self.direction + 1

def create_tank():
"""Return an instance of your tank
"""
return MyTank()

This a basic tank that spins and fires. Upon any event, it will spin in the opposite direction. For more details, check out Anatomy, Physics & World, Commands, Debugging, Events, and Game Engine Logic.

Building

To build your code

build.sh my_tank.py

Running

ctdesktop TANK_HASH ANOTHER_TANK_HASH ETC_TANK_HASHES

You may enter multiple tank hashes as well as duplicate tank hashes.