Beispiel #1
0
	void handleMouseButtonUp (VariantMap eventData)
	{
		isAdding = false;
		bunnyType++;
		bunnyType %= 5;
		currentTexture = bunnyTextures [bunnyType];

	}
Beispiel #2
0
	void handleUpdate (VariantMap eventData)
	{

		if (isAdding) {

			var scale = new Vector2 ();
			var initPos = new Vector2 (minX, maxY);


			for (var i = 0; i < amount; i++) {

				var bunny = new Bunny ();
				bunnies.Add (bunny);

				var node = scene.CreateChild ();
				bunny.node = node;

				var sprite = (StaticSprite2D)node.CreateComponent ("StaticSprite2D");
				sprite.BlendMode = BlendMode.BLEND_ALPHA;
				sprite.Sprite = currentTexture;

				node.Position2D = bunny.position = initPos;
				bunny.speed.x = (float)(random.NextDouble () * 10);
				bunny.speed.y = (float)(random.NextDouble () * 10) - 5;


				scale.x = scale.y = (0.5f + ((float)random.NextDouble ()) * 0.5f);
				node.Scale2D = scale;

				node.Rotation2D = (((float)random.NextDouble ()) - 0.5f);
			}
		}

		foreach (var bunny in bunnies) {

			var px = bunny.position.x;
			var py = bunny.position.y;

			var speedX = bunny.speed.x;
			var speedY = bunny.speed.y;

			px += speedX * .002f;
			py += speedY * .002f;

			if (px > maxX) {
				speedX *= -1;
				px = maxX;
			} else if (px < minX) {
				speedX *= -1;
				px = minX;
			}

			if (py > maxY) {
				speedY = 0;
				py = maxY;

			} else if (py < minY) {

				speedY *= -0.95f;

				if (((float)random.NextDouble ()) > 0.5f) {
					speedY -= ((float)random.NextDouble ()) * 6f;
				}

				py = minY;
			}

			bunny.speed.x = speedX;
			bunny.speed.y = speedY + gravity;

			bunny.position.x = px;
			bunny.position.y = py;
			bunny.node.Position2D = bunny.position;
			;

		}
				
	}
Beispiel #3
0
	void handleMouseButtonDown (VariantMap eventData)
	{
		isAdding = true;
	}