Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

BrettBox Intro »

You do not own this project, so changes will not be saved

/* 
 * Hello World example,
 * Feel free to tinker and mess about with this code, that's what it's for.
 * 
 * Controls!
 *  Use the mouse to move the player,
 *  press up and down to move the crocs.
 * 
 * This aims to show off some example code for:
 *  loading images
 *  setting font
 *  clearing the screen
 *  getting mouse and keyboard controls
 *  drawing text and images
 * 
 * Enjoy!
 */

// global, how fast the crocodile moves
$CROC_SPEED   = 2.5
// the padding between crocs
$CROC_PADDING = 32
// how many crocs to draw
$NUM_CROCS    = 0

// Our Images, all locals
crocImg        = new Image( "BB.gif" )
playerImgLeft  = new Image( "BB.gif" )
playerImgRight = new Image( "BB.gif" )
playerImg      = playerImgRight

// for tracking player moving left or right
lastMouseX = 0
isMovingLeft = false

// croc starts at the bottom of the screen
crocY = getScreenHeight() - 40

// the mainloop, this is run 60 times a second
onEachFrame() do |delta|
    /* Background
     * 
     * Fill the whole screen with one colour to wipe the last frme.
     * Then draw an array of boxes.
     */
    fill( 10, 10, 50 )
    
    // ensure all drawn images are fully visible
    setAlpha( 1 )
    
    /* Player
     * 
     * Draw the user where the mouse is
     * and have player face left or right.
     */
    controls = getControls()
    mouseX = controls.getMouseX()
    mouseY = controls.getMouseY()
    
    // work out if we look left, right
    if mouseX < lastMouseX
        playerImg = playerImgLeft
    else if mouseX > lastMouseX
        playerImg = playerImgRight
    end
    
    // the true says you want it centred at that location
    drawImage( playerImg, mouseX, mouseY, true )
    lastMouseX = mouseX

    /* Crocodiles
     * 
     * Move crocadile up or down,
     * and draw lots of them in a row!
     * But limit their movement to within screen size
     */
    crocWidth = crocImg.getWidth() + $CROC_PADDING
    
    crocSpeed = $CROC_SPEED * delta
    if controls.isKeyDown("up") or controls.isKeyDown("w")
        crocY = (crocY - crocSpeed).max( 0 )
    else if controls.isKeyDown("down") or controls.isKeyDown("s")
        crocY = (crocY + crocSpeed).min( getScreenHeight() )
    end
    crocX = ( getScreenWidth() - crocWidth*$NUM_CROCS + $CROC_PADDING )/2
    
    $NUM_CROCS.times() do |i|
        drawImage( crocImg, crocX + i*crocWidth, crocY )
    end

    /* Text
     *
     * Draw the text with a highlighting outline.
     * It appearres partially transparent so you can see
     * the player behind it.
     */
    setFont( 'Arial', 72, 'bold italic' )
    setColor( 255, 245, 238, 0.75 )
    // fill fills the area,..
    fillText( "", 40, 100 )
    
    setColor( 255, 255, 255, 0.75 )
    // ... draw draws an outline.
    drawText( "", 40, 100 )
end

ERRORS

YOUR BROWSER DOES NOT SUPPORT HTML5!

Please use one of these instead

Our games cannot run in your browser