Fixed item drag, added score
This commit is contained in:
parent
fd1c693f01
commit
4afe114bdd
@ -6,7 +6,6 @@ const CombatLog = require('./combat.log');
|
|||||||
const CombatCryps = require('./combat.cryps');
|
const CombatCryps = require('./combat.cryps');
|
||||||
const CombatSkills = require('./combat.skills');
|
const CombatSkills = require('./combat.skills');
|
||||||
const CombatHitBox = require('./combat.hitbox');
|
const CombatHitBox = require('./combat.hitbox');
|
||||||
const Button = require('./elements/box');
|
|
||||||
|
|
||||||
const renderResolutions = require('./combat.render.resolutions');
|
const renderResolutions = require('./combat.render.resolutions');
|
||||||
|
|
||||||
|
|||||||
@ -262,27 +262,30 @@ class ItemList extends Phaser.Scene {
|
|||||||
|
|
||||||
this.input.on('dragend', (pointer, item) => {
|
this.input.on('dragend', (pointer, item) => {
|
||||||
if (!(item instanceof Item)) return false;
|
if (!(item instanceof Item)) return false;
|
||||||
|
// Check first for hitbox interaction
|
||||||
// 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
|
|
||||||
const hitBox = itemCheckHitbox(this, pointer);
|
const hitBox = itemCheckHitbox(this, pointer);
|
||||||
if (hitBox) {
|
if (hitBox) {
|
||||||
|
// hitbox can only be the combinerhitbox, deletehitbox or cryp avatar
|
||||||
hitBox.itemDeselect();
|
hitBox.itemDeselect();
|
||||||
// Allocate to specific combiner slot
|
|
||||||
if (hitBox instanceof CombinerHitBox) {
|
if (hitBox instanceof CombinerHitBox) {
|
||||||
allocate(item, hitBox);
|
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;
|
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
|
// Scene will restart if there is vbox change
|
||||||
deallocate(item);
|
deallocate(item);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const Phaser = require('phaser');
|
|||||||
// Scenes constantly showing
|
// Scenes constantly showing
|
||||||
const MenuCrypList = require('./menu.cryps.list');
|
const MenuCrypList = require('./menu.cryps.list');
|
||||||
const MenuNavigation = require('./menu.navigation');
|
const MenuNavigation = require('./menu.navigation');
|
||||||
|
const MenuScore = require('./menu.score');
|
||||||
const ItemList = require('./item.list');
|
const ItemList = require('./item.list');
|
||||||
// Scenes which change depending on menu context
|
// Scenes which change depending on menu context
|
||||||
const Zones = require('./zones');
|
const Zones = require('./zones');
|
||||||
@ -14,6 +15,7 @@ const FIXED_MENU_SCENES = [
|
|||||||
'MenuCrypList',
|
'MenuCrypList',
|
||||||
'MenuNavigation',
|
'MenuNavigation',
|
||||||
'ItemList',
|
'ItemList',
|
||||||
|
'MenuScore',
|
||||||
];
|
];
|
||||||
|
|
||||||
const MAIN_MENU_SCENES = [
|
const MAIN_MENU_SCENES = [
|
||||||
@ -37,6 +39,7 @@ class Menu extends Phaser.Scene {
|
|||||||
|
|
||||||
this.scene.manager.add('MenuCrypList', MenuCrypList, true);
|
this.scene.manager.add('MenuCrypList', MenuCrypList, true);
|
||||||
this.scene.manager.add('MenuNavigation', MenuNavigation, true);
|
this.scene.manager.add('MenuNavigation', MenuNavigation, true);
|
||||||
|
this.scene.manager.add('MenuScore', MenuScore, true);
|
||||||
this.scene.manager.add('ItemList', ItemList, true);
|
this.scene.manager.add('ItemList', ItemList, true);
|
||||||
this.registry.set('inMenu', true);
|
this.registry.set('inMenu', true);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
24
client/src/scenes/menu.score.js
Normal file
24
client/src/scenes/menu.score.js
Normal 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;
|
||||||
Loading…
x
Reference in New Issue
Block a user