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

squids

v6.1.2

Published

Squids is a 2D library for developing games for web browsers that is extremely easy to learn and use.

Downloads

15

Readme

Squids

A 2D Library for web games

What?

At its core, Squids is an abstraction of the Canvas API. It aims to be accessible to beginners and extensible for experts.

How?

Lets start with an example: /example

Start by making an index.html and including Squids.

<!-- index.html -->
<!doctype html>
<html>
	<body>
		<script src="squids.min.js"></script>
		<script src="game.js"></script>
	</body>
</html>

That gets you all of Squids (Graphics), Sleepless Lib (Utilities), and Howler (Sound)

Next, lets load an image and display it on screen:

// game.js
// vec is short for vector
let screen = vec(canvas.width, canvas.height);

load_image("squid.png", function(image)
{
	// We make a new Squid object to store and control our image
	let squid = new Squid(screen.dup().div(2), image);
	// screen.dup().div(2) gives us a new vector duplicated from screen divided by two
	// this is the center of our screen

	// lets scale our image down a bit
	squid.scale = 0.5;


	// this vector will be the direction our squid will be moving on the x and y axis
	let direction = vec(1, 1);

	// our squid is drawing automatically on the screen now, but if we want our squid to move
	// we need to have it "listen" for a tick event
	squid.listen("tick", function(delta, num_ticks)
	{
		// now we can make our squid do something
		// lets make it move to the right

		let speed = delta / 100;
		squid.velocity.x += direction.x * speed;
		squid.velocity.y += direction.y * speed;

		// now our squid is really fast, so let's add some friction
		squid.velocity.mlt(0.90, 0.90);

		// let's bounce off the walls as well
		if(squid.position.x + (squid.image.size().x * squid.scale) / 2 >= screen.x)
		{
			direction.x = -1;
		}

		if(squid.position.x < (squid.image.size().x * squid.scale) / 2)
		{
			direction.x = 1;
		}

		// let's bounce off the floor and ceiling as well
		if(squid.position.y + (squid.image.size().y * squid.scale) / 2 >= screen.y)
		{
			direction.y = -1;
		}

		if(squid.position.y < (squid.image.size().y * squid.scale) / 2)
		{
			direction.y = 1;
		}
	});

	// to make everything start running... we need to tell squids to start ticking
	tick(true);
});

input

If you want to detect input, by default, Squids will track mouse position and keys that are currently pressed down. You can query the mouse position quite easily:

let mouse_pos = vec(mouse_x, mouse_y);

Getting keys down is also simple:

// keys stores each key as an object with the value of either true or false for down/up
// {a: false, space: true} - true being DOWN, and false being UP
let is_space_down = keys["space"];
let is_akey_down = keys["a"];

Listeners

These are the order that listeners are called:

  • pretick
  • tick
  • posttick
  • prephysics
  • postphysics
  • precollide
  • collide
  • postcollide
  • draw
  • draw0
  • draw1
  • draw2
  • draw3
  • draw4

multiple draw calls allow placing squids on different "layers". draw5 will draw ON TOP of draw4 etc...

There are also listeners for body events:

  • resize
  • mousedown
  • mouseup
  • mousemove
  • keyup
  • keydown
  • blur
  • focus

Why?

We believe that making web based games should be easy and fun. Most games are just images moving on a screen and reacting to input, so that's what we built. Also, we do it for fun, and hope that others enjoy it as well. :)