Bring the kingdom a little bit of gameplay!

This commit is contained in:
ExeVirus 2024-02-24 23:29:48 -05:00
parent d1771cb45a
commit 44decb6b37
17 changed files with 180 additions and 18 deletions

View File

@ -154,6 +154,15 @@ Got the keyboard keys all working using keyboardjs! Also got some bugs from swit
Added a cool hip logo, also changed the main screen to be semi-centered Added a cool hip logo, also changed the main screen to be semi-centered
### Day 24 - part 3: (1.5 hours)
Started the KingdomManager class, learned about 9-slice, created a progress meter class, implemented a callback so game keys affect the resource meter, meter correctly maxes out at 100 percent fill. Supports other colors for future bars, not very flexible otherwise. Created placeholders for
the target building cost, and current resource amount. Support `Backspace` to go back to the main menu once in game so no refresh required.
Got new assets for the meter and kingdom manager background. It'll probably end up being a meter, resource amount, building, and building description. I will model the attack waves similar, but that progress bar will merely count up with time :D, maybe have checkpoints, but unlikely.
I guess next is to add the building list (big json of thing, textureName, description, and cost) and tracking system for KingdomManager. Add teh bitmap text for the current progress, and maybe then some of the key callbacks when they do or do not have buildings on them. Perhaps implement the building system? uncertain as of yet.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 690 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

2
docs/bundle.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,92 @@
Copyright © 2020-2022 GGBotNet (https://ggbot.net/fonts/), with Reserved Font Name "Fortzilla".
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 690 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

View File

@ -13,7 +13,6 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
import { constants } from './constants.js'; import { constants } from './constants.js';
import keyboard from 'keyboardjs';
export class KeyButton extends Phaser.GameObjects.Sprite { export class KeyButton extends Phaser.GameObjects.Sprite {
percent = -1; percent = -1;

View File

@ -1,3 +1,4 @@
import { ProgressBar } from './ProgressBar.js'
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// //
// Class: KindomManager // Class: KindomManager
@ -8,12 +9,42 @@
// - dealing with collisions with buildings // - dealing with collisions with buildings
// - Handling the display and update of the bottom of the screen // - Handling the display and update of the bottom of the screen
// - Current Resource Collected (number + bar graph) // - Current Resource Collected (number + bar graph)
// - // - Current
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
export class KindomManager export class KindomManager extends Phaser.GameObjects.Container
{ {
constructor(scene) { constructor(scene, x, y, width, height) {
this.scene = scene; super(scene, x, y);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.background = scene.add.nineslice(x, y, 'kBack', '', width, height, 25, 25, 25, 25);
this.inset = scene.add.nineslice(x, y, 'kInset', '', width-24, height-24, 25, 25, 25, 25);
this.resourceMeter = new ProgressBar(scene, 1920/2, 850, 1500, 26, 'meterYellow', 5, 0);
//this.minWidth = 9; // nineslice left and right = 18 pixels
//this.meterBack = scene.add.nineslice(x, y, 'meterBack', '', width-80, 26, this.minWidth, this.minWidth);
//this.meterYellow = scene.add.nineslice(x-width/2+40 + this.minWidth, y, 'meterYellow', '', this.minWidth*2, 24, this.minWidth, this.minWidth);
this.target = 1000;
this.resource = 0;
}
activation (keyButton) {
if(keyButton.keyText == '⌫') {
this.scene.scene.start('MainMenu');
} else {
this.addResource(20);
}
}
update(time,delta)
{
}
addResource(amt)
{
this.resource += amt;
this.resourceMeter.setPercent(this.resource/this.target);
} }
} }

View File

@ -0,0 +1,28 @@
// ----------------------------------------------------------------------------
//
// Class: ProgressBar
// Desc: Implements:
// - a Progress Bar
// minWidth is the pixels neded on left and right of the 9 slice
// ----------------------------------------------------------------------------
export class ProgressBar extends Phaser.GameObjects.Container
{
constructor(scene, x, y, width, height, meterTexture, minWidth, fillPercent) {
super(scene, x, y);
this.x = x;
this.width = width;
this.minWidth = minWidth;
this.meterBack = scene.add.nineslice(x, y, 'meterBack', '', width, height, this.minWidth, this.minWidth);
this.meterYellow = scene.add.nineslice(x, y, meterTexture, '', width, height-2, this.minWidth, this.minWidth);
this.setPercent(fillPercent);
}
setPercent(fillPercent)
{
fillPercent = Math.max(Math.min(fillPercent, 1),0); //clamp to 0,1
this.meterYellow.width = Math.max(this.width * fillPercent, this.minWidth*2); //minWdith = 18
this.meterYellow.x = this.x - this.width/2 + Math.max(this.width/2*fillPercent, this.minWidth);
console.log(fillPercent, Math.max(this.width * fillPercent, this.minWidth*2), this.x - this.width/2 + Math.max(this.width/2*fillPercent, this.minWidth))
}
}

View File

@ -27,7 +27,7 @@ const keyText = [
'~','1','2','3','4','5','6','7','8','9','0','-','=','⌫', '~','1','2','3','4','5','6','7','8','9','0','-','=','⌫',
'TAB','Q','W','E','R','T','Y','U','I','O','P','[',']','\\', 'TAB','Q','W','E','R','T','Y','U','I','O','P','[',']','\\',
'CAPS','A','S','D','F','G','H','J','K','L',';','"','ENTER', 'CAPS','A','S','D','F','G','H','J','K','L',';','"','ENTER',
'','Z','X','C','V','B','N','M',',','.','/' 'SHFT','Z','X','C','V','B','N','M',',','.','/'
] ]

View File

@ -23,6 +23,10 @@ export class AssetLoader extends Scene
this.load.image('key_red', 'assets/key_red.png'); this.load.image('key_red', 'assets/key_red.png');
this.load.image('key_blue', 'assets/key_blue.png'); this.load.image('key_blue', 'assets/key_blue.png');
this.load.image('logo', 'assets/logo.png'); this.load.image('logo', 'assets/logo.png');
this.load.image('kBack', 'assets/kmanager/kBack.png');
this.load.image('kInset', 'assets/kmanager/kInset.png');
this.load.image('meterBack', 'assets/kmanager/meterBack.png');
this.load.image('meterYellow', 'assets/kmanager/meterYellow.png');
this.load.bitmapFont('sono', 'assets/sono.png', 'assets/sono.xml'); this.load.bitmapFont('sono', 'assets/sono.png', 'assets/sono.xml');
} }

