Skip to content

Commit 3bb65ec

Browse files
committed
Teleporter edentities with custom curves
1 parent 5d2e477 commit 3bb65ec

File tree

8 files changed

+397
-18
lines changed

8 files changed

+397
-18
lines changed

desktop_version/src/Editor.cpp

Lines changed: 220 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include "Vlogging.h"
2828

2929
#define SCRIPT_LINE_PADDING 6
30+
#define LERP(a, b, t) ((a) + (t) * ((b) - (a)))
31+
#define POINT_OFFSET 12
32+
#define POINT_SIZE 6
33+
#define TELEPORTER_ARC_SMOOTHNESS 255
3034

3135
editorclass::editorclass(void)
3236
{
@@ -49,6 +53,7 @@ editorclass::editorclass(void)
4953
register_tool(EditorTool_WARP_LINES, "Warp Lines", "I", SDLK_i, false);
5054
register_tool(EditorTool_CREWMATES, "Crewmates", "O", SDLK_o, false);
5155
register_tool(EditorTool_START_POINT, "Start Point", "P", SDLK_p, false);
56+
register_tool(EditorTool_TELEPORTERS, "Teleporters", "^2", SDLK_2, true);
5257
}
5358

5459
void editorclass::reset(void)
@@ -89,11 +94,18 @@ void editorclass::reset(void)
8994
levy = 0;
9095
keydelay = 0;
9196
lclickdelay = 0;
97+
rclickdelay = 0;
9298
savekey = false;
9399
loadkey = false;
94100
updatetiles = true;
95101
changeroom = true;
96102

103+
dragging = false;
104+
dragging_entity = -1;
105+
dragging_point = 1;
106+
drag_offset_x = 0;
107+
drag_offset_y = 0;
108+
97109
entframe = 0;
98110
entframedelay = 0;
99111

