UNPKG

verbkit

Version:

verbkit game toolkit

139 lines (103 loc) 3.68 kB
/// <reference path="PixiTS/pixi.d.ts" /> /// <reference path="utils.ts" /> /// <reference path="gameobject.ts" /> class Collidable { debugGraphic:PIXI.Sprite; bounds:Rectangle = new Rectangle(); applicable:GameObject[] = []; position:Vector2 = vec2(0, 0); constructor(x:number, y:number, width:number, height:number) { this.debugGraphic = PIXI.Sprite.fromImage("img/pixel.png"); this.debugGraphic.x = x; this.debugGraphic.y = y; this.debugGraphic.scale.x = width; this.debugGraphic.scale.y = height; this.bounds.x = x; this.bounds.y = y; this.bounds.width = width; this.bounds.height = height; this.position.x = x; this.position.y = y; } contact(gameObject:GameObject = undefined) {} connectedTo(gameObject:GameObject) {} update() { this.debugGraphic.x = this.position.x; this.debugGraphic.y = this.position.y; this.bounds.x = this.position.x this.bounds.y = this.position.y; } } class SpringBoard extends Collidable { power:number = 0; effect:Vector2 = new Vector2(); connector:Connector = new Connector(); constructor(x:number, y:number, width:number, height:number, power:number) { super(x, y, width, height); this.power = power; this.automatic(); } automatic() { this.connector.active = true; } contact(gameObject:GameObject) { if(this.connector.active) { if(gameObject.bounds.intersects(this.bounds)) { gameObject.direction.x = this.effect.x * this.power; gameObject.direction.y = this.effect.y * this.power; } } super.contact(gameObject); } update() { super.update(); } } class ConveyorBelt extends Collidable { power:number = 0; direction:number = 0; connector:Connector = new Connector(); constructor(x:number, y:number, width:number, height:number, power:number, direction:number = 1) { super(x, y, width, height); this.power = power; this.direction = direction; this.connector.active = true; } contact(gameObject:GameObject) { if(gameObject.bounds.intersects(this.bounds)) { gameObject.graphic.y = this.bounds.y - gameObject.graphic.height; if(this.connector.active) { gameObject.graphic.x += (this.direction * this.power); } } super.contact(gameObject); } } class SpikeRow extends Collidable { damage:number = 0; constructor(x:number, y:number, width:number, height:number, damage:number = 1) { super(x, y, width, height); this.damage = damage; this.debugGraphic.tint = 0xff9809; } contact(gameObject:GameObject) { if(gameObject.bounds.intersects(this.bounds)) { gameObject.graphic.y = this.bounds.y - gameObject.graphic.height; if(gameObject instanceof Character && (<Character>gameObject).attributes["health"] !== undefined) { var n:number = <number>(<Character>gameObject).attributes["health"]; n -= this.damage; (<Character>gameObject).attributes["health"] = n; } } } } class Teleportor extends Collidable { destination:Vector2 = new Vector2; constructor(x:number, y:number, width:number, height:number) { super(x, y, width, height); } setDestination(x:number, y:number) { } contact(gameObject:GameObject = undefined) { if(gameObject === undefined) { } } }