Skip to content

Commit

Permalink
prevent having multiple stickmen on the screen, also add playerst.spa…
Browse files Browse the repository at this point in the history
…wnID
  • Loading branch information
jacob1 committed Nov 20, 2014
1 parent 8233b28 commit 6066ae8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 21 deletions.
93 changes: 72 additions & 21 deletions src/simulation/Simulation.cpp
Expand Up @@ -86,6 +86,8 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)

if ((player.spwn == 1 && tempPart.type==PT_STKM) || (player2.spwn == 1 && tempPart.type==PT_STKM2))
continue;
if ((tempPart.type == PT_SPAWN && elementCount[PT_SPAWN]) || (tempPart.type == PT_SPAWN2 && elementCount[PT_SPAWN2]))
continue;
if (!elements[tempPart.type].Enabled)
continue;

Expand Down Expand Up @@ -136,6 +138,14 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
player2.elem = PT_DUST;
player2.rocketBoots = false;
}
else if (parts[i].type == PT_SPAWN)
{
player.spawnID = i;
}
else if (parts[i].type == PT_SPAWN2)
{
player2.spawnID = i;
}
else if (parts[i].type == PT_FIGH)
{
//TODO: 100 should be replaced with a macro
Expand Down Expand Up @@ -1922,7 +1932,9 @@ void Simulation::clear_sim(void)
elementRecount = true;
fighcount = 0;
player.spwn = 0;
player.spawnID = -1;
player2.spwn = 0;
player2.spawnID = -1;
//memset(pers_bg, 0, WINDOWW*YRES*PIXELSIZE);
//memset(fire_r, 0, sizeof(fire_r));
//memset(fire_g, 0, sizeof(fire_g));
Expand Down Expand Up @@ -2640,6 +2652,16 @@ void Simulation::kill_part(int i)//kills particle number i
{
player2.spwn = 0;
}
else if (parts[i].type == PT_SPAWN)
{
if (player.spawnID == i)
player.spawnID = -1;
}
else if (parts[i].type == PT_SPAWN2)
{
if (player2.spawnID == i)
player2.spawnID = -1;
}
else if (parts[i].type == PT_FIGH)
{
fighters[(unsigned char)parts[i].tmp].spwn = 0;
Expand Down Expand Up @@ -2671,6 +2693,16 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type
player.spwn = 0;
else if (parts[i].type == PT_STKM2)
player2.spwn = 0;
else if (parts[i].type == PT_SPAWN)
{
if (player.spawnID == i)
player.spawnID = -1;
}
else if (parts[i].type == PT_SPAWN2)
{
if (player2.spawnID == i)
player2.spawnID = -1;
}
else if (parts[i].type == PT_FIGH)
{
fighters[(unsigned char)parts[i].tmp].spwn = 0;
Expand All @@ -2679,6 +2711,17 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type
else if (parts[i].type == PT_SOAP)
Element_SOAP::detach(this, i);

if ((t == PT_STKM || t == PT_STKM2 || t == PT_SPAWN || t == PT_SPAWN2) && elementCount[t])
{
kill_part(i);
return;
}
else if ((t == PT_STKM && player.spwn) || (t == PT_STKM2 && player2.spwn))
{
kill_part(i);
return;
}

parts[i].type = t;
if (elements[t].Properties & TYPE_ENERGY)
{
Expand Down Expand Up @@ -2985,8 +3028,21 @@ int Simulation::create_part(int p, int x, int y, int tv)
if (parts[i].tmp > 300)
parts[i].tmp=300;
break;
case PT_BIZR: case PT_BIZRG: case PT_BIZRS:
parts[i].ctype = 0x47FFFF;
break;
case PT_DTEC:
case PT_TSNS:
parts[i].tmp2 = 2;
break;
case PT_VIRS:
case PT_VRSS:
case PT_VRSG:
parts[i].pavg[1] = 250;
break;
case PT_STKM:
if (player.spwn==0)
{
if (player.spwn == 0)
{
parts[i].life = 100;
Element_STKM::STKM_init_legs(this, &player, i);
Expand All @@ -2995,12 +3051,16 @@ int Simulation::create_part(int p, int x, int y, int tv)
}
else
{
parts[i].type=0;
parts[i].type = 0;
return -1;
}
create_part(-3,x,y,PT_SPAWN);
int spawnID = create_part(-3, x, y, PT_SPAWN);
if (spawnID >= 0)
player.spawnID = spawnID;
break;
}
case PT_STKM2:
{
if (player2.spwn==0)
{
parts[i].life = 100;
Expand All @@ -3013,20 +3073,11 @@ int Simulation::create_part(int p, int x, int y, int tv)
parts[i].type=0;
return -1;
}
create_part(-3,x,y,PT_SPAWN2);
break;
case PT_BIZR: case PT_BIZRG: case PT_BIZRS:
parts[i].ctype = 0x47FFFF;
break;
case PT_DTEC:
case PT_TSNS:
parts[i].tmp2 = 2;
break;
case PT_VIRS:
case PT_VRSS:
case PT_VRSG:
parts[i].pavg[1] = 250;
int spawnID = create_part(-3, x, y, PT_SPAWN2);
if (spawnID >= 0)
player2.spawnID = spawnID;
break;
}
case PT_FIGH:
{
unsigned char fcount = 0;
Expand Down Expand Up @@ -3607,13 +3658,13 @@ void Simulation::update_particles_i(int start, int inc)
kill_part(i);
continue;
}

if (parts[i].type == PT_SPAWN && !player.spwn)
create_part(-1, parts[i].x, parts[i].y, PT_STKM);
else if (parts[i].type == PT_SPAWN2 && !player2.spwn)
create_part(-1, parts[i].x, parts[i].y, PT_STKM2);
}

if (!player.spwn && player.spawnID >= 0)
create_part(-1, (int)parts[player.spawnID].x, (int)parts[player.spawnID].y, PT_STKM);
else if (!player2.spwn && player2.spawnID >= 0)
create_part(-1, (int)parts[player2.spawnID].x, (int)parts[player2.spawnID].y, PT_STKM2);

//the main particle loop function, goes over all particles.
for (i=0; i<=parts_lastActiveIndex; i++)
if (parts[i].type)
Expand Down
1 change: 1 addition & 0 deletions src/simulation/Stickman.h
Expand Up @@ -11,6 +11,7 @@ struct playerst
char spwn; //if stick man was spawned
unsigned int frames; //frames since last particle spawn - used when spawning LIGH
bool rocketBoots;
int spawnID; //id of the SPWN particle that spawns it
};

#endif

0 comments on commit 6066ae8

Please sign in to comment.