Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- PlatformBros
- -- Use this function to perform your initial setup
- function setup()
- ground = 100
- x = 100
- y = ground + 25
- velocity = 0
- gravity = -900
- speed = 200
- onGround = false
- platforms = {}
- addPlatform(0, 200, ground)
- local sx1 = 200
- local sx2 = 300
- local sy = ground
- for i = 0,100 do
- addPlatform(sx1, sx2, sy)
- sx1 = sx2 + math.random(100, 150)
- sx2 = sx1 + math.random(50, 150)
- sy = sy + math.random(-150, 150)
- end
- end
- function addPlatform(x1, x2, y)
- table.insert(platforms, Platform(x1, x2, y))
- end
- -- This function gets called once every frame
- function draw()
- translate(-x + 250, -y + 250)
- -- This sets a dark background color
- background(40, 40, 50)
- -- This sets the line thickness
- strokeWidth(5)
- -- Do your drawing here
- sprite("Planet Cute:Character Boy",x,y+50,100)
- x = x + DeltaTime * speed
- onGround = false
- for k,v in pairs(platforms) do
- v:draw()
- if x > v.x1 - 25 and x < v.x2 + 25 and y >= v.y and y + DeltaTime * velocity <= v.y then
- y = v.y
- velocity = 0
- onGround = true
- end
- end
- if not onGround then
- y = y + DeltaTime * velocity
- velocity = velocity + DeltaTime * gravity
- end
- end
- function jump()
- if onGround then
- velocity = velocity + 500
- end
- end
- function touched(touch)
- if touch.state == BEGAN then
- jump()
- end
- end
- --# Platform
- Platform = class()
- function Platform:init(x1, x2, y)
- -- you can accept and set parameters here
- self.x1 = x1
- self.x2 = x2
- self.y = y
- end
- function Platform:draw()
- -- Codea does not automatically call this method
- stroke(255, 235, 0, 255)
- line(self.x1, self.y, self.x2, self.y)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement