Browse Source

BunnyMark

Josh Engebretson 10 years ago
parent
commit
24d9bdaaf4

+ 1 - 0
BunnyMark/.gitignore

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

+ 0 - 0
BunnyMark/BunnyMark.atomic


+ 5 - 0
BunnyMark/Resources.asset

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

+ 5 - 0
BunnyMark/Resources/Components.asset

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

+ 5 - 0
BunnyMark/Resources/Scenes.asset

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

+ 31 - 0
BunnyMark/Resources/Scenes/Scene.scene

@@ -0,0 +1,31 @@
+<?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="365" />
+	<attribute name="Next Replicated Component ID" value="1979" />
+	<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="PhysicsWorld" id="1" />
+	<component type="Octree" id="2" />
+	<component type="DebugRenderer" id="3" />
+	<component type="Renderer2D" id="1976" />
+	<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>
+</scene>

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

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

+ 5 - 0
BunnyMark/Resources/Scripts.asset

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

+ 125 - 0
BunnyMark/Resources/Scripts/main.js

@@ -0,0 +1,125 @@
+// This script is the main entry point of the game
+
+var halfWidth = Atomic.graphics.width * Atomic.PIXEL_SIZE * 0.5;
+var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
+
+
+var maxX = halfWidth;
+var minX = -halfWidth;
+var maxY = halfHeight;
+var minY = -halfHeight;
+
+
+Atomic.player.loadScene("Scenes/Scene.scene");
+
+var scene = Atomic.player.currentScene;
+
+var sheet = Atomic.cache.getResource("SpriteSheet2D", "Sprites/bunnys_sheet.xml");
+
+var bunny1 = sheet.getSprite("bunny1");
+var bunny2 = sheet.getSprite("bunny2");
+var bunny3 = sheet.getSprite("bunny3");
+var bunny4 = sheet.getSprite("bunny4");
+var bunny5 = sheet.getSprite("bunny5");
+
+var bunnyTextures = [bunny1, bunny2, bunny3, bunny4, bunny5];
+var bunnyType = 2;
+var currentTexture = bunnyTextures[bunnyType];
+
+var bunnys = [];
+var count = 0;
+var amount = 10;
+var gravity = -0.5;
+
+var isAdding = false;
+
+scene.subscribeToEvent("MouseButtonDown", function() {
+
+    isAdding = true;
+
+});
+
+scene.subscribeToEvent("MouseButtonUp", function() {
+
+    isAdding = false;
+    bunnyType++;
+    bunnyType %= 5;
+    currentTexture = bunnyTextures[bunnyType];
+});
+
+
+exports.update = function() {
+
+    var scale = [0, 0];
+
+    if (isAdding) {
+
+        if (count < 200000) {
+
+            for (var i = 0; i < amount; i++) {
+
+                var node = scene.createChild();
+                var bunny = node.createComponent("StaticSprite2D");
+                bunny.blendMode = Atomic.BLEND_ALPHA;
+                bunny.sprite = currentTexture;
+
+                bunny.position = [minX, maxY];
+                bunny.speedX = Math.random() * 10;
+                bunny.speedY = (Math.random() * 10) - 5;
+
+                //bunny.anchor.y = 1;
+
+                bunnys.push(bunny);
+
+
+                scale[0] = scale[1] = (0.5 + Math.random() * 0.5);
+                bunny.scale2D = scale;
+
+                bunny.rotation2D = (Math.random() - 0.5)
+                count++;
+            }
+        }
+
+    }
+
+
+    for (var i = 0; i < bunnys.length; i++) {
+
+        var bunny = bunnys[i];
+        var p = bunny.position;
+
+        p[0] += bunny.speedX * .002;
+        p[1] += bunny.speedY * .002;
+
+        bunny.speedY += gravity;
+
+        if (p[0] > maxX) {
+            bunny.speedX *= -1;
+            p[0] = maxX;
+        } else if (p[0] < minX) {
+            bunny.speedX *= -1;
+            p[0] = minX;
+        }
+
+        if (p[1] > maxY) {
+            bunny.speedY = 0;
+            p[1] = maxY;
+        } else if (p[1] < minY) {
+            bunny.speedY *= -0.95;
+            //bunny.spin = (Math.random() - 0.5) * 0.2
+            
+            if (Math.random() > 0.5) {
+                bunny.speedY -= Math.random() * 6;
+            }
+
+            p[1] = minY;
+        }
+
+        bunny.node.position2D = p;
+
+    }
+
+}
+
+
+;

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

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

+ 5 - 0
BunnyMark/Resources/Sprites.asset

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

BIN
BunnyMark/Resources/Sprites/bunnys.png


+ 5 - 0
BunnyMark/Resources/Sprites/bunnys.png.asset

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

+ 10 - 0
BunnyMark/Resources/Sprites/bunnys_sheet.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Created with TexturePacker http://www.codeandweb.com/texturepacker-->
+<!-- $TexturePacker:SmartUpdate:1a17c841c2e0285d52a986d357f78c54:1/1$ -->
+<TextureAtlas imagePath="bunnys.png">
+    <SubTexture name="bunny1" x="2" y="47" width="26" height="37"/>
+    <SubTexture name="bunny2" x="2" y="86" width="26" height="37"/>
+    <SubTexture name="bunny3" x="2" y="125" width="26" height="37"/>
+    <SubTexture name="bunny4" x="2" y="164" width="26" height="37"/>
+    <SubTexture name="bunny5" x="2" y="2" width="26" height="37"/>
+</TextureAtlas>