Git Product home page Git Product logo

benhammondmusic / tanks Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 8.03 MB

Multiplayer, animated artillery game in JavaScript, JQuery, and HTML Canvas; built in one week. Incorporated programmatically generated terrain and destruction when collision detected, gravity for tank placement, scalable multiplayer mode, and responsive, accessible design.

Home Page: https://benhammondmusic.github.io/tanks/

CSS 8.32% HTML 23.31% JavaScript 68.37%
javascript jquery canvas jcanvas artillery-game tank-game

tanks's Introduction

Tanks! by benhammond.tech

Play the Game!

Screen recording showing game play

Concept:

"What goes up must come down..."

Players take turns lobbing projectiles; anyone sustaining a hit is destroyed. Last one standing wins!

Screenshots/Wireframe:

Most Recent Screenshot Textured screenshot showing a sunset background and a bullet exploding in multiplayer mode

Progress Screenshot Screenshot showing a tank exploding in multiplayer mode

Initial Wireframe Initial Hand Drawn Wireframe

Tech:

- HTML
- CSS / Bootstrap
- JavaScript / jQuery
- HTML Canvas / jCanvas

Approach:

As a kid Tank Wars was an early favorite, and the simple yet compelling game play seemed perfect for my first JS project. Some initial googling of simple games introduced me to HTML Canvas as a well supported, thoroughly documented way to draw shapes and lines in the browser. It was important for me to get started quickly with a simple version, while also having the ability to make the game more complex and detailed if time allowed.

Challenges:

One of the first challenges was simply learning HTML Canvas itself; some ideas that may be standard in animation seemed quirky (e.g. rotating the canvas, drawing a straight line, and rotating back to accomplish an angled line). I got a lot of initial ideas from studying simple JS clock animations.

A second challenge came in implementing the actual physics and math to calculate a projectile's path. While fairly straightforward and well documented in high-school course websites, it took some work translating the physics (gravitational vertical acceleration) and trigonometry (SIN, COSIN) speak into my computer code.

Animation was also problematic; converting my static drawing loops into smooth animations was important for gameplay but eluded me. jCanvas proved to be a helpful library for using jQuery methods to create, manipulate, and importantly animate things drawn with HTML Canvas. I decided to overlay two canvas elements: the first with static background images I'd already made with traditional canvas, and the second with animations using the jCanvas library.

Known Bugs and Wonkiness Being Fixed:

  • Stretch cloud image to fill screen regardless of screen width
  • Need to refactor and separate graphics from logic... they are too intertwined.
  • Terrain generation and drawing needs to be scoped out of game.newGame() to make Change Terrain button.operational, and to allow New Game button to start play on existing terrain.
  • Display explosion after shot lands.
  • Modal flashes the Resume button on ENTER initial screen. ENTER functionality in general.
  • Animation timing in general.
  • Mobile resizing / zooming / clicking. Disable double tap to zoom, etc.
  • Refactor my hack fix for the kill left - skip right bug.

Future Ideas:

Graphics

  • Flatten terrain directly below tanks.
  • More animations (tank dropping down into place).
  • Add chem trails to see last shot. Slow fade out?
  • Make craters more jagged, more visually interesting (color?).
  • Utilize more actual images.
  • Use some Bézier/Quadratic curves for terrain instead of all straight lines.
  • Add snow capped mountains.
  • Add Trees.

Responsiveness / UI

  • Split bootstrap button on new-game to change num players.
  • Make mobile responsive and playable with on-screen controls to fire keyboard inputs.
  • Add touch functionality for better mobile game-play.
  • Save current number of players at game start into local storage so game refresh with the same.

Logic / Game Play

  • Add computer logic for Robot players.
  • Adjust max shot deltaX deltaY based on screen size (better game play if bullet isn't above screen very much).
  • Give tanks more than 1 starting hitpoint; require multiple shots to kill, damage based on shot proximity. Falling could harm tank as well.
  • Randomize starting player. Weight towards those in the middle since they are most in danger?
  • Spread tanks further apart, rather than evenly spaced.
  • Allow shots off screen horizontally to wrap back from other side?
  • Allow shots that hit bottom of screen (where ground has been destroyed to bounce).
  • Integrate terrain steepness? Increase as gameplay continues in multiple rounds?
  • Keep running tally of player wins; allow names for players. Allow custom tank objects.
  • Build your own level: click on screen to add terrain nodes. Place your own tanks like in Settlers of Catan.
  • Add Day/Night displays, with limited visibility.
  • Add wind to buffet shots around horizontally. Trees could indicate wind-direction and velocity.

Resources

External Libraries

  • KeyDrown.JS - Library to speed up user held keys.
  • jCanvas.JS - Library to use jQuery on HTML Canvas (easier animations).
  • PleaseRotate.JS - Library to politely ask user to rotate phone to landscape.

Blog

Read more at blog.benhammond.tech

Install Instructions

  • Visit the link below and play in Chrome browser with javascript enabled. Safari seems to work as well. Works best on a desktop computer using the keyboard, but limited mouse/touch integration also allows game play via mobile and other devices.

App Demo

tanks's People

Contributors

benhammondmusic avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

uspa-technology

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.