View File

@ -10,10 +10,7 @@ export class Game extends Scene
super('Game'); super('Game');
} }
preload () preload () {}
{
this.kingdomManager = new KindomManager();
}
init(data) init(data)
{ {
@ -23,6 +20,9 @@ export class Game extends Scene
create () create ()
{ {
this.kingdomManager = new KindomManager(this, 1920/2, 910, 1600, 230);
// console.log(this.kingdomManager);
// this.add.existing(this.kingdomManager);
for(let i = 0; i < 4; i++) { for(let i = 0; i < 4; i++) {
for(let j = 0; j < 14; j++) { for(let j = 0; j < 14; j++) {
if (j < constants.rowLengths[i]) { if (j < constants.rowLengths[i]) {
@ -32,19 +32,18 @@ export class Game extends Scene
} }
} }
this.add.image(1920/2,80,'logo').setScale(0.6);
this.add.image(1920/2,80,'logo').setScale(0.6);
this.events.on('shutdown', this.shutdown, this); this.events.on('shutdown', this.shutdown, this);
let scene = this.scene
this.kingdomManager = {
activation: function(keyButton) {
scene.start('MainMenu');
}
}
} }
shutdown () shutdown ()
{ {
this.input.keyboard.shutdown(); this.input.keyboard.shutdown();
} }
update(time, delta)
{
this.kingdomManager.update(time,delta);
}
} }