Skip to content

Commit

Permalink
Turn common::scene_get_tile() into a method of Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Sep 27, 2024
1 parent 162a0df commit bfd388d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions client.c3
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn Vector2 cast_ray(Scene *scene, Vector2 p1, Vector2 p2) {
Vector2 start = p1;
while (start.distance(p1) < FAR_CLIPPING_PLANE) {
Vector2 c = hitting_cell(p1, p2);
if (common::scene_get_tile(scene, c)) break;
if (scene.get_tile(c)) break;
Vector2 p3 = ray_step(p1, p2);
p1 = p2;
p2 = p3;
Expand All @@ -297,7 +297,7 @@ fn void render_walls(Color *display, int display_width, int display_height, floa
Vector2 c = hitting_cell(camera.position, p);
Vector2 v = p - camera.position;
zbuffer[x] = v.dot(d);
if (common::scene_get_tile(scene, c)) {
if (scene.get_tile(c)) {
render_column_of_wall(display, display_width, display_height, zbuffer, wall, wall_width, wall_height, x, p.x, p.y, c.x, c.y);
}
}
Expand Down Expand Up @@ -507,7 +507,7 @@ fn void update_particles(Color *image_pixels, int image_width, int image_height,
particle.velocity_z -= common::BOMB_GRAVITY*deltaTime;

Vector2 new_position = particle.position + particle.velocity*deltaTime;
if (common::scene_get_tile(scene, new_position)) {
if (scene.get_tile(new_position)) {
float dx = math::abs(math::floor(particle.position.x) - math::floor(new_position.x));
float dy = math::abs(math::floor(particle.position.y) - math::floor(new_position.y));

Expand Down
6 changes: 3 additions & 3 deletions common.c3
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn Scene *allocate_default_scene() @extern("allocate_default_scene") @wasm {
return scene;
}

fn bool scene_get_tile(Scene *scene, Vector2 p) {
fn bool Scene.get_tile(Scene *scene, Vector2 p) {
int x = (int)math::floor(p.x);
int y = (int)math::floor(p.y);
if (!(0 <= x && x < scene.width && 0 <= y && y < scene.height)) return false;
Expand All @@ -90,7 +90,7 @@ fn bool scene_can_rectangle_fit_here(Scene *scene, float px, float py, float sx,
int y2 = (int)math::floor(py + sy*0.5f);
for (int x = x1; x <= x2; ++x) {
for (int y = y1; y <= y2; ++y) {
if (scene_get_tile(scene, {x, y})) {
if (scene.get_tile({x, y})) {
return false;
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ fn bool update_bomb(Bomb *bomb, Scene* scene, float delta_time) {

float nx = bomb.position.x + bomb.velocity.x*delta_time;
float ny = bomb.position.y + bomb.velocity.y*delta_time;
if (scene_get_tile(scene, {nx, ny})) {
if (scene.get_tile({nx, ny})) {
float dx = math::abs(math::floor(bomb.position.x) - math::floor(nx));
float dy = math::abs(math::floor(bomb.position.y) - math::floor(ny));

Expand Down

0 comments on commit bfd388d

Please sign in to comment.