Permalink
Browse files

End game after 10 turns

  • Loading branch information...
2 parents 0f123f1 + de5bf96 commit c1d4ccb4453a273b621e611f8f9ebdb477abd166 @josephg josephg committed Apr 1, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 game.coffee
View
@@ -41,10 +41,17 @@ unit_stats = image 'unit_stats.png'
player_text = {red: image('player1_text.png'), blue: image('player2_text.png')}
hp_text = image 'HP.png'
hp_num = [image('1.png'), image('1.png'), image('2.png'), image('3.png')]
+
indicator =
red: image 'indicator.png'
blue: image 'indicator2.png'
+cloud = image 'cloud.png'
+spark =
+ img: image 'spark.png'
+ tileWidth: 150
+ tileHeight: 75
+
wiz =
img: image 'Wizard Spritesheet.png'
tileWidth: 100
@@ -232,6 +239,7 @@ movementShadow =
gameoverscreen =
red: image 'redteamwinscreen.png'
blue: image 'blueteamwinscreen.png'
+ draw: image 'drawscreen.png'
splashscreen = image 'titlescreen.png'
@@ -299,6 +307,8 @@ future = null
pendingActions = []
endDays = []
+cloudX = 0
+
reset = ->
reversing = false
reversingState = 0
@@ -886,6 +896,20 @@ unitsToMove = {}
turnStart = ->
unitsToMove = getActiveUnits currentPlayer
+
+ finalDay = endDays[10].activeUnits
+ if finalDay.length > 0 and currentPlayer is 'red'
+ # Whoever has units here wins.
+ redUnits = (u for u in finalDay when u.owner is 'red')
+ blueUnits = (u for u in finalDay when u.owner is 'blue')
+ state = 'gameover'
+ winner = if redUnits.length and blueUnits.length
+ 'draw'
+ else if redUnits.length
+ 'red'
+ else
+ 'blue'
+
for d, i in unitsToMove
if d.length
return goToEvening i
@@ -973,6 +997,9 @@ manhattan = (a,b) -> Math.abs(a.x-b.x) + Math.abs(a.y-b.y)
hoveredUnit = null
+sparkFrame = 10
+sparkX = 0
+
atom.run
update: (dt) ->
if state in ['splash', 'gameover']
@@ -1224,6 +1251,22 @@ atom.run
ctx.drawImage hp_text, 155, 60
ctx.drawImage hp_num[hoveredUnit.hp], 240, 60
+ tile_x = Math.floor(sparkFrame) % 3
+ tile_y = Math.floor sparkFrame / 3
+ sparkFrame += 0.25 * (if reversing then -1 else 1)
+ if sparkFrame > 150+Math.floor(Math.random()*100)
+ sparkFrame = 0
+ sparkX = if Math.random() < 0.5 then 1000 else 20
+ if sparkFrame < 6
+ ctx.drawImage spark.img, tile_x * spark.tileWidth, tile_y * spark.tileHeight, spark.tileWidth, spark.tileHeight, sparkX, canvas.height - spark.tileHeight - 40, spark.tileWidth, spark.tileHeight
+
+ cloudSpeed = 1
+ cloudX += cloudSpeed * (if reversing then -1 else 1)
+ ctx.globalAlpha = 0.4
+ ctx.drawImage cloud, cloudX % canvas.width, canvas.height - cloud.height
+ ctx.drawImage cloud, (cloudX % canvas.width) - cloud.width, canvas.height - cloud.height
+ ctx.globalAlpha = 1
+
if reversing
reversingState = Math.min(reversingState + 0.015, 0.5)
else

0 comments on commit c1d4ccb

Please sign in to comment.