-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from MisterGC/feature/score-times-and-end
Feature/score times and end
- Loading branch information
Showing
14 changed files
with
215 additions
and
27 deletions.
There are no files selected for viewing
Submodule clayground
updated
2 files
+9 −4 | plugins/clay_world/ClayWorld.qml | |
+3 −1 | plugins/svg_tools/svginspector.cpp |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// (c) [email protected] - zlib license, see "LICENSE" file | ||
import QtQuick 2.12 | ||
|
||
Rectangle { | ||
id: theGameEnding | ||
|
||
property Referee referee: null | ||
|
||
visible: false | ||
anchors.fill: parent | ||
Component.onCompleted: { | ||
referee.playerDied.connect(onPlayerDied); | ||
referee.gardenDied.connect(onGardenDied); | ||
referee.seasonEnded.connect(onSeasonEnded); | ||
} | ||
|
||
function onGardenDied() {showEnd("Garden died!");} | ||
function onPlayerDied() {showEnd("Player died!");} | ||
function onSeasonEnded() {showEnd("Season ended!");} | ||
|
||
function showEnd(txt) { | ||
if (!visible) { | ||
theEndTxt.text = txt; | ||
visible = true; | ||
} | ||
} | ||
|
||
Text { | ||
id: theEndTxt | ||
anchors.centerIn: parent | ||
font.pixelSize: parent.height * .1 | ||
text: "The Game ends ..." | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// (c) [email protected] - zlib license, see "LICENSE" file | ||
import QtQuick 2.12 | ||
|
||
Item { | ||
property var gardens: [] | ||
property var player: undefined | ||
property real gardenPercentage: 100.0 | ||
property int maxEnergyGarden: 0 | ||
property int timeElapsed: 0 | ||
|
||
readonly property int seasonLength: 300 | ||
readonly property real seasonPercentage: Math.round(timeElapsed * 100.0 / seasonLength) | ||
onSeasonPercentageChanged: { | ||
if (seasonPercentage >= 100) { | ||
theOneSecTimer.stop(); | ||
seasonEnded(); | ||
} | ||
} | ||
|
||
onPlayerChanged: { | ||
if (player) { | ||
player.energyChanged.connect(_onPlayerEnergyChanged); | ||
theOneSecTimer.start(); | ||
} | ||
else { | ||
theOneSecTimer.stop(); | ||
gardens=[]; | ||
gardenPercentage=100.0; | ||
maxEnergyGarden=0; | ||
timeElapsed=0; | ||
} | ||
} | ||
|
||
|
||
signal playerDied() | ||
signal gardenDied() | ||
signal seasonEnded() | ||
|
||
Timer { | ||
id: theOneSecTimer | ||
interval: 1000 | ||
Component.onCompleted: start() | ||
onTriggered: timeElapsed++ | ||
repeat: true | ||
} | ||
|
||
onGardenPercentageChanged: { | ||
if (gardenPercentage <= 0) gardenDied() | ||
} | ||
|
||
function addGarden(garden) { | ||
gardens.push(garden); | ||
garden.energyChanged.connect(_onGardenEnergyChanged); | ||
maxEnergyGarden += garden.maxEnergy; | ||
} | ||
|
||
function _onGardenEnergyChanged() { | ||
let energy = 0; | ||
for (const g of gardens) | ||
energy += g.energy; | ||
gardenPercentage = Math.round((energy/maxEnergyGarden) * 100.0); | ||
} | ||
|
||
function _onPlayerEnergyChanged() { | ||
if (player.energy <= 0) | ||
playerDied(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// (c) [email protected] - zlib license, see "LICENSE" file | ||
import QtQuick 2.12 | ||
|
||
Rectangle { | ||
id: theStartScreen | ||
|
||
property Referee referee: null | ||
signal requestStart() | ||
|
||
visible: false | ||
anchors.fill: parent | ||
|
||
Text { | ||
anchors.centerIn: parent | ||
font.pixelSize: parent.height * .07 | ||
text: "Welcome to the Game" | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters