dino_game_v2.rb
# Check whether the dino will collide with an obstacle

Check whether the dino will collide with an obstacle
Check whether the dino will collide with an obstacle
def collision?(population, dino, x, y)
		obs_height = 24
		col = false
		col_set = false
		distance_to_obstacles = Array.new
		i = 0
		@obstacles.each do |c|
			obs_width = c.width
			distance_to_obstacles << c.x-x-obs_width
			if x.between?(c.x-15, c.x+2*c.width)
				if y.between?(c.y-obs_height, c.y+obs_height)
					if not col_set
						return true, distance_to_obstacles, obs_width
					end
				else
					col = false
				end
			else 
				if c.type == "0"
					if x > c.x + c.width + 50
						@obstacles.delete_at(i)
					end
				elsif c.type == "1"
					if x > c.x + c.width + 100
						@obstacles.delete_at(i)
					end 
				end
				col = false
			end
			i += 1
		end	
		obs_width = @obstacles[0].width
		return col, distance_to_obstacles, obs_width
	end
def collision? ( population , dino , x , y ) obs_height = 24 col = false col_set = false distance_to_obstacles = Array . new i = 0 @obstacles . each do | c | obs_width = c . width distance_to_obstacles << c . x - x - obs_width if x . between? ( c . x - 15 , c . x + 2 * c . width ) if y . between? ( c . y - obs_height , c . y + obs_height ) if not col_set return true , distance_to_obstacles , obs_width end else col = false end else if c . type == "0" if x > c . x + c . width + 50 @obstacles . delete_at ( i ) end elsif c . type == "1" if x > c . x + c . width + 100 @obstacles . delete_at ( i ) end end col = false end i += 1 end obs_width = @obstacles [ 0 ] . width return col , distance_to_obstacles , obs_width end
Check whether the dino will collide with an obstacle
Check whether the dino will collide with an obstacle
population
<not_specific>
dino
<not_specific>
x
<not_specific>
y
<not_specific>