From: Brendan Hansen Date: Mon, 29 Nov 2021 20:25:16 +0000 (-0600) Subject: using shorter for-loops in examples X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=f96335c9b39f5bbf568a6a2023d4c0d8bedae105;p=heartbreak.git using shorter for-loops in examples --- diff --git a/tests/minesweeper.onyx b/tests/minesweeper.onyx index 96b5d57..ca8513a 100644 --- a/tests/minesweeper.onyx +++ b/tests/minesweeper.onyx @@ -49,19 +49,19 @@ generate_board :: (use this: ^Board, mine_count: i32) { for ^cell: true_cells do *cell = .Empty; memory.alloc_slice(^mine_locations, mine_count); - for i: mine_count { + for mine_count { while true { mx, my := random.between(0, width - 1), random.between(0, height - 1); if get_true_cell(this, mx, my) != .Mine { set_true_cell(this, mx, my, .Mine); - mine_locations[i] = .{mx, my}; + mine_locations[it] = .{mx, my}; break; } } } - for ^mine_pos: mine_locations { - for neighbor: neighbors(this, mine_pos.x, mine_pos.y) { + for ^ mine_locations { + for neighbor: neighbors(this, it.x, it.y) { cell := get_true_cell(this, neighbor.x, neighbor.y); if cell == .Empty do cell = .Number1; elseif cell&.Is_Number do cell += 1; @@ -145,19 +145,19 @@ flood_reveal :: (use this: ^Board, x, y: i32) => { reveal_cell(this, p.x, p.y); if get_true_cell(this, p.x, p.y) & .Is_Number do continue; - for n: neighbors(this, p.x, p.y, include_corners=true) { - true_cell := get_true_cell(this, n.x, n.y); - visible_cell := get_visible_cell(this, n.x, n.y); + for neighbors(this, p.x, p.y, include_corners=true) { + true_cell := get_true_cell(this, it.x, it.y); + visible_cell := get_visible_cell(this, it.x, it.y); if true_cell != .Mine && visible_cell == .Covered { - positions << n; + positions << it; } } } } reveal_mines :: (use this: ^Board) { - for ^mine: mine_locations { - reveal_cell(this, mine.x, mine.y); + for ^ mine_locations { + reveal_cell(this, it.x, it.y); } } diff --git a/tests/simp.onyx b/tests/simp.onyx index 26133d8..ba0e2bc 100644 --- a/tests/simp.onyx +++ b/tests/simp.onyx @@ -145,7 +145,7 @@ draw :: () { hb.graphics.drawImage(dummy, 100, 100, 100, 100); hb.graphics.newQuad(4, 4, 8, 8, dummy) |> hb.graphics.drawQuad(200, 100, 100, 100); - for it: squares { + for squares { hb.graphics.setColor(it.r, it.g, it.b, it.a); hb.graphics.rectangle(.Fill, it.x, it.y, it.w, it.h); } diff --git a/tests/snake.onyx b/tests/snake.onyx index 46583eb..1d12f17 100644 --- a/tests/snake.onyx +++ b/tests/snake.onyx @@ -44,8 +44,8 @@ snake_make :: (head: Vec2i) -> Snake { } snake_move :: (use this: ^Snake) { - for i: iter.as_iterator(range.{ body.count - 1, 1, -1 }) { - body[i] = body[i - 1]; + for iter.as_iterator(range.{ body.count - 1, 1, -1 }) { + body[it] = body[it - 1]; } body[0] = head; @@ -54,11 +54,11 @@ snake_move :: (use this: ^Snake) { snake_grow :: (use this: ^Snake, amount := 1) { last := body[body.count - 1]; - for i: amount do body << last; + for amount do body << last; } snake_draw :: (use this: ^Snake, cell_size: f32) { - for it: iter.enumerate(body) { + for iter.enumerate(body) { hb.graphics.setColor(0, 0.6 - 0.4 * (~~it.index / cast(f32) body.count), 0); hb.graphics.rectangle(.Fill, ~~it.value.x * cell_size, ~~it.value.y * cell_size, cell_size, cell_size); } @@ -142,7 +142,7 @@ reset_game :: () { } cell_contains_snake_body :: (p: Vec2i) => { - for ^it: the_snake.body { + for ^ the_snake.body { if *it == p do return true; } return false; @@ -294,7 +294,7 @@ draw_menu :: (y: f32) { menu_info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(active_menu.options); if menu_info.kind != .Struct do return; - for it: iter.enumerate(menu_info.members) { + for iter.enumerate(menu_info.members) { text := *(cast(^str) array.first(it.value.tags, (t) => t.type == str).data); height := hb.graphics.getTextHeight(text);