ソースを参照

✨ Start work on the Rebus minigame

- Add levels contant
- Add RebusGame scene
Pedro Schneider 3 年 前
コミット
7f65edac16

+ 5 - 0
index.html

@@ -15,6 +15,11 @@
     
     <!-- Pandora Engine -->
     <script type="text/javascript" src="libraries/pandora.min.js"></script>
+
+    <!-- Game -->
+    <!-- Rébus -->
+    <script type="text/javascript" src="src/elements/earth/rebus/Levels.js"></script>
+    <script type="text/javascript" src="src/elements/earth/rebus/RebusGame.js"></script>
   </head>
   
   <body>

ファイルの差分が大きいため隠しています
+ 1 - 1
libraries/pandora.min.js


+ 33 - 0
src/elements/earth/rebus/Levels.js

@@ -0,0 +1,33 @@
+const REBUS_LEVELS = {
+    tutorial: {
+        optionCards: [
+            {
+                path: "assets/textures/monke.png",
+                name: "Macaco",
+            },
+            {
+                path: "assets/textures/oca.png",
+                name: "Oca",
+            },
+            {
+                path: "assets/textures/key.png",
+                name: "Chave",
+            },
+        ],
+
+        questionCards: [
+            {
+                path: "assets/textures/glasses.png",
+                name: "Óculos",
+            },
+            {
+                path: "assets/textures/house.png",
+                name: "Casa",
+            },
+        ],
+    },
+
+    level1: {
+
+    },
+}

+ 120 - 0
src/elements/earth/rebus/RebusGame.js

@@ -0,0 +1,120 @@
+class RebusQuestionCard extends Object2D
+{
+    thumb = null;
+    imgName = "";
+
+    fillColor = new Color(200, 200, 200);
+
+    _setup()
+    {
+        var sprite = new Sprite2D("sprite", this.thumb);
+        sprite.width = 250;
+        sprite.height = 250;
+        sprite.setPosition(0, -75);
+        this.addChild(sprite);
+    }
+
+    _draw(delta, db)
+    {
+        db.rectMode(CENTER);
+        db.fill(this.fillColor.getP5Color());
+        db.rect(0, 0, 300, 400, 10, 10);
+        db.textAlign(CENTER, CENTER);
+        db.fill(0);
+        db.textSize(40);
+        db.text(this.imgName, 0, 100);
+    }
+}
+
+class RebusOptionCard extends RebusQuestionCard
+{
+    isAnswer = false;
+
+    mouseOver = false;
+    mousePress = false;
+
+    _setup()
+    {
+        var sprite = new Sprite2D("sprite", this.thumb);
+        sprite.width = 250;
+        sprite.height = 250;
+        sprite.setPosition(0, -75);
+        this.addChild(sprite);
+
+        var area = new Area2D("area", SHAPES.RECT, new Rect(300, 400), true);
+        area.connect("mouseEntered", this, "_onMouseEntered");
+        area.connect("mouseExited", this, "_onMouseExited");
+        this.addChild(area);
+    }
+
+    _update(delta)
+    {
+        if (this.mouseOver)
+        {
+            if (InputHandler.mouseIsClicked)
+            {
+                console.log("selected");
+            }
+
+            if (InputHandler.mouseIsPressed)
+            {
+                this.scale.x = max(this.scale.x - 3.0 * delta, 0.95);
+                this.scale.y = max(this.scale.y - 3.0 * delta, 0.95);
+            }
+            else
+            {
+                this.scale.x = min(this.scale.x + 2.0 * delta, 1.1);
+                this.scale.y = min(this.scale.y + 2.0 * delta, 1.1);
+            }
+        }
+
+        else
+        {
+            this.scale.x = max(this.scale.x - 2.0 * delta, 1);
+            this.scale.y = max(this.scale.y - 2.0 * delta, 1);
+        }
+    }
+
+    _onMouseEntered()
+    {
+        this.mouseOver = true;
+    }
+
+    _onMouseExited()
+    {
+        this.mouseOver = false;
+    }
+}
+
+class RebusGame extends Object2D
+{
+    levelData = null;
+
+    _setup()
+    {
+        for (let i = 0; i < this.levelData.optionCards.length; i++)
+        {
+            var newCard = new RebusOptionCard("OptionCard" + i);
+            AssetHandler.loadTexture(this.levelData.optionCards[i].name, this.levelData.optionCards[i].path);
+            newCard.thumb = AssetHandler.getTextureByName(this.levelData.optionCards[i].name);
+            newCard.imgName = this.levelData.optionCards[i].name;
+            newCard.setPosition((i + 1) * (1920 / 4), 3 * (1080 / 4));
+            this.addChild(newCard)
+        }
+
+        for (let i = 0; i < this.levelData.questionCards.length; i++)
+        {
+            var newCard = new RebusQuestionCard("OptionCard" + i);
+            AssetHandler.loadTexture(this.levelData.questionCards[i].name, this.levelData.questionCards[i].path);
+            newCard.thumb = AssetHandler.getTextureByName(this.levelData.questionCards[i].name);
+            newCard.imgName = this.levelData.questionCards[i].name;
+            newCard.setPosition((i + 1) * (1920 / (this.levelData.questionCards.length + 1)), 1080 / 4);
+            this.addChild(newCard)
+        }
+    }
+
+    _draw(delta, db)
+    {
+        background(52);
+    }
+}

+ 5 - 5
src/main.js

@@ -1,15 +1,15 @@
-let test, test2, but;
-
 GameHandler._preload = function()
 {
-    AssetHandler.loadTexture("monke", "/assets/textures/monke.png");
     AssetHandler.loadFont("Lato", "/assets/fonts/Lato-Regular.ttf");
-    AssetHandler.loadAudio("bonk", "/assets/audio/thonk.wav");
-    AssetHandler.loadAudio("music", "/assets/audio/music.ogg");
 }
 
 GameHandler._setup = function()
 {
     GameHandler.drawDebugFPS(true);
     GameHandler.drawDebugBufferBounds(true);
+    textFont(AssetHandler.getP5FontByName("Lato"));
+
+    rg = new RebusGame("Rebus game");
+    rg.levelData = REBUS_LEVELS.tutorial;
+    GameHandler.addRootObject(rg);
 }