Hi, I am João, 16 years old and I am from Portugal… I have used codea for 1 year and now, without any programming lessons, just by using codea, I learned a lot, and because of that I made a lot of cool tools most of them calculators to help in school such as quadratic formula resolver (sry for my English xD) and yesterday I started making a snake game because my brother bet I couldn’t do it… So, this is what I done so far (remember I have few skills and I couldn’t learn until now how you use classes)
-- Snake
-- João Lopes
-- 07/12/2015
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
-- Innitial Score
score = 0
-- Innitial Snake Position
snake1X = WIDTH/2
snake1Y = HEIGHT/2
-- Initial Speed And Difficulty
speed = 3
-- Initial State At The Game Start
status = notColided
-- Spawn The Firts Ellipse
ellipsex = math.random(WIDTH)
ellipsey = math.random(HEIGHT)
-- Parameters To Change Difficulty
parameter.action("Easy", function() speed = 1 alert("Dificulty Set To Easy") end)
parameter.action("Medium", function() speed = 2 alert("Dificulty Set To Medium") end)
parameter.action("Hard", function() speed = 3 alert("Dificulty Set To Hard") end)
parameter.action("Impossible", function() speed = 10 alert("Dificulty Set To Impossible") end)
-- Innitial Snake Size
snakeW = 20
snakeH = 20
end
function draw()
-- Black BackGround
background(0)
-- Draw The Initial Snake
pushStyle()
fill(0, 0, 255, 255)
stroke(255, 255, 0, 255)
rectMode(CENTER)
strokeWidth(3)
rect(snake1X, snake1Y, snakeW, snakeH)
popStyle()
-- Make The Snake Grow As It Colides
if createsnake == true then
snakeW = snakeW + 20
snakeH = snakeH + 20
createsnake = false
end
-- Draw The TouchPad
pushStyle()
rectMode(CENTER)
noFill()
stroke(255, 255, 0, 255)
strokeWidth(3)
rect(WIDTH*0.8, HEIGHT*0.1, 75,75)
rect(WIDTH*0.8, HEIGHT*0.23, 75, 75)
rect(WIDTH*0.9, HEIGHT*0.1, 75, 75)
rect(WIDTH*0.7, HEIGHT*0.1, 75, 75)
popStyle()
-- Set Up Of The TouchPad Commands
if CurrentTouch.x > WIDTH*0.8 - 37.5 and CurrentTouch.x < WIDTH*0.8 + 37.5 and CurrentTouch.y > HEIGHT*0.1 - 37.5 and CurrentTouch.y < HEIGHT*0.1 + 37.5 then snake1Y = snake1Y - speed
elseif CurrentTouch.x > WIDTH*0.8 - 37.5 and CurrentTouch.x < WIDTH*0.8 + 37.5 and CurrentTouch.y > HEIGHT*0.23 - 37.5 and CurrentTouch.y < HEIGHT*0.23 +37.5 then snake1Y = snake1Y + speed
elseif CurrentTouch.x > WIDTH*0.7 - 37.5 and CurrentTouch.x < WIDTH*0.7 + 37.5 and CurrentTouch.y > HEIGHT*0.1 - 37.5 and CurrentTouch.y < HEIGHT*0.1 +37.5 then snake1X = snake1X - speed
elseif CurrentTouch.x > WIDTH*0.9 - 37.5 and CurrentTouch.x < WIDTH*0.9 + 37.5 and CurrentTouch.y > HEIGHT*0.1 - 37.5 and CurrentTouch.y < HEIGHT*0.1 +37.5 then snake1X = snake1X + speed
end
-- Alert "Game Over If Snake Colides With The Limits Of Your Display And Restart The Game
if snake1X + 10 >= WIDTH then
snake1X = WIDTH - 10
alert("GameOver", "Score ".. score)
restart()
elseif snake1X - 10 <= 0 then
snake1X = 0 + 10
alert("GameOver", "Score ".. score)
restart()
elseif snake1Y + 10 >= HEIGHT then
snake1Y = HEIGHT - 10
alert("GameOver", "Score ".. score)
restart()
elseif snake1Y - 10 <= 0 then
snake1Y = 0 + 10
alert("GameOver", "Score ".. score)
restart()
end
-- Draw Score
pushStyle()
fontSize(100)
fill(255)
textMode(CORNER)
text(score, WIDTH*0.03, HEIGHT*0.85)
popStyle()
-- Detect If Snake Colides With The Ellipse And If So, Score Raises By 10 And Another Ellipse Spawns
if snake1X >= ellipsex - 10 and snake1X <= ellipsex + 10 and snake1Y >= ellipsey - 10 and snake1Y <= ellipsey + 10 then
sound(SOUND_PICKUP, 21838)
status = Colided
ellipsex = math.random(WIDTH)
ellipsey = math.random(HEIGHT)
score = score + 10
createsnake = true
end
-- Spawn The First Ellipse
if status == notColided then
pushStyle()
fill(0)
stroke(255)
strokeWidth(3)
ellipseMode(CENTER)
ellipse(ellipsex, ellipsey, 20)
popStyle()
end
end