So, I created a game using Codea. I’m planning to make it longer (at the moment it’s just a test) but I’d like to see if there’s other things I can do to make it easier to code/use!
Here’s the code:
-- App
displayMode(FULLSCREEN)
-- Initial setup, using those shown below
function setup()
stylesetup() -- using text style
textsetup() -- plot
varsetup() -- variable assignment
graphicsetup() -- setting images
end
function varsetup()
tabx = 1
page = 'PLAY'
end
function textsetup()
--text
texttab = {}
table.insert(texttab,1,"I smile at him brightly.")
table.insert(texttab,'-name-... we caught the killer!')
table.insert(texttab,"He looks up groggily. He was sitting by the cliff, watching the water below.")
table.insert(texttab,"'So who was it.' his voice is flat, uninterested.")
table.insert(texttab,"I go up to him, putting a hand on his shoulder.")
table.insert(texttab,"It was -name-.")
table.insert(texttab,"Reset to play again.")
end
function stylesetup()
--setup
rectMode(CENTER)
textMode(CENTER)
fontSize(25)
font("Marion-Regular")
textWrapWidth(0)
end
function graphicsetup()
backarrow = readImage("UI:Grey Slider Left")
end
function draw()
background(40, 40, 50)
if page == 'MENU' then
menu()
elseif page == 'PLAY' then
firstend()
end -- I will add code here to have more text in the future
end
function touched(t)
if page == 'PLAY' then
if t.x > WIDTH/18-50 and t.x < WIDTH/18 + 50 and t.y > HEIGHT - 90 and t.y < HEIGHT-10 then
page = 'MENU'
elseif t.state==ENDED then
if tabx < #texttab then
tabx = tabx + 1
else
page = 'MENU'
end
end
end
if page == 'MENU' then
if t.state == ENDED and t.x < WIDTH/2+50 and t.x > WIDTH/2-50 and t.y < HEIGHT-130 and t.y > HEIGHT-170 then
page = 'PLAY'
end
end
end
function firstend()
textMode(CORNER)
pushStyle()
fill(59, 59, 59, 255)
rect(WIDTH/2,70,WIDTH-40,80)
fill(179, 179, 179, 255)
text(texttab[tabx],35,55)
popStyle()
sprite(backarrow,WIDTH/18,HEIGHT-50,100)
end
function menu()
textMode(CENTER)
pushStyle()
background(255, 255, 255, 255)
fill(0, 0, 0, 255)
fontSize(50)
text('PLAY',WIDTH/2,HEIGHT-150)
popStyle()
end