GithubHelp home page GithubHelp logo

tblazevic / moonlander Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 2.0 1.68 MB

JavaScript arcade game inspired by Lunar Lander

Home Page: https://tblazevic.github.io/moonlander

CSS 0.22% HTML 1.66% JavaScript 98.12%
javascript threejs lunar-lander moonlander particle-system

moonlander's Introduction

Moonlander [play here]

Gameplay

This game was inspired by Lunar Lander.
The player controls lander rotation and thrusters in order to safely land on the surface.
The player can land on marked areas to earn extra points and fuel.
The game goes on until no fuel is remaining.

game

Technologies used

The game is written in JavaScript and runs entirely on the client side.
Threejs is used for rendering and running the game requires a WebGL enabled browser.

Project architecture

  • constants.js - game, ui and particle parameters
  • globals.js - global variables
  • terrainData.js - terrain points
  • sound.js - sound effects
  • hud.js - HUD code
  • particles.js - particle systems
  • main.js - main game functionality

The lander, terrain and camera

The lander itself is a quad with a texture. Using thrusters does not directly change velocity or acceleration, but jerk, in order to have smoother landings. Horizontal speed is slightly decreasing to enable strategic decisions regarding fuel consumption. Vertical speed is only affected by gravity.

The lander is spawned randomly, with a random horizontal speed forcing the player to use some more fuel before attempting to land.

The terrain is defined through an array of points. Between each pair of points, a quad is positioned, rotated and scaled to connect the two points.

Once the altitude drops below a certain threshold, the camera zooms in and follows the center point between the lander and terrain directly below. It makes the game less static and helps with landing.

Collision detection

The shape of the lander is approximated with 3 circles which makes collision detection easier due to rotation.
Each circle is checked against every line segment defined by the terrain (basic circle-line intersection).

lander

colliders

Upon collision, the landing is safe if 4 conditions are met:

  • velocity magnitude must not be too high
  • rotation angle must not be too high
  • landing terrain must have a slope of 0
  • both landing legs must be grounded

HUD

The HUD is made with a separate scene and camera which are additively rendered on top of the world scene and world camera. It contains score and fuel information on the left, lander parameters on the right and some basic information in the middle. Bonus markings are rendered in world space.

landing

Particle systems

One particle system is attached to the thruster and it emits particles in a cone.
The other one creates a circular explosion when the player crashes.

thruster

explosion

Audio

Audio is played through the HTML5 audio element. There are 4 sounds in the game:

  • crash.mp3 - played on crash
  • morse.mp3 - randomly played every x seconds
  • alarm.mp3 - played every x seconds once the next crash means game over
  • rocket.mp3 - looped while using thrusters

moonlander's People

Contributors

tblazevic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

moonlander's Issues

cheat mode :-)

Given that, more than a game, this is a proof of concept and a study, it would be interesting the possibility to enable/disable a "cheat mode" which shows calculated parabolic trajectory at any instant; a further update would be to have the trajectory as bold as the lander speed in each point.

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.