@@ -716,6 +728,73 @@ static void draw_entities(void)
716728
font::print(PR_BOR | PR_CJK_HIGH, x, y - 8, text, 210, 210, 255);
717729
break;
718730
}
731+
case 14: // Teleporters
732+
{
733+
graphics.drawtele(x, y, 1, graphics.getcol(100));
734+
graphics.draw_rect(x, y, 8 * 12, 8 * 12, graphics.getRGB(164, 164, 255));
735+
736+
int sprite = 0;
737+
if (customentities[i].p5 % 2 == 0)
738+
{
739+
sprite += 3;
740+
}
741+
742+
if (customentities[i].p5 >= 2)
743+
{
744+
sprite += 6;
745+
}
746+
747+
graphics.draw_sprite(customentities[i].p3, customentities[i].p4, sprite, graphics.crewcolourreal(0));
748+
749+
SDL_Point triangle[4] = {
750+
{ x + 37 + POINT_OFFSET, y + 37 + POINT_OFFSET },
751+
{ customentities[i].p1 + POINT_OFFSET, customentities[i].p2 + POINT_OFFSET },
752+
{ customentities[i].p3 + POINT_OFFSET, customentities[i].p4 + POINT_OFFSET },
753+
{ x + 37 + POINT_OFFSET, y + 37 + POINT_OFFSET}
754+
};
755+
756+
SDL_SetRenderDrawColor(gameScreen.m_renderer, 164, 255, 255, 255);
757+
SDL_RenderDrawLines(gameScreen.m_renderer, triangle, SDL_arraysize(triangle));
758+
759+
SDL_Point points[TELEPORTER_ARC_SMOOTHNESS + 1];
760+
761+
for (int j = 0; j <= TELEPORTER_ARC_SMOOTHNESS; j++)
762+
{
763+
float progress = (float)j / TELEPORTER_ARC_SMOOTHNESS;
764+
float left_line_x = LERP(x + 37 + POINT_OFFSET, customentities[i].p1 + POINT_OFFSET, progress);
765+
float left_line_y = LERP(y + 37 + POINT_OFFSET, customentities[i].p2 + POINT_OFFSET, progress);
766+
float right_line_x = LERP(customentities[i].p1 + POINT_OFFSET, customentities[i].p3 + POINT_OFFSET, progress);
767+
float right_line_y = LERP(customentities[i].p2 + POINT_OFFSET, customentities[i].p4 + POINT_OFFSET, progress);
768+
769+
SDL_Point coords;
770+
coords.x = LERP(left_line_x, right_line_x, progress);
771+
coords.y = LERP(left_line_y, right_line_y, progress);
772+
773+
points[j] = coords;
774+
}
775+
776+
SDL_SetRenderDrawColor(gameScreen.m_renderer, 164, 255, 164, 255);
777+
SDL_RenderDrawLines(gameScreen.m_renderer, points, SDL_arraysize(points));
778+
779+
int offset = POINT_OFFSET - (POINT_SIZE / 2);
780+
781+
SDL_Color point1 = graphics.getRGB(255, 255, 255);
782+
SDL_Color point2 = graphics.getRGB(255, 255, 255);
783+
784+
if (ed.dragging_entity == i && ed.dragging_point == 1)
785+
{
786+
point1 = graphics.getRGB(164, 164, 255);
787+
}
788+
else if (ed.dragging_entity == i && ed.dragging_point == 2)
789+
{
790+
point2 = graphics.getRGB(164, 164, 255);
791+
}
792+
793+
graphics.draw_rect(customentities[i].p1 + offset, customentities[i].p2 + offset, POINT_SIZE, POINT_SIZE, point1);
794+
graphics.draw_rect(customentities[i].p3 + offset, customentities[i].p4 + offset, POINT_SIZE, POINT_SIZE, point2);
795+
796+
break;
797+
}
719798
case 15: // Crewmates
720799
graphics.draw_sprite(x - 4, y, 144, graphics.crewcolourreal(entity->p1));
721800
graphics.draw_rect(x, y, 16, 24, graphics.getRGB(164, 164, 164));
@@ -988,6 +1067,10 @@ static void draw_cursor(void)
9881067
// 2x3
9891068
graphics.draw_rect(x, y, 16, 24, blue);
9901069
break;
1070+
case EditorTool_TELEPORTERS:
1071+
// 12x12
1072+
graphics.draw_rect(x, y, 96, 96, blue);
1073+
break;
9911074
default:
9921075
break;
9931076
}
@@ -1362,6 +1445,15 @@ void editorclass::draw_tool(EditorTools tool, int x, int y)
13621445
case EditorTool_START_POINT:
13631446
graphics.draw_sprite(x, y, 184, graphics.col_crewcyan);
13641447
break;
1448+
case EditorTool_TELEPORTERS:
1449+
{
1450+
graphics.fill_rect(x, y, 16, 16, graphics.getRGB(16, 16, 16));
1451+
SDL_Color color = graphics.getcol(100);
1452+
graphics.set_texture_color_mod(graphics.grphx.im_teleporter, color.r, color.g, color.b);
1453+
graphics.draw_texture_part(graphics.grphx.im_teleporter, x, y, 136, 40, 16, 16, 1, 1);
1454+
graphics.set_texture_color_mod(graphics.grphx.im_teleporter, 255, 255, 255);
1455+
break;
1456+
}
13651457
default:
13661458
break;
13671459
}
@@ -2192,6 +2284,20 @@ void editorclass::tool_place()
21922284
add_entity(tilex + (levx * 40), tiley + (levy * 30), 16, 0);
21932285
lclickdelay = 1;
21942286
break;
2287+
case EditorTool_TELEPORTERS:
2288+
{
2289+
lclickdelay = 1;
2290+
int x = tilex + (levx * 40);
2291+
int y = tiley + (levy * 30);
2292+
2293+
int point1x = SDL_clamp((x + 9) * 8, -POINT_OFFSET, SCREEN_WIDTH_PIXELS - POINT_OFFSET);
2294+
int point1y = SDL_clamp((y - 4) * 8 + 37, -POINT_OFFSET, SCREEN_HEIGHT_PIXELS - POINT_OFFSET);
2295+
int point2x = SDL_clamp((x + 16) * 8 + 38, -POINT_OFFSET, SCREEN_WIDTH_PIXELS - POINT_OFFSET);
2296+
int point2y = SDL_clamp((y + 8) * 8, -POINT_OFFSET, SCREEN_HEIGHT_PIXELS - POINT_OFFSET);
2297+
2298+
add_entity(x, y, 14, point1x, point1y, point2x, point2y, 1, 7);
2299+
break;
2300+
}
21952301
default:
21962302
break;
21972303
}
@@ -2444,15 +2550,16 @@ static void start_at_checkpoint(void)
24442550
{
24452551
extern editorclass ed;
24462552

2447-
// Scan the room for a start point or a checkpoint, the start point taking priority
2553+
// Scan the room for a start point or a checkpoint/teleporter, the start point taking priority
24482554
int testeditor = -1;
24492555
bool startpoint = false;
24502556

24512557
for (size_t i = 0; i < customentities.size(); i++)
24522558
{
24532559
startpoint = customentities[i].t == 16;
24542560
const bool is_startpoint_or_checkpoint = startpoint ||
2455-
customentities[i].t == 10;
2561+
customentities[i].t == 10 ||
2562+
customentities[i].t == 14;
24562563
if (!is_startpoint_or_checkpoint)
24572564
{
24582565
continue;
@@ -2493,26 +2600,31 @@ static void start_at_checkpoint(void)
24932600
game.edsavey = (customentities[testeditor].y % 30) * 8;
24942601
game.edsaverx = 100 + tx;
24952602
game.edsavery = 100 + ty;
2603+
game.edsavedir = 0;
2604+
game.edsavegc = 0;
24962605

24972606
if (!startpoint)
24982607
{
24992608
// Checkpoint spawn
2500-
if (customentities[testeditor].p1 == 0) // NOT a bool check!
2609+
if (customentities[testeditor].t == 14) {
2610+
// Actually, teleporter!
2611+
game.edsavex += 48;
2612+
game.edsavey += 44;
2613+
game.edsavedir = 1;
2614+
}
2615+
else if (customentities[testeditor].p1 == 0) // NOT a bool check!
25012616
{
25022617
game.edsavegc = 1;
25032618
game.edsavey -= 2;
25042619
}
25052620
else
25062621
{
2507-
game.edsavegc = 0;
25082622
game.edsavey -= 7;
25092623
}
2510-
game.edsavedir = 0;
25112624
}
25122625
else
25132626
{
25142627
// Start point spawn
2515-
game.edsavegc = 0;
25162628
game.edsavey++;
25172629
game.edsavedir = 1 - customentities[testeditor].p1;
25182630
}
@@ -2668,6 +2780,78 @@ static void handle_draw_input()
26682780
}
26692781
}
26702782

2783+
void check_if_dragging(void)
2784+
{
2785+
extern editorclass ed;
2786+
2787+
ed.dragging_entity = -1;
2788+
2789+
// Is the mouse currently over a teleporter point? Loop through entities.
2790+
for (size_t i = 0; i < customentities.size(); i++)
2791+
{
2792+
// If it's not in the current room, continue.
2793+
if (customentities[i].x < ed.levx * 40 || customentities[i].x >= (ed.levx + 1) * 40 ||
2794+
customentities[i].y < ed.levy * 30 || customentities[i].y >= (ed.levy + 1) * 30)
2795+
{
2796+
continue;
2797+
}
2798+
2799+
// If it's not a teleporter, continue.
2800+
if (customentities[i].t != 14)
2801+
{
2802+
continue;
2803+
}
2804+
2805+
// Okay, it's a teleporter. First, is our mouse on a point?
2806+
SDL_Rect point = {
2807+
customentities[i].p3 + POINT_OFFSET - (POINT_SIZE / 2),
2808+
customentities[i].p4 + POINT_OFFSET - (POINT_SIZE / 2),
2809+
POINT_SIZE,
2810+
POINT_SIZE
2811+
};
2812+
2813+
SDL_Point mouse = { key.mx, key.my };
2814+
2815+
if (SDL_PointInRect(&mouse, &point))
2816+
{
2817+
// We're on the second point!
2818+
ed.dragging_entity = i;
2819+
ed.dragging_point = 2;
2820+
ed.drag_offset_x = key.mx - customentities[i].p3;
2821+
ed.drag_offset_y = key.my - customentities[i].p4;
2822+
2823+
if (key.leftbutton)
2824+
{
2825+
ed.dragging = true;
2826+
}
2827+
else if (key.rightbutton && (ed.rclickdelay == 0))
2828+
{
2829+
customentities[i].p5 = (customentities[i].p5 + 1) % 4;
2830+
ed.rclickdelay = 1;
2831+
}
2832+
break;
2833+
}
2834+
2835+
// Nope, let's check the other point...
2836+
point.x = customentities[i].p1 + POINT_OFFSET - (POINT_SIZE / 2);
2837+
point.y = customentities[i].p2 + POINT_OFFSET - (POINT_SIZE / 2);
2838+
2839+
if (SDL_PointInRect(&mouse, &point))
2840+
{
2841+
// We're on the first point!
2842+
ed.dragging_entity = i;
2843+
ed.dragging_point = 1;
2844+
ed.drag_offset_x = key.mx - customentities[i].p1;
2845+
ed.drag_offset_y = key.my - customentities[i].p2;
2846+
if (key.leftbutton)
2847+
{
2848+
ed.dragging = true;
2849+
}
2850+
break;
2851+
}
2852+
}
2853+
}
2854+
26712855
void editorclass::get_input_line(const enum TextMode mode, const std::string& prompt, std::string* ptr)
26722856
{
26732857
state = EditorState_DRAW;
@@ -2867,7 +3051,30 @@ void editorinput(void)
28673051
}
28683052

28693053
// Mouse input
2870-
if (key.leftbutton && ed.lclickdelay == 0)
3054+
if (ed.dragging)
3055+
{
3056+
if (key.leftbutton && INBOUNDS_VEC(ed.dragging_entity, customentities))
3057+
{
3058+
if (ed.dragging_point == 1)
3059+
{
3060+
customentities[ed.dragging_entity].p1 = key.mx - ed.drag_offset_x;
3061+
customentities[ed.dragging_entity].p2 = key.my - ed.drag_offset_y;
3062+
}
3063+
else
3064+
{
3065+
customentities[ed.dragging_entity].p3 = key.mx - ed.drag_offset_x;
3066+
customentities[ed.dragging_entity].p4 = key.my - ed.drag_offset_y;
3067+
}
3068+
}
3069+
else
3070+
{
3071+
ed.dragging = false;
3072+
}
3073+
}
3074+
3075+
check_if_dragging();
3076+
3077+
if ( key.leftbutton && ed.lclickdelay == 0 && !ed.dragging)
28713078
{
28723079
ed.tool_place();
28733080
}
@@ -2876,11 +3083,16 @@ void editorinput(void)
28763083
ed.lclickdelay = 0;
28773084
}
28783085

