1.0.1 • Published 6 years ago

aframe-super-shooter v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

aframe-super-shooter

Simple Shooter Kit for A-Frame.

This is a set of components and systems (under a single file) to provide a way of building simple shooting experiences, where a "shooter" shoots "bullets" that can hit "targets".

diagram

  • One entity bullet defines the look of all the instances of itself that are going to be shot.
  • Shooter defines the source position and orientation of the bullets.
  • Collisions among bullet's and target's bounding boxes are checked.

So you just define which entities are bullets, targets and shooters, and manage the logic among them using events:

Shooter:

  • Emit an event shot on a shooter to make it shoot
  • Emit an event changebullet on a shooter to change active bullet

Target:

  • Listen to event hit on a target to know when it was hit by a bullet
  • Listen to event die on a target to know when its life was finished

API

Shooter component

PropertyDescriptionDefault Value
bulletsarray of bullets (their names) that this shooter can use'normal'
useBulletcurrent bullet used'normal'
cyclewhen changing to next or prev bullet type, cycle to the first or last (resp.) type when reaching the last/first (resp.)false

Bullet component

PropertyDescriptionDefault Value
nameName of this bullet type'normal'
lifeLife that gets from targets when hit1.0
speedIn m/s aprox.1.0
maxTimeWhen this time (in seconds) is elapsed, the bullet dissapears.1.0
cacheSizeHow many copies of this bullet can be on screen at the same time10

Target component

PropertyDescriptionDefault Value
staticThis object moves or changes shape. If static==false, bounding box is recalculated continuouslytrue
lifeInternal life of target. Each time a bullet hits it, this life is reduced by bullet's life, and when it gets <= 0 the event 'die' is emmited to the target0
activeWhether this target is included in collision tests.true

Installation

Browser

Install and use by directly including the browser files:

<head>
  <script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
  <script src="aframe-shooter-component.min.js"></script>
</head>

<body>
  <a-scene>
    <a-entity bullet geometry="primitive: sphere"></a-entity>
    <a-entity target geometry="primitive: box"></a-entity>
    <a-entity shooter id="gun" geometry="primitive: box></a-entity>
  </a-scene>

  <script>
    document.body.addEventListener('mousedown', function(){
      document.getElementById('gun').emit('shoot');
    });
  </script>
</body>

npm

Install via npm:

npm install aframe-super-shooter

Then require and use.

require('aframe');
require('aframe-super-shooter');