/**
	 * This class represents a single player / spaceship
	 * on the screen. It creates the required display objects,
	 * and contains logic for movement, shooting and hit detection
	 *
	 * @param   {Game} 	 game A reference to the parent game object
	 * @param   {Number} x    Starting position x
	 * @param   {Number} y    Starting position y
	 * @param   {String} name Name of the player this ship belongs to
	 *
	 * @constructor
	 */
	constructor( game, x, y, name ) {

		// record
		this._record = global.ds.record.getRecord( 'player/' + name );

		// public properties
		this.name = name;
		this.tint = this._getTint();

		// private properties
		this._game = game;
		this._isDestroyed = false;
		this._timeLastBulletFired = 0;
		this._hitHighlightStart = null;
		this._speed = 0;
		this._health = MAX_HEALTH;

		// text
		this._textStyle = { font : '14px Arial', fill: 'rgb(0,255,0)', align : 'center' };
		this._text = new PIXI.Text( name, this._textStyle );
		this._text.anchor.x = 0.5;
		this._text.anchor.y = 0.5;
		this._game.stage.addChild( this._text );

		// container
		this._container = new PIXI.Container();
		this._container.position.x = x;
		this._container.position.y = y;

		// body
		this._body = PIXI.Sprite.fromImage( '/img/spaceship-body.png' );
		this._body.tint = this.tint;
		this._body.anchor.x = 0.5;
		this._body.anchor.y = 0.5;
		this._container.addChild( this._body );

		// turret
		this._turret = PIXI.Sprite.fromImage( '/img/spaceship-turret.png' );
		this._turret.tint = this.tint;
		this._turret.anchor.x = 0.45;
		this._turret.anchor.y = 0.6;
		this._turret.pivot.x = 1;
		this._turret.pivot.y = 7;
		this._container.addChild( this._turret );

		// explosion will be added to stage once spaceship destroyed
		this._explosion = new PIXI.extras.MovieClip( global.EXPLOSION_FRAMES.map( PIXI.Texture.fromImage ) );
		this._explosion.anchor.x = 0.5;
		this._explosion.anchor.y = 0.5;
		this._explosion.loop = false;

		// add spaceship to visible stage
		this._game.stage.addChild( this._container );

		// bind to gameloop
		this._game.on( 'update', this._update.bind( this ) );
	}
Example #2
0
	//create new particles
	createParticles(){
		this.particleUpdater = 0;
		this.particlesContainer = new PIXI.ParticleContainer(500, {
		    scale: true,
		    position: true,
		    rotation: true,
		    uvs: true,
		    alpha: true
		});
		this.addChild(this.particlesContainer);
		this.particles = [];
		for (let i = 0; i < 50; i++)
		{
		    let particle = PIXI.Sprite.fromImage('./assets/particle2.png');
		    particle.anchor.set(0.5, 1);
		    particle.scale.set(1, 1);
		    let angle = (Math.random() * 180 + 90) /180 * Math.PI;
		    particle.x = config.width / 2 + Math.sin(angle) * 100;
		    particle.y = config.height / 2 + Math.cos(angle) * 50;
		    particle.alpha = 0;
		    particle.direction = angle;
		    particle.turningSpeed = 0;
		    particle.speed = 1 + Math.random() * 1.5;
		    this.particles.push(particle);
		    this.particlesContainer.addChild(particle);
		}
	}
Example #3
0
function Image (nodeName) {
  var sprite = pixi.Sprite.fromImage("./bunny.png");
  // var sprite = new pixi.Sprite(new pixi.Texture.fromImage("./bunny.png"), {x:100, y:0, width:26, height:37});
  sprite.anchor.x = 0.5;
  sprite.anchor.y = 0.5;
  Element.call(this, nodeName, sprite);
}
Example #4
0
  function Spring() {
		var texture = PIXI.Texture.fromFrame('Spring.png');
    PIXI.Sprite.call(this, texture); 

    this.update = function() {

    };
 }
Example #5
0
 row.forEach((cell, x) => {
   if (cell === 1) {
     let wall = PIXI.Sprite.fromImage('images/wall_block.png');
     wall.x = x * tileSize;
     wall.y = (y * tileSize) - 16;
     rowContainer.addChild(wall);
   }
 });
