--- /dev/null
+Things that look like comments in this file are likely comments
+in the actual codebase, at or near where the feature will be
+implemented.
+
+
+// Highlight the object that you are going to interact with
+
+Start the actual gameplay system:
+ - "Orders" arrive with requirements
+ - You visit stations to get the ingredients
+ - You build the order
+ - You give it to the customer
+
+Automated asset loader for:
+ - Textures
+ - Fonts
+ - Sounds
+ - Shaders?
+
+
MAJOR_VERSION :: 0
MINOR_VERSION :: 1
-DEBUG :: true
+DEBUG :: false
#load_path "/home/brendan/dev/onyx"
use package glfw3
Player_Controls :: struct {
- up := GLFW_KEY_W;
- down := GLFW_KEY_S;
- left := GLFW_KEY_A;
- right := GLFW_KEY_D;
- interact := GLFW_KEY_F;
- pick_up := GLFW_KEY_G;
+ up : i32;
+ down : i32;
+ left : i32;
+ right : i32;
+ interact : i32;
+ pick_up : i32;
+}
+
+player_1_controls :: Player_Controls.{
+ up = GLFW_KEY_W,
+ down = GLFW_KEY_S,
+ left = GLFW_KEY_A,
+ right = GLFW_KEY_D,
+ interact = GLFW_KEY_F,
+ pick_up = GLFW_KEY_G,
+}
+
+player_2_controls :: Player_Controls.{
+ up = GLFW_KEY_UP,
+ down = GLFW_KEY_DOWN,
+ left = GLFW_KEY_LEFT,
+ right = GLFW_KEY_RIGHT,
+ interact = GLFW_KEY_COMMA,
+ pick_up = GLFW_KEY_PERIOD,
}
Player :: struct {
use entity: Entity;
holding: Entity_ID;
-
controls: Player_Controls;
+ color := Color.{1,1,1};
Size :: 16.0f
init_data :: struct {
pos := Vector2.{400, 200};
- controls := Player_Controls.{};
+ controls: Player_Controls = player_1_controls;
+ color := Color.{1,1,1};
}
init :: (use this: ^Player, data: init_data) {
this.holding = Entity_Nothing;
this.controls = data.controls;
+ this.color = data.color;
+
+ this.flags |= .Solid;
}
get_rect :: (use this: ^Player) => Rect.{ pos.x - Size, pos.y - Size, Size * 2, Size * 2 };
try_move(this, .{delta.x, 0}, walls);
try_move(this, .{0, delta.y}, walls);
+ // Highlight the object that you are going to interact with
+
//
// Try to pick up nearby objects
//
if is_key_just_up(controls.pick_up) {
if holding != Entity_Nothing {
holding_object := entity_manager->get(holding);
- holding_object.pos = pos + .{20, 0};
+ vtable := ^entity_manager.entity_types[holding_object.type];
+ if vtable.get_rect != null_proc {
+ r := vtable.get_rect(holding_object);
+ holding_object.pos = pos + .{Size + r.w / 2 + 4, 0};
+ }
holding = Entity_Nothing;
} else {
defer memory.free_slice(^objects);
// This should first sort by the distance to the object
- target_object := objects[0];
- this.holding = target_object.id;
+ while i := 0; i < objects.count {
+ defer i += 1;
+ if objects[i] == this do continue;
+
+ target_object := objects[i];
+ this.holding = target_object.id;
+ break;
+ }
// Should this fire an event on the target object?
}
ent_rect := get_rect(this);
for obsticles {
- // Don't check collision on the object that you are carrying because it probably won't make sense.
+ // Don't check collision on the object that you are carrying or yourself because it probably won't make sense.
+ if it == this do continue;
if it.id == this.holding do continue;
vtable := ^entity_manager.entity_types[it.type];
}
draw :: (use this: ^Player) {
- immediate_set_color(.{1,1,1});
+ immediate_set_color(color);
rect := this->get_rect();
immediate_image(^player_texture, rect.x, rect.y, rect.w, rect.h);
if vertex_count == 0 do return;
shader_use(imgui_shader);
+ shader_set_uniform(imgui_shader, #cstr "u_texture_enabled", 1.0f if rendering_type == .Image else 0.0f);
+
immediate_mesh.vertex_count = vertex_count;
mesh_update_verticies(immediate_mesh, vertex_data);
mesh_draw(immediate_mesh);
- shader_set_uniform(imgui_shader, #cstr "u_texture_enabled", 0.0f);
vertex_count = 0;
+ rendering_type = .Plain;
}
immediate_clear :: (color: Color) {
immediate_vertex :: (x, y: f32, t_x := 0.0f, t_y := 0.0f) {
if vertex_count >= Maximum_Vertex_Count do immediate_flush();
+ set_rendering_type(.Plain);
vertex_data[vertex_count] = .{ .{x, y}, .{t_x, t_y}, immediate_color };
}
immediate_triangle :: (x1, x2, x3: Vector2) {
if vertex_count + 3 > Maximum_Vertex_Count do immediate_flush();
+ set_rendering_type(.Plain);
vertex_data[vertex_count + 0] = .{ x1, .{0,0}, immediate_color };
vertex_data[vertex_count + 1] = .{ x2, .{0,0}, immediate_color };
immediate_rectangle :: (x, y, w, h: f32) {
if vertex_count + 6 > Maximum_Vertex_Count do immediate_flush();
+ set_rendering_type(.Plain);
vertex_data[vertex_count + 0] = .{ .{x, y}, .{0,0}, immediate_color };
vertex_data[vertex_count + 1] = .{ .{x+w, y}, .{0,0}, immediate_color };
immediate_image :: (image: ^Texture, x, y, w, h: f32) {
if vertex_count > 0 do immediate_flush();
+ set_rendering_type(.Image);
texture_use(image);
shader_use(imgui_shader);
- shader_set_uniform(imgui_shader, #cstr "u_texture_enabled", 1.0f);
shader_set_uniform(imgui_shader, #cstr "u_texture", 0);
vertex_data[vertex_count + 0] = .{ .{x, y}, .{0,0}, immediate_color };
vertex_data[vertex_count + 4] = .{ .{x+w, y+h}, .{1,1}, immediate_color };
vertex_data[vertex_count + 5] = .{ .{x, y+h}, .{0,1}, immediate_color };
vertex_count += 6;
-
- immediate_flush();
}
immediate_ellipse :: () {}
immediate_color: Color;
immediate_mesh: ^Mesh(Immediate_Vertex);
+
+ Rendering_Type :: enum {
+ Plain;
+ Image;
+ }
+ rendering_type := Rendering_Type.Plain;
+
+ set_rendering_type :: (new_type: typeof rendering_type) {
+ if rendering_type != new_type {
+ immediate_flush();
+ rendering_type = new_type;
+ }
+ }
}
#if DEBUG { debug_font = font_lookup(.{"./assets/fonts/calibri.ttf", 16}); }
entity_manager = entity_manager_create();
- player := entity_manager->make(Player, .{
- pos = .{300, 300}
- });
+ entity_manager->make(Player, .{ pos = .{300, 300}, controls=player_1_controls });
+ entity_manager->make(Player, .{ pos = .{400, 300}, controls=player_2_controls, color=.{1,0,0} });
entity_manager->make(Wall, .{ .{100, 100}, .{400, 50} });
- entity_manager->make(Wall, .{ .{100, 100}, .{50, 400} });
- entity_manager->make(Wall, .{ .{450, 100}, .{50, 400} });
- entity_manager->make(Wall, .{ .{100, 450}, .{400, 50} });
+ // entity_manager->make(Wall, .{ .{100, 100}, .{50, 400} });
+ // entity_manager->make(Wall, .{ .{450, 100}, .{50, 400} });
+ // entity_manager->make(Wall, .{ .{100, 450}, .{400, 50} });
entity_manager->make(Door, .{ .{150, 150}, .{50, 50} });
entity_manager->make(Door, .{ .{400, 150}, .{50, 50} });