Skip to content

Commit

Permalink
ES6
Browse files Browse the repository at this point in the history
  • Loading branch information
nrkn committed Oct 28, 2015
1 parent fd992c7 commit e3bbdda
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions js/es6/SimpleRL.js
@@ -0,0 +1,57 @@
const viewport = document.getElementById( 'viewport' )

const map = [
'#### ####',
'# #### #',
'# #',
'## ##',
' # # ',
' # # ',
'## ##',
'# #',
'# #### #',
'#### ####'
]

var player = {
x: 2,
y: 2
}

const setTile = tile =>
map[ player.y ] =
map[ player.y ].substr( 0, player.x ) +
tile +
map[ player.y ].substr( player.x + 1 )

const movePlayer = point => {
if( map[ point.y ][ point.x ] === ' ' )
player = point
}

const modifiers = {
37: { x: -1, y: 0 },
38: { x: 0, y: -1 },
39: { x: 1, y: 0 },
40: { x: 0, y: 1 }
}

const tick = e => {
setTile( ' ' )

if( e.keyCode in modifiers ){
const modifier = modifiers[ e.keyCode ]

movePlayer({
x: player.x + modifier.x,
y: player.y + modifier.y
})
}

setTile( '@' )

viewport.textContent = map.join( '\n' )
}

document.addEventListener( 'keyup', tick, false )
tick( { keyCode: null } )
10 changes: 10 additions & 0 deletions js/es6/index.html
@@ -0,0 +1,10 @@
<!doctype html>
<title>SimpleRL - JavaScript</title>
<meta charset="utf-8" />
<style>
body {
font-family: monospace;
}
</style>
<pre id="viewport"></pre>
<script src="SimpleRL.js"></script>

0 comments on commit e3bbdda

Please sign in to comment.