Example #6
0
export function loadSprite(name, size) {
  // const texture = Pixi.Texture.fromImage(name);
  const sprite = Pixi.Sprite.fromImage(name);
  if (size) {
    sprite.width = size.x;
    sprite.height = size.y;
  }
  return sprite;
}
Example #7
0
var Tile = function(gid, texture)
{
    PIXI.Sprite.call(this, texture);

    this.gid = gid;

    // tiled always anchors sprites bottom left
    this.anchor.set(0,1);
};
Example #8
0
function Snowball (scale, random) {
  PIXI.Sprite.call(this, snowballsTextures[(snowballsTextures.length * random()) | 0]);
  this.rotation = 2 * Math.PI * random();
  this.pivot.set(32, 32);
  this.scale.set(scale, scale);
  this.dieTimeout = 6000;

  this.box = [0,0,0,0];
}
Example #9
0
var Bar = function() {
  this.view = new PIXI.DisplayObjectContainer();
  this.view.position.y = Config.layout.screenSize.h/Config.layout.scale/2 - 20;

  this.base = PIXI.Sprite.fromFrame('bar_base.png');
  this.base.position.x = -40;
  this.base.position.y = -7;
  this.view.addChild(this.base);

  this.bar = PIXI.Sprite.fromFrame('bar_filling.png');
  this.bar.position.x = -37;
  this.bar.position.y = -4;
  this.view.addChild(this.bar);

  this.cover = PIXI.Sprite.fromFrame('bar_cover.png');
  this.cover.position.x = -40;
  this.cover.position.y = -7;
  this.view.addChild(this.cover);

  this.bar.scale.x = 0;
}
Example #10
0
function TableView() {
	PixiApp.call(this, 640, 960);
	this.backgroundColor = 0xcccccc;

	this.table = PIXI.Sprite.fromImage("./img/table_top.png");
	this.addChild(this.table);

	this.sliderView = new SliderView();
	this.addChild(this.sliderView);

	this.on("resize", this.onResize.bind(this));

	this.loadAssets();
}
Example #11
0
  function Ramp(texture, xPos, yPos) {
    PIXI.Sprite.call(this, texture); 
    this.position.x = Math.floor(xPos);
    this.position.y = Math.floor(yPos);
    this.half_width = this.width / 2;
    this.half_height = this.height / 2;

    this.getCx = function() {
      return this.position.x + this.half_width;
    };

    this.getCy = function() {
      return this.position.y + this.half_height;
    };

    this.update = function() {

    };
 }
Example #12
0
var Projectile = function() {
  this.view = new PIXI.DisplayObjectContainer();
  this.image = PIXI.Sprite.fromFrame('cupcake.png');
  this.image.anchor.x = 0.5;
  this.image.anchor.y = 0.5;
  this.frames = [];
  this.velocity = 0;
  this.eaten = false;
  this.recipe = null;

  this.view.addChild(this.image);

  var i = Config.recipes.length;
  while (i--) {
    var frameId = Config.recipes[i].id + '.png';
    var frame = PIXI.Texture.fromFrame(frameId);
    this.frames[i] = frame;
  }
}
Example #13
0
    _updateEntity(entity) {
        if (!entity.position || !entity.texture) { return; }

        let cacheEntry = this._spriteCache[entity.id];
        if (cacheEntry) {
            cacheEntry.sprite.setTexture(PIXI.Texture.fromFrame(entity.texture.frame));
        } else {
            const sprite = PIXI.Sprite.fromFrame(entity.texture.frame);
            // TODO don't assume anchor point...
            sprite.anchor = { x: 0.5, y: 0.8 };
            cacheEntry = this._spriteCache[entity.id] = {
                sprite: sprite
            };
            this._entityLayer.addChild(sprite);
        }

        cacheEntry.sprite.position = entity.position;
        cacheEntry.visited = true;
    }
Example #14
0
function Player (name, footprints) {
  this.name = name;
  PIXI.Sprite.call(this, playerTexture);
  this.life = 201;
  this.maxLife = 999;
  this.meltingSpeed = 0.0025;
  this.moveSpeed = conf.playerMoveSpeed;
  this.maxMoveBack = 120;
  this.dead = false;
  this.controls = null; // Set me later
  this.vel = [0,0];

  this.position.x = conf.WIDTH / 2;
  this.position.y = conf.HEIGHT - 50;
  this.maxProgress = conf.HEIGHT - this.maxMoveBack - 25;

  this._m = 0;
  this.pivot.set(250, 200);

  if (footprints)
    footprints.addChild(this.footprints = new Footprints());

  this.box = [0,0,0,0];
}
Example #15
0
File: Snowball.js Project: gre/ld31
function Snowball (scale) {
  PIXI.Sprite.call(this, snowballTexture);
  this.scale.set(scale, scale);
}
Example #16
0
  function Rock(texture, posX, yPlacement, height_delta) {
    PIXI.Sprite.call(this, texture); 
    this.gameWidth = FP.getWidth();
    this.setupPositioning(posX, yPlacement, height_delta);
    this.speedIncrease = FP.isMobile() ? FP.GAME_MOBILE_SPEED_INCREASE : FP.GAME_SPEED_INCREASE;
 }
