Code Monkey home page Code Monkey logo

vectron's Introduction

vectron

simple vector-based game engine, made with node-sdl

the engine itself runs on 128x128 resolution, but rescales to fit current window

basic usage

node index.js path, where path is the path to the app file

if no path is specified, it will default to apps/demo.js

api reference

apps run at 50 FPS by default, that can be changed by setting __FRAMERATE and including in the export

  • class Vector
    • basic line segment object

    • constructor(Number x1,Number y1,Number x2,Number y2): Vector
    • Vector.prototype.draw()

      • Renders a white line segment from (x1,y1) to (x2,y2)
      • A line segment is only rendered for 1 frame
    • Vector.intersect(Vector v1,Vector v2)

      • Checks if v1 intersects with v2
    • Vector.isBetween(Vector v1, {x: Number, y: Number})

      • Checks if point (x,y) is part of v1
    • Vector.isEdgeTouching(Vector v1, Vector v2)

      • Checks if any of both edges from v1 touch any point from v2
    • Vector.(add/sub/mul/div)(Vector v1, Vector v2)

      • Adds, subtracts, multiplies or divide v1 by v2
  • keydown(String key): Boolean

events

every single event gets runs with this set to {Vector,keydown}, so both Vector and keydown are only accessible from inside the functions

  • start()
    • This function only runs once, at the start of the execution of the app
  • update(dt)
    • This function executes every frame of the app, with a deltaTime argument
  • fixedupdate(fdt)
    • This function executes with a constant framerate, regardless of the current window framerate, with a fixedDeltaTime argument
  • end()
    • This function executes before the current window closes (great for destroying Speaker instances)

example app

//generates lines randomly scattered around the screen

const __FRAMERATE = 50

const start=()=>{}
const end=()=>{}
const fixedupdate=()=>{}

function update(){
    const r=()=>Math.floor(Math.random()*128)
    const v = new this.Vector(r(),r(),r(),r())
    console.log(v)
    v.draw()
}

module.exports={start,end,fixedupdate,update,__FRAMERATE}

i suck at explaining shit ongodd

vectron's People

Contributors

shidemuri avatar

Watchers

 avatar

vectron's Issues

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.