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

@mrfrase3/ts-invaders

v0.1.2

Published

browser-based space invaders

Downloads

2

Readme

👾 TS Invaders 👾

Description

A Typescript re-write/refactor/overhaul of a space invaders codepen I found

Original CodePen by Anthony Del Ciotto Gist By insipx

Example

Features

  • fully typed
  • importable by other projects, just feed it a canvas element
  • fairly configurable and simple to use
  • improvements for optimisation/memory leaks (entity recycling, etc)
  • 4.0kB compressed

TODO

  • [ ] add space ships
  • [ ] add barriers
  • [ ] allow configuring colors

Installation

  1. TBA

Usage

import TSInvaders from 'ts-invaders';

const canvas = document.getElementById('game-canvas');
const game = new TSInvaders(canvas, { /* config go here */ });
game.start();

// later on
game.destroy();

You can check out the example code here

The main class has the following methods:

  • constructor(canvas: HTMLCanvasElement, config: InvaderConfig = {})
  • async start(): Promise<void> (async loads assets)
  • destroy(): void (cleans up event listeners)

The InvaderConfig has the following:

export interface InvaderConfig {
  // where to get the sprite PNG from
  spriteUrl?: string; // 'https://mrfrase3.github.io/ts-invaders/sprites.png'
  // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code
  leftKeys?: string[]; // ['ArrowLeft', 'KeyA']
  rightKeys?: string[]; // ['ArrowRight', 'KeyD']
  fireKeys?: string[]; // ['Space', 'KeyW', 'ArrowUp']
  textBlinkFrequency?: number; // 750 (ms)
  playerLives?: number; // 3
  scores?: ScoreMap; // see below
  font?: string; // 'monospace'
  title?: string; // 'TS Invaders'
  startText?: string; // 'Press space to play!'
  // methods to get/set the high score from somewhere
  // defaults to local storage under 'invaders-high-score'
  getHighScore?: () => number;
  setHighScore?: (score: number) => void;
}

const defaultScores: ScoreMap = {
  'alien-kill': 25, // when you kill an alien
  'player-kill': 0, // when an alien kills you
  'wave-clear': 500, // when you complete a wave (get rid of all visible aliens)
  'wave-modifier': 1, // increases alien-kill each wave by a multiple (kill * wave * modifier) 0 to disable
};

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a new branch: git checkout -b feature/your-feature
  3. Make your changes and commit them: git commit -m "Add your feature"
  4. Push to the branch: git push origin feature/your-feature
  5. Submit a pull request

License

This project is licensed under the MIT License.

Contact