Fixed item drag, added score

This commit is contained in:
Mashy 2019-03-05 20:35:07 +10:00
parent fd1c693f01
commit 4afe114bdd
4 changed files with 44 additions and 15 deletions

View File

@ -6,7 +6,6 @@ const CombatLog = require('./combat.log');
const CombatCryps = require('./combat.cryps');
const CombatSkills = require('./combat.skills');
const CombatHitBox = require('./combat.hitbox');
const Button = require('./elements/box');
const renderResolutions = require('./combat.render.resolutions');

View File

@ -262,27 +262,30 @@ class ItemList extends Phaser.Scene {
this.input.on('dragend', (pointer, item) => {
if (!(item instanceof Item)) return false;
// Allocate to combiner if clicked without movement form inventory (return 0)
if (!Math.hypot(item.x - item.origX, item.y - item.origY)) {
const cBox = findUnallocated();
if (cBox) allocate(item, cBox);
return true;
}
// Check for hitboxes
// Check first for hitbox interaction
const hitBox = itemCheckHitbox(this, pointer);
if (hitBox) {
// hitbox can only be the combinerhitbox, deletehitbox or cryp avatar
hitBox.itemDeselect();
// Allocate to specific combiner slot
if (hitBox instanceof CombinerHitBox) {
allocate(item, hitBox);
} else if (hitBox instanceof DeleteHitBox) {
ws.sendVboxDrop(vbox.instance, item.index);
} else {
ws.sendVboxApply(vbox.instance, hitBox.cryp.id, item.index);
} return true;
}
// If not interacting with hitbox and didn't move much try to allocate the item
if (Math.hypot(item.x - item.origX, item.y - item.origY) < Math.hypot(item.width, item.height)) {
// Check theres a free combiner slot
const cBox = findUnallocated();
if (cBox) {
allocate(item, cBox);
return true;
}
// Allocate to cryp hitbox
if (hitBox instanceof DeleteHitBox) ws.sendVboxDrop(vbox.instance, item.index);
else ws.sendVboxApply(vbox.instance, hitBox.cryp.id, item.index);
}
// If the item hasn't been allocated deallocate the item
// If the item hasn't been allocated above reset to natural location
// Check if item needs to be deallocated
// Scene will restart if there is vbox change
deallocate(item);
return true;

View File

@ -3,6 +3,7 @@ const Phaser = require('phaser');
// Scenes constantly showing
const MenuCrypList = require('./menu.cryps.list');
const MenuNavigation = require('./menu.navigation');
const MenuScore = require('./menu.score');
const ItemList = require('./item.list');
// Scenes which change depending on menu context
const Zones = require('./zones');
@ -14,6 +15,7 @@ const FIXED_MENU_SCENES = [
'MenuCrypList',
'MenuNavigation',
'ItemList',
'MenuScore',
];
const MAIN_MENU_SCENES = [
@ -37,6 +39,7 @@ class Menu extends Phaser.Scene {
this.scene.manager.add('MenuCrypList', MenuCrypList, true);
this.scene.manager.add('MenuNavigation', MenuNavigation, true);
this.scene.manager.add('MenuScore', MenuScore, true);
this.scene.manager.add('ItemList', ItemList, true);
this.registry.set('inMenu', true);
return true;

View File

@ -0,0 +1,24 @@
const Phaser = require('phaser');
const { POSITIONS: { NAVIGATION }, TEXT } = require('./constants');
const X = NAVIGATION.x();
const Y = NAVIGATION.y();
const HEIGHT = NAVIGATION.height();
class MenuScore extends Phaser.Scene {
constructor() {
super({ key: 'MenuScore' });
}
create() {
const { score } = this.registry.get('player');
this.add.text(X, Y, `Wins: ${score.wins}`, TEXT.HEADER);
this.add.text(X, Y + HEIGHT * 0.1, `Losses: ${score.losses}`, TEXT.HEADER);
}
cleanUp() {
this.scene.remove();
}
}
module.exports = MenuScore;