commit c3c303252699a1fc422967c8ce1f98a0cafc71bb
parent 7434263502290f74197d18a3c4e16977782d39ee
Author: Samdal <samdal@protonmail.com>
Date: Tue, 6 Jul 2021 10:32:54 +0200
remove floor in main.c and change to uint
Diffstat:
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/frag.glsl b/frag.glsl
@@ -8,11 +8,11 @@ uniform vec2 u_food;
void main()
{
- vec2 st = (gl_FragCoord.xy / u_resolution.xy) * 31.0;
- int x = int(floor(st.x));
- int y = int(floor(st.y));
- diffuseColor.g = float(u_map[y] & (1 << x));
- diffuseColor.r = float(x == int(u_food.x) && y == int(u_food.y));
+ vec2 st = (gl_FragCoord.xy / u_resolution.xy) * 32.0;
+ uint x = uint(floor(st.x));
+ uint y = uint(floor(st.y));
+ diffuseColor.g = float(uint(u_map[y]) & uint(1 << x));
+ diffuseColor.r = float(x == uint(u_food.x) && y == uint(u_food.y));
diffuseColor.b = 0.0;
diffuseColor.a = 1.0;
}
diff --git a/main.c b/main.c
@@ -87,7 +87,7 @@ void new_game()
body->pos = (gs_vec2){16.0f, 16.0f};
// place tail piece in map_buffer
- map_buffer[(int)floor(body->pos.y)] |= (1 << (int)floor(body->pos.x));
+ map_buffer[(int)body->pos.y] |= (1 << (int)body->pos.x);
for (uint32_t i = 1; i <= 3; i++) {
// create snake piece
@@ -100,7 +100,7 @@ void new_game()
body->next = NULL;
// place snake piece in map_buffer
- map_buffer[(int)floor(body->pos.y)] |= (1 << (int)floor(body->pos.x));
+ map_buffer[(int)body->pos.y] |= (1 << (int)body->pos.x);
}
// place food at random position
@@ -140,7 +140,7 @@ void move_snake()
} else {
// remove tail from buffer
body = tail;
- map_buffer[(int)floor(body->pos.y)] &= ~(1 << (int)floor(body->pos.x));
+ map_buffer[(int)body->pos.y] &= ~(1 << (int)body->pos.x);
// move each snake piece to the next ones position
while (body->next) {
@@ -158,7 +158,7 @@ void move_snake()
}
}
// add head to buffer
- map_buffer[(int)floor(body->pos.y)] |= (1 << (int)floor(body->pos.x));
+ map_buffer[(int)body->pos.y] |= (1 << (int)body->pos.x);
}
void init()