Couple Questions:
1. what are you making this with? are you using flashpunk, flixel, or just regular old flash?
2. what it the purpose of the mushrooms? could there be one object and then the mushrooms are all displayed using a tilemap?
1. I'm using Flixel to develop this.
2. I guess I could actually display them as tilemap objects but the mushrooms aren't the real problem here, it's the lightsources that they use. See John Sandoval's light tutorial for GM to see the theory on how I'm doing it, or just look at this code:
Mushroom class:
package Helpers.CaveGen
{
import org.flixel.FlxPoint;
import org.flixel.FlxSprite;
import org.flixel.FlxU;
import org.flixel.FlxG;
/**
* ...
* @author Ashkin
*/
public class Mushroom extends FlxSprite
{
[Embed(source = 'mushrooms.png')] public var ImgMushrooms:Class;
public var infocus:Boolean = false;
public var light:Light;
public var removed:Boolean = false;
public function Mushroom(X:int, Y:int)
{
super(X, Y);
loadGraphic(ImgMushrooms, true, true);
addAnimation("1", [0], 10, true);
addAnimation("2", [1], 10, true);
addAnimation("3", [2], 10, true);
addAnimation("4", [3], 10, true);
var random:int = Math.round(Math.random() * 3);
if (random == 0)
{
play("1");
}
if (random == 1)
{
play("2");
}
if (random == 2)
{
play("3");
}
if (random == 3)
{
play("4");
}
var random2:int = Math.round(Math.random());
if (random2 == 0)
{
facing = LEFT;
}
if (random2 == 1)
{
facing == RIGHT;
}
light = new Light(this, CaveGen.darkness, 100, 0xBAFFFF, 0.5);
light.on = true;
CaveGen.lights.add(light);
CaveGen.mushrooms.add(this);
}
override public function update():void
{
super.update();
}
override public function destroy():void
{
CaveGen.mushrooms.remove(this);
super.destroy();
}
}
}
Light class:
package Helpers.CaveGen
{
import org.flixel.FlxSprite;
import org.flixel.FlxG;
/**
* ...
* @author Ashkin
*/
public class Light extends FlxSprite
{
[Embed(source = 'light.png')] public var ImgLight:Class;
public var darkness:FlxSprite;
public var object:FlxSprite;
public var flickeramount:int = 100;
public var on:Boolean = false;
public function Light(_object:FlxSprite, _darkness:FlxSprite, _flickeramount:int = 100, tint:int = 0xFFFFFF, size:Number = 1):void
{
super(0, 0, ImgLight);
object = _object;
flickeramount = _flickeramount;
color = tint;
scale.x = size;
scale.y = size;
darkness = _darkness;
blend = "screen";
}
override public function update():void
{
if (on)
{
super.update();
}
}
override public function draw():void
{
if (on && Math.random()*100 <= flickeramount)
{
darkness.stamp(this, object.getScreenXY(null, CaveGen.camera).x - width/2, object.getScreenXY(null, CaveGen.camera).y - height/2);
}
}
}
}
Excuse the messy code.