summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/editor.c32
-rw-r--r--src/players.c13
-rw-r--r--src/throwables.c13
3 files changed, 35 insertions, 23 deletions
diff --git a/src/editor.c b/src/editor.c
index b04c5dd..6d107f7 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -101,6 +101,26 @@ void update_editor(platform_window* window)
}
}
+void draw_floor_grid(platform_window* window) {
+ map_info info = get_map_info(window);
+
+ for (int y = 0; y < MAP_SIZE_Y; y++) {
+ int x1 = 0;
+ int y1 = y*info.tile_height;
+ int x2 = MAP_SIZE_X*info.tile_width;
+ int y2 = y*info.tile_height;
+ renderer->render_line(x1, y1, x2, y2, 1, rgba(255,0,0,80));
+ }
+
+ for (int x = MAP_SIZE_X-1; x >= 0; x--) {
+ int x1 = x*info.tile_width;
+ int y1 = 0;
+ int x2 = x*info.tile_width;
+ int y2 = MAP_SIZE_Y*info.tile_height;
+ renderer->render_line(x1, y1, x2, y2, 1, rgba(255,0,0,80));
+ }
+}
+
void draw_placing_rectangle(platform_window* window) {
map_info info = get_map_info(window);
int mouse_tile_y = (_global_mouse.y + _global_camera.y) / info.tile_height;
@@ -110,13 +130,12 @@ void draw_placing_rectangle(platform_window* window) {
if (mouse_tile_x >= loaded_map.width || mouse_tile_y >= loaded_map.height) return;
tile t = loaded_map.heightmap[mouse_tile_y][mouse_tile_x];
-
- //renderer->render_rectangle_outline(t.tl.x, t.tl.y, t.tr.x - t.tl.x, t.br.y - t.tr.y, 2, rgb(255,0,0));
+ box box = get_render_box_of_square(window, (vec3f){mouse_tile_x, mouse_tile_y, 0}, (vec3f){1,1,t.height});
- renderer->render_line(t.tl.x, t.tl.y, t.tr.x, t.tr.y, 1, rgb(0,0,255)); // top
- renderer->render_line(t.tl.x, t.tl.y, t.bl.x, t.bl.y, 1, rgb(0,0,255)); // left
- renderer->render_line(t.tr.x, t.tr.y, t.br.x, t.br.y, 1, rgb(0,0,255)); // right
- renderer->render_line(t.bl.x, t.bl.y, t.br.x, t.br.y, 1, rgb(0,0,255)); // bottom
+ render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgba(255,0,0, 70));
+ render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgba(255,0,0, 70));
+ render_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, rgba(255,0,0, 70));
+ render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgba(255,0,0, 70));
}
static bool push_icon_button(int x, int y, int w, image* img, bool isSelected) {
@@ -231,6 +250,7 @@ void draw_lighting_panel(platform_window* window) {
void draw_editor(platform_window* window)
{
if (is_editing_map) {
+ draw_floor_grid(window);
draw_placing_rectangle(window);
renderer->render_rectangle(_global_camera.x, _global_camera.y, editor_width, window->height, rgb(73, 140, 138));
diff --git a/src/players.c b/src/players.c
index d7074a2..0889dab 100644
--- a/src/players.c
+++ b/src/players.c
@@ -65,7 +65,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d
float newy = p->playery - speed;
if (is_in_bounds(p->playerx, newy)) {
p->playery = newy;
- object o = check_if_player_collided_with_object(window, *p);
+ object o = check_if_player_collided_with_object(*p);
if (o.active) p->playery = o.position.y+o.size.y + pad_between_player_and_obj;
}
}
@@ -74,7 +74,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d
float newy = p->playery + speed;
if (is_in_bounds(p->playerx, newy)) {
p->playery = newy;
- object o = check_if_player_collided_with_object(window, *p);
+ object o = check_if_player_collided_with_object(*p);
if (o.active) p->playery = o.position.y - get_player_size_in_tile() - pad_between_player_and_obj;
}
}
@@ -83,7 +83,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d
float newx = p->playerx - speed;
if (is_in_bounds(newx, p->playery)) {
p->playerx = newx;
- object o = check_if_player_collided_with_object(window, *p);
+ object o = check_if_player_collided_with_object(*p);
if (o.active) p->playerx = o.position.x+o.size.x + pad_between_player_and_obj;
}
}
@@ -92,7 +92,7 @@ void move_user(platform_window* window, u32 id, protocol_move_type move, float d
float newx = p->playerx + speed;
if (is_in_bounds(newx, p->playery)) {
p->playerx = newx;
- object o = check_if_player_collided_with_object(window, *p);
+ object o = check_if_player_collided_with_object(*p);
if (o.active) p->playerx = o.position.x-get_player_size_in_tile() - pad_between_player_and_obj;
}
}
@@ -117,10 +117,7 @@ bool check_if_player_collided_with_box(player p, box o) {
return b1 && b2;
}
-object check_if_player_collided_with_object(platform_window* window, player p) {
- map_info info = get_map_info(window);
- float player_size = get_player_size(window);
-
+object check_if_player_collided_with_object(player p) {
for (int i = 0; i < MAX_OBJECTS; i++) {
object o = loaded_map.objects[i];
if (!o.active) continue;
diff --git a/src/throwables.c b/src/throwables.c
index 86a9734..c18d410 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -33,14 +33,10 @@ bool check_if_throwable_collided_with_object(throwable* b, vec3f oldpos, vec3f n
if (b->position.z <= o.h + o.size.z && b->position.z >= o.h) {
box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.h}, o.size);
- if (o.type == OBJECT_PLANTBOX1 && oldpos.x < o.position.x && newpos.x > o.position.x) {
- log_infox("intersect {%.2f %.2f}{%.2f %.2f} {%.2f %.2f}{%.2f %.2f}",
- oldpos.x, oldpos.y, newpos.x, newpos.y, o.position.x, o.position.y, o.position.x, o.position.y + o.size.y);
-
- //if (lines_intersect((vec2f){15.99, 8.58}, (vec2f){16.05, 8.58}, (vec2f){16.00, 8.00}, (vec2f){16.00, 9.00})) {
- // log_info("POOOp");
- //}
- }
+ //if (o.type == OBJECT_PLANTBOX1 && oldpos.x < o.position.x && newpos.x > o.position.x) {
+ // log_infox("intersect {%.2f %.2f}{%.2f %.2f} {%.2f %.2f}{%.2f %.2f}",
+ // oldpos.x, oldpos.y, newpos.x, newpos.y, o.position.x, o.position.y, o.position.x, o.position.y + o.size.y);
+ //}
// top
if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
@@ -111,7 +107,6 @@ void update_throwables_server() {
throwables[i].rotation += SERVER_TICK_RATE*3.0f*throwables[i].bounces;
-
throwables[i].alive_time += SERVER_TICK_RATE;
if (throwables[i].alive_time >= 2.0f) {