27
27
#include " Vlogging.h"
28
28
29
29
#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
30
34
31
35
editorclass::editorclass (void )
32
36
{
@@ -49,6 +53,7 @@ editorclass::editorclass(void)
49
53
register_tool (EditorTool_WARP_LINES, " Warp Lines" , " I" , SDLK_i, false );
50
54
register_tool (EditorTool_CREWMATES, " Crewmates" , " O" , SDLK_o, false );
51
55
register_tool (EditorTool_START_POINT, " Start Point" , " P" , SDLK_p, false );
56
+ register_tool (EditorTool_TELEPORTERS, " Teleporters" , " ^2" , SDLK_2, true );
52
57
}
53
58
54
59
void editorclass::reset (void )
@@ -89,11 +94,18 @@ void editorclass::reset(void)
89
94
levy = 0 ;
90
95
keydelay = 0 ;
91
96
lclickdelay = 0 ;
97
+ rclickdelay = 0 ;
92
98
savekey = false ;
93
99
loadkey = false ;
94
100
updatetiles = true ;
95
101
changeroom = true ;
96
102
103
+ dragging = false ;
104
+ dragging_entity = -1 ;
105
+ dragging_point = 1 ;
106
+ drag_offset_x = 0 ;
107
+ drag_offset_y = 0 ;
108
+
97
109
entframe = 0 ;
98
110
entframedelay = 0 ;
99
111
@@ -716,6 +728,73 @@ static void draw_entities(void)
716
728
font::print (PR_BOR | PR_CJK_HIGH, x, y - 8 , text, 210 , 210 , 255 );
717
729
break ;
718
730
}
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
+ }
719
798
case 15 : // Crewmates
720
799
graphics.draw_sprite (x - 4 , y, 144 , graphics.crewcolourreal (entity->p1 ));
721
800
graphics.draw_rect (x, y, 16 , 24 , graphics.getRGB (164 , 164 , 164 ));
@@ -988,6 +1067,10 @@ static void draw_cursor(void)
988
1067
// 2x3
989
1068
graphics.draw_rect (x, y, 16 , 24 , blue);
990
1069
break ;
1070
+ case EditorTool_TELEPORTERS:
1071
+ // 12x12
1072
+ graphics.draw_rect (x, y, 96 , 96 , blue);
1073
+ break ;
991
1074
default :
992
1075
break ;
993
1076
}
@@ -1362,6 +1445,15 @@ void editorclass::draw_tool(EditorTools tool, int x, int y)
1362
1445
case EditorTool_START_POINT:
1363
1446
graphics.draw_sprite (x, y, 184 , graphics.col_crewcyan );
1364
1447
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
+ }
1365
1457
default :
1366
1458
break ;
1367
1459
}
@@ -2192,6 +2284,20 @@ void editorclass::tool_place()
2192
2284
add_entity (tilex + (levx * 40 ), tiley + (levy * 30 ), 16 , 0 );
2193
2285
lclickdelay = 1 ;
2194
2286
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
+ }
2195
2301
default :
2196
2302
break ;
2197
2303
}
@@ -2444,15 +2550,16 @@ static void start_at_checkpoint(void)
2444
2550
{
2445
2551
extern editorclass ed;
2446
2552
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
2448
2554
int testeditor = -1 ;
2449
2555
bool startpoint = false ;
2450
2556
2451
2557
for (size_t i = 0 ; i < customentities.size (); i++)
2452
2558
{
2453
2559
startpoint = customentities[i].t == 16 ;
2454
2560
const bool is_startpoint_or_checkpoint = startpoint ||
2455
- customentities[i].t == 10 ;
2561
+ customentities[i].t == 10 ||
2562
+ customentities[i].t == 14 ;
2456
2563
if (!is_startpoint_or_checkpoint)
2457
2564
{
2458
2565
continue ;
@@ -2493,26 +2600,31 @@ static void start_at_checkpoint(void)
2493
2600
game.edsavey = (customentities[testeditor].y % 30 ) * 8 ;
2494
2601
game.edsaverx = 100 + tx;
2495
2602
game.edsavery = 100 + ty;
2603
+ game.edsavedir = 0 ;
2604
+ game.edsavegc = 0 ;
2496
2605
2497
2606
if (!startpoint)
2498
2607
{
2499
2608
// 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!
2501
2616
{
2502
2617
game.edsavegc = 1 ;
2503
2618
game.edsavey -= 2 ;
2504
2619
}
2505
2620
else
2506
2621
{
2507
- game.edsavegc = 0 ;
2508
2622
game.edsavey -= 7 ;
2509
2623
}
2510
- game.edsavedir = 0 ;
2511
2624
}
2512
2625
else
2513
2626
{
2514
2627
// Start point spawn
2515
- game.edsavegc = 0 ;
2516
2628
game.edsavey ++;
2517
2629
game.edsavedir = 1 - customentities[testeditor].p1 ;
2518
2630
}
@@ -2668,6 +2780,78 @@ static void handle_draw_input()
2668
2780
}
2669
2781
}
2670
2782
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
+
2671
2855
void editorclass::get_input_line (const enum TextMode mode, const std::string& prompt, std::string* ptr)
2672
2856
{
2673
2857
state = EditorState_DRAW;
@@ -2867,7 +3051,30 @@ void editorinput(void)
2867
3051
}
2868
3052
2869
3053
// 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 )
2871
3078
{
2872
3079
ed.tool_place ();
2873
3080
}
@@ -2876,11 +3083,16 @@ void editorinput(void)
2876
3083
ed.lclickdelay = 0 ;
2877
3084
}
2878
3085
2879
- if (key.rightbutton )
3086
+ if (key.rightbutton && !ed. dragging )
2880
3087
{
2881
3088
ed.tool_remove ();
2882
3089
}
2883
3090
3091
+ if (!key.rightbutton )
3092
+ {
3093
+ ed.rclickdelay = 0 ;
3094
+ }
3095
+
2884
3096
if (key.middlebutton )
2885
3097
{
2886
3098
ed.direct_mode_tile = cl.gettile (ed.levx , ed.levy , ed.tilex , ed.tiley );
0 commit comments