Some random small projects i made using https://github.com/willmexe/Game-Engine-CS
at main 7.3 kB view raw
1using Proj.Modules.Input; 2using Proj.Modules.Ui; 3using Proj.Modules.Debug; 4using Proj.Modules.Graphics; 5using Proj.Modules.Misc; 6using System.Collections.Generic; 7using SDL2; 8using System; 9using System.Numerics; 10using System.Text.Json; 11using System.Text.Json.Serialization; 12using Newtonsoft.Json; 13using System.IO; 14 15namespace Proj.Game { 16 public class map_format { 17 public List<Vector2> nodes { get; set; } 18 public List<string> textures { get; set; } 19 } 20 21 public class node_editor : scene { 22 List<Vector2> nodes = new List<Vector2>(); 23 24 bool load_tex = false; 25 bool load_tex_button = false; 26 bool export_button = false; 27 bool export_input = false; 28 string value = ""; 29 string export_file = ""; 30 bool hide = false; 31 32 bool edit_mode = false; 33 34 List<IntPtr> textures = new List<IntPtr>(); 35 List<string> textures_string = new List<string>(); 36 37 public node_editor() { 38 39 } 40 41 public override void on_load() { 42 game_manager.set_asset_pack("bloons"); 43 44 font_handler.load_font("bloons_font", "FiraCode", 22); 45 46 } 47 48 public override void update() { 49 50 // Node Editor 51 52 if(!hide) { 53 if(mouse.button_just_pressed(0) && !math_uti.mouse_inside(280, 10, 200, 30) && !math_uti.mouse_inside(280, 50, 80, 30) && !math_uti.mouse_inside(0, 0, 250, 1280) && !math_uti.mouse_inside(280, 100, 200, 30) && !math_uti.mouse_inside(280, 140, 100, 30) && !math_uti.mouse_inside(280, 690, 20, 20) && !math_uti.mouse_inside(280, 190, 180, 30)) { 54 if(!edit_mode) 55 nodes.Add(new Vector2(mouse.x, mouse.y)); 56 } 57 } else { 58 if(mouse.button_just_pressed(0) && !math_uti.mouse_inside(10, 690, 20, 20)) { 59 if(!edit_mode) 60 nodes.Add(new Vector2(mouse.x, mouse.y)); 61 else { 62 63 } 64 } 65 } 66 67 if(math_uti.mouse_inside(280, 20, 200, 30) && mouse.button_just_pressed(0)) { 68 load_tex = !load_tex; 69 } 70 71 if(load_tex) { 72 input.set_input_state("load_texture"); 73 } else if(input.input_state == "load_texture") { 74 input.set_input_state("general"); 75 } 76 77 if(math_uti.mouse_inside(280, 100, 200, 30) && mouse.button_just_pressed(0)) { 78 export_input = !export_input; 79 } 80 81 if(load_tex_button) { 82 load_tex_button = false; 83 load_tex = false; 84 if(value != "") { 85 textures.Add(texture_handler.load_texture(value, game_manager.renderer)); 86 textures_string.Add(value); 87 } 88 } 89 90 if(export_input) { 91 input.set_input_state("export_file"); 92 } else if(input.input_state == "export_file") { 93 input.set_input_state("general"); 94 } 95 96 if(mouse.button_just_pressed(1)) { 97 if(!edit_mode) { 98 for(var i = 0; i < nodes.Count; i++) { 99 if(math_uti.point_distance(new Vector2(nodes[i].X, nodes[i].Y), new Vector2(mouse.x, mouse.y)) < 5) { 100 nodes.RemoveAt(i); 101 break; 102 } 103 } 104 } 105 } 106 107 if(export_button) { 108 export_button = false; 109 export_input = false; 110 111 var _export_output = new map_format { 112 nodes = nodes, 113 textures = textures_string 114 }; 115 116 var json_string = JsonConvert.SerializeObject(_export_output); 117 118 string full_path = game_manager.executable_path + "\\src\\resources\\bloons\\data\\maps\\" + export_file; 119 System.IO.File.WriteAllText(full_path, json_string); 120 } 121 } 122 123 public override void render() { 124 SDL.SDL_Rect rect; 125 rect.x = 0; 126 rect.y = 0; 127 rect.w = 270; 128 rect.h = 1280; 129 130 foreach(IntPtr tex in textures) { 131 draw.texture(game_manager.renderer, tex, 1280 / 2 , 720 / 2, 0); 132 } 133 134 if(!hide) 135 draw.rect(game_manager.renderer, rect, 0, 0, 0, 100, true); 136 137 for(var i = 0; i < nodes.Count; i++) { 138 string text = "#" + i + " X: " + nodes[i].X.ToString() + " Y: " + nodes[i].Y.ToString(); 139 IntPtr texture; 140 SDL.SDL_Rect rect1; 141 142 font_handler.get_text_and_rect(game_manager.renderer, text, "bloons_font", out texture, out rect1, 0, 0); 143 144 if(!hide) { 145 draw.texture(game_manager.renderer, texture, 135, 20 * (i + 1), 0); 146 } 147 148 SDL.SDL_Rect rect2; 149 150 rect2.x = (int)nodes[i].X - 3; 151 rect2.y = (int)nodes[i].Y - 3; 152 rect2.w = 6; 153 rect2.h = 6; 154 155 rect1.x = 125 - rect1.w / 2; 156 rect1.y = 20 * (i + 1) - rect1.h / 2; 157 158 if(math_uti.mouse_inside(rect1.x, rect1.y, rect1.w, rect1.h - 8)) { 159 if(mouse.button_just_pressed(0)) { 160 if(i > 0) { 161 var save = nodes[i]; 162 nodes[i] = nodes[i - 1]; 163 nodes[i - 1] = save; 164 } 165 } 166 if(mouse.button_just_pressed(1)) { 167 if(i < nodes.Count - 1) { 168 var save = nodes[i]; 169 nodes[i] = nodes[i + 1]; 170 nodes[i + 1] = save; 171 } 172 } 173 draw.rect(game_manager.renderer, rect2, 52, 134, 235, 255, true); 174 175 if(input.get_key_just_pressed(input.key_backspace)) { 176 nodes.RemoveAt(i); 177 } 178 179 SDL.SDL_Rect marker; 180 marker.x = 2; 181 marker.y = rect1.y; 182 marker.w = 5; 183 marker.h = 22; 184 185 draw.rect(game_manager.renderer, marker, 52, 134, 235, 255, true); 186 } else { 187 draw.rect(game_manager.renderer, rect2, 255, 255, 255, 255, true); 188 } 189 } 190 191 if(!hide) { 192 zgui.input_box(280, 10, 200, 30, "bloons_font", ref value, "texture name", "load_texture"); 193 zgui.button(280, 50, 80, 30, ref load_tex_button, "bloons_font", "Load"); 194 195 zgui.input_box(280, 100, 200, 30, "bloons_font", ref export_file, "export filename", "export_file"); 196 zgui.button(280, 140, 100, 30, ref export_button, "bloons_font", "Export"); 197 198 zgui.button(280, 190, 180, 30, ref edit_mode, "bloons_font", edit_mode ? "texture_edit" : "node_edit"); 199 } 200 201 zgui.button(!hide ? 280 : 10, 690, 20, 20, ref hide, "bloons_font", !hide ? "<" : ">"); 202 } 203 } 204}