From: Brendan Hansen Date: Thu, 3 Feb 2022 15:11:45 +0000 (-0600) Subject: updates X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=0c1c254516f6a594aee0e023f9f7450633375c07;p=bar-game.git updates --- diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index 19ea6b4..d723eb5 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -2,7 +2,7 @@ // // Editor features to be added: // -// - [ ] Create new entity +// - [x] Create new entity // - [ ] Edit entity properties in UI // - [ ] Serialize / Deserialize a scene // @@ -47,14 +47,13 @@ editor_update :: (dt: f32) { #local handle_placing_entities :: () { if active_index < 0 do return; + mouse_pos := mouse_get_position_vector(); - if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) { + if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) && mouse_pos.x < ~~window_width - sidebar_width && mouse_pos.y > menubar_height { entity_type := ^scene.entity_types.entries[active_index].value; - printf("ADDING {}\n", entity_type); - pos := mouse_get_position_vector(); - entity := entity_type.make(^scene); // scene->make(entity_type); - entity.pos = pos; + entity := entity_type.create_default(^scene); + entity.pos = mouse_pos; } } diff --git a/src/entity/manager.onyx b/src/entity/manager.onyx index 68119d5..84ff8b0 100644 --- a/src/entity/manager.onyx +++ b/src/entity/manager.onyx @@ -31,7 +31,7 @@ IsEntity :: interface (e: $E) { } Entity_Info :: struct { - make : (scene: ^Entity_Manager) -> ^Entity = null_proc; + create_default : (scene: ^Entity_Manager) -> ^Entity = null_proc; update : (entity: ^Entity, dt: f32) -> void = null_proc; draw : (entity: ^Entity) -> void = null_proc; @@ -53,7 +53,6 @@ Entity_Manager :: struct { register :: entity_manager_register; add :: entity_manager_add; make :: entity_manager_make; - make_old :: entity_manager_make_old; update :: entity_manager_update; draw :: entity_manager_draw; get :: entity_manager_get; @@ -99,7 +98,7 @@ entity_manager_register :: (use this: ^Entity_Manager, $entity_type: type_expr) info := Entity_Info.{}; - info.make = #solidify entity_manager_make { entity_type=entity_type }; + info.create_default = #solidify entity_manager_create_default { entity_type=entity_type }; @CompilerFeatures // Maybe there should be data stored in the Type_Info_Struct about // the functions/methods that are defined in the structs scope. I don't know if that @@ -125,14 +124,14 @@ entity_manager_add :: (use this: ^Entity_Manager, entity: ^$T) -> Entity_ID wher return entity.id; } -entity_manager_make :: (use this: ^Entity_Manager, $entity_type: type_expr) -> ^entity_type where IsEntity(^entity_type) { +#local entity_manager_create_default :: (use this: ^Entity_Manager, $entity_type: type_expr) -> ^entity_type where IsEntity(^entity_type) { entity := new(entity_type, allocator=entity_allocator); entity_type.init(entity, entity_type.init_data.{}); this->add(entity); return entity; } -entity_manager_make_old :: (use this: ^Entity_Manager, $entity_type: type_expr, data: entity_type.init_data = .{}) -> ^entity_type where IsEntity(^entity_type) { +entity_manager_make :: (use this: ^Entity_Manager, $entity_type: type_expr, data: entity_type.init_data = .{}) -> ^entity_type where IsEntity(^entity_type) { entity := new(entity_type, allocator=entity_allocator); entity_type.init(entity, data); this->add(entity); diff --git a/src/entity/player.onyx b/src/entity/player.onyx index 736b4b8..7d4d26f 100644 --- a/src/entity/player.onyx +++ b/src/entity/player.onyx @@ -171,8 +171,8 @@ Wall :: struct { size: Vector2; init_data :: struct { - pos := Vector2.{0, 0}; - size := Vector2.{0, 0}; + pos := Vector2.{0, 0}; + size := Vector2.{10, 10}; } init :: (use this: ^Wall, data: init_data) { diff --git a/src/main.onyx b/src/main.onyx index 28656ea..8c40123 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -45,22 +45,22 @@ init :: () { #if DEBUG { debug_font = font_lookup(.{"./assets/fonts/calibri.ttf", 16}); } scene = entity_manager_create(); - scene->make_old(Player, .{ pos = .{300, 300}, controls=player_1_controls }); - scene->make_old(Player, .{ pos = .{400, 300}, controls=player_2_controls, color=.{1,0,0} }); - - scene->make_old(Wall, .{ .{100, 100}, .{400, 50} }); - // scene->make_old(Wall, .{ .{100, 100}, .{50, 400} }); - // scene->make_old(Wall, .{ .{450, 100}, .{50, 400} }); - // scene->make_old(Wall, .{ .{100, 450}, .{400, 50} }); - - scene->make_old(Door, .{ .{150, 150}, .{50, 50} }); - scene->make_old(Door, .{ .{400, 150}, .{50, 50} }); - scene->make_old(Door, .{ .{400, 400}, .{50, 50} }); - scene->make_old(Door, .{ .{150, 400}, .{50, 50} }); - - scene->make_old(Item, .{ pos=.{ 250, 250 }, color=.{1,0,0} }); - scene->make_old(Item, .{ pos=.{ 275, 250 }, color=.{0,1,0} }); - scene->make_old(Item, .{ pos=.{ 300, 250 }, color=.{0,0,1} }); + scene->make(Player, .{ pos = .{300, 300}, controls=player_1_controls }); + scene->make(Player, .{ pos = .{400, 300}, controls=player_2_controls, color=.{1,0,0} }); + + scene->make(Wall, .{ .{100, 100}, .{400, 50} }); + // scene->make(Wall, .{ .{100, 100}, .{50, 400} }); + // scene->make(Wall, .{ .{450, 100}, .{50, 400} }); + // scene->make(Wall, .{ .{100, 450}, .{400, 50} }); + + scene->make(Door, .{ .{150, 150}, .{50, 50} }); + scene->make(Door, .{ .{400, 150}, .{50, 50} }); + scene->make(Door, .{ .{400, 400}, .{50, 50} }); + scene->make(Door, .{ .{150, 400}, .{50, 50} }); + + scene->make(Item, .{ pos=.{ 250, 250 }, color=.{1,0,0} }); + scene->make(Item, .{ pos=.{ 275, 250 }, color=.{0,1,0} }); + scene->make(Item, .{ pos=.{ 300, 250 }, color=.{0,0,1} }); #if DEBUG { println("Registered Entity types:");