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
- ▶Language Reference
- ▶Core
- ▶Graphics
- ▶Image Class
- new
- clear
- clearTransforms
- clone
- drawCircle
- drawEllipse
- drawImage
- drawInnerSegment
- drawLine
- drawPixel
- drawPolygon
- drawRect
- drawRotatedImage
- drawRoundedRect
- drawSegment
- drawText
- fill
- fillCircle
- fillEllipse
- fillInnerSegment
- fillPolygon
- fillRect
- fillRoundedRect
- fillSegment
- fillText
- getAlpha
- getBlue
- getColors
- getGreen
- getHeight
- getPixel
- getPixelAlpha
- getPixelBlue
- getPixelGreen
- getPixelRed
- getRed
- getWidth
- isOverlap
- isPixelOverlap
- multAlpha
- rotate
- scale
- setAlpha
- setBlend
- setColor
- setFont
- setPixel
- setTransform
- size
- transform
- translate
- undoTransform
- ▶Transformations
- How Alignment Works
- Using Colors
- drawCircle
- drawEllipse
- drawImage
- drawInnerSegment
- drawLine
- drawPixel
- drawPolygon
- drawRect
- drawRotatedImage
- drawRoundedRect
- drawSegment
- drawText
- fill
- fillCircle
- fillEllipse
- fillInnerSegment
- fillPolygon
- fillRect
- fillRoundedRect
- fillSegment
- fillText
- getAlpha
- getBlue
- getColors
- getGreen
- getRed
- multAlpha
- setAlpha
- setBlend
- setColor
- setFont
- ▶Image Class
- ▶Audio
- ▶Controls
- ▶Collisions
- ▶Utility
- ▶Debugging
