Skip to content

Instantly share code, notes, and snippets.

@wndxlori
Last active May 8, 2019 21:53
Show Gist options
  • Select an option

  • Save wndxlori/fdee58d65070719299a54f6877b61d02 to your computer and use it in GitHub Desktop.

Select an option

Save wndxlori/fdee58d65070719299a54f6877b61d02 to your computer and use it in GitHub Desktop.

Revisions

  1. wndxlori revised this gist Apr 23, 2019. No changes.
  2. wndxlori created this gist Apr 22, 2019.
    54 changes: 54 additions & 0 deletions main.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # the first 2 or 4 values of the primitive conventionally are x, y, (w, h, or x2, y2)
    # the last 4 values conventionally are r, g, b, a (color)
    # custom values for primitive are in the middle
    # labels x, y, text, size, alignment, r, g, b, a
    # sprites x, y, w, h, path, angle, alpha
    # lines x, y, x1, y1, r, g, b, a
    # solids x, y, w, h, r, g, b, a
    # borders x, y, w, h, r, g, b, a
    # sounds ".wav|.ogg"

    def defaults game_state
    game_state.game.ship_x ||= game_state.grid.w_half - 33
    end

    def render game_state
    game_state.outputs.labels << [ game_state.grid.w_half, game_state.grid.h - 10, "Galaga", 1, 1, 0, 0, 255, 255]
    game_state.outputs.sprites << [ game_state.game.ship_x, 10, 66, 66, "ship_blue.png", 90]
    if game_state.game.bullet_x
    game_state.outputs.sprites << [ game_state.game.bullet_x, game_state.game.bullet_y, 10, 10, "blue_bullet.png"]
    end
    end

    def calc game_state
    if game_state.game.bullet_x
    game_state.game.bullet_y += 8
    if game_state.game.bullet_y > game_state.grid.h
    game_state.game.bullet_x = game_state.game.bullet_y = nil
    end
    end
    game_state.game.ship_x -= game_state.grid.w if game_state.game.ship_x >= game_state.grid.w
    game_state.game.ship_x += game_state.grid.w if game_state.game.ship_x <= 0
    end

    def inputs game_state
    if game_state.inputs.controller_one.key_held.right
    game_state.game.ship_x += 10
    elsif game_state.inputs.controller_one.key_held.left
    game_state.game.ship_x -= 10
    end

    if ( game_state.inputs.controller_one.key_down.a ||
    game_state.inputs.controller_one.key_down.b ) && !game_state.game.bullet_x
    game_state.game.bullet_x = game_state.game.ship_x + 28
    game_state.game.bullet_y = 76
    end
    end


    def tick game_state
    defaults game_state
    render game_state
    calc game_state
    inputs game_state
    end