npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

game_functions

v1.0.0

Published

Simple functions for making games, such as vector-cartesian conversion functions and vector transformations.

Downloads

3

Readme

Heya folks. This is my first NPM lib so bear with me. This is a simple library of functions I usually include with my games, so I figured it might be easier to just deply and publish with NPM rather than laboriously copy and paste everything.

All functions in here focus on 2D game development and most involve vectors and their use.

if you want to use any of these in 3D, you'll need to re-add the z-dimension to the resulting vector.

All functions work with objects, that is to say {x:0,y:0} and the like. I don't beleive in the array format of vectors, but because I love people, I included a function to convert between array and objects. It also works exclusively with radians, but has convenient radian to degree convesion functions.

With that being said, here are the functions.

Functions

Lengthdir(length, direction) turns a polar coordinate, distance and a direction, (direction in radians) to a cartesian coordinate. This is extremely useful for game development for lots of reasons. Suffice to say if you're making games you probably want this.

Angle_difference(angle1, angle2) gives you the shortest angular direction from angle1 to angle2, from -pi to +pi.

lerp_distance(p1, p2, dis) gives a point which is dis units from p1, in the direction of p2 from p1.

lerp(p1, p2, percent) gives a point which is percent (value 0-1) of the way from p1 to p2.

dtr(degrees) converts degrees to radians. Very useful if you don't want to do calculations yourself; I use it to add random values.

rtd(radians) converts radians to degrees. Useless except to give human-readable feedback about a given situation.

point_distance(point1, point2) gives standard euclidean distance from point1 to point2.

manhattan(point1, point2) cheapened distance function. Don't try to compare it to numerical values. I mainly use it for Astar pathfinding.

compare_dis(point1, point2, dis) Cheapened distance function used to compare a numerical value to the distance of two points. Cheaper because it avoids the sqrt function. Use only when speed and optimization are very important.

lerp_1d(x1, x2, percent) returns an x value percent (value 0-1) of the way from x1 to x2. so lerp(1,3,.5) would return 2.

unitify(vector) returns a normalized unit vector of the given vector.

rotate_x(vector, direction) when complete, this will do the matrix multiplications to rotate a vector in the X dimension. Useful for 3D or 2d-to-3d transformations.

ar_to_obj(array) transforms the hated array format of vectors to the amazing and perfect json/object format of vectors

random_about(radius) generates a 1D random value from -val/2 to val/2, with mean 0.