' Blox
' Done by TrickyKeyboard,
' trickykeyboard@moscowmail.com!
' My first released game! Yeah!
' By the way, the best game feeling you can get by listening "Rock The Block" by "Sash!" while playing this.. :D

  open window 640, 512

  dim block(9, 7)

  for y = 0 to 7
    for x = 0 to 9
      block(x, y) = int(ran(3))
    next
  next

  l_x = 192
  l_y = 128

  check = 1

  time = 10

  light = 255

  repeat
    setdrawbuf dw
    dw = 1 - dw
    setdispbuf dw
    clear window

    if (check = 1) then
      for type = 0 to 2
        for x = 0 to 9
          if (block(x, 0) = type) and (block(x, 1) = type) and (block(x, 2) = type) and (block(x, 3) = type) and (block(x, 4) = type) and (block(x, 5) = type) and (block(x, 6) = type) and (block(x, 7) = type) then
            for y = 0 to 7
              score_memory = score_memory + (type + 1) * 10
              block(x, y) = int(ran(4))
            next

            time = time + 10
            light = 255
            quake = 64
          endif
        next
      next

      check = 0
    endif

    if (light > 127) then
      light = light - 1
    endif

    setrgb 1, light, 0, 0
    setrgb 2, 0, light, 0
    setrgb 3, 0, 0, light
    gtriangle 0, 0 to 640, 0 to 640, 512
    gtriangle 0, 0 to 0, 512 to 640, 512

    b_x = l_x
    b_y = l_y

    if (quake > 0) then
      quake = quake - 1
      b_x = b_x - (quake / 2) + ran(quake + 1)
      b_y = b_y - (quake / 2) + ran(quake + 1)
    endif

    for y = 0 to 7
      for x = 0 to 9
        if (block(x, y) = 0) then
          setrgb 1, 255, 0, 0
          setrgb 2, 0, 0, 0
          setrgb 3, 255, 0, 0
        elseif (block(x, y) = 1) then
          setrgb 1, 0, 255, 0
          setrgb 2, 0, 0, 0
          setrgb 3, 0, 255, 0
        elseif (block(x, y) = 2) then
          setrgb 1, 0, 0, 255
          setrgb 2, 0, 0, 0
          setrgb 3, 0, 0, 255
        elseif (block(x, y) = 3) then
          setrgb 1, 255, 255, 255
          setrgb 2, 0, 0, 0
          setrgb 3, 255, 255, 255
        endif

        gtriangle x * 32 + b_x, y * 32 + b_y to x * 32 + b_x + 32, y * 32 + b_y to x * 32 + b_x + 32, y * 32 + b_y + 32
        gtriangle x * 32 + b_x, y * 32 + b_y to x * 32 + b_x, y * 32 + b_y + 32 to x * 32 + b_x + 32, y * 32 + b_y + 32
      next
    next

    if (state = 0) then
      setrgb 1, 255, 255, 0
    elseif (state = 1) then
      setrgb 1, 0, 255, 255
    endif

    line p_x * 32 + b_x + 16, 0 to p_x * 32 + b_x + 16, 512
    line 0, p_y * 32 + b_y + 16 to 640, p_y * 32 + b_y + 16

    setrgb 1, 255, 255, 255

    if (score_memory > 0) then
      score_memory = score_memory - 1
      score = score + 1
    endif

    text 32, 32, "Score: " + str$(score)

    time = time - 0.01

    if (time < 0) then
      quit = 1
    endif

    text 32, 48, "Time: " + str$(int(time))

    command = peek("port1")

    if (command = 0) then
      hold = 0
    endif

    if (hold = 0) then
      if (command = 8) then
        quit = 1
      elseif (command = 16) then
        p_y = p_y - 1

        if (p_y < 0) then
          p_y = 7
        endif

        hold = 1
      elseif (command = 32) then
        p_x = p_x + 1

        if (p_x > 9) then
          p_x = 0
        endif

        hold = 1
      elseif (command = 64) then
        p_y = p_y + 1

        if (p_y > 7) then
          p_y = 0
        endif

        hold = 1
      elseif (command = 128) then
        p_x = p_x - 1

        if (p_x < 0) then
          p_x = 9
        endif

        hold = 1
      elseif (command = 16384) then
        if (state = 0) then
          state = 1
          s_x = p_x
          s_y = p_y
          beep
          light = 191
          quake = 2
        elseif (state = 1) then
          if (p_x > s_x - 2) and (p_x < s_x + 2) and (p_y > s_y - 2) and (p_y < s_y + 2) then
            current = block(p_x, p_y)
            block(p_x, p_y) = block(s_x, s_y)
            block(s_x, s_y) = current
            check = 1
            beep
            light = 191
            quake = 4
          endif

          state = 0
        endif

        hold = 1
      endif
    endif
  until (quit = 1)

  score = score + score_memory
  score = score + int(time) * 10

  print "Thanks for playing!"
  print "Oh, and you got " + str$(score) + " points!"
  print "Now get back to your work, slacker! :)"

  end