2879-
if (key.rightbutton)
3086+
if (key.rightbutton && !ed.dragging)
28803087
{
28813088
ed.tool_remove();
28823089
}
28833090

3091+
if (!key.rightbutton)
3092+
{
3093+
ed.rclickdelay = 0;
3094+
}
3095+
28843096
if (key.middlebutton)
28853097
{
28863098
ed.direct_mode_tile = cl.gettile(ed.levx, ed.levy, ed.tilex, ed.tiley);

desktop_version/src/Editor.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum EditorTools
2828
EditorTool_WARP_LINES,
2929
EditorTool_CREWMATES,
3030
EditorTool_START_POINT,
31+
EditorTool_TELEPORTERS,
3132

3233
NUM_EditorTools
3334
};
@@ -197,7 +198,7 @@ class editorclass
197198

198199
int old_tilex, old_tiley;
199200
int tilex, tiley;
200-
int keydelay, lclickdelay;
201+
int keydelay, lclickdelay, rclickdelay;
201202
bool savekey, loadkey;
202203
int levx, levy;
203204
int entframe, entframedelay;
@@ -215,6 +216,13 @@ class editorclass
215216
};
216217
bool x_modifier, z_modifier, c_modifier, v_modifier, b_modifier, h_modifier, toolbox_open;
217218

219+
bool dragging;
220+
221+
int dragging_entity;
222+
int dragging_point;
223+
int drag_offset_x;
224+
int drag_offset_y;
225+
218226
int roomnamehide;
219227
bool saveandquit;
220228
bool help_open, shiftkey;

desktop_version/src/Ent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class entclass
3939
float newxp, newyp;
4040
bool isplatform;
4141
int x1,y1,x2,y2;
42+
int p1x, p1y, p2x, p2y, p3x, p3y;
43+
int pathtime, pathmaxtime;
4244
//Collision Rules
4345
int onentity;
4446
bool harmful;

0 commit comments

Comments
 (0)