using System;
using Microsoft.DirectX.DirectDraw;
using Global;
using Global.GlobalClass;
using KillerInstinct.DirectX;
namespace KillerInstinct.Sprites{
public class TreeClass : SpriteClass
{
private int delay = 0;
private int fireCount = 0;
private const int MAX_FIRES = 70;
private int hitsFire = 0;
private SpriteClass[] sprList = new SpriteClass[MAX_FIRES];
public TreeClass(string file, float x, float y)
{
frame.Width = 150;
frame.Height = 150;
framesCount = 4;
framesPerRow = 4;
whichFrame = 0;
layer = LAYER_TREE;
collisionType = CollisionType.BoundingBox;
shrink_factor = 0.2f;
Init(file, CONST.COLORKEY_WHITE, x, y);
}
public override void Update()
{
if (delay == CONST.FRAMES_PER_SECOND/2)
{
if (whichFrame < framesCount-1) whichFrame++;
else whichFrame = 0;
delay = 0;
}
else
{
delay++;
}
}
public override void ReactToCollision(SpriteClass s)
{
if (s.GetType() == typeof(ShotClass))
{
// only explode on BIG shots
if (((ShotClass)s).ShotType != ShotClass.ShotTypes.AltBasic &&
((ShotClass)s).ShotType != ShotClass.ShotTypes.AltL2 &&
((ShotClass)s).ShotType != ShotClass.ShotTypes.AltL3)
{
int newFireCount = global.random(MAX_FIRES/10, MAX_FIRES/2);
if (fireCount+newFireCount < MAX_FIRES)
{
for (int i=0; i<newFireCount; ++i)
{
DamageClass d = new DamageClass(
DamageClass.GetDamageResource(DamageClass.FIRE),
GetFrameMiddle().X+global.random(-50,40),
GetFrameMiddle().Y+global.random(-50,40),
15, 15, 3, 3);
global.spriteList.Add(d);
sprList[fireCount+i] = d;
}
fireCount += newFireCount;
}
hitsFire++;
global.dbg.Out(Debug.DBG2, "TreeClass.ReactToCollision: " + " [" + hitsFire + " hit(s) with " + fireCount + " fires]");
}
}
if (hitsFire>=3)
{
global.dbg.Out(Debug.DBG2, "TreeClass.ReactToCollision: " + " [delete " + fireCount + " fires]");
hitsFire = 0;
// delete fire
for (int i=0; i<fireCount; ++i)
global.spriteList.Delete(sprList[i]);
framesCount = 1;
framesPerRow = 1;
whichFrame = global.random(0, framesCount-1);
layer = 1;
collisionType = CollisionType.NoCollision;
ChangeBitmap(CONST.BMP_TREE_BURNED, CONST.COLORKEY_WHITE);
}
s.speed = 0;
}
}
}
|