Ver Fonte

Butterflies JS

Josh Engebretson há 10 anos atrás
pai
commit
4a31c595c1
34 ficheiros alterados com 349 adições e 0 exclusões
  1. 1 0
      Butterflies/.gitignore
  2. 0 0
      Butterflies/Butterflies.atomic
  3. 5 0
      Butterflies/Resources.asset
  4. 5 0
      Butterflies/Resources/Components.asset
  5. 63 0
      Butterflies/Resources/Components/Butterfly.js
  6. 7 0
      Butterflies/Resources/Components/Butterfly.js.asset
  7. 39 0
      Butterflies/Resources/Components/Spawner.js
  8. 7 0
      Butterflies/Resources/Components/Spawner.js.asset
  9. 5 0
      Butterflies/Resources/Particles.asset
  10. 39 0
      Butterflies/Resources/Particles/particle.pex
  11. 5 0
      Butterflies/Resources/Particles/particle.pex.asset
  12. BIN
      Butterflies/Resources/Particles/texture.png
  13. 5 0
      Butterflies/Resources/Particles/texture.png.asset
  14. 5 0
      Butterflies/Resources/Scenes.asset
  15. 48 0
      Butterflies/Resources/Scenes/Scene.scene
  16. 5 0
      Butterflies/Resources/Scenes/Scene.scene.asset
  17. 5 0
      Butterflies/Resources/Scripts.asset
  18. 3 0
      Butterflies/Resources/Scripts/main.js
  19. 7 0
      Butterflies/Resources/Scripts/main.js.asset
  20. 5 0
      Butterflies/Resources/Sprites.asset
  21. BIN
      Butterflies/Resources/Sprites/1.png
  22. 5 0
      Butterflies/Resources/Sprites/1.png.asset
  23. BIN
      Butterflies/Resources/Sprites/2.png
  24. 5 0
      Butterflies/Resources/Sprites/2.png.asset
  25. BIN
      Butterflies/Resources/Sprites/3.png
  26. 5 0
      Butterflies/Resources/Sprites/3.png.asset
  27. BIN
      Butterflies/Resources/Sprites/4.png
  28. 5 0
      Butterflies/Resources/Sprites/4.png.asset
  29. BIN
      Butterflies/Resources/Sprites/5.png
  30. 5 0
      Butterflies/Resources/Sprites/5.png.asset
  31. BIN
      Butterflies/Resources/Sprites/6.png
  32. 5 0
      Butterflies/Resources/Sprites/6.png.asset
  33. 55 0
      Butterflies/Resources/Sprites/butterfly.scml
  34. 5 0
      Butterflies/Resources/Sprites/butterfly.scml.asset

+ 1 - 0
Butterflies/.gitignore

@@ -0,0 +1 @@
+Cache/*

+ 0 - 0
Butterflies/Butterflies.atomic


+ 5 - 0
Butterflies/Resources.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "c5a14ededf7c8df707fd8b3f83ffe0d3",
+	"FolderImporter": {}
+}

+ 5 - 0
Butterflies/Resources/Components.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "454d0bd8b7099b6e27219171adfda921",
+	"FolderImporter": {}
+}

+ 63 - 0
Butterflies/Resources/Components/Butterfly.js

@@ -0,0 +1,63 @@
+'atomic component';
+
+var halfWidth = Atomic.graphics.width * Atomic.PIXEL_SIZE * 0.5;
+var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
+
+exports.component = function(self) {
+
+    var node = self.node;
+    node.scale2D = [2, 2];
+    self.speed = 1 + 2 * Math.random();
+    self.rotationSpeed = 10;
+    self.direction = Math.random() * Math.PI * 2;
+    self.time = 0.0;
+
+    self.start = function() {
+
+        self.pos = node.getPosition2D();
+        self.spr = node.getComponent("AnimatedSprite2D");
+
+    }
+
+    self.update = function(timeStep) {
+
+        self.time += timeStep;
+        if (self.time % 1000 / 1000 < 0.5) self.desiredDirection = Math.random() * Math.PI * 2;
+        self.direction = self.circWrapTo(self.direction, self.desiredDirection, self.rotationSpeed * timeStep);
+        self.pos[0] += Math.cos(self.direction) * self.speed * timeStep;
+        self.pos[1] += Math.sin(self.direction) * self.speed * timeStep;
+        node.position2D = self.pos;
+        node.rotation2D = (self.direction + Math.PI * 3 / 2) * (180 / Math.PI);
+        if (self.pos[0] < -halfWidth || self.pos[1] < -halfHeight || self.pos[0] > halfWidth || self.pos[1] > halfHeight)
+            node.remove();
+    }
+
+    self.circWrapTo = function(value, target, step) {
+        if (value == target) return target;
+        var max = Math.PI * 2;
+        var result = value;
+        var d = self.wrappedDistance(value, target, max);
+        if (Math.abs(d) < step) return target;
+        result += (d < 0 ? -1 : 1) * step;
+        if (result > max) result = result - max;
+        else if (result < 0) result = max + result;
+        return result;
+    };
+    self.wrappedDistance = function(a, b, max) {
+
+        if (a == b) return 0;
+        var l;
+        var r;
+        if (a < b) {
+            l = -a - max + b;
+            r = b - a;
+        } else {
+            l = b - a;
+            r = max - a + b;
+        }
+        if (Math.abs(l) > Math.abs(r)) return r;
+        else return l;
+    };
+
+
+}

+ 7 - 0
Butterflies/Resources/Components/Butterfly.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "95b3015b5a33af615714a15daac1cd8d",
+	"JavascriptImporter": {
+		"IsComponentFile": true
+	}
+}

+ 39 - 0
Butterflies/Resources/Components/Spawner.js

@@ -0,0 +1,39 @@
+'atomic component';
+
+exports.component = function(self) {
+
+    var viewport = Atomic.renderer.getViewport(0);
+    var animationSet = Atomic.cache.getResource("AnimationSet2D", "Sprites/butterfly.scml");
+
+    self.update = function(timeStep) {
+
+        if (Atomic.input.getMouseButtonDown(Atomic.MOUSEB_LEFT)) {
+
+            var mpos = Atomic.input.getMousePosition();
+            var pos = viewport.screenToWorldPoint(mpos[0], mpos[1], 0);
+
+            var butterfly = self.scene.createChild("Butterfly");
+            butterfly.position2D = pos;
+
+            var spr = butterfly.createComponent("AnimatedSprite2D");
+
+            spr.animationSet = animationSet;
+            spr.setAnimation("idle");
+            spr.color = [.1 + Math.random() * .9, .1 + Math.random() * .9, .1 + Math.random() * .9, 1];
+            spr.blendMode = Atomic.BLEND_ALPHA;
+            butterfly.createJSComponent("Components/Butterfly.js");
+
+        } else if (Atomic.input.getMouseButtonPress(Atomic.MOUSEB_RIGHT)) {
+
+            var emitter = self.scene.createChild("ButterflyEmitter");
+            var mpos = Atomic.input.getMousePosition();
+            var pos = viewport.screenToWorldPoint(mpos[0], mpos[1], 0);
+            emitter.position2D = pos;
+            var pex = emitter.createComponent("ParticleEmitter2D");
+            pex.effect = Atomic.cache.getResource("ParticleEffect2D", "Particles/particle.pex");
+
+        }
+
+    }
+
+}

+ 7 - 0
Butterflies/Resources/Components/Spawner.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "45592974555d02de64d8f3637f3802cc",
+	"JavascriptImporter": {
+		"IsComponentFile": true
+	}
+}

+ 5 - 0
Butterflies/Resources/Particles.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "446a4b7ae157fcb28a8d8698fcbb07d0",
+	"FolderImporter": {}
+}

+ 39 - 0
Butterflies/Resources/Particles/particle.pex

@@ -0,0 +1,39 @@
+<particleEmitterConfig>
+  <texture name="texture.png"/>
+  <sourcePosition x="300.00" y="300.00"/>
+  <sourcePositionVariance x="736.96" y="157.51"/>
+  <speed value="1"/>
+  <speedVariance value="10"/>
+  <particleLifeSpan value="10"/>
+  <particleLifespanVariance value="20"/>
+  <angle value="0"/>
+  <angleVariance value="360"/>
+  <gravity x="-44.6" y="-226.78"/>
+  <radialAcceleration value="-44.26"/>
+  <tangentialAcceleration value="-8.79"/>
+  <radialAccelVariance value="154.06"/>
+  <tangentialAccelVariance value="470.19"/>
+  <startColor red="0.1" green="0.1" blue="0.1" alpha="1.0"/>
+  <startColorVariance red="0.5" green="0.5" blue="0.5" alpha="1.0"/>
+  <finishColor red="0.1" green="0.1" blue="0.1" alpha="1.0"/>
+  <finishColorVariance red="0.5" green="0.5" blue="0.5" alpha="1.0"/>
+  <maxParticles value="1000"/>
+  <startParticleSize value="2"/>
+  <startParticleSizeVariance value="5"/>
+  <finishParticleSize value="20"/>
+  <FinishParticleSizeVariance value="30"/>
+  <duration value="-1.00"/>
+  <emitterType value="0"/>
+  <maxRadius value="43.98"/>
+  <maxRadiusVariance value="377.4"/>
+  <minRadius value="84.07"/>
+  <minRadiusVariance value="307.95"/>
+  <rotatePerSecond value="271.58"/>
+  <rotatePerSecondVariance value="243.34"/>
+  <blendFuncSource value="770"/>
+  <blendFuncDestination value="1"/>
+  <rotationStart value="43.88"/>
+  <rotationStartVariance value="275.21"/>
+  <rotationEnd value="184.57"/>
+  <rotationEndVariance value="180.85"/>
+</particleEmitterConfig>

+ 5 - 0
Butterflies/Resources/Particles/particle.pex.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "f8c6188180699fbedda600eae3f4a49f",
+	"PEXImporter": {}
+}

BIN
Butterflies/Resources/Particles/texture.png


+ 5 - 0
Butterflies/Resources/Particles/texture.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "119e283e886e515dd05420f7fe21d273",
+	"TextureImporter": {}
+}

+ 5 - 0
Butterflies/Resources/Scenes.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "2ba799b159e9302bcd82f1bfa61d1085",
+	"FolderImporter": {}
+}

+ 48 - 0
Butterflies/Resources/Scenes/Scene.scene

@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<scene id="1">
+	<attribute name="Name" value="" />
+	<attribute name="Time Scale" value="1" />
+	<attribute name="Smoothing Constant" value="50" />
+	<attribute name="Snap Threshold" value="5" />
+	<attribute name="Elapsed Time" value="0" />
+	<attribute name="Next Replicated Node ID" value="369" />
+	<attribute name="Next Replicated Component ID" value="1985" />
+	<attribute name="Next Local Node ID" value="16778496" />
+	<attribute name="Next Local Component ID" value="16777216" />
+	<attribute name="Variables" />
+	<attribute name="Variable Names" value="" />
+	<component type="Octree" id="2" />
+	<component type="DebugRenderer" id="3" />
+	<component type="Renderer2D" id="1976" />
+	<component type="JSComponent" id="1981">
+		<attribute name="ComponentFile" value="JSComponentFile;Components/Spawner.js" />
+	</component>
+	<node id="361">
+		<attribute name="Is Enabled" value="true" />
+		<attribute name="Name" value="Camera" />
+		<attribute name="Position" value="0 0 -5" />
+		<attribute name="Rotation" value="1 0 0 0" />
+		<attribute name="Scale" value="1 1 1" />
+		<attribute name="Variables" />
+		<component type="Camera" id="1973">
+			<attribute name="Near Clip" value="0" />
+			<attribute name="Orthographic" value="true" />
+			<attribute name="Orthographic Size" value="8" />
+		</component>
+	</node>
+	<node id="368">
+		<attribute name="Is Enabled" value="true" />
+		<attribute name="Name" value="Node" />
+		<attribute name="Position" value="0 0 0" />
+		<attribute name="Rotation" value="1 0 0 0" />
+		<attribute name="Scale" value="1 1 1" />
+		<attribute name="Variables" />
+		<component type="ParticleEmitter2D" id="1984">
+			<attribute name="Layer" value="1" />
+			<attribute name="Order in Layer" value="1" />
+			<attribute name="Particle Effect" value="ParticleEffect2D;Particles/particle.pex" />
+			<attribute name="Sprite " value="Sprite2D;Particles/texture.png" />
+			<attribute name="Blend Mode" value="addalpha" />
+		</component>
+	</node>
+</scene>

+ 5 - 0
Butterflies/Resources/Scenes/Scene.scene.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "f2b371bcae7cd3102046cd26214fab71",
+	"SceneImporter": {}
+}

+ 5 - 0
Butterflies/Resources/Scripts.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "e4a74b5d6803ecf9eb1be3ec3fea325d",
+	"FolderImporter": {}
+}

+ 3 - 0
Butterflies/Resources/Scripts/main.js

@@ -0,0 +1,3 @@
+// This script is the main entry point of the game
+
+Atomic.player.loadScene("Scenes/Scene.scene");

+ 7 - 0
Butterflies/Resources/Scripts/main.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "eca179757c676750cf21705aac3161ad",
+	"JavascriptImporter": {
+		"IsComponentFile": false
+	}
+}

+ 5 - 0
Butterflies/Resources/Sprites.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "084acd70b72b2db1f3204453d2af4a0b",
+	"FolderImporter": {}
+}

BIN
Butterflies/Resources/Sprites/1.png


+ 5 - 0
Butterflies/Resources/Sprites/1.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "e2e40bd07c80688fb2d8013db3748ce8",
+	"TextureImporter": {}
+}

BIN
Butterflies/Resources/Sprites/2.png


+ 5 - 0
Butterflies/Resources/Sprites/2.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "0715a2e165d35e821d120908263d623a",
+	"TextureImporter": {}
+}

BIN
Butterflies/Resources/Sprites/3.png


+ 5 - 0
Butterflies/Resources/Sprites/3.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "126a73567e64033c69a67fba65f2862f",
+	"TextureImporter": {}
+}

BIN
Butterflies/Resources/Sprites/4.png


+ 5 - 0
Butterflies/Resources/Sprites/4.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "98beee1b3dd7608051e00918466ca722",
+	"TextureImporter": {}
+}

BIN
Butterflies/Resources/Sprites/5.png


+ 5 - 0
Butterflies/Resources/Sprites/5.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "63cfca5a7aef8b399f623681d705ac80",
+	"TextureImporter": {}
+}

BIN
Butterflies/Resources/Sprites/6.png


+ 5 - 0
Butterflies/Resources/Sprites/6.png.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "31375181ba3b9c9ce1786336c1c6f215",
+	"TextureImporter": {}
+}

+ 55 - 0
Butterflies/Resources/Sprites/butterfly.scml

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="r4.1" pixel_mode="1">
+    <folder id="0">
+        <file id="0" name="1.png" width="18" height="18" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="1" name="2.png" width="18" height="18" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="2" name="3.png" width="18" height="18" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="3" name="4.png" width="18" height="18" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="4" name="5.png" width="18" height="18" pivot_x="0.5" pivot_y="0.5"/>
+        <file id="5" name="6.png" width="18" height="18" pivot_x="0.5" pivot_y="0.5"/>
+    </folder>
+    <entity id="0" name="butterfly">
+        <animation id="0" name="idle" length="500" interval="100">
+            <mainline>
+                <key id="0">
+                    <object_ref id="0" timeline="0" key="0" z_index="0"/>
+                </key>
+                <key id="1" time="100">
+                    <object_ref id="0" timeline="0" key="1" z_index="0"/>
+                </key>
+                <key id="2" time="200">
+                    <object_ref id="0" timeline="0" key="2" z_index="0"/>
+                </key>
+                <key id="3" time="300">
+                    <object_ref id="0" timeline="0" key="3" z_index="0"/>
+                </key>
+                <key id="4" time="400">
+                    <object_ref id="0" timeline="0" key="4" z_index="0"/>
+                </key>
+                <key id="5" time="500">
+                    <object_ref id="0" timeline="0" key="5" z_index="0"/>
+                </key>
+            </mainline>
+            <timeline id="0" name="1">
+                <key id="0" spin="0">
+                    <object folder="0" file="0"/>
+                </key>
+                <key id="1" time="100" spin="0">
+                    <object folder="0" file="1"/>
+                </key>
+                <key id="2" time="200" spin="0">
+                    <object folder="0" file="2"/>
+                </key>
+                <key id="3" time="300" spin="0">
+                    <object folder="0" file="3"/>
+                </key>
+                <key id="4" time="400" spin="0">
+                    <object folder="0" file="4"/>
+                </key>
+                <key id="5" time="500" spin="0">
+                    <object folder="0" file="5"/>
+                </key>
+            </timeline>
+        </animation>
+    </entity>
+</spriter_data>

+ 5 - 0
Butterflies/Resources/Sprites/butterfly.scml.asset

@@ -0,0 +1,5 @@
+{
+	"version": 1,
+	"guid": "1717377a5edb73848a5f149b2f8ac7cb",
+	"SpriterImporter": {}
+}