Last active
April 15, 2016 23:53
-
-
Save litonico/df0ba2c69302130970c55163198ed46f to your computer and use it in GitHub Desktop.
Tiny Roguelike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tinyrogue.rb | |
# litonico | |
# This software is licensed to the public domain | |
require 'io/console' | |
CLEARALL = "\x1b[2J\x1b[1;1H" | |
BACKGROUND_MAP = <<-MAP | |
........ | |
........ | |
........ | |
........ | |
........ | |
MAP | |
MAP_WIDTH = 8 | |
TRAILING_NEWLINE = 1 | |
$player_pos = [3, 2] | |
def left | |
$player_pos[0] -= 1 | |
end | |
def right | |
$player_pos[0] += 1 | |
end | |
def up | |
$player_pos[1] -= 1 | |
end | |
def down | |
$player_pos[1] += 1 | |
end | |
puts "wasd to move, q to quit" | |
loop do | |
input = STDIN.getch | |
print CLEARALL | |
exit if input == "q" | |
left if input == "a" | |
right if input == "d" | |
up if input == "w" | |
down if input == "s" | |
player_coord = $player_pos[0] + $player_pos[1]*(MAP_WIDTH+TRAILING_NEWLINE) | |
player_map = String.new BACKGROUND_MAP | |
player_map[player_coord] = "@" | |
puts player_map | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment