Преглед на файлове

✨ Start working on a prototype for the food hunt minigame

Pedro Schneider преди 3 години
родител
ревизия
2c1187750a

+ 5 - 0
index.html

@@ -20,6 +20,11 @@
     <script type="text/javascript" src="src/elements/EelementSelector.js"></script>
     <!-- Earth -->
     <script type="text/javascript" src="src/elements/earth/EarthMinigameSelector.js"></script>
+    <!-- Food Hunt -->
+    <script type="text/javascript" src="src/elements/earth/foodHunt/FoodHuntFruit.js"></script>
+    <script type="text/javascript" src="src/elements/earth/foodHunt/FoodHuntPlayer.js"></script>
+    <script type="text/javascript" src="src/elements/earth/foodHunt/FoodHuntTree.js"></script>
+    <script type="text/javascript" src="src/elements/earth/foodHunt/FoodHuntGame.js"></script>
     <!-- Rébus -->
     <script type="text/javascript" src="src/elements/earth/rebus/RebusLevels.js"></script>
     <script type="text/javascript" src="src/elements/earth/rebus/level_selector/RebusLevelButton.js"></script>

Файловите разлики са ограничени, защото са твърде много
+ 1 - 1
libraries/pandora.min.js


+ 3 - 1
src/elements/earth/EarthMinigameSelector.js

@@ -122,7 +122,9 @@ class EarthMinigameSelector extends Object2D
 
     _onFoodHuntSelected()
     {
-        console.log("Food hunt has been selected");
+        var fh = new FoodHuntGame("FoodHuntGame");
+        GameHandler.addRootObject(fh);
+        this.queueFree();
     }
 
     _onLetterHuntSelected()

+ 25 - 0
src/elements/earth/foodHunt/FoodHuntFruit.js

@@ -0,0 +1,25 @@
+class FoodHuntFruit extends Object2D
+{
+    /** @type {Number} */
+    static G = 10;
+
+    /** @type {Color} */
+    color = new Color(0, 0, 0);
+    /** @type {Number} */
+    r = 20
+
+    _setup()
+    {
+
+    }
+
+    _update( /** @type {Number} */ delta)
+    {
+        
+    }
+
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
+    {
+        ellipse(0, 0, this.r);
+    }
+}

+ 114 - 0
src/elements/earth/foodHunt/FoodHuntGame.js

@@ -0,0 +1,114 @@
+class FoodHuntGame extends Object2D
+{
+    /** @type {Button} */
+    backButton = null;
+
+    /** @type {FoodHuntPlayer} */
+    player = null;
+    /** @type {FoodHuntTree} */
+    tree = null;
+    /** @type {Object2D} */
+    fruits = null;
+
+    /** @type {Timer} */
+    initialTimer = null;
+    /** @type {Timer} */
+    gameTimer = null;
+    /** @type {Timer} */
+    fruitsTimer = null;
+
+    /** @type {Boolean} */
+    gameStarted = false;
+    /** @type {Boolean} */
+    gameEnded = false;
+
+    _setup()
+    {
+        // Create back button
+        this.backButton = new Button("BackButton");
+        this.backButton.setLabel("Voltar");
+        this.backButton.setFontSize(30);
+        this.backButton.setPosition(20, 20);
+        this.backButton.setSize(110, 75);
+        this.backButton.connect("mouseClicked", this, "_onBackClicked");
+        this.addChild(this.backButton);
+
+        this.tree = new FoodHuntTree("Tree");
+        this.addChild(this.tree);
+
+        this.fruits = new Object2D("Fruits");
+        this.addChild(this.fruits);
+
+        this.player = new FoodHuntPlayer("Player");
+        this.player.updatePaused = true;
+        this.addChild(this.player);
+
+        this.initialTimer = new Timer("InitialTimer", 4, true, true);
+        this.initialTimer.connect("timeout", this, "_onInitialTimerTimeout");
+        this.addChild(this.initialTimer);
+
+        this.gameTimer = new Timer("GameTimer", 60, false, true);
+        this.gameTimer.connect("timeout", this, "_onGameTimerTimeout");
+        this.addChild(this.gameTimer);
+
+        this.fruitsTimer = new Timer("FruitsTimer", 1, false, true);
+        this.fruitsTimer.connect("timeout", this, "_onFruitsTimerTimeout");
+        this.addChild(this.fruitsTimer);
+    }
+
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
+    {
+        background(52);
+
+        if (!this.gameStarted)
+        {
+            db.textAlign(CENTER, CENTER);
+            db.fill(255);
+            db.textSize(200);
+            var tl = int(this.initialTimer.timeLeft - 0.00001);
+            if (tl >= 1)
+                db.text(`${tl}`, 1920 / 2, 200);
+            else
+            {
+                db.textSize(100);
+                db.text(`Começar!`, 1920 / 2, 200);
+            }
+
+        }
+        else if (!this.gameEnded)
+        {
+            db.textAlign(RIGHT, TOP);
+            db.fill(255);
+            db.textSize(75);
+            db.text(`${int(this.gameTimer.timeLeft - 0.0001 + 1)}`, 1920 - 10, 0 + 10);
+        }
+    }
+
+    _onBackClicked()
+    {
+        var ems = new EarthMinigameSelector("EarthMiniGameSelector");
+        GameHandler.addRootObject(ems);
+        this.queueFree();
+    }
+
+    _onInitialTimerTimeout()
+    {
+        this.gameStarted = true;
+        this.player.updatePaused = false;
+        this.gameTimer.start();
+        this.fruitsTimer.start();
+        console.log("start");
+    }
+
+    _onFruitsTimerTimeout()
+    {
+        console.log("fruit fell");
+        this.fruitsTimer.start(random(3, 4));
+    }
+
+    _onGameTimerTimeout()
+    {
+        this.gameEnded = true;
+        console.log("game ended");
+    }
+}

+ 29 - 0
src/elements/earth/foodHunt/FoodHuntPlayer.js

@@ -0,0 +1,29 @@
+class FoodHuntPlayer extends Object2D
+{
+    /** @type {Number} */
+    direction = 0;
+
+    _setup()
+    {
+        this.setPosition(1920 / 2, 1080 - 300);
+    }
+
+    _update( /** @type {Number} */ delta)
+    {
+        this.direction = 0;
+        if (keyIsDown(LEFT_ARROW)) this.direction -= 1;
+        if (keyIsDown(RIGHT_ARROW)) this.direction += 1;
+    }
+
+    _draw( /** @type {Number} */ delta, /** @type {p5.Graphics} */ db)
+    {
+        db.rectMode(CENTER);
+        db.rect(0, 0, 100, 200);
+        db.fill(200);
+        db.rect(0, 0, 110, 110);
+
+        this.position.x += 400 * this.direction * delta;
+        if (this.position.x >= 1920 - 50) this.position.x = 1920 - 55;
+        else if (this.position.x <= 55) this.position.x = 55;
+    }
+}

+ 16 - 0
src/elements/earth/foodHunt/FoodHuntTree.js

@@ -0,0 +1,16 @@
+class FoodHuntTree extends Object2D
+{
+    _setup()
+    {
+        this.setPosition(1920 / 2, 1080 / 2 - 100);
+    }
+
+    _draw( /** @type {Number} */ delta, /** @type {p5.Graphics} */ db)
+    {
+        db.rectMode(CENTER);
+        db.fill("#823c11");
+        db.rect(0, 0, 300, 800);
+        db.fill("#07630d");
+        db.rect(0, -400,  1700, 600, 100, 100)
+    }
+}

+ 6 - 13
src/main.js

@@ -26,20 +26,13 @@ GameHandler._preload = function()
 
 GameHandler._setup = function()
 {
-    // GameHandler.drawDebugFPS(true);
-    // GameHandler.drawDebugBufferBounds(true);
+    GameHandler.drawDebugFPS(true);
+    GameHandler.drawDebugBufferBounds(true);
     // textFont(AssetHandler.getP5FontByName("Lato"));
 
-    // rg = new RebusGame("Rebus game");
-    // rg.levelData = REBUS_LEVELS.tutorial;
-    // GameHandler.addRootObject(rg);
+    var fh = new FoodHuntGame("FoodHunGame");
+    GameHandler.addRootObject(fh);
 
-    // let rls = new RebusLevelSelector("LevelSelector");
-    // GameHandler.addRootObject(rls);
-
-    // var ems = new EarthMinigameSelector("EarthMinigameSelector");
-    // GameHandler.addRootObject(ems);
-
-    var menu = new EelementSelector("ElementSelector");
-    GameHandler.addRootObject(menu);
+    // var menu = new EelementSelector("ElementSelector");
+    // GameHandler.addRootObject(menu);
 }