diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | main.exe | bin | 369152 -> 370688 bytes | |||
-rw-r--r-- | main.odin | 197 | ||||
-rw-r--r-- | main.pdb | bin | 3821568 -> 3862528 bytes |
4 files changed, 183 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adb36c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.exe
\ No newline at end of file Binary files differ@@ -6,27 +6,53 @@ import "core:bufio" import "core:io" import "core:strconv" import "core:strings" +import "core:math/rand" instructions: string = "Use space to stay still, and HJKL to move." +Direction :: enum {still, up, down, left, right} + +rand_state := rand.create(69) + +state_type :: struct { + gameboard : [16][16]rune, + flow : [16]bool, + spawning : [16]bool, + player_row : int, +} + +block::'O' +water::'~' +player::'@' + +difficulty::0.4 +log_length::0.6 + main :: proc() { - fmt.println("What's your name? ") - name: string = getln() - defer delete(name) - fmt.printf("Hello %v! Welcome to shitty frogger.\n\n", name) + //fmt.println("What's your name? ") + //name: string = getln() + //defer delete(name) + //fmt.printf("Hello %v! Welcome to shitty frogger.\n\n", name) - fmt.println(instructions) + win : bool = false - // Two options for this implementation: - // 1. Structs for rows that contain data about what direction they flow - // - Problem: No neat way to declare the lines with a custom length at runtime - // - Solution: Pointer shit maybe. Ugh. - // 2. Separate array that contains booleans for what direction they flow - // - Problem: Data feels separate, which feels wonky, but might be fine - // - // - // - // + state : state_type + + populate_board(&state) + + fmt.println(state) + draw_board(state) + + for !win { + fmt.println(instructions) + walk(&state, getdir()) + progress_board(&state) + draw_board(state) + if state.player_row==0 { + win = true + } + } + fmt.println("You win, brotha.") } getln :: proc() -> string { @@ -57,3 +83,144 @@ getrune :: proc() -> rune { read_input := rune(buf[0]) return read_input } + +getdir :: proc() -> Direction { + for { + switch getrune() { + case ' ': + return .still + case 'h': + return .left + case 'j': + return .down + case 'k': + return .up + case 'l': + return .right + case: // default + fmt.println("Not a valid direction.") + } + } +} + +populate_board :: proc(state:^state_type) { + using state + for i:=0; i<len(flow); i+=1 { + flow[i] = rand.float32(&rand_state) < 0.5 + } + for i:=0; i<len(flow); i+=1 { + spawning[i] = rand.float32(&rand_state) < 0.5 + } + for _ in gameboard { + progress_board(state) + } + player_row=len(gameboard)-1 + gameboard[player_row][len(gameboard)/2] = player +} + +progress_board :: proc(state:^state_type) { + // TODO: MAKE THIS ACTUALLY DO ANYTHING + for row, i in state.gameboard { + new_block:rune=water + if state.spawning[i] { + new_block=block + } + append(&state.gameboard[i], new_block, state.flow[i]) + } + for is_spawning, i in state.spawning { + if rand.float32(&rand_state)<1-log_length { + if is_spawning { + if rand.float32(&rand_state) < difficulty { + state.spawning[i] = !is_spawning + } + } else { + if rand.float32(&rand_state) > difficulty { + state.spawning[i] = !is_spawning + } + } + } + } +} + +append :: proc(array:^[16]rune, appendee:rune, front:bool) { + if front { + // Put appendee at the start of rune-array + // X 1 2 3 4 5 + // ^ # # # # # + for i:=len(array)-1; i!=0; i-=1 { + array[i] = array[i-1] + } + array[0] = appendee + return + } else { + // Put appendee at the end of rune-array + // 0 1 2 3 4 X + // # # # # # ^ + for _, i in array { + if i < len(array)-1 { + array[i] = array[i+1] + } + } + array[len(array)-1] = appendee + return + } +} + +find_player :: proc(state:state_type) -> int { + for x, i in state.gameboard[state.player_row] { + if x==player {return i} + } + return -1 +} + +walk :: proc(state:^state_type, dir:Direction) { + using state + player_column : int = find_player(state^) + fmt.println(player_column) + current_rubric : ^rune = &gameboard[player_row][player_column] + target : ^rune = current_rubric + switch dir { + case .up: + if player_row!=0 { + target = &gameboard[player_row-1][player_column] + } + if target^==block {player_row-=1} + case .down: + if player_row!=len(gameboard)-1 { + target = &gameboard[player_row+1][player_column] + } + if target^==block {player_row+=1} + case .left: + if player_column!=0 { + target = &gameboard[player_row][player_column-1] + } + case .right: + if player_column!=len(gameboard[0])-1 { + target = &gameboard[player_row][player_column+1] + } + case .still: + return + case: // default + fmt.println("Something just went very wrong. That's not a direction you can walk in.") + return + } + if target^==block { + target^=player + current_rubric^=block + } + return +} + +draw_board :: proc(state:state_type) { + for row, i in state.gameboard { + if state.flow[i] { + fmt.printf("> ") + } else { + fmt.printf("< ") + } + for rubric, j in row { + fmt.printf("%v ", state.gameboard[i][j]) + } + fmt.printf("\n") + } +}
\ No newline at end of file Binary files differ |