Catalog npm
Back to packageRELEASE DETAILS

1.2.1

npm

2d-gaming

This is an Angular package fo developing 2d games in angular. [Please Give Feedback Here](https://cwestblue.github.io/deployWeb/forms).

2dangualr4angularangular2canvascreatedrawgamegaminghtmlmakephysicstypescripttweens
Published13 Apr 2017
Direct dependencies28
Transitive dependenciesNot calculated

README

Current package documentation

2d-gaming

Description

This is an Angular package fo developing 2d games in angular. Please report issues/questions/any ideas to better help this package.

Installing

  1. Run npm instll 2d-gaming
  2. Import { TwoDGaming } from '2d-gaming'; Into your module
  3. Import { GameAreaObject, ObjectComponent, ObjectDesign, PositionObject } from '2d-gaming' into the file of your game.

Getting Started

Setup your game
  1. Setup your game area. Each area object will have a name, width, height and gravity.
First Create Your Game Object
    // Create A New File gameArea.ts
    import { GameAreaObject } from '2d-gaming';

    export class GameArea implements OnInit{

        component: GameAreaObject;

        constructor() {
            this.component = new GameAreaObject('myGame', '300px', '300px');
            this.game.gravity = 0;
        }
    };
Then SetUp Your Object In Your Component
// Create A New File game.component.ts
  import {GameAreaObject, ObjectComponent, ObjectDesign, PositionObject, ObjectArray } from '2d-gaming';
  import {GameArea} from './gameArea.ts':
  @Component({
      selector: 'app-game',
      templateUrl: './game.html'
  })

  export class GameComponent implements OnInit {
      gameObject: GameArea

      ngOnInit() {
          this.gameObject = new GameArea();
          this.gameObject.component.doEveryFrame = (() => this.doPerFrame());
      }

      start() {
          this.gameObject.component.start(); // this starts the game
      }

      stop() {
          this.gameObject.component.stop(); // this stops and resets the game
      }

      doPerFrame() {
          // put code here you want to run everyFrame
      }
  }

<!--- In game.html Place This-->
<app-game-area></app-game-area>
<button (click)="start()">Start</button>
  1. Now lets add a player.
// Create A New File player.ts
  import {GameAreaObject, ObjectComponent, ObjectDesign, PositionObject } from '2d-gaming'

  export class Player {
      component: ObjectComponent;
      position: PositionObject;
      design: ObjectDesign;

      constructor(public game: GameAreaObject) {
          this.design = new ObjectDesign(20, 20, 'square', 'green'); // create a design. we will add this to our player
          this.position = new PositionObject(150, 150); // create a position object. we will add this to our player
          this.component = new ObjectComponent(this.game, this.design, this.position) // add the design and position to the player.
          // we inject a gameObject into the constructor so the player can know what game it belongs to
      }
  }

Now SetUp the player in the component
  // back in game.component.ts
  gameObject: GameArea;
  playerObject: Player; //Import Player from the previous file

  ngOnInit() {
      this.gameObject = new GameArea();
      this.playerObject = new Player(this.gameObject.component); // Create a new Instance of it and inject the component of the gameObject in its constructor
  }
  1. Lets give our player movement.
// Im using HostListener. You can use another event detection if you pefer
   @HostListener('document:keyup', ['$event'])

  onKeyup(e: KeyboardEvent) {
      const code = e.keyCode;
      this.playerObject.component.clearMovement();
  }

  @HostListener('document:keydown', ['$event'])

  onkeydown(e: KeyboardEvent) {
      const code = e.keyCode;
      // D Key
    if (code === 68) {
        this.playerObject.component.moveRight(1.5); // move right
    }
    // A Key
    if (code === 65) {
        this.playerObject.component.moveLeft(1.5); //move left
    }
    // W Key
    if (code === 87) {
        this.playerObject.moveUp(1.5); // move up
    }
    // S Key
    if (code === 83) {
        this.playerObject.component.moveDown(1.5); // move down
    }
  }
  1. Lets add an object that will move from one point to another. To do this we set object.path. The path object has a x and y value for the points you want your object to move to.
// Create a new file item.ts
import {GameAreaObject, ObjectComponent, ObjectDesign, PositionObject, IPath } from '2d-gaming'

  export class item {
      component: ObjectComponent;
      position: PositionObject;
      design: ObjectDesign;

      constructor(public game: GameAreaObject) {
          this.design = new ObjectDesign(20, 20, 'square', 'red'); // create a design. we will add this to our object
          this.position = new PositionObject(100, 100); // create a position object. we will add this to our object
          this.component = new ObjectComponent(this.game, this.design, this.position) // add the design and position to the object.
          // we inject a gameObject into the constructor so the object can know what game it belongs to
          this.component.newPath = {
              x: 200, // New X Pos
              y: 200, // New Y Pos
              speed: 1, // Speed It Moves At
              infinit: false // If it stops at designated location or continue after
          }
      }
  }
add the object to our component
  gameObject: GameArea;
  playerObject: Player; //Import Player from the previous file
  movingObject: item; //Import item from the previous file

  ngOnInit() {
      this.gameObject = new GameArea();
      this.playerObject = new Player(this.gameObject.component); // Create a new Instance of it and inject the component of the gameObject in its constructor
      this.movingObject = new item(this.gameObject.component)
  }
Now Run And click Start

Objects In Package

Initialize each object like this

   var Init = new Object();

ObjectComponent

CallDescriptionParamaters
draw()draws the object on the canvasnone
shoot()shoots the bulletsnone
nameDescription
gamethe gameArea it belongs to
designa designObject
positiona PositionObject
movementa Movement Object
bulletsitems your wanting to shoot
scorehow points stored in this object
isBarrierif object is a barrier

DesignObject

NameDescription
shapeis type image, square, circle, text
widthwidth of the connected object
heightheight of the connected Object
coloris a color unless shape is image then is an image url
textthe text of an text shape

PositionObject

NameDescription
xPosx position
yPosy position

MovementObject

NameDescription
speedYthe speed of the object on the y axis
speedXspeed of object on x axis
gravitygravity of object
positiona PositionObject
NameDescriptionparamater
moveright()moves object rightspeed: number
moveLeft()moves object leftspeed: number
moveUp()moves object upspeed: number
moveDown()moves object downspeed: number
newPosmoves object to new locationxPos: number, yPos: number, speed: number, infinit: boolean

GameComponent

callDescriptionParamaters
.start()starts the gamenone
stop()stops the gamenone
.clear()clears the game areanone
.doEveryFrame()runs every framefunction
.everyinterval()returns true or false. Do somthing every intervalnumber for when you want the interval to be set at
nameDescription
framethe current frame your on
areaThe element container of the game
gravitythe gravity of the game
crashHandlerhandles collides in game
heightheight of the game
widthwidth of the game
gameObjectsall objects in game
namename of the game

ObjectArray

This is a object that lets have multiple objects in one. Its main purpose is to create multiple intances of one object.
callDescriptionParamaters
add()Adds an Objectitem: ObjectComponent
addMulti()Adds array of objectsitems: ObjectComponent[]
multiply()adds multiple instances of one objectitem: ObjectComponent, howMany: number
removeFromGame()removes its items from the gamenone
nameDescription
itemsarray of objectcomponents

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 28

Native requirements
28 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@angular/common
Environment
{
  "local_name": "@angular/common",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
@angular/compiler
Environment
{
  "local_name": "@angular/compiler",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
@angular/core
Environment
{
  "local_name": "@angular/core",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
@angular/forms
Environment
{
  "local_name": "@angular/forms",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
@angular/http
Environment
{
  "local_name": "@angular/http",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
@angular/platform-browser
Environment
{
  "local_name": "@angular/platform-browser",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
@angular/platform-browser-dynamic
Environment
{
  "local_name": "@angular/platform-browser-dynamic",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
@angular/router
Environment
{
  "local_name": "@angular/router",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
core-js
Environment
{
  "local_name": "core-js",
  "alias": false,
  "peer_metadata": null
}
^2.4.1runtime
rxjs
Environment
{
  "local_name": "rxjs",
  "alias": false,
  "peer_metadata": null
}
^5.1.0runtime
zone.js
Environment
{
  "local_name": "zone.js",
  "alias": false,
  "peer_metadata": null
}
^0.8.4runtime
@angular/cli
Environment
{
  "local_name": "@angular/cli",
  "alias": false,
  "peer_metadata": null
}
1.0.0development
@angular/compiler-cli
Environment
{
  "local_name": "@angular/compiler-cli",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development
@types/jasmine
Environment
{
  "local_name": "@types/jasmine",
  "alias": false,
  "peer_metadata": null
}
2.5.38development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
~6.0.60development
codelyzer
Environment
{
  "local_name": "codelyzer",
  "alias": false,
  "peer_metadata": null
}
~2.0.0development
jasmine-core
Environment
{
  "local_name": "jasmine-core",
  "alias": false,
  "peer_metadata": null
}
~2.5.2development
jasmine-spec-reporter
Environment
{
  "local_name": "jasmine-spec-reporter",
  "alias": false,
  "peer_metadata": null
}
~3.2.0development
karma
Environment
{
  "local_name": "karma",
  "alias": false,
  "peer_metadata": null
}
~1.4.1development
karma-chrome-launcher
Environment
{
  "local_name": "karma-chrome-launcher",
  "alias": false,
  "peer_metadata": null
}
~2.0.0development
karma-cli
Environment
{
  "local_name": "karma-cli",
  "alias": false,
  "peer_metadata": null
}
~1.0.1development
karma-jasmine
Environment
{
  "local_name": "karma-jasmine",
  "alias": false,
  "peer_metadata": null
}
~1.1.0development
karma-jasmine-html-reporter
Environment
{
  "local_name": "karma-jasmine-html-reporter",
  "alias": false,
  "peer_metadata": null
}
^0.2.2development
karma-coverage-istanbul-reporter
Environment
{
  "local_name": "karma-coverage-istanbul-reporter",
  "alias": false,
  "peer_metadata": null
}
^0.2.0development
protractor
Environment
{
  "local_name": "protractor",
  "alias": false,
  "peer_metadata": null
}
~5.1.0development
ts-node
Environment
{
  "local_name": "ts-node",
  "alias": false,
  "peer_metadata": null
}
~2.0.0development
tslint
Environment
{
  "local_name": "tslint",
  "alias": false,
  "peer_metadata": null
}
~4.5.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
~2.2.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "b6351ba388faa07ece5e0c558e85f292a085cc5c",
  "tarball": "https://registry.npmjs.org/2d-gaming/-/2d-gaming-1.2.1.tgz",
  "integrity": "sha512-tdnZDMBJoRtS9osbe9xrAjFAwJUWoBtZ5DJea2M6/bA4YymRvvhsAfdAYVzr9f6LLrK0e5x7FoMynNJwA5y46w==",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIH6mvMyfDPjGxLAQ+OOiU4Zneu6mcUeDBOsT5/Mj7MNXAiBugGHHeI5atY/LH5mb6o8Lov3AQgn7fe0/a1uYOCtteQ=="
    }
  ]
}

Repository

PENDING
cwestblue/2d-gaming

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:10 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:af6dfc8688be06ac0fb3ee4bbfbbdb84be1fb1a5f9bb9d368e36dc53426e28b7

Other collected versions

2.1.011 May2.0.310 May2.0.210 May2.0.110 May2.0.09 May1.8.102 MayView all collected versions →