Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Bounce
- Main = class()
- function setup()
- displayMode(FULLSCREEN)
- supportedOrientations(LANDSCAPE_ANY)
- Setup:init()
- RoundRect()
- i = h50 --Object's Initial Height
- j = WIDTH --Tube's Initial Width
- n = WIDTH
- p2 = WIDTH
- print(score)
- tubeHeightBottom = HEIGHT * math.random(10,50) * .01
- tubeHeightTop = h60 - tubeHeightBottom
- --Game state
- menu = 1
- play = 2
- gameover = 3
- state = menu
- -- Change value for game speed
- speed = 12
- -- Game Score
- score = 0
- -- Highscore not implemented
- --highScore = 0
- --Colors
- r1 = 30
- g1 = 60
- b1 = 110
- a1 = 255
- --Background particle
- particle = image(WIDTH*2,HEIGHT*2)
- setContext(particle)
- for p = 1, 400 do
- fill(math.random(100, 230), 20, 101, 255)
- roundRect(math.random(WIDTH * 2),math.random(HEIGHT * 2),5 , 5, 5)
- end
- setContext()
- end
- function draw()
- background(21, 37, 43, 255)
- for p = 1,30 do
- sprite(particle,0,0)
- end
- resetMatrix()
- if r1 > 0 then
- r1 = i - 190
- end
- --Menu
- if state == menu then
- fill(r1, g1, b1, a1)
- rect(0, 0, WIDTH, h10 + 15)
- rect(0, h90, WIDTH, h10 )
- fill(255, 255, 255, 255)
- ellipse(w15, i, w15)
- text("Tap to play", w50, h50)
- fontSize(70)
- font("ArialRoundedMTBold")
- if CurrentTouch.state == BEGAN then
- state = play
- end
- end
- --Playing
- if state == play then
- fill(r1, g1, b1, a1)
- rect(0, 0, WIDTH, h10 + 15)
- rect(0, h90, WIDTH, h10 )
- --Tube Color
- fill(r1, g1, b1, a1)
- --Tube
- if j <= WIDTH and j >- w10 then
- rectMode(CORNER)
- --Tube: #Bottom
- --roundRect(x,y,w,h,r)
- --rect(x,y,w,h)
- roundRect(j, h10, w10, tubeHeightBottom, 15)
- --Tube: #Top
- roundRect(j, h10 + tubeHeightBottom + h30, w10,tubeHeightTop, 15)
- --Speed:
- j = j - speed
- if j <=- w10 then
- j = WIDTH
- score = score + 1
- tubeHeightBottom = HEIGHT * math.random(10,50) * .01
- tubeHeightTop = h60 - tubeHeightBottom
- end
- end
- if i > h10 then
- --Flight
- if CurrentTouch.state == BEGAN and i< HEIGHT then
- i = i + 10
- ellipse(w15, i, w20 - 10)
- end
- --Drawing
- fill(r1 + 20, g1 + 20, b1 + 20, a1)
- ellipse(w15, i, w15)
- --Gravity
- i = i - 5
- elseif i <= h20 then
- --Lands on ground
- fill(255, 255, 255, 255)
- ellipse(w15, i, w15)
- state = gameover
- end
- fill(255, 255, 255, 255)
- fontSize(50)
- font("ArialRoundedMTBold")
- text(score, w90, h90)
- if j <= w25 and j >= w10 then
- if i >= h10 and i <= tubeHeightBottom + w10 then
- state = gameover
- elseif i >= HEIGHT - tubeHeightTop then
- state = gameover
- end
- end
- end
- --Gameover
- if state==gameover then
- background(58, 112, 221, 255)
- fill(255, 255, 255, 255)
- fontSize(100)
- font("ArialRoundedMTBold")
- text("GAMEOVER", w50, h50)
- text(score, w50, h20)
- end
- end
- RoundRect = class()
- function roundRect(x,y,w,h,r)
- -- [[ pushStyle() saves the current graphic styles like stroke, width, etc. You can then do your thing and call popStyle at the end to return to this state.]]
- pushStyle()
- -- [[ insetPos and insetSize contain the co-ordinates for the internal "fill" rectangle. InsetPos.x = x, insetPos.y = y, insetSize.x = w and insetSize.y = h. In effect this creates a rectangle that is smaller than a factor of "r" within the rectangle co-ordinates specified in roundRect. ]]
- insetPos = vec2(x+r,y+r)
- insetSize = vec2(w-2*r,h-2*r)
- -- Copy fill into stroke
- -- [[ Since Codea 1.3 you can retrieve the style information from all style functions by calling them without arguments. This way you only have to set the fill style once as you would for the normal rectangle function. You can read all about how this rounded rectangle function evolved on the Codea Forums.]]
- local red,green,blue,a = fill()
- stroke(red,green,blue,a)
- -- [[noSmooth() will disable smooth (unaliased) line drawing. It is useful for drawing thin lines. This initial rectangle is used to fill in the centre of your rounded rectangle, it has the usual 90 degree corners. Four lines are then drawn around this to give the rounded corner look. You can see this yourself by commenting out the 4 lines drawn below. ]]
- noSmooth()
- rectMode(CORNER)
- rect(insetPos.x,insetPos.y,insetSize.x,insetSize.y)
- if r > 0 then
- -- [[ You have to use smooth() if you want to use the ROUND option for lineCapMode. Four lines are now drawn around the filler rectangle. One on each edge. Because the lines have rounded ends when you overlap them it makes the corners look rounded, albeit a bit like a ball if you get the proportions wrong. Each of the lines are twice the width of the corner radius. ]]
- smooth()
- lineCapMode(ROUND)
- strokeWidth(r*2)
- line(insetPos.x, insetPos.y,
- insetPos.x + insetSize.x, insetPos.y)
- line(insetPos.x, insetPos.y,
- insetPos.x, insetPos.y + insetSize.y)
- line(insetPos.x, insetPos.y + insetSize.y,
- insetPos.x + insetSize.x, insetPos.y + insetSize.y)
- line(insetPos.x + insetSize.x, insetPos.y,
- insetPos.x + insetSize.x, insetPos.y + insetSize.y)
- end
- popStyle()
- end
- Setup = class()
- function Setup:init(x)
- -- Width Scale
- w95=WIDTH* .95
- w90=WIDTH* .9
- w85=WIDTH* .85
- w80=WIDTH* .8
- w75=WIDTH* .75
- w70=WIDTH* .7
- w65=WIDTH* .65
- w60=WIDTH* .6
- w55=WIDTH* .55
- w50=WIDTH* .5
- w45=WIDTH* .45
- w40=WIDTH* .4
- w35=WIDTH* .35
- w30=WIDTH* .3
- w25=WIDTH* .25
- w20=WIDTH* .2
- w15=WIDTH* .15
- w10=WIDTH* .1
- -- Height Scale
- h95=HEIGHT* .95
- h90=HEIGHT* .9
- h85=HEIGHT* .85
- h80=HEIGHT* .8
- h75=HEIGHT* .75
- h70=HEIGHT* .7
- h65=HEIGHT* .65
- h60=HEIGHT* .6
- h55=HEIGHT* .55
- h50=HEIGHT* .5
- h45=HEIGHT* .45
- h40=HEIGHT* .4
- h35=HEIGHT* .35
- h30=HEIGHT* .3
- h25=HEIGHT* .25
- h20=HEIGHT* .2
- h15=HEIGHT* .15
- h10=HEIGHT* .1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement