Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
clooth committed Aug 26, 2012
0 parents commit 67bb63d
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions README.md
@@ -0,0 +1,5 @@
# Chronicle

## TODO:

- Create tools for easier development workflow. (Cakefile?)
Binary file added assets/img/body.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions assets/js/anim_frame_polyfill.coffee
@@ -0,0 +1,24 @@
(() ->
lastTime = 0
vendors = ['ms', 'moz', 'webkit', 'o']
x = 0
while x < vendors.length && !window.requestAnimationFrame
window.requestAnimationFrame = window["#{vendors[x]}RequestAnimationFrame"]
window.cancelAnimationFrame = window["#{vendors[x]}CancelAnimationFrame"] ||
window["#{vendors[x]}CancelRequestAnimationFrame"]
x++

if not window.requestAnimationFrame
window.requestAnimationFrame = (callback, element) ->
currentTime = new Date().getTime()
timeToCall = Math.max(0, 16 - (currentTime - lastTime))
id = window.setTimeout () ->
callback(currentTime + timeToCall)
, timeToCall
lastTime = currentTime + timeToCall
id

if not window.cancelAnimationFrame
window.cancelAnimationFrame = (id) ->
clearTimeout(id)
)()
37 changes: 37 additions & 0 deletions assets/js/app.coffee
@@ -0,0 +1,37 @@
canvas = document.getElementById 'game'
context = canvas.getContext '2d'

socket = new io.connect 'http://localhost:8100'

# Main class to handle keystroes
class KeyMaster
@UP = 'UP'
@RIGHT = 'RIGHT'
@DOWN = 'DOWN'
@LEFT = 'LEFT'

constructor: () ->
# Keycode map
@Keys =
37: KeyMaster.LEFT
38: KeyMaster.UP
39: KeyMaster.RIGHT
40: KeyMaster.DOWN

# Handler for a keystroke event
handleStroke: (event) ->
if event?
keyCode = event.keyCode
else
keyCode = window.event.keyCode

socket.send @Keys[keyCode]

# Main game class
class Chronicle
constructor: (@players) ->


socket.on 'news', (data) ->
console.log data
socket.emit 'my other event', my: 'data'
118 changes: 118 additions & 0 deletions assets/js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions assets/js/lib/jquery.min.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions assets/js/lib/ocanvas-2.2.1.min.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions assets/js/logo_animation.coffee
@@ -0,0 +1,30 @@
(() ->
logo = $ '#logo'
unless logo.length > 0
return

logo.css 'opacity', 1.0
logo.data 'blink', false

updateLogo = () ->
opacity = parseFloat(logo.css('opacity')).toFixed(2)
opacity = parseFloat(opacity)

if logo.data().blink == true
opacity += 0.02
else
opacity -= 0.02

if opacity >= 1.00
logo.data 'blink', false
opacity = 1.00
else if opacity <= 0.2
logo.data 'blink', true
opacity = 0.2

opacity = opacity.toFixed(2)

requestAnimationFrame updateLogo
logo.css 'opacity', opacity
updateLogo()
)()
14 changes: 14 additions & 0 deletions package.json
@@ -0,0 +1,14 @@
{
"name": "chronicle",
"description": "An mmorpg game built with nodejs",
"author": "Nico Hämäläinen <nico@bender.fi>",
"version": "0.0.0",
"license": "MIT",

"dependencies": {
"express" : "3.x",
"socket.io": "0.9.x"
},

"engine": "node >= 0.8.8"
}
33 changes: 33 additions & 0 deletions public/index.html
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chronicle</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
background: #3c3d3d url('assets/img/body.png') repeat center center;
}
#logo {
position: absolute;
width: 680px;
height: 120px;
left: 50%;
top: 50%;
margin-left: -340px;
margin-top: -60px;
}
</style>
<script src="assets/js/lib/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<img id="logo" src="assets/img/logo.png" alt="Chronicle Logo">
<script src="assets/js/app.js"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions public/map.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chronicle</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
background: #3c3d3d url('assets/img/body.png') repeat center center;
}
#map {
width: 100%;
height: 100%;
}
</style>
<script src="assets/js/lib/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<canvas id="game"></canvas>
<script src="assets/js/app.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions server.coffee
@@ -0,0 +1,22 @@
express = require 'express'
app = express()
http = require 'http'
server = http.createServer(app)
io = require('socket.io').listen(server)

server.listen 8100

app.use '/assets', express.static "#{__dirname}/assets"

# Main index page
app.get '/', (request, response) ->
response.sendfile "#{__dirname}/public/index.html"

# Map test page
app.get '/map', (request, response) ->
response.sendfile "#{__dirname}/public/map.html"

io.sockets.on 'connection', (socket) ->
socket.emit 'news', hello: 'world'
socket.on 'my other event', (data) ->
console.log data
Empty file added src/player.coffee
Empty file.

0 comments on commit 67bb63d

Please sign in to comment.