# Create three random circles
create()
create()
create()
# Create a yellow square
square <- create()
square.setSides({1 Meter}, {100 Centimeters})
square.setColor("yellow")
# Create three random circles
create()
create()
create()
# Create a yellow square
square <- create()
square.setSides({1 Meter}, {100 Centimeters})
square.setColor("yellow")
create()
create()
create()
setGravity(0, {9.8 Meters/Second^2}) # Make gravity go upwards
setWalls(true, true, true, true) # We need to add the top wall
function makeColumn(x)
items <- round(rand(8,14))
size <- {0.5 Meters}
for i in 1:items
brick <- create()
brick.setSides(size, size)
brick.setPosition(x, size*i-size/2)
end loop
end function
makeColumn({0 Meters})
makeColumn({1 Meter})
makeColumn({2 Meters})
ball <- create()
ball.setDiameter({1 Meters})
ball.setPosition({-3 meters}, {8 meters})
ball.setAngularVelocity({1000 Degrees per Second})
ball.setDensity({100 Kilograms per Meter Squared})
setWalls(true, true, true, true) # We need to add the top wall
repeat(create(), 5)
function reverseGravity() # Define a function to reverse gravity
x, y <- getGravity()
setGravity(0, -y)
end function
timer({2 Seconds}, reverseGravity, true) # Repeat a function call every 2 seconds
# Select which images to choose from
imgs <- { "smiley", "diamond", "discoball", "basketball", "beachball" }
backdrops <- { "seacave", "underwater", "beach" }
# Choose a random background image
setBackgroundImage(backdrops.sample(1){1})
# Create 10 bouncy balls
items <- repeat(create(), 10)
items.setSpring(0.95)
# Choose random ball images
map(items, x.setImage(imgs.sample(1){1}))
# Click to create or remove balls
repeat(create(), 5)
onMouseDown(function(event)
items <- findPoint(event.x, event.y) # Find clicked items
if items.length() = 0 then # Nothing was clicked
p <- create()
p.setPosition(event.x, event.y)
p.setImage("soccerball")
else
items.remove() # Remove the clicked item
end if
end function)
# Use the Left and Right arrow keys to move the paddle
# A function to create a line of bricks
function makeGrid(count, centerY, centerX, width, height)
for i in 1:count
makeBrick(centerX+(i-count/2-0.5)*width, centerY, width, height)
end loop
end function
# A function to create a single brick
function makeBrick(x, y, width, height)
brick <- create("brick")
brick.setSides(width, height)
brick.setPosition(x, y)
brick.setFixed().setFriction(0)
brick.onStartCollision <- function() brick.remove()
end function
# Remove gravity and bound the area
setGravity(0, 0)
setWalls(true, true, true, true)
#Create two lines of bricks
makeGrid(9, 7, 0, 1, 0.5)
makeGrid(9, 6.5, 0, 1, 0.5)
# Create the paddle
paddle <- create("paddle")
paddle.setSides(2.5, 0.4)
paddle.setFixed()
paddle.setPosition(0, 0.3)
paddle.setFriction(0)
paddle.setColor("black")
# Create the Ball
ball <- create("ball")
ball.setPosition(0, 2)
ball.setDiameter(0.7)
ball.setSpring(1.02)
ball.setVelocity(rand(-3, 3), 10)
ball.setFriction(0)
ball.setDensity(20)
# Control Paddle Movement
onStep(function()
x,y <- paddle.getPosition()
direction <- 0
if not (KeyDown(37) and KeyDown(39)) then
if KeyDown(37) then # Left-arrow key
direction <- -1
else if KeyDown(39) then # Right-arrow key
direction <- 1
end if
end if
paddle.SetPosition(x+{0.14 Meters}*direction, y)
end function)
#Control game over condition
ball.onStartCollision <- function(event)
if event.object.getClass() = "BottomWall" then
stop()
setBackgroundColor("red")
alert("Game Over!")
ball.remove()
end if
end function
# Click a ball to make it jump
ObjectBase.onClick <- function() self.applyImpulse(0, -50)
repeat(create(), 5)
All contents Copyright 2013. All rights reserved. Created by Scott Fortmann-Roe.