Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hamin/YourFace
Browse files Browse the repository at this point in the history
Conflicts:
	css/master.css
	public/client.coffee
	public/client.js
  • Loading branch information
ribeto committed Jun 26, 2011
2 parents 5820d48 + 467bb5d commit 0cbe9ad
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 26 deletions.
Binary file added assets/bullet.png
Loading
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/bullet_blue.png
Loading
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/explosion.png
Loading
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/explosion_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions css/master.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
body{ overflow: hidden;}

.playingField {
border-style: solid;
border-color: green;
Expand Down
55 changes: 37 additions & 18 deletions public/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,34 @@ updateDivPosition = (divName,newPosition) ->
console.log "newPosition = #{newPosition}"
$(".#{divName}").offset left: newPosition

shoot = (position) ->
++bulletNum
bullets.push bulletNum
bulletName = "b#{bulletNum}"
console.log "shoot bitch shoot! bulletName=#{bulletName} x: #{position.x} y: #{position.y}"
$("#playingField").append "<div id='#{bulletName}' class='bullet'></div>"
$("##{bulletName}").offset left: position.x, top: position.y
$("##{bulletName}").animate {top: (position.y - 915) }, 400, () ->
$("##{bulletName}").remove() if $("##{bulletName}").offset().top is 8


#client = new Faye.Client "http://192.168.201.92:3000/faye"
client = new Faye.Client "http://localhost:3000/faye"
shoot = (position, isOpp) ->
++bulletNum
bullets.push bulletNum
bulletName = "b#{bulletNum}"
console.log "shoot bitch shoot! bulletName=#{bulletName} x: #{position.x} y: #{position.y}"
$("#playingField").append "<div id='#{bulletName}' class='bullet'></div>"

$("##{bulletName}").offset left: position.x, top: position.y
sign = -1
sign = 1 if isOpp is true
$("##{bulletName}").animate {top: (position.y + sign*915) }, 400, () ->
i = bullets.indexOf bulletName
bullets.splice i

# If it hits opponent remove the field and do some stuff
oppTop = $('.opponent').offset().top
oppLeft = $('.opponent').offset().left
oppWidth = oppLeft + $('.opponent').width()
if $("##{bulletName}").offset().left in [oppLeft..oppWidth]
console.log("BOOM!!!!")

# If it leaves playing field remove the bullet
if ( isOpp is true && $("##{bulletName}").offset().top > 800 ) or ( isOpp is false && $("##{bulletName}").offset().top < 8 )
$("##{bulletName}").remove()

client = new Faye.Client "http://192.168.201.92:3000/faye"
# client = new Faye.Client "http://localhost:3000/faye"

client.subscribe "/yourface", (message) ->
if clientId < 0
Expand All @@ -76,9 +91,12 @@ $(document).ready () ->
client.subscribe "/opponentPos", (message) ->
if message.oppClientId isnt clientId
updateDivPosition "opponent", message.curLeftPos


# Arrow Button Bindings 

client.subscribe "/fire", (message) ->
if message.oppClientId isnt clientId
shoot {x: message.x, y: message.y}, true

# Arrow Button Bindings
$('body').keydown (event) ->
console.log "keyCode #{event.keyCode}"
curLeftPos = $(".me").offset().left
Expand All @@ -91,8 +109,9 @@ $(document).ready () ->
# right
if event.keyCode is 39
updateDivPosition "me", curLeftPos + offset
if event.keyCode is 32
console.log "about to shoot"
shoot x: curLeftPos+50, y: curTopPos-15
if event.keyCode is 16
shoot {x: curLeftPos+50, y: curTopPos-15}, false
oppY = $('.opponent').offset().top + $('.opponent').height()
client.publish '/fire', x: curLeftPos+50, y: oppY, oppClientId: clientId

client.publish "/opponentPos", {curLeftPos: $(".me").offset().left, oppClientId: clientId}
52 changes: 44 additions & 8 deletions public/client.js

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

0 comments on commit 0cbe9ad

Please sign in to comment.