Hello,
So at the end of my post is the code for the spikes, but the way they work is that when they're not active, they start a timer. When this timer elapses, they become non active again.
While active, if you walk within 2 tiles of them, you get skewered. But here's the problem, if I have multiple spikes, they all hit me, even if I'm only on one of them. Here's the code.
spike@[] spikes(0); bool shitby=false;
class spike
{
int numb=random(1,4);
int x,y;
bool active=false;
timer activetimer; int activetime=random(300,500);
spike(int sx, int sy)
{
x=sx;
y=sy;
}
}
void spikeloop()
{
for (uint i=0; i<spikes.length(); i++)
{
if(spikes[i].active==false and spikes[i].activetimer.elapsed>=spikes[i].activetime)
{
spikes[i].active=true;
spikes[i].activetimer.restart();
p.play_3d("sounds/spike"+spikes[i].numb+".ogg",me.x,me.y,me.z,spikes[i].x,spikes[i].y,0,false);
}
else if(spikes[i].active==true and spikes[i].activetimer.elapsed>=spikes[i].activetime)
{
spikes[i].activetimer.restart();
spikes[i].active=false;
shitby=false;
}
if(me.x>spikes[i].x-2 and me.x<spikes[i].x+2 and me.y>spikes[i].y-2 and me.y<spikes[i].y+2 and spikes[i].active==true and shitby==false)
{
p.play_3d("sounds/spikehit"+random(1,2)+".ogg",me.x,me.y,me.z,spikes[i].x,spikes[i].y,0,false);
pain();
lhit="An iron spike";
health-=1;
shitby=true;}}
}
void spawn_spike(int x, int y)
{
spike s1(x,y);
spikes.insert_last(s1);
}
void destroy_all_spikes()
{
spikes.resize(0);
}
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)