# Colorkeys version TEDDO0.3
# by John Marczk
# based on code by Ed Heil
# johnmarczak.com
#

Shoes.app :width => 800, :height => 600, :title =>"Arianas Computer Game!" do
  @flashy = false
  @letter = false
  @last_letter = false
  @vid = video File.join(File.dirname(__FILE__), 'assets\sounds', 'a.mp3')
  @time = Time.now
  @backgroundcolors = [white, white]
  
  def randomcolor(noalpha=nil)
    if noalpha
      rgb(rand(256), rand(256), rand(256))
    else
      rgb(rand(256), rand(256), rand(256),rand(256))
    end
  end

  def drawbackground(c1=@backgroundcolors[0], c2=@backgroundcolors[1])
      background gradient(c1, c2)
	  
	  #fade_background
  end
  
  
  def do_letter
  	     if @letter
		     @pressed =    para @letter
			 @pressed.style(:top => 0,
							:size => self.height / 2,
						    :align => "center",
						    :font => "Trebuchet MS"				    
							)
			if @letter === @last_letter
				@pressed.style( :stroke => black)
			else
				@pressed.style( :stroke => white)
			end
			
		end
		 		 

  end

  
  def randomize_colors(key = nil)
    @backgroundcolors = [randomcolor(true), randomcolor(true)]
	@last_letter = @letter;
	@letter = key;
  end

  def fade_background()
  background black
  end
  
  
    
  keypress do | key |
    case key
      when " "
      @flashy = (not @flashy)
      when "\n"
      randomize_colors(key)
      when :escape
      exit
	  else 
	  randomize_colors(key)
	  @vid.play 

    end
  end


  click do | button, left, top |
    if button == 3
      @flashy = (not @flashy)
    end
    if button == 1
     randomize_colors
    end
  end

  
  randomize_colors
  
  animate(1) do
    clear do
	  drawbackground     
	   if @flashy
        randomize_colors
       end
    end
	do_letter

  end
  
end
