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
- ▶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
