Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="home">
    <div class="container">
<!--        <h1>Welcome!</h1>-->
<!--        <p>maybe you would like to play a little game of Arkanoid while you wait? :)</p>-->
        <a href="#" id="start">Insert new coin</a><br/>
        <canvas id="board" width="800" height="480" style="border:1px solid black"></canvas>
            <li>click on the board to start</li>
            <li>use mouse to move the paddle</li>
            <li>clear all the blocks by shooting at them with the ball</li>
            <li>loose a "life" when you "loose" the ball</li>
            <li>add a new "life" by clicking the "insert new coin" link; game will be faster each time</li>
            <li>some physics is off, this is on purpose to make it extra hard (*kuch*)</li>
            <li>be sure to ping me when you managed to clear the board!</a></strong> :)</li>
        <p><em><small>Disclaimer: Game is made by me - I typed every single line of code; but I used diff. resources on the net. The goal is to refresh some physic principals, to have fun and to learn some coffeescripting, html5 and game development on the way. Since it's a learning thing, the game is not perfect and kinda buggy :)
        &copy; DaktaDeo 2013 - All rights reserved</small></em></p>
              #$ ?= require 'jquery' # For Node.js compatibility
class Board
  showmessage:(msg,$context) ->
    $context.font ="bold 20px sans-serif"

class Block
  constructor:(@x,@y,@width,@height,@row,@color,@hit) ->
  draw: ($context)->
    if @hit ==0 || @hit == undefined
    console.log "bwam"
    if collision($ball.x,$ball.y,$ball.diameter,@x+1,@y+1,@width,@height) && @hit==0
      $ball.dx = -$ball.dx
      $ball.dy = -$ball.dy

class Ball
  constructor:(@x,@y,@diameter,@dx,@dy,@color) ->
  draw:($context) ->
    # Draws a circle of radius 20 at the coordinates 100,100 on the canvas

class Paddle
  constructor:(@x,@y,@width,@height,@row,@color,@hits) ->
  draw: ($context)->
    #if @hit ==0 || @hit == undefined
    #console.log "ping"
    if collision($ball.x,$ball.y,$ball.diameter,@x+1,@y+1,@width,@height)
      newY = ($paddle.y + ($paddle.height/2)) - $ball.y
      normalisedY = newY/($paddle.height/2)
      angle = normalisedY * 75 # 75 = maxbounceangle

      $ball.dx = 5 * Math.cos(angle) #10 = ballspeed
      $ball.dy = 5 * -Math.sin(angle)

      if $ball.x < @width/2 + @x+1
        $ball.dx = -$ball.dx

      #$ball.dy = -$ball.dy
coin = 1
$game = null
$board = null
$paddle = null
$ball  = new Ball(150,150,10,5,5,"#c0392b")

$colors = [
  ["#2f484b", "#2f484b","#2f484b", "#2f484b", "#2f484b", "#7fa6aa", "#7fa6aa", "#7fa6aa", "#fbb03b"],
  ["#990033", "#B2003C", "#CB0045", "#E4004E", "#FE0057", "#FF1967", "#FF3378"],
  ["#FFDF81", "#FFD868", "#FFD24E", "#FFCB34", "#FFC51A", "#FFBF00", "#E6AC00", "#CC9900"],
  ["#990000", "#B20000", "#CB0000", "#E40000", "#FE0000", "#FF1919", "#FF3333", "#FF4D4D", "#FF6767"],
  ["#003300", "#004C00", "#006500", "#007E00", "#009700", "#00B000", "#00C900", "#00E200", "#00FB00", "#16FF15"],
  ["#003366", "#004080", "#004D99", "#005AB2", "#0067CB", "#0074E4", "#0081FE", "#198EFF", "#339BFF", "#4DA7FF", "#67B4FF"]


$(document).ready ->
  $context = $("#board")[0].getContext("2d")
  $board = new Board(0,0,$("#board").width(),$("#board").height())
  $paddle =new Paddle(210,$board.height-10,150,10,0,"#000")

  $("#board").on("click", (ev) ->
   if coin == 1

  $("#start").on("click",(ev) ->
    coin =1
    $resetcount += 1
    if $resetcount == 5
      $board.showmessage("I'm BROKE :(",$context)
      $ball  = new Ball(150,150,10,2,2,"#c0392b")
      $paddle = new Paddle(210,$board.height-10,150-($resetcount*30),10,0,"#000")

  #mouse events
    $paddle.x = mouse(ev).x #- $(this).offsetLeft + 300 - ($board.width/2)

  #generate all the bricks
  createRow i, row for row,i in $level1

  #start game
  #$game = setInterval(drawgame,10)


  block.draw($context) for block in $blocks


  #collision detection: playground
  if $ball.x<0 || $ball.x >$board.width
    $ball.dx = -$ball.dx

  if $ball.y<0 #|| $ball.y>$board.height
    $ball.dy = -$ball.dy
  else if $ball.y>$board.height
    #you just died
    $board.showmessage("GAME OVER",$context)

  $ball.x += $ball.dx
  $ball.y += $ball.dy

  #collision detection: paddle

  #collision detection: blocks
  block1.collides($ball) for block1 in $blocks

collision = (circleX, circleY, radius, squareX, squareY, width, height) ->
  distance = 0
  if (circleX < squareX)
    distance += Math.pow(circleX - squareX, 2)
  else if (circleX > squareX + width)
    distance += Math.pow(circleX - squareX - width, 2)

  if (circleY < squareY)
    distance += Math.pow(circleY - squareY, 2)
  else if (circleY > squareY + height)
    distance += Math.pow(circleY - squareY - height, 2)

  return distance <= Math.pow(radius, 2)

  $context.clearRect($board.x,$board.y, $board.width,$board.height)

createRow=(index,$row) ->
  createBlock i, block,index for block,i in $row

createBlock=(index,$block,row) ->
  if $block ==1
    $tile = new Block(100*index,20*row,100,20,row,$colors[0][row])

  rect = $("#board")[0].getBoundingClientRect()
  return {
    x: ev.clientX - rect.left,
    y: ev.clientY -

  $game = setInterval(drawgame,5)
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.