Example #17
0
/* global requestAnimationFrame */

const PIXI = require('pixi.js')
const TweenMax = require('gsap')
// You can use either `new PIXI.WebGLRenderer`, `new PIXI.CanvasRenderer`, or `PIXI.autoDetectRenderer`
// which will try to choose the best renderer for the environment you are in.
var renderer = new PIXI.WebGLRenderer(800, 600)

// The renderer will create a canvas element for you that you can then insert into the DOM.
document.body.appendChild(renderer.view)

// You need to create a root container that will hold the scene you want to draw.
var stage = global.stage = new PIXI.Container()

// Declare a global variable for our sprite so that the animate function can access it.
const bunny = global.bunny = PIXI.Sprite.fromImage('bunny.gif')
bunny.position.x = 400
bunny.position.y = 300

bunny.anchor.x = 0.5
bunny.anchor.y = 0.5

bunny.scale.x = 2
bunny.scale.y = 2

stage.addChild(bunny)

const hat = global.hat = PIXI.Sprite.fromImage('hat.png')
hat.position = {x: 0, y: -25}
hat.scale = {x: 0.1, y: 0.1}
hat.anchor = {x: 0.5, y: 0.5}
Example #18
0
function Tavern () {
  PIXI.Sprite.call(this, beerTexture);
  this.position.x = 2;
  this.position.y = -10;
}
Example #19
0
function Spike() {
  PIXI.Sprite.call(this, spikeTexture);
  this.position.x = 2;
  this.position.y = -10;
}
Example #20
0
    onAssetsLoaded: function(loader, res) {

      var me = this
      var stage = this.stage

      /*-----------------------*/
      // viewcontainer
      /*-----------------------*/
      var viewcontainer = this.viewcontainer = new PIXI.Container()
      stage.addChild(viewcontainer)

      viewcontainer.fadeIn()

      /*-----------------------*/
      // slotbody
      /*-----------------------*/
      var slotbody = this.slotbody = new PIXI.Container()
      viewcontainer.addChild(slotbody)

      slotbody.alpha = 0
      slotbody.position.y = -30

      /*-----------------------*/
      // バー
      /*-----------------------*/
      var bar = this.bar = new PIXI.Sprite(res.bar.texture)
      slotbody.addChild(bar)
      bar.position.x = barpos_active.x
      bar.position.y = barpos_active.y
      bar.anchor.x = 0
      bar.anchor.y = 1

      /*-----------------------*/
      // slotbg
      /*-----------------------*/
      var slotbg = new PIXI.Sprite(res.slotbg.texture)
      slotbody.addChild(slotbg)
      slotbg.anchor.set(0.5)
      slotbg.position.y = 0

      if (util.isMobileNow()) slotbg.scale.set(SCALE_MOBILE, SCALE_MOBILE)

      /*-----------------------*/
      // バーヒット
      /*-----------------------*/
      var barhit = this.barhit = new PIXI.Graphics()
      slotbody.addChild(barhit)
      barhit.beginFill(0xFF4455, 0.0)
        // barhit.lineStyle(1, 0xFF0000)//debug

      if (util.isMobileNow()) {
        barhit.drawRect(0, 0, 100, 100)
        barhit.x = 100
        barhit.y = -130
      } else {
        barhit.drawRect(0, 0, 150, 150)
        barhit.x = 150
        barhit.y = -170
      }

      barhit.interactive = true
      barhit.buttonMode = true
      barhit.on(CLICK, function() {

        me.startBar()
      })

      /*-----------------------*/
      // ベットホルダ
      /*-----------------------*/
      var betholder = this.betholder = new PIXI.Container()
      stage.addChild(betholder)
      betholder.position.x = this.renderer.width / 2
      betholder.position.y = (util.isMobileNow()) ? 10 : 60

      /*-----------------------*/
      // ベット
      /*-----------------------*/
      var betbase = this.betbase = new PIXI.Sprite(res.bet.texture)
      betholder.addChild(betbase)
      betbase.position.x = -120
      betbase.position.y = 40
      betbase.anchor.set(0.5)
      if (util.isMobileNow()) {
        betbase.scale.set(SCALE_MOBILE_BET)
        betbase.position.x = 10

      }

      /*-----------------------*/
      // ベットタイトル
      /*-----------------------*/

      var title_str = '',
        title_color, title_size
      if (this.goodnum_user === null) {
        title_str = 'ログインしないとできないナムよ'
        title_color = 0xff2222

        //フィルタ
        // var filter = new PIXI.filters.SepiaFilter()
        var filter = new PIXI.filters.DotScreenFilter()
        slotbg.filters = [filter]
        betholder.filters = [filter]

      } else if (this.goodnum_user > 0) {
        title_str = 'グッナムをベットするナムよ'
        title_color = 0xffb2b2
        title_size = '18px Arial'
      } else {
        title_str = 'グッナムがないのでできないナムね'
        title_color = 0xff2222
        title_size = '18px Arial'
      }
      var bettitle_txt = new PIXI.Text(title_str, {
        font: title_size,
        fill: title_color,
        align: 'left'
      })
      betbase.addChild(bettitle_txt)
        // bettitle_txt.anchor.x = 0.5
      bettitle_txt.position.x = -180
      bettitle_txt.position.y = -50
        // if (util.isMobileNow()) bettitle_txt.position.set(0, 0)

      /*-----------------------*/
      // minus
      /*-----------------------*/
      var btnsize = 60
      var btnx = -220
      var graphics_hit

      var minus = new PIXI.Container()
      betbase.addChild(minus)

      minus.position.set(btnx, 30)
      minus.interactive = true
      minus.buttonMode = true
      minus.on(CLICK, function() {
        me.removeBet()
      })

      graphics_hit = new PIXI.Graphics()
      minus.addChild(graphics_hit)
      graphics_hit.beginFill(0xFF0000, 0)
      graphics_hit.drawRect(-btnsize / 2, -btnsize / 2, btnsize, btnsize)

      var minus_img = new PIXI.Sprite(res.minus.texture)
      minus.addChild(minus_img)
      minus_img.anchor.set(0.5)

      /*-----------------------*/
      // plus
      /*-----------------------*/
      var plus = new PIXI.Container()
      betbase.addChild(plus)

      plus.position.set(btnx, -30)
      plus.interactive = true
      plus.buttonMode = true
      plus.on(CLICK, function() {
        me.addBet()
      })

      graphics_hit = new PIXI.Graphics()
      plus.addChild(graphics_hit)
      graphics_hit.beginFill(0xFF0000, 0)
      graphics_hit.drawRect(-btnsize / 2, -btnsize / 2, btnsize, btnsize)

      var plus_img = new PIXI.Sprite(res.plus.texture)
      plus.addChild(plus_img)
      plus_img.anchor.set(0.5)

      /*-----------------------*/
      // bet数
      /*-----------------------*/
      var bet_txt = this.bet_txt = new PIXI.Text('0', {
        font: '24px Arial',
        fill: 0xffb2b2,
        align: 'center'
      })
      betbase.addChild(bet_txt)
      bet_txt.anchor.set(0.5)
      bet_txt.position.set(-26, 0)

      /*-----------------------*/
      // 残bet数
      /*-----------------------*/
      var rest_txt = this.rest_txt = new PIXI.Text(this.goodnum, {
        font: '24px Arial',
        fill: 0xffb2b2,
        align: 'left'
      })
      betbase.addChild(rest_txt)
      rest_txt.position.set(155, 0)
      rest_txt.anchor.set(0.5)

      /*-----------------------*/
      // 結果ビュー
      /*-----------------------*/
      this.setView_win(res)
      this.setView_lose(res)

      /*-----------------------*/
      //
      /*-----------------------*/
      var max = 50,
        slotblockH = 160,
        slotblockW = 100
        //ヒットかどうか判定
      var hit = (Math.random() < 0.5) ? true : false
        //ヒットならばヒット番号を決定
      var hitnum = 0
      if (hit) {
        // hitnum = Math.ceil(Math.random()*4)
        var hitary = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4]
        hitnum = hitary.shuffle().pop()
      }

      // var lineholder = new PIXI.Container()

      var slotholder = this.slotholder = new PIXI.Sprite(res.slotmask.texture)
      slotbg.addChild(slotholder)
      slotholder.position.x = -182
      slotholder.position.y = -10
      slotholder.alpha = ALPHA_SLOTHOLDER_DEACTIVE
      slotholder.visible = false

      var slotmask = new PIXI.Sprite(res.slotmask.texture)
      slotbg.addChild(slotmask)
      slotmask.position.x = slotholder.x
      slotmask.position.y = slotholder.y
      slotholder.mask = slotmask

      //結果配列
      var result_list = this.result_list = []
      for (var i = 0, len = 3; i < len; i++) {
        var d = getLine()
        var line = d.line
        line.x = (i * (slotblockW + 10)) + 20
        line.y = slotmarginY - ((max - 3) * slotblockH)
          // line.cacheAsBitmap = true
        slotholder.addChild(line)

        this.lines.push(line)

        //結果を格納
        result_list.push(d.result)

      }

      /*-----------------------*/
      // キャンセル
      /*-----------------------*/
      var btn_cancel = this.btn_cancel = new PIXI.Sprite(res.btn_cancel.texture)
      viewcontainer.addChild(btn_cancel)
      btn_cancel.anchor.set(0.5)
      btn_cancel.position.y = (util.isMobileNow()) ? 170 : 240
        // btn_cancel.alpha = 0
      btn_cancel.interactive = true
      btn_cancel.buttonMode = true
      btn_cancel.on(CLICK, function() {
        btn_cancel.off(CLICK)
        me.hide()
      })

      btn_cancel.fadeIn(1000)

      /*-----------------------*/
      // OK
      /*-----------------------*/
      var btn_ok = this.btn_ok = new PIXI.Sprite(res.btn_ok.texture)
      viewcontainer.addChild(btn_ok)
      btn_ok.anchor.set(0.5)
      btn_ok.position.y = (util.isMobileNow()) ? 150 : 180
      btn_ok.interactive = true
      btn_ok.buttonMode = true
      btn_ok.on(CLICK, function() {
        btn_ok.off(CLICK)
        me.hide()
      })
      btn_ok.alpha = 0
      btn_ok.visible = false

      /*-----------------------*/
      // getLine
      /*-----------------------*/
      function getLine() {
        var result = 0
        var line = new PIXI.Container()

        for (var i = 0, len = max; i < len; i++) {
          var graphics = new PIXI.Graphics()
          line.addChild(graphics)
            // graphics.beginFill(0xFFFFFF)
            // graphics.lineStyle(1, 0xFF0000)
          graphics.drawRect(0, 0, slotblockW, slotblockH)

          graphics.y = i * slotblockH
          graphics.cacheAsBitmap = true

          //ラベル
          var force = null
          if (hitnum > 0 && i === 0) force = hitnum

          var d = getLabel(force)
          var label = d.label
          graphics.addChild(label)
          label.anchor.set(0.5)
          label.x = slotblockW / 2
          label.y = slotblockH / 2
            //結果を判断
          if (i === 0) {
            result = d.num
          }
        }

        return {
          line: line,
          result: result
        }
      }

      /*-----------------------*/
      // getLabel
      /*-----------------------*/
      function getLabel(force) {
        var label
        var num = Math.ceil(Math.random() * 4)
        if (force) {
          num = force
        }
        if (num === 1) {
          label = new PIXI.Sprite(res.slotitem1.texture)
        } else if (num === 2) {
          label = new PIXI.Sprite(res.slotitem2.texture)
        } else if (num === 3) {
          label = new PIXI.Sprite(res.slotitem3.texture)
        } else {
          label = new PIXI.Sprite(res.slotitem4.texture)
        }

        // ret = new PIXI.Text((rnd) + 'ナム', {
        //     font: '34px Arial',
        //     fill: color,
        //     align: 'center'
        //   })

        return {
          label: label,
          num: num
        }
      }

      this.onresize()

      /*-----------------------*/
      // start
      /*-----------------------*/
      me.start()
    },
