Skip to content
Browse files

implemented attack and basic gamplay done.

  • Loading branch information...
1 parent ea1b59e commit d669d6d431397ecbd868a3ee98576b675ad86f9c @jamesflorentino committed Apr 10, 2012
View
BIN client/assets/marine.fla
Binary file not shown.
View
2 client/assets/marine.json
@@ -1 +1 @@
-{"images": ["marine.png"], "frames": {"width": 112, "height": 97, "count": 108, "regX": 0, "regY": 0}, "animations": {"onDefendEnd": [71, 79], "onMove": [4, 15], "onRifleShot1": [30, 35], "all": [0, 0], "onRifleShot2": [36, 38], "onDefendStart": [59, 65], "onRifleShot3": [39, 41], "onDieStart": [80, 107], "onRifleShotEnd": [48, 58], "onRifleShotStart": [23, 29], "onRifleShot4": [42, 47], "onMoveStart": [1, 3], "onDefend": [66, 70], "onMoveEnd": [16, 22]}}
+{"images": ["marine.png"], "frames": {"width": 113, "height": 92, "count": 108, "regX": 0, "regY": 0}, "animations": {"onRifleShot4": [42, 47], "onDieStart": [80, 107], "onRifleShot2": [36, 38], "all": [0, 0], "onRifleShot3": [39, 41], "onRifleShotEnd": [48, 58], "onDefend": [66, 70], "onDefendEnd": [71, 79], "onMoveEnd": [16, 22], "onDefendStart": [59, 65], "onRifleShotStart": [23, 29], "onMoveStart": [1, 3], "onMove": [4, 15], "onRifleShot1": [30, 35]}}
View
BIN client/assets/marine.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN client/assets/marine.swf
Binary file not shown.
View
BIN client/assets/marine_alternate.fla
Binary file not shown.
View
1 client/assets/marine_alternate.json
@@ -0,0 +1 @@
+{"images": ["marine_alternate.png"], "frames": {"width": 113, "height": 92, "count": 108, "regX": 0, "regY": 0}, "animations": {"onMove": [4, 15], "onRifleShot1": [30, 35], "onDefendEnd": [71, 79], "onMoveStart": [1, 3], "onMoveEnd": [16, 22], "onRifleShot4": [42, 47], "onDefend": [66, 70], "all": [0, 0], "onRifleShot2": [36, 38], "onDefendStart": [59, 65], "onRifleShotStart": [23, 29], "onDieStart": [80, 107], "onRifleShot3": [39, 41], "onRifleShotEnd": [48, 58]}}
View
BIN client/assets/marine_alternate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN client/assets/marine_alternate.swf
Binary file not shown.
View
BIN client/assets/marine_blue.swf
Binary file not shown.
View
BIN client/source/images/marine copy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN client/source/images/marine.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN client/source/images/marine_alternate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN client/source/images/startup copy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN client/source/images/startup.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 client/source/index.html.jade
@@ -1,14 +1,16 @@
extends layout
append head
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
- <meta name="viewport" content="user-scalable=no, width=960" />
+ <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
- //<link href='http://fonts.googleapis.com/css?family=Maven+Pro:400,500,700,900' rel='stylesheet' type='text/css'>
- //<link href='http://fonts.googleapis.com/css?family=Play:400,700' rel='stylesheet' type='text/css'>
- //<link href='http://fonts.googleapis.com/css?family=Orbitron:400,500,700,900' rel='stylesheet' type='text/css'>
+ <link rel="apple-touch-icon" href="images/iphone.png"/>
+ <link rel="apple-touch-startup-image" href="images/startup.png" />
+ <link href='http://fonts.googleapis.com/css?family=Maven+Pro:400,500,700,900' rel='stylesheet' type='text/css'>
+ <link href='http://fonts.googleapis.com/css?family=Play:400,700' rel='stylesheet' type='text/css'>
+ <link href='http://fonts.googleapis.com/css?family=Orbitron:400,500,700,900' rel='stylesheet' type='text/css'>
title HTML5 Game Prototype
- script(src="http://localhost:1337/socket.io/socket.io.js")
- //script(src="http://192.168.254.113:1337/socket.io/socket.io.js")
+ //script(src="http://localhost:1337/socket.io/socket.io.js")
+ script(src="http://192.168.254.104:1337/socket.io/socket.io.js")
script(src="javascripts/lib/jquery.js")
//script(src="javascripts/lib/jquery.mobile.js")
script(src="javascripts/lib/easel.js")
View
3 client/source/javascripts/settings.js
@@ -18,6 +18,9 @@ Wol.AssetList = [
name: 'marine',
url: '/images/marine.png'
},{
+ name: 'marine_alternate',
+ url: '/images/marine_alternate.png'
+ },{
name: 'hex_act',
url: '/images/hex_act.png'
},{
View
6 client/source/javascripts/wol/GameModel.coffee
@@ -3,7 +3,7 @@
window.DEBUG = false
HOST = 'http://localhost:1337'
-#HOST = 'http://192.168.254.113:1337'
+HOST = 'http://192.168.254.104:1337'
@Wol
@io
@@ -26,6 +26,9 @@ class Wol.Models.GameModel extends Wol.Models.Model
console.log 'sending', eventName, data
@socket.emit eventName, data
this
+
+ getUserById: (userId) ->
+ @users.find (user) -> user.get('userId') is userId
bindEvents: ->
@socket.on 'connect', (data) =>
@@ -70,5 +73,6 @@ class Wol.Models.GameModel extends Wol.Models.Model
setUserName: (userName) ->
@socket.emit 'setUserName',
userName: userName
+ raceName: 'lemurian'
this
View
22 client/source/javascripts/wol/GameView.coffee
@@ -126,8 +126,6 @@ class Views.GameView extends GameUi
assetsReady: =>
# once the assets are loaded, we can now build our user-interface
@buildElements().setConfigurations()
- @ui.curtain.hide()
- @play()
if window.debug is true
@debug()
return
@@ -196,19 +194,29 @@ class Views.GameView extends GameUi
this
startGame: =>
+ console.log 'start game'
@play()
+ @ui.curtain.hide()
this
addUser: (data) =>
+ console.log 'addUser', data
@ui.console.log data.message
+ me = @model.user
+ user = @model.getUserById data.userId
+ user.set alternateColor: (=>
+ Boolean @model.users.find (u)=>
+ return false if u is me
+ u.get('raceName') is user.get('raceName') and u.get('playerNumber') < user.get('playerNumber')
+ )()
this
addUnit: (data) =>
- console.log 'addUnit', data
@ui.console.log data.message
{userId, unitId, unitCode, unitName, tileX, tileY, face} = data
{unitStats, unitCommands} = data
- unit = @elements.unitContainer.createUnitByCode unitCode
+ user = @model.getUserById userId
+ unit = @elements.unitContainer.createUnitByCode unitCode, user.get('alternateColor')
unit.set
tileX: tileX
tileY: tileY
@@ -255,13 +263,18 @@ class Views.GameView extends GameUi
actUnit: (data) =>
{unitId, commandCode, targets} = data
@elements.hexContainer.removeActiveTile()
+ tiles = @elements.hexContainer.get 'selection'
+ tiles.selected = []
unitActive = @elements.unitContainer.getUnitById unitId
firstTarget = @elements.unitContainer.getUnitById targets[0].unitId
+ @elements.hexContainer.set
+ activeTile: @elements.hexContainer.addTile {tileX: unitActive.get('tileX'), tileY: unitActive.get('tileY')}, 'move'
unitActive.flip (if unitActive.el.x > firstTarget.el.x then 'left' else' right')
#events
unitActive.unbind('attackEnd').bind 'attackEnd', =>
unitActive.unbind 'attackEnd'
unitActive.unbind 'attack'
+ @elements.hexContainer.removeTiles tiles.selected if tiles.selected?
targets.forEach (targetData) =>
unit = @elements.unitContainer.getUnitById targetData.unitId
return if !unit
@@ -298,6 +311,7 @@ class Views.GameView extends GameUi
targets.each (targetData) =>
unit = @elements.unitContainer.getUnitById targetData.unitId
return if !unit
+ tiles.selected.push @elements.hexContainer.addTile {tileX: unit.get('tileX'), tileY: unit.get('tileY')}, 'target'
unit.defend()
unitActive.act
View
12 client/source/javascripts/wol/Unit.coffee
@@ -2,7 +2,9 @@
Views = Wol.Views
FrameData =
- marine: {"images": ["marine.png"], "frames": {"width": 112, "height": 97, "count": 108, "regX": 0, "regY": 0}, "animations": {"onRifleShot4": [42, 47], "onRifleShot3": [39, 41], "onRifleShot2": [36, 38], "all": [0, 0], "onRifleShot1": [30, 35], "onRifleShotStart": [23, 29], "onDieStart": [80, 107], "onDefendEnd": [71, 79], "onMoveEnd": [16, 22], "onDefendStart": [59, 65], "onMove": [4, 15], "onRifleShotEnd": [48, 58], "onMoveStart": [1, 3], "onDefend": [66, 70]}}
+ marine: {"images": ["marine.png"], "frames": {"width": 113, "height": 92, "count": 108, "regX": 0, "regY": 0}, "animations": {"onRifleShot4": [42, 47], "onDieStart": [80, 107], "onRifleShot2": [36, 38], "all": [0, 0], "onRifleShot3": [39, 41], "onRifleShotEnd": [48, 58], "onDefend": [66, 70], "onDefendEnd": [71, 79], "onMoveEnd": [16, 22], "onDefendStart": [59, 65], "onRifleShotStart": [23, 29], "onMoveStart": [1, 3], "onMove": [4, 15], "onRifleShot1": [30, 35]}}
+
+ marine_alternate: {"images": ["marine_alternate.png"], "frames": {"width": 113, "height": 92, "count": 108, "regX": 0, "regY": 0}, "animations": {"onMove": [4, 15], "onRifleShot1": [30, 35], "onDefendEnd": [71, 79], "onMoveStart": [1, 3], "onMoveEnd": [16, 22], "onRifleShot4": [42, 47], "onDefend": [66, 70], "all": [0, 0], "onRifleShot2": [36, 38], "onDefendStart": [59, 65], "onRifleShotStart": [23, 29], "onDieStart": [80, 107], "onRifleShot3": [39, 41], "onRifleShotEnd": [48, 58]}}
Wol.Units =
getAnimation: (frameDataName, images) ->
@@ -27,8 +29,6 @@ Wol.Units =
Units = Wol.Units
-
-
class Wol.Models.Commands extends Wol.Collections.Collection
init: ->
@@ -152,9 +152,11 @@ class Wol.Views.Marine extends Wol.Views.AnimatedUnit
setAnimation: ->
@height = 125
@walkSpeed = 600
- @frameDataName = 'marine'
+ assetName = 'marine'
+ assetName = 'marine_alternate' if @alternateColor is true
+ @frameDataName = assetName
@images = [
- Wol.getAsset 'marine'
+ Wol.getAsset assetName
]
@el.regX = 30
@el.regY = 87
View
4 client/source/javascripts/wol/UnitContainer.coffee
@@ -6,9 +6,9 @@ class Wol.Views.UnitContainer extends Wol.Views.View
@units = []
return
- createUnitByCode: (unitCode) ->
+ createUnitByCode: (unitCode, alternateColor = false) ->
switch unitCode
- when Wol.UnitNames.MARINE then new Wol.Views.Marine()
+ when Wol.UnitNames.MARINE then new Wol.Views.Marine alternateColor: alternateColor
addUnit: (unit) ->
@el.addChild unit.el
View
2 client/source/javascripts/wol/Wol.coffee
@@ -106,3 +106,5 @@ class Wol.Collections.Collection extends Wol.Events.EventDispatcher
find: (callback) ->
result = @collections.filter callback
result[0]
+
+ each: (callback) -> @collections.each callback
View
4 client/source/layout.jade
@@ -2,7 +2,7 @@ html
block head
block title HTML5 prototype game yo!
link(rel="icon", type="image/png", href="favico.png")
- link(rel="stylesheet", href="stylesheets/site.css")
+ <link rel="stylesheet" href="stylesheets/site.css" type="text/css" media="screen, mobile" title="main" charset="utf-8">
block body
#game
canvas Your browser doesn't support HTML5. Download Chrome, Firefox, or Safari to play this game.
@@ -19,7 +19,7 @@ html
.confirm.button Confirm
.cancel.button Cancel
#top-vignette.hidden
- #curtain.hidden
+ #curtain
.text Connecting...
.top.cover
.bottom.cover
View
58 server/build/server.js
@@ -11,7 +11,7 @@ var Collection, EventDispatcher, Hex, HexGrid, MAX_PLAYERS_PER_ROOM, MAX_USERS_P
PORT = Number(process.env.PORT || 1337);
-MAX_PLAYERS_PER_ROOM = 2;
+MAX_PLAYERS_PER_ROOM = 1;
MAX_USERS_PER_ROOM = 2;
@@ -211,7 +211,6 @@ User = (function(_super) {
}
User.prototype.initialize = function() {
- console.log("====================");
console.log("User Event: " + (this.get('name')) + " <" + this.id + "> enters a game");
};
@@ -272,7 +271,6 @@ Room = (function(_super) {
};
Room.prototype.announce = function(eventName, data) {
- console.log("====================");
console.log("Room Event: " + eventName);
console.log(data);
this.users.forEach(function(user) {
@@ -354,6 +352,12 @@ Room = (function(_super) {
});
};
+ Room.prototype.getPlayers = function() {
+ return this.users.map(function(user) {
+ return user.get('playerType') === PlayerType.PLAYER;
+ });
+ };
+
Room.prototype.reset = function() {
this.users = [];
return this.units = [];
@@ -565,15 +569,18 @@ ServerProtocol = {
});
return room[0];
},
- joinRoom: function(user, room) {
- var playerType, roomId, roomName, socket, totalUsers, userId, userName;
+ joinRoom: function(user, room, raceName) {
+ var playerType, players, roomId, roomName, socket, totalUsers, userId, userName;
if (room === void 0) return;
userId = user.id;
userName = user.get('name');
roomId = room.id;
roomName = room.get('name');
socket = user.get('socket');
playerType = PlayerType.PLAYER;
+ user.set({
+ raceName: raceName
+ });
if (room.totalUsers >= MAX_USERS_PER_ROOM) {
user.announce('roomError', {
message: 'Room is already full'
@@ -587,30 +594,51 @@ ServerProtocol = {
playerType: playerType
});
if (user.get('playerType') === PlayerType.PLAYER) {
+ players = room.getPlayers();
+ user.set({
+ playerNumber: players.length
+ });
ServerProtocol.assignEvents(userId, roomId);
}
socket.on('disconnect', function() {
+ console.log("" + userName + " left " + roomName);
room.removeUser(user);
if (room.users.length === 0) {
+ room.set({
+ ready: false
+ });
room.reset();
return;
}
- room.announce('removeUser', {
+ return room.announce('removeUser', {
roomId: roomId,
userId: userId,
userName: userName,
message: "" + playerType + " " + userName + " has left the game."
});
- return console.log("" + userName + " left " + roomName);
});
user.announce('joinRoom', {
roomId: roomId,
roomName: roomName,
message: "Hi " + userName + ", you have joined " + roomName + " <" + roomId + ">"
});
+ room.users.each(function(u) {
+ if (u === user) return;
+ return user.announce('addUser', {
+ userId: u.id,
+ userName: u.get('name'),
+ playerNumber: u.get('playerNumber'),
+ playerType: u.get('playerType'),
+ raceName: u.get('raceName'),
+ message: "" + playerType + " " + userName + " has joined the game."
+ });
+ });
room.announce('addUser', {
userId: userId,
userName: userName,
+ playerNumber: user.get('playerNumber'),
+ playerType: user.get('playerType'),
+ raceName: user.get('raceName'),
message: "" + playerType + " " + userName + " has joined the game."
});
if (totalUsers >= MAX_PLAYERS_PER_ROOM) {
@@ -631,7 +659,7 @@ ServerProtocol = {
socket = user.get('socket');
roomId = room.id;
room.units.each(function(unit) {
- user.announce('addUnit', {
+ user.announce('updateUnit', {
userId: unit.get('userId'),
unitId: unit.id,
tileX: unit.get('tileX'),
@@ -648,6 +676,9 @@ ServerProtocol = {
startGame: function(roomId) {
var players, room, unit, unitB;
room = ServerProtocol.getRoomById(roomId);
+ room.announce('startGame', {
+ message: 'Game has started'
+ });
players = room.users.filter(function(u) {
return u.get('playerType') === PlayerType.PLAYER;
});
@@ -841,7 +872,7 @@ onConnect = function(socket) {
var user;
user = null;
socket.on('setUserName', function(data) {
- var userName;
+ var raceName, userName;
if (user != null) return;
userName = data.userName;
user = new User({
@@ -852,10 +883,13 @@ onConnect = function(socket) {
userId: user.id,
userName: user.get('name')
});
- ServerProtocol.joinRoom(user, testRoom);
+ raceName = 'lemurian';
+ ServerProtocol.joinRoom(user, testRoom, raceName);
});
- socket.on('joinRoom', function(roomId) {
- var room;
+ socket.on('joinRoom', function(roomId, options) {
+ var raceName, room;
+ if (options != null) raceName = options.raceName;
+ raceName || (raceName = 'lemurian');
room = ServerProtocol.getRoomById(roomId);
ServerProtocol.joinRoom(user, room);
});
View
55 server/source/server.coffee
@@ -9,7 +9,7 @@
# Global Variables
# =========================================
PORT = Number(process.env.PORT or 1337)
-MAX_PLAYERS_PER_ROOM = 2
+MAX_PLAYERS_PER_ROOM = 1
MAX_USERS_PER_ROOM = 2
PlayerType =
SPECTATOR: 'spectator'
@@ -139,7 +139,6 @@ class Collection extends Model
class User extends Model
initialize: ->
- console.log "===================="
console.log "User Event: #{@get 'name'} <#{@id}> enters a game"
return
@@ -188,7 +187,6 @@ class Room extends Model
user[0]
announce: (eventName, data) ->
- console.log "===================="
console.log "Room Event: #{eventName}"
console.log data
@users.forEach (user) ->
@@ -249,7 +247,11 @@ class Room extends Model
@trigger 'unitTurn', unit: activeUnit
console.log "unit selected", activeUnit
return
-
+
+ getPlayers: ->
+ @users.map (user) ->
+ user.get('playerType') is PlayerType.PLAYER
+
reset: ->
@users = []
@units = []
@@ -403,14 +405,15 @@ ServerProtocol =
room = ServerData.rooms.filter (room) -> room.id is roomId
room[0]
- joinRoom: (user, room) ->
+ joinRoom: (user, room, raceName) ->
return if room is undefined
userId = user.id
userName = user.get 'name'
roomId = room.id
roomName = room.get 'name'
socket = user.get 'socket'
playerType = PlayerType.PLAYER
+ user.set raceName: raceName
# reject the user if the room is full
# if room.totalUsers > MAX_USERS_PER_ROOM
@@ -421,38 +424,55 @@ ServerProtocol =
# add the user to the room
room.addUser user
totalUsers = room.totalUsers
-
+
# set the player type to listen to the user's requests
playerType = PlayerType.SPECTATOR if totalUsers > MAX_PLAYERS_PER_ROOM
user.set playerType: playerType
# spectators can only read from the system
if user.get('playerType') is PlayerType.PLAYER
+ players = room.getPlayers()
+ user.set playerNumber: players.length
ServerProtocol.assignEvents userId, roomId
# when the user disconnects, remove him from the list
socket.on 'disconnect', ->
+ console.log "#{userName} left #{roomName}"
room.removeUser user
if room.users.length is 0
+ room.set ready: false
room.reset()
return
room.announce 'removeUser',
roomId: roomId
userId: userId
userName: userName
message: "#{playerType} #{userName} has left the game."
- console.log "#{userName} left #{roomName}"
# tell the user that he is subscribed to the room's update
user.announce 'joinRoom',
roomId: roomId
roomName: roomName
message: "Hi #{userName}, you have joined #{roomName} <#{roomId}>"
-
+
+ # populate the earlier list of users to the client
+ room.users.each (u) ->
+ return if u is user
+ user.announce 'addUser',
+ userId: u.id
+ userName: u.get 'name'
+ playerNumber: u.get 'playerNumber'
+ playerType: u.get 'playerType'
+ raceName: u.get 'raceName'
+ message: "#{playerType} #{userName} has joined the game."
+
# announce the new user to the room list
room.announce 'addUser',
userId: userId
userName: userName
+ playerNumber: user.get 'playerNumber'
+ playerType: user.get 'playerType'
+ raceName: user.get 'raceName'
message: "#{playerType} #{userName} has joined the game."
# start the game if the game has the minimum number of players
@@ -469,7 +489,7 @@ ServerProtocol =
socket = user.get 'socket'
roomId = room.id
room.units.each (unit) ->
- user.announce 'addUnit',
+ user.announce 'updateUnit',
userId: unit.get 'userId'
unitId: unit.id
tileX: unit.get 'tileX'
@@ -485,6 +505,8 @@ ServerProtocol =
startGame: (roomId) ->
room = ServerProtocol.getRoomById roomId
+ room.announce 'startGame',
+ message: 'Game has started'
players = room.users.filter (u) ->
u.get('playerType') is PlayerType.PLAYER
# deploy a few units at the beginning of the game.
@@ -679,17 +701,24 @@ onConnect = (socket) ->
# supply the server with a username
socket.on 'setUserName', (data) ->
return if user?
- userName = data.userName
+ {userName} = data
user = new User socket: socket, name: userName
user.announce 'setUserName',
userId: user.id
userName: user.get 'name'
- # DEBUG - deploy user to a default room
- ServerProtocol.joinRoom user, testRoom
+ # ====================================
+ # D E B U G
+ # ====================================
+ raceName = 'lemurian'
+ ServerProtocol.joinRoom user, testRoom, raceName
return
# adds the user to an existing room by roomId
- socket.on 'joinRoom', (roomId) ->
+ socket.on 'joinRoom', (roomId, options) ->
+ # sets the lemurian race as the default race
+ if options?
+ {raceName} = options
+ raceName or= 'lemurian'
room = ServerProtocol.getRoomById roomId
ServerProtocol.joinRoom user, room
return
View
43 server/test.js
@@ -0,0 +1,43 @@
+var onConnect = function (socket) {
+
+ var user = null;
+
+ socket.on('testUserName', function (data) {
+ if (user) return;
+ var userName = data.userName;
+ user.announce('setUserName', {
+ userId: user.id,
+ userName user.get('name')
+ });
+ ServerProtocol.joinRoom(user, testRoom);
+ });
+
+ socket.on('joinRoom', function (roomId) {
+ var room = ServerProtocol.getRoomById(roomId);
+ ServerProtocol.joinRoom(user, room);
+ });
+
+}
+
+
+var ServerProtocol = {
+ createRoom: function (roomName) {
+ var room = new Room({
+ name: roomName
+ });
+
+ var roomId = room.id;
+
+ room.bind('unitTurn', function (event) {
+ var unit = event.unit;
+ unit.set({
+ moved: false,
+ acted: false
+ });
+
+ unit.stats.set({
+ actions: unit.stats.get('baseActions')
+ });
+ });
+ }
+};

0 comments on commit d669d6d

Please sign in to comment.
Something went wrong with that request. Please try again.