Skip to content

Commit

Permalink
Merge pull request #16 from FlyingPiMonster/actionlog
Browse files Browse the repository at this point in the history
Adds most of the actions from #7.
  • Loading branch information
ricochet1k authored May 19, 2017
2 parents 6d9cffc + 3caeb09 commit 00ebc1f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 17 deletions.
62 changes: 57 additions & 5 deletions src/scripts/actions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {SQUARE_SIZE, TWEEN_DURATION} from './const';
import {SQUARE_SIZE, TWEEN_DURATION, S} from './const';
import {tween, tweenRotation, interp} from './tween';

export function actionLine(room, action, from, to) {
export function actionLine(room, action, from, to, color = 0xffff00) {
let g = new PIXI.Graphics();
room.g.addChild(g);

const color = 0xffff00;

const fx = (from.x + 0.5) * SQUARE_SIZE;
const fy = (from.y + 0.5) * SQUARE_SIZE;
const tx = (to.x + 0.5) * SQUARE_SIZE;
Expand Down Expand Up @@ -47,4 +45,58 @@ export function bump(g, gRot, obj, a) {
g.x = SQUARE_SIZE * interp(x, a.x, v);
g.y = SQUARE_SIZE * interp(y, a.y, v);
});
}
}

export function flash(container, color = 0xffff00) {
let g = new PIXI.Graphics();
g.position.set(S(5), S(5));
g.pivot.set(S(5), S(5));
container.addChild(g);

g.clear();
g.beginFill(color);
g.drawCircle(S(5), S(5), S(5));
g.endFill();

tween(TWEEN_DURATION, {}, v => {
if (v === 1) {
container.removeChild(g);
return;
}

if (v < 0.5) {
v = v;
} else {
v = (1 - v);
}

g.alpha = v;
});
}

export function say(container, text) {
const textBubbleStyle = {
fontSize: S(5),
};

var text = new PIXI.Text(text, textBubbleStyle);

var bubble = new PIXI.Graphics();
bubble.beginFill(0xFFFFFF, 1);
bubble.drawRoundedRect(0, 0, text.width, text.height, 3);
bubble.endFill();

bubble.position.set(S(5) - (text.width / 2), -S(5));
text.position.set(S(5) - (text.width / 2), -S(5));

container.addChild(bubble);
container.addChild(text);

tween(TWEEN_DURATION, {}, v => {
if (v === 1) {
container.removeChild(text);
container.removeChild(bubble);
return;
}
});
}
9 changes: 7 additions & 2 deletions src/scripts/objects/tower.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ export default class Tower extends GameObject {
switch (k) {
case 'repair':
case 'build':
case 'attack':
actionLine(room, k, {x: obj.x, y: obj.y}, a);
break;
case 'heal':
actionLine(room, k, {x: obj.x, y: obj.y}, a, 0x00FF00);
break;
case 'attack':
actionLine(room, k, {x: obj.x, y: obj.y}, a, 0x0000FF);
break;

default:
console.log("tower actionLog", k, a, this);
Expand Down Expand Up @@ -80,7 +85,7 @@ export default class Tower extends GameObject {
}




preRender(ts) {
super.preRender(ts);
Expand Down
30 changes: 20 additions & 10 deletions src/scripts/skins/original/creep.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import {S, SQUARE_SIZE, TWEEN_DURATION} from '../../const';
import {tween, tweenRotation, interp} from '../../tween';
import {actionLine, bump} from '../../actions';
import {actionLine, bump, flash, say} from '../../actions';

export class CreepSkin {
constructor(creep) {
Expand Down Expand Up @@ -38,6 +38,9 @@ export class CreepSkin {
break;

case 'say':
if(a) {
say(this.g, a.message);
}
break;

case 'repair':
Expand All @@ -47,13 +50,19 @@ export class CreepSkin {
break;

case 'attacked':
// actionLine(room, k, a, {x: obj.x, y: obj.y});
flash(this.g, 0xFF0000);
break;
case 'healed':
flash(this.g, 0x00FF00);
break;

case 'rangedAttack':
actionLine(room, k, {x: obj.x, y: obj.y}, a);
actionLine(room, k, {x: obj.x, y: obj.y}, a, 0x0000FF);
break;

case 'attack':
bump(this.g, g, obj, a)

default:
console.log("actionLog", k, a, this);
}
Expand Down Expand Up @@ -92,12 +101,14 @@ export class CreepSkin {
g.arc(m, m, pr-pw, +workAL, -workAL, true);
g.endFill();

g.lineStyle(0, 0, 0);
g.beginFill(0xffff00);
let e = S(2.5) * Math.sqrt(obj.energy / obj.energyCapacity);
if (e > 0) e = Math.max(1, e);
g.drawCircle(m, m, e);
g.endFill();
if(obj.energyCapacity) {
g.lineStyle(0, 0, 0);
g.beginFill(0xffff00);
let e = S(2.5) * Math.sqrt(obj.energy / obj.energyCapacity);
if (e > 0) e = Math.max(1, e);
g.drawCircle(m, m, e);
g.endFill();
}

tweenRotation(TWEEN_DURATION/2, g, this.creep.lastObj, obj);
}
Expand All @@ -106,4 +117,3 @@ export class CreepSkin {

}
}

0 comments on commit 00ebc1f

Please sign in to comment.