Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

Bombs 'n' Booty - Part 1 »

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

/*
images
*/
backgroundImage = new Image( "background.png" )
playerImage = new Image( "player.png" )

/*
game objects
*/
background = new Background( backgroundImage )
player = new Player( playerImage )
/*
main loop
*/
onEachFrame() do
    background.draw()
player.setDirection()
    player.move()
player.checkBounds()
player.draw()
end

/*
classes
*/
class Background
    def new( image )
        @image = image
    end

    def draw()
        drawImage( @image, 0, 0 )
    end
end

class Player
    def new( image )
        @image = image

        @positionX = getScreenWidth() / 2 - ( getWidth() / 2 )
        @positionY = getScreenHeight() / 2 - ( getHeight() / 2 )

        @direction = "none"
        @speed = 4
        @score = 0
        @isAlive = true
    end

    def draw()
        if( @isAlive )   //Only draw him if he's alive
            drawImage( @image, @positionX, @positionY )
        end
    end

    def getWidth()
        return @image.getWidth()
    end

    def getHeight()
        return @image.getHeight()
    end

    def setDirection()
        controls = getControls()
        /*
        Get keyboard input, if correct key is prssed set
        the corresponding direction
        */
        if controls.isKeyPressed( "w" )
            @direction = "north"
        else if controls.isKeyPressed( "d" )
            @direction = "east"
        else if controls.isKeyPressed( "s" )
            @direction = "south"
        else if controls.isKeyPressed( "a" )
            @direction = "west"
        end
    end

    def move()   //This updates his co-ordinates to make him move
        if( @isAlive )   //Only move him if he's alive
            if( @direction == "north" )
                @positionY = @positionY - @speed
            else if( @direction == "east" )
                @positionX = @positionX + @speed
            else if( @direction == "south" )
                @positionY = @positionY + @speed
            else if( @direction == "west" )
                @positionX = @positionX - @speed
            end
        end
    end

    def checkBounds()   //This stops the little guy from going off the screen
        if( @positionX <= 0 )
            @positionX = 0
        else if( @positionX >= getScreenWidth() - getWidth() )
            @positionX = getScreenWidth() - getWidth()
        end
        if( @positionY <= 0 )
            @positionY = 0
        else if( @positionY >= getScreenHeight() - getHeight() )
            @positionY = getScreenHeight() - getHeight()
        end
    end
end

ERRORS

YOUR BROWSER DOES NOT SUPPORT HTML5!

Please use one of these instead

Our games cannot run in your browser