Code Monkey home page Code Monkey logo

solar-lander's Introduction

Solar-Lander

a small java orbit-sim project using the libGDX framework with a controllable lander

Keybinds

WASD : Movement
V (HOLD) : Show Force Vectors of Lander(redundant, see bottom boxes)
Space (HOLD) : Show Hitboxes
Z (HOLD) : -10x Zoom Out
X (HOLD) : -100x Zoom Out

How it Works

Physics

The program uses primarily uses two physics equations to determine orbits and velocities

(1). The Law of Gravitation: F = G * (m1 * m2) / r^2

  • F is the gravitational force between the two objects/planets
  • G is the universal gravitational constant, 6.674 x 10^-11
  • m1 and m2 are the masses of the two objects
  • r is the distance between the center of mass for each object.\

(2). Orbital Velocity: V = SQRT((G * M) / R)

  • V is the orbital velocity
  • G is the universal gravitational constant, 6.674 x 10^-11
  • M is the mass of the central body(assuming orbiting body has insignificant mass in comparison)
  • R is the distance between the center of mass for each object.

Code

Generation

  • the program starts by generating an array of solarObjects solarSystem[]
  • solarSystem[0] is reserved for the central body / sun
  • other planets are generated with random radii [700 - 200] and corresponding mass based on (4/3) * pi * (radius)
  • then it gets assigned a random position between [10,000 , 0] and [10,000 , 10,000]
  • if the planet fails orbitCheck() (it overlaps another planet) it gets new properties
  • planets are assigned a starting velocity based on equation (2)
    • by default the starting velocity puts them into a perfect circular orbit

Game-Loop

  • position and velocity changes are calculated for both lander and solarSystem[]
  • the main viewport extendView is updated and the lander sprite are rendered with a SpriteBatch
  • planets and other objects are rendered using a ShapeRender object on extendView
  • the ui/labels are then updated and rendered on viewport screenView
  • the minimap viewport miniView is updated and has the scaled down system rendered within

solar-lander's People

Contributors

charleco 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.