6
0

2 Коміти ea15cb2846 ... 2c1187750a

Автор SHA1 Опис Дата
  Pedro Schneider 2c1187750a ✨ Start working on a prototype for the food hunt minigame 3 роки тому
  Pedro Schneider 8da9b1ad3d 📝 Add type anotations to all member variables 3 роки тому

+ 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)
+    }
+}

+ 3 - 1
src/elements/earth/rebus/game/RebusCardVisualEffect.js

@@ -21,10 +21,12 @@
 
 class RebusCardVisualEffect extends Object2D
 {
+    /** @type {number} */
     glowIterations = 7;
+    /** @type {number} */
     glowAmount = 0;
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         db.rectMode(CENTER);
         if (this.parent.selected)

+ 9 - 3
src/elements/earth/rebus/game/RebusGame.js

@@ -21,12 +21,18 @@
 
 class RebusGame extends Object2D
 {
+    /** @type {Object} */
     levelData = null;
+    /** @type {Boolean} */
     gameFinished = false;
+    /** @type {number} */
     points = 3;
 
+    /** @type {Button} */
     backButton = null;
+    /** @type {Button} */
     continueButton = null;
+    /** @type {Button} */
     timer = null;
 
     _setup()
@@ -48,7 +54,7 @@ class RebusGame extends Object2D
             newCard.connect("selected", this, "_onCardSelected");
             this.addChild(newCard);
         }
-        
+
         for (let i = 0; i < this.levelData.questionCards.length; i++)
         {
             var newCard = new RebusQuestionCard("OptionCard" + i);
@@ -82,7 +88,7 @@ class RebusGame extends Object2D
         this.addChild(this.timer);
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         background(52);
     }
@@ -94,7 +100,7 @@ class RebusGame extends Object2D
         this.queueFree();
     }
 
-    _onCardSelected(isAnswer)
+    _onCardSelected( /** @type {Boolean} */ isAnswer)
     {
         if (!isAnswer)
             this.points--;

+ 4 - 1
src/elements/earth/rebus/game/RebusGameVisualEffects.js

@@ -21,11 +21,14 @@
 
 class RebusGameVisualEffects extends Object2D
 {
+    /** @type {String} */
     suffix = "";
+    /** @type {number} */
     bgOpacity = 0;
+    /** @type {number} */
     textOpacity = 0;
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         if (this.parent.gameFinished)
         {

+ 13 - 2
src/elements/earth/rebus/game/RebusOptionCard.js

@@ -21,18 +21,29 @@
 
 class RebusOptionCard extends Object2D
 {
+    /** @type {TextureRes} */
     thumb = null;
+    /** @type {String} */
     imgName = "";
+    /** @type {Boolean} */
     isAnswer = false;
+    /** @type {Boolean} */
     selected = false;
+    /** @type {Boolean} */
     selectable = true;
 
+    /** @type {Color} */
     fillColor = new Color(200, 200, 200);
+    /** @type {Boolean} */
     mouseOver = false;
+    /** @type  {Boolean} */
     mousePress = false;
 
+    /** @type {Boolean} */
     tweenStarted = false;
+    /** @type {Tween} */
     tween = null;
+    /** @type {Timer} */
     timer = null;
 
     _initSignals()
@@ -64,7 +75,7 @@ class RebusOptionCard extends Object2D
         this.addChild(this.timer);
     }
 
-    _update(delta)
+    _update( /** @type {number} */ delta)
     {
         if (this.visible && !this.tweenStarted)
         {
@@ -101,7 +112,7 @@ class RebusOptionCard extends Object2D
         }
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         db.rectMode(CENTER);
         db.fill(this.fillColor.getP5Color());

+ 5 - 1
src/elements/earth/rebus/game/RebusQuestionCard.js

@@ -21,10 +21,14 @@
 
 class RebusQuestionCard extends Object2D
 {
+    /** @type {TextureRes} */
     thumb = null;
+    /** @type {String} */
     imgName = "";
 
+    /** @type {Color} */
     fillColor = new Color(200, 200, 200);
+    /** @type {Tween} */
     tween = null;
 
     _setup()
@@ -46,7 +50,7 @@ class RebusQuestionCard extends Object2D
         this.tween.startAll();
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         if (this.visible) this.tween.startAll();
 

+ 1 - 0
src/elements/earth/rebus/level_selector/RebusLevelButton.js

@@ -21,6 +21,7 @@
 
 class RebusLevelButton extends Button
 {
+    /** @type {Object} */
     levelData = null;
 
     _initSignals()

+ 5 - 3
src/elements/earth/rebus/level_selector/RebusLevelSelector.js

@@ -21,6 +21,7 @@
 
 class RebusLevelSelector extends Object2D
 {
+    /** @type {Object} */
     gridMargins = {
         left: 0,
         right: 0,
@@ -28,6 +29,7 @@ class RebusLevelSelector extends Object2D
         down: 0
     };
 
+    /** @type {number} */
     gridCols = 5;
 
     _setup()
@@ -64,7 +66,7 @@ class RebusLevelSelector extends Object2D
         this.addChild(this.backButton);
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         background(52);
 
@@ -76,7 +78,7 @@ class RebusLevelSelector extends Object2D
         db.text("Escolha o nível", 1920 / 2, 200);
     }
 
-    _onTutorialSelected(levelData)
+    _onTutorialSelected( /** @type {Object} */ levelData)
     {
         var rg = new RebusTutorial("RebusTutorial");
         rg.levelData = levelData;
@@ -84,7 +86,7 @@ class RebusLevelSelector extends Object2D
         this.queueFree();
     }
 
-    _onLevelSelected(levelData)
+    _onLevelSelected( /** @type {Object} */ levelData)
     {
         var rg = new RebusGame("RebusGame");
         rg.levelData = levelData;

+ 11 - 3
src/elements/earth/rebus/tutorial/RebusTutorial.js

@@ -21,17 +21,25 @@
 
 class RebusTutorial extends Object2D
 {
+    /** @type {Object} */
     levelData = null;
+    /** @type {Boolean} */
     gameFinished = false;
+    /** @type {Number} */
     points = 3;
 
+    /** @type {Button} */
     backButton = null;
     continueButton = null;
     timer = null;
 
+    /** @type {Number} */
     tutorialStep = 0;
+    /** @type {Array} */
     questionCards = [];
+    /** @type {Array} */
     optionCards = [];
+    /** @type {Number} */
     answerIdx = 0;
 
     _setup()
@@ -92,7 +100,7 @@ class RebusTutorial extends Object2D
         this.addChild(new RebusTutorialVisualEffects);
     }
 
-    _update(delta)
+    _update( /** @type {Number} */ delta)
     {
         switch (this.tutorialStep)
         {
@@ -111,7 +119,7 @@ class RebusTutorial extends Object2D
         }
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         background(52);
     }
@@ -132,7 +140,7 @@ class RebusTutorial extends Object2D
     {
         this.continueButton.hide();
         this.tutorialStep++;
-        
+
         switch (this.tutorialStep)
         {
             case 4:

+ 4 - 1
src/elements/earth/rebus/tutorial/RebusTutorialVisualEffects.js

@@ -21,11 +21,14 @@
 
 class RebusTutorialVisualEffects extends Object2D
 {
+    /** @type {String} */
     text = "";
+    /** @type {Number} */
     bgOpacity = 0;
+    /** @type {Number} */
     textOpacity = 0;
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         switch (this.parent.tutorialStep)
         {

+ 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);
 }