Skip to content
Browse files

animate gorilla

and change font
  • Loading branch information...
1 parent 1ac16a4 commit 72a176d822eae2590e7befd57c1cf38d934eaf30 @despo committed Apr 6, 2012
View
BIN public/images/gorilla-left-hand-up.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/gorilla-right-hand-up.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
65 views/gorillas.coffee
@@ -219,12 +219,19 @@ class Painter
),
@f
+ update_score: ->
+ console.log @player_1.games_won()
+ $('#score label').text(@player_1.games_won() + '>Score<' + @player_2.games_won())
+
animate_banana:(player) ->
@timeout = setTimeout (=>
@draw_scene()
if @banana_hit_gorilla(player) == true
- return
+ @update_score()
+ @player_1.reset_state()
+ @player_2.reset_state()
@next_player_turn(player)
+ return
if @banana_has_collided(player) == true
@next_player_turn(player)
return
@@ -252,6 +259,14 @@ class Painter
y = player.banana.y()
if @player_2.check_colission(x, y) || @player_1.check_colission(x, y)
dead_player = if @player_2.dead == true then @player_2 else @player_1
+ winner = if @player_2.dead == false then @player_2 else @player_1
+ winner.win()
+ @timeout = setTimeout (=>
+ @start_time = new Date()
+ winner.animate = true
+ @animate_win(winner, @start_time)
+ ),
+ @f
x = dead_player.x+dead_player.width/2
y = dead_player.y
@star(x, y) for o in [ -3...3 ]
@@ -261,6 +276,17 @@ class Painter
@colission = [x, y]
return true
+ animate_win:(player, @start_time) ->
+ @timeout = setTimeout (=>
+ return unless player.animate == true and player.animations < 10
+ now = new Date()
+ time = now - @start_time
+ @draw_scene()
+ player.animate_win()
+ @animate_win(player, @start_time)
+ ),
+ 750
+
next_player_turn:(player) ->
next_player = if player.player_number == 2 then 1 else 2
window.show_player_field('player_'+next_player, 'angle')
@@ -290,8 +316,13 @@ class Painter
class Gorilla
constructor:(@context, @player_number) ->
+ @wins = 0
@width = 40
+ @dead = false
@height = 40
+ @animate = false
+ @animations = 0
+ @right_hand = false
image: ->
image = new Image()
@@ -304,12 +335,13 @@ class Gorilla
@context.drawImage(@image(), @x, @y, @width, @height)
redraw:() ->
- @draw(@x, @y)
+ @draw(@x, @y) unless @animate == true
grab_banana:(force, angle) ->
@banana = new Banana(@context, @x+@width, @y-@height, force, angle)
throw_banana:(time) ->
+ @context.drawImage(@right_hand_image(), @x, @y, @width, @height)
@banana.draw_frame(time)
check_colission:(x, y) ->
@@ -318,6 +350,35 @@ class Gorilla
return true
false
+ win: ->
+ @wins++
+
+ games_won: ->
+ @wins
+
+ reset_state: ->
+ @animations = 0
+ @dead = false
+ @aniamate = false
+
+ right_hand_image: ->
+ image = new Image()
+ image.src = 'images/gorilla-right-hand-up.png'
+ image
+
+ left_hand_image: ->
+ image = new Image()
+ image.src = 'images/gorilla-left-hand-up.png'
+ image
+
+ animate_win: ->
+ @right_hand = !@right_hand
+ @animations++
+ if @right_hand == true
+ return @context.drawImage(@right_hand_image(), @x, @y, @width, @height)
+ @context.drawImage(@left_hand_image(), @x, @y, @width, @height)
+
+
class Banana
constructor:(@context, @initx, @inity, @force, @angle) ->
@projection_x = 0
View
3 views/index.haml
@@ -16,3 +16,6 @@
%label{ :for => '#player_2_velocity' } velocity
%input{ :id => "player_2_velocity", :maxlength => 3 }
%canvas{ :id => "gorillas", :width => "1024", :height => "640" }
+
+#score
+ %label#value 0>Score<0
View
18 views/style.scss
@@ -2,8 +2,8 @@ body {
background-color: #0000a0;
margin: 0 auto;
text-align: center;
- font-family: courier, serif;
- font-size: 20px;
+ font-family: "andale mono","monotype.com",monaco,"courier new",courier,monospace;
+ font-size: 16px;
color: #fff;
}
@@ -39,7 +39,7 @@ label {
font-size: 16px;
}
-#player_1_angle, #player_2_angle, #player_1_velocity, #player_2_velocity, label {
+#player_1_angle, #player_2_angle, #player_1_velocity, #player_2_velocity, #player_1 label, #player_2 label {
display: none;
}
@@ -53,5 +53,15 @@ label {
position: absolute;
}
-canvas {
+.score .player_1, .score .player_2 {
+ background-color: #0000a0;
+}
+
+#score {
+ margin-top: -50px;
+}
+
+#score label {
+ background-color: #0000a0;
+ display: inline-block;
}

0 comments on commit 72a176d

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