Skip to content

Commit

Permalink
Add edentity blocks & createblock()
Browse files Browse the repository at this point in the history
This adds editor entity blocks (boxes which do different things on collision) like activity zones, hurt boxes, etc.

This also adds a command to go along with it, to both match `createentity` and so block spawning can be behind conditions.
  • Loading branch information
AllyTally committed Jan 16, 2023
1 parent 172e3a8 commit 4b83bac
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 10 deletions.
30 changes: 24 additions & 6 deletions desktop_version/src/CustomLevels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,15 @@ bool customlevelclass::load(std::string& _path)
edEntityEl->QueryIntAttribute("p5", &entity.p5);
edEntityEl->QueryIntAttribute("p6", &entity.p6);

const char* activitytext = "";
const char* activitycolour = "";

edEntityEl->QueryStringAttribute("activitytext", &activitytext);
edEntityEl->QueryStringAttribute("activitycolour", &activitycolour);

entity.activitytext = activitytext;
entity.activitycolour = activitycolour;

customentities.push_back(entity);
}
}
Expand Down Expand Up @@ -1409,14 +1418,23 @@ bool customlevelclass::save(const std::string& _path)
{
tinyxml2::XMLElement *edentityElement = doc.NewElement( "edentity" );
edentityElement->SetAttribute( "x", customentities[i].x);
edentityElement->SetAttribute( "y", customentities[i].y);
edentityElement->SetAttribute( "t", customentities[i].t);
edentityElement->SetAttribute( "p1", customentities[i].p1);
edentityElement->SetAttribute( "p2", customentities[i].p2);
edentityElement->SetAttribute( "p3", customentities[i].p3);
edentityElement->SetAttribute( "y", customentities[i].y);
edentityElement->SetAttribute( "t", customentities[i].t);
edentityElement->SetAttribute( "p1", customentities[i].p1);
edentityElement->SetAttribute( "p2", customentities[i].p2);
edentityElement->SetAttribute( "p3", customentities[i].p3);
edentityElement->SetAttribute( "p4", customentities[i].p4);
edentityElement->SetAttribute( "p5", customentities[i].p5);
edentityElement->SetAttribute( "p6", customentities[i].p6);
edentityElement->SetAttribute( "p6", customentities[i].p6);
if (!customentities[i].activitytext.empty())
{
edentityElement->SetAttribute("activitytext", customentities[i].activitytext.c_str());
}
if (!customentities[i].activitycolour.empty())
{
edentityElement->SetAttribute("activitycolour", customentities[i].activitycolour.c_str());
}

edentityElement->LinkEndChild( doc.NewText( customentities[i].scriptname.c_str() )) ;
msg->LinkEndChild( edentityElement );
}
Expand Down
2 changes: 2 additions & 0 deletions desktop_version/src/CustomLevels.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class CustomEntity
//parameters
int p1, p2, p3, p4, p5, p6;
std::string scriptname;
std::string activitycolour;
std::string activitytext;
};


