From 46e13804c80d000735fc6bbc22f303ea721f6127 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Thu, 12 Jan 2023 08:34:56 +0100 Subject: Playable --- .gitignore | 1 + main.exe | Bin 369152 -> 370688 bytes main.odin | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- main.pdb | Bin 3821568 -> 3862528 bytes 4 files changed, 183 insertions(+), 15 deletions(-) create mode 100644 .gitignore 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 diff --git a/main.exe b/main.exe index 016fbd3..fa90986 100644 Binary files a/main.exe and b/main.exe differ diff --git a/main.odin b/main.odin index 5357595..2f0152d 100644 --- a/main.odin +++ b/main.odin @@ -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 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 diff --git a/main.pdb b/main.pdb index 6397bcf..98f8fb3 100644 Binary files a/main.pdb and b/main.pdb differ -- cgit v1.2.1