Procházet zdrojové kódy

✨ Finish shapes

- Finish Shape2D game object;
- Finish Rect and Ellipse components.
Pedro Schneider před 3 roky
rodič
revize
250fc477d8

+ 1 - 0
index.html

@@ -18,6 +18,7 @@
       Pandora Engine
     *******************************-->
     <!-- Components -->
+    <script src="pandora/components/Ellipse.js"></script>
     <script src="pandora/components/Rect.js"></script>
     <script src="pandora/components/Vector2.js"></script>
     

+ 6 - 0
pandora/components/Ellipse.js

@@ -0,0 +1,6 @@
+class Ellipse {
+    constructor(rx, ry=rx){
+        this.rx = rx;
+        this.ry = ry;
+    }
+}

+ 1 - 3
pandora/components/Rect.js

@@ -1,9 +1,7 @@
 class Rect
 {
-    constructor(x, y, w, h)
+    constructor(w, h=w)
     {
-        this.x = x;
-        this.y = y;
         this.w = w;
         this.h = h;
     }

+ 41 - 2
pandora/game_objects/2d_objects/Shape2D.js

@@ -1,10 +1,49 @@
 class Shape2D extends Object2D
 {
-    constructor(name, shape = null, data = null)
+    constructor(name, shapeType = null, shape = null)
     {
         super(name);
 
+        this.shapeType = shapeType;
         this.shape = shape;
-        this.data = data;
+
+        this.shapeMode = CORNER;
+        this.fillColor = color(255);
+        this.noFill = false;
+        this.strokeWeight = 1;
+        this.strokeColor = color(0);
+        this.noStroke = false;
+    }
+
+    draw(delta)
+    {
+        push();
+        translate(this.position.x, this.position.y);
+        rotate(this.rotationDegrees);
+        scale(this.scale.x, this.scale.y);
+
+        fill(this.fillColor);
+        strokeWeight(this.strokeWeight)
+        stroke(this.strokeColor);
+        
+        if (this.noFill) noFill();
+        if(this.noStroke) noStroke();
+        switch (this.shapeType)
+        {
+            case SHAPES.RECT:
+                rectMode(this.shapeMode);
+                rect(this.position.x, this.position.y, this.shape.w, this.shape.h);
+                break;
+            case SHAPES.ELLIPSE:
+                ellipseMode(this.shapeMode);
+                ellipse(this.position.x, this.position.y, this.shape.rx, this.shape.ry);
+        }
+
+        this._draw(delta);
+
+        for (let i = 0; i < this.children.length; i++)
+            this.children[i].draw(delta);
+
+        pop()
     }
 }