Expand Down
62 changes: 58 additions & 4 deletions desktop_version/src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ static void addedentity( int xp, int yp, int tp, int p1 = 0, int p2 = 0, int p3
entity.p5=p5;
entity.p6=p6;
entity.scriptname="";
entity.activitytext="";
entity.activitycolour="";

customentities.push_back(entity);
}
Expand Down Expand Up @@ -798,14 +800,66 @@ void editorrender(void)
}
break;
}
case 19: //Script Triggers
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),customentities[i].p1*8,customentities[i].p2*8,graphics.getRGB(255,164,255));
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),8,8,graphics.getRGB(255,255,255));
case 19: // Script Triggers
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), customentities[i].p1 * 8, customentities[i].p2 * 8, graphics.getRGB(255, 164, 255));
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), 8, 8, graphics.getRGB(255, 255, 255));
if (i == edent_under_cursor)
{
graphics.bprint((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8)-8,customentities[i].scriptname,210,210,255);
graphics.bprint((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8) - 8, customentities[i].scriptname, 210, 210, 255);
}
break;
case 20: // Activity Zones
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), customentities[i].p1 * 8, customentities[i].p2 * 8, graphics.getRGB(164, 255, 255));
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), 8, 8, graphics.getRGB(255, 255, 255));
if (i == edent_under_cursor)
{
graphics.bprint((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8) - 8, customentities[i].scriptname, 210, 210, 255);
}
break;
case 21: // Collision Boxes
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), customentities[i].p1 * 8, customentities[i].p2 * 8, graphics.getRGB(164, 255, 164));
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), 8, 8, graphics.getRGB(255, 255, 255));
break;
case 22: // Damage Boxes
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), customentities[i].p1 * 8, customentities[i].p2 * 8, graphics.getRGB(255, 164, 164));
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), 8, 8, graphics.getRGB(255, 255, 255));
break;
case 23: // Directional Boxes
{
int x = (customentities[i].x * 8) - (ed.levx * 40 * 8);
int y = (customentities[i].y * 8) - (ed.levy * 30 * 8);

// Move x and y to the center of the box
x += (customentities[i].p1 - 1) * 4;
y += (customentities[i].p2 - 1) * 4;

if (customentities[i].p3 == 0)
{
// UP ARROW
graphics.bprint(x, y, "\xE2\x86\x91", 255, 255, 255);
}
else if (customentities[i].p3 == 1)
{
// DOWN ARROW
graphics.bprint(x, y, "\xE2\x86\x93", 255, 255, 255);
}
else if (customentities[i].p3 == 2)
{
// LEFT ARROW
graphics.bprint(x, y, "\xE2\x86\x90", 255, 255, 255);
}
else if (customentities[i].p3 == 3)
{
// RIGHT ARROW
graphics.bprint(x, y, "\xE2\x86\x92", 255, 255, 255);
}
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), customentities[i].p1 * 8, customentities[i].p2 * 8, graphics.getRGB(255, 255, 164));
break;
}
case 24: // Safe Boxes
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), customentities[i].p1 * 8, customentities[i].p2 * 8, graphics.getRGB(164, 164, 255));
fillboxabs((customentities[i].x * 8) - (ed.levx * 40 * 8), (customentities[i].y * 8) - (ed.levy * 30 * 8), 8, 8, graphics.getRGB(255, 255, 255));
break;
case 50: //Warp lines
if(customentities[i].p1>=2) //Horizontal
{
Expand Down
1 change: 1 addition & 0 deletions desktop_version/src/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ void entityclass::createblock( int t, int xp, int yp, int w, int h, int trig /*=
block.type = ACTIVITY;
block.wp = w;
block.hp = h;
block.script = script;
block.rectset(xp, yp, w, h);

//Ok, each and every activity zone in the game is initilised here. "Trig" in this case is a variable that
Expand Down
18 changes: 18 additions & 0 deletions desktop_version/src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,24 @@ void mapclass::loadlevel(int rx, int ry)
obj.createblock(TRIGGER, ex, ey, ent.p1 * 8, ent.p2 * 8, 300 + tempscriptbox, "custom_" + ent.scriptname);
tempscriptbox++;
break;
case 20: // Activity Zone
obj.customactivitytext = ent.activitytext;
obj.customactivitycolour = ent.activitycolour;
obj.customscript = ent.scriptname;
obj.createblock(ACTIVITY, ex, ey, ent.p1 * 8, ent.p2 * 8, 35, "custom_" + ent.scriptname, true);
break;
case 21: // Collision Box
obj.createblock(BLOCK, ex, ey, ent.p1 * 8, ent.p2 * 8);
break;
case 22: // Damage Box
obj.createblock(DAMAGE, ex, ey, ent.p1 * 8, ent.p2 * 8);
break;
case 23: // Directional Box
obj.createblock(DIRECTIONAL, ex, ey, ent.p1 * 8, ent.p2 * 8, ent.p3);
break;
case 24: // Safe Box
obj.createblock(SAFE, ex, ey, ent.p1 * 8, ent.p2 * 8);
break;
case 50: // Warp Lines
obj.customwarpmode=true;
switch (ent.p1)
Expand Down
34 changes: 34 additions & 0 deletions desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,40 @@ void scriptclass::run(void)
words[8] = word8;
words[9] = word9;
}
else if (words[0] == "createblock")
{
int i = BLOCK;
if (words[1] == "block")
{
i = BLOCK;
}
else if (words[1] == "trigger" || words[1] == "script")
{
i = TRIGGER;
}
else if (words[1] == "damage")
{
i = DAMAGE;
}
else if (words[1] == "directional")
{
i = DIRECTIONAL;
}
else if (words[1] == "safe")
{
i = SAFE;
}
else if (words[1] == "activity")
{
i = ACTIVITY;
}
else
{
i = ss_toi(words[1]);
}

obj.createblock(i, ss_toi(words[2]), ss_toi(words[3]), ss_toi(words[4]), ss_toi(words[5]), ss_toi(words[6]), words[7], true);
}
else if (words[0] == "createcrewman")
{
// Note: Do not change the "r" variable, it's used in custom levels
Expand Down

0 comments on commit 4b83bac

Please sign in to comment.