Skip to content

Commit

Permalink
repaint windows with the same colour
Browse files Browse the repository at this point in the history
  • Loading branch information
despo committed Apr 3, 2012
1 parent bef217a commit 33bb27a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions views/gorillas.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Building
@width = 70 + Math.floor(Math.random()*40) @width = 70 + Math.floor(Math.random()*40)
@base_height = 100 @base_height = 100
@randomize_color() @randomize_color()
@windows = []
@colissions = [] @colissions = []


position_at_x:() -> position_at_x:() ->
Expand All @@ -29,16 +30,24 @@ class Building
@draw_colission(colission[0], colission[1]) for colission in @colissions @draw_colission(colission[0], colission[1]) for colission in @colissions


build_windows:(x, y) -> build_windows:(x, y) ->
if @windows.length > 0
for window in @windows
@create_window window[0], window[1], window[2]
return

rows = Math.round (@height)/31 rows = Math.round (@height)/31
windows_per_floor = Math.floor(@width/15) windows_per_floor = Math.floor(@width/15)
current_distance = 30 current_distance = 30
total_height = 30 total_height = 30
for row in [0...rows] for row in [0...rows]
@create_window x+(position*15), 620+total_height-@height for position in [1...windows_per_floor] for position in [1...windows_per_floor]
color = @randomize_window_color()
@create_window x+(position*15), 620+total_height-@height, color
@windows.push [x+(position*15), 620+total_height-@height, color]

total_height += current_distance total_height += current_distance


create_window:(x, y) -> create_window:(x, y, color) ->
color = @randomize_window_color()
@context.fillStyle = color @context.fillStyle = color
@context.fillRect x, y, 8, 16 @context.fillRect x, y, 8, 16


Expand All @@ -54,7 +63,7 @@ class Building
color color


check_colission:(x, y) -> check_colission:(x, y) ->
if @position_at_y() < y && (@x < x && (@x + @width) > x) if @position_at_y() < y && (@x < x-10 && (@x + @width) > x-10)
@colissions.push [x, y] @colissions.push [x, y]
@draw_colission(x, y) @draw_colission(x, y)
return true return true
Expand Down

0 comments on commit 33bb27a

Please sign in to comment.