Skip to content

Commit

Permalink
Make server aware of pits.
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext committed Feb 6, 2011
1 parent 9fb31bb commit c68cbf4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'em-websocket'
require 'json'

width = 500
height = 500
class Ball
attr_accessor :x, :y, :vx, :vy

Expand All @@ -28,6 +30,21 @@ def initialize
self.y = 200
end
end

class Pit
attr_accessor :x, :y
def initialize(x,y)
self.x = x
self.y = y
end
end

pits = []
pits[0] = Pit.new(75,75)
pits[1] = Pit.new(width-75, 75)
pits[2] = Pit.new(75, height-75)
pits[3] = Pit.new(width-75, height-75)

def dist(x1, y1, x2, y2)
x_diff = (x1-x2) ** 2
y_diff = (y1-y2) ** 2
Expand All @@ -53,7 +70,11 @@ def dist(x1, y1, x2, y2)
if (dist(cue.x, cue.y, ballX, ballY) < 40)
overlap = true
end

pits.each do |pit|
if (dist(pit.x, pit.y, ballX, ballY) < 40)
overlap = true
end
end
end while overlap==true

balls << Ball.new(ballX, ballY)
Expand Down

0 comments on commit c68cbf4

Please sign in to comment.