Example #21
0
 function Main(puffName) {
   var texture = PIXI.Texture.fromFrame(FP.PLANE_PATH + puffName + '.png'); 
   PIXI.Sprite.call(this, texture);
 }
Example #22
0
File: Foot.js Project: gre/ld31
function Foot (width) {
  PIXI.Sprite.call(this, footsTextures[~~(Math.random()*footsTextures.length)]);
  this.rotation = Math.random() * 2 * Math.PI;
  this.pivot.set(12, 12);
  this.height = this.width = width;
}
Example #23
0
 function TapRightLabel(tapType, options) {
   this.options = options || {};
   this.texture = PIXI.Texture.fromFrame(FP.UI_PATH + tapType + '.png'); 
   PIXI.Sprite.call(this, this.texture);
   this.setupDimention();
 }
Example #24
0
File: MapTile.js Project: gre/ld31
function MapTile (index) {
  PIXI.Sprite.call(this, mapTextures[index % mapTextures.length]);
};
Example #25
0
function DebugSprite (observe) {
  PIXI.Sprite.call(this, debugTexture);
  this.o = observe;
}
Example #26
0
 each(tiles, tile => {
     const sprite = PIXI.Sprite.fromFrame(gameMap.name + "-" + tile.id);
     sprite.anchor = { x: 0.5, y: 0.5 };
     sprite.position = { x: i * gameMap.tileWidth, y: j * gameMap.tileHeight };
     this._mapLayer.addChild(sprite);
 });