Pleas can any one help me i want to creat a main menu with a select botton but i dont now what is the code and i want it 3 select bouttun firs eazy go to eazy game normal go normal game hard go to hard game i have a gift for the best answer
I think this is what you’re after. I tried to make it as generic as I could and also allow you to change the text, colors, font, size, and locations without very much trouble. In the touched function you can replace the print statements to do whatever you want when that option is selected. I have the display set so you can see the print statements when you select an option. You can uncomment the displayMode to display it in fullscreen mode when this is added to your code. If you have any questions, just ask.
-- menu1
function setup()
--displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT) -- set for portrait mode
end
function draw()
menu()
end
function menu()
background(0,0,200)
w=WIDTH/2 -- set width value
eh=HEIGHT-400 -- set height of different options
nh=HEIGHT-600 -- eh easy, nh normal, hh hard
hh=HEIGHT-800
font("Zapfino") -- set font used
fontSize(48) -- set font size
fill(255,0,0) -- set font color
menuTitle1="Main Menu" -- main title
menuTitle2="Select Option"
text(menuTitle1,w,HEIGHT-100) -- display titles
text(menuTitle2,w,HEIGHT-200)
fill(0,255,0) -- set easy values
t1="Easy"
text(t1,w,eh)
w1,h1=textSize(t1) -- width and height of easy text
t2="Normal" -- set normal values
text(t2,w,nh)
w2,h2=textSize(t2) -- width and height of normal text
t3="Hard" -- set hard values
text(t3,w,hh)
w3,h3=textSize(t3) -- width and height of hard text
end
function touched(t)
if t.state==BEGAN then
if t.x>w-w1/2 and t.x<w+w1/2 and t.y>eh-h1/2 and t.y<eh+h1/2 then
print("easy option selected") -- call easy routine here
end
if t.x>w-w2/2 and t.x<w+w2/2 and t.y>nh-h2/2 and t.y<nh+h2/2 then
print("normal option selected") -- call normal routine here
end
if t.x>w-w3/2 and t.x<w+w3/2 and t.y>hh-h3/2 and t.y<hh+h3/2 then
print("hard option selected") -- call hard routine here
end
end
end
I want the eazy bouttun go to eazy game and he hard bottun go to the hard game and the normal game
I well give you the eazy and the normal and the hard games
And can you ad for mr the code i want all this thing in on app
Pleas help me
--# CloudLevels
CloudLevels = class()
CULLPADDING = 300
function CloudLevels:init()
-- you can accept and set parameters here
self.clouds = {}
self.nextCloudHeight = 81
end
function CloudLevels:generateNextCloud()
cloud = Cloud()
cloud.position = vec2(math.random(-WIDTH/2,WIDTH/2),
self.nextCloudHeight)
table.insert(self.clouds, cloud)
self.nextCloudHeight = self.nextCloudHeight + math.random(150,300)
end
function CloudLevels:cullClouds(floor)
for i,v in ipairs(self.clouds) do
if v.position.y < floor then
table.remove(self.clouds,i)
end
end
end
function CloudLevels:isColliding(pos)
for i,v in ipairs(self.clouds) do
if v:isColliding(pos) then
return true
end
end
return false
end
function CloudLevels:update(cam)
curHeight = -cam.y + HEIGHT + CULLPADDING
if curHeight > self.nextCloudHeight then
self:generateNextCloud()
end
self:cullClouds(-cam.y - CULLPADDING)
end
function CloudLevels:draw()
-- Codea does not automatically call this method
for i,v in ipairs(self.clouds) do
v:draw()
end
end
function CloudLevels:touched(touch)
-- Codea does not automatically call this method
end
--# Cloud
Cloud = class()
function Cloud:init()
-- you can accept and set parameters here
self.shapes = {}
self.position = vec2(0,0)
-- Generate random cloud
numCircles = math.random(4, 5)
spacing = 30
for i = 1,numCircles do
x = i * spacing - ((numCircles/2)*spacing)
y = (math.random() - 0.5) * 30
rad = math.random(spacing, 2*spacing)
table.insert(self.shapes, {x=x, y=y, r=rad})
end
self.width = numCircles * spacing + spacing
end
function Cloud:isColliding(pos)
startp = self.position.x - self.width/2
endp = self.position.x + self.width/2
if pos.x < endp and pos.x > startp and
pos.y < (self.position.y + 30) and
pos.y > (self.position.y + 10) then
return true
end
return false
end
function Cloud:draw()
pushStyle()
pushMatrix()
translate(self.position.x, self.position.y)
noStroke()
ellipseMode(RADIUS)
fill(167, 190, 221, 255)
for i,s in ipairs(self.shapes) do
ellipse(s.x, s.y - 5, s.r)
end
fill(255, 255, 255, 255)
for i,s in ipairs(self.shapes) do
ellipse(s.x, s.y + 5, s.r)
end
popMatrix()
popStyle()
end
--# Super_sponge
Girl = class()
function Girl:init()
-- you can accept and set parameters here
self.position = vec2(0,0)
self.velocity = vec2(0,0)
end
function Girl:jump(power)
sound(SOUND_JUMP)
self.velocity = self.velocity + vec2(0,power)
end
function Girl:computeVelocity()
gravity = vec2(Gravity.x, math.min(Gravity.y,-1)):normalize()
gravity = gravity * 15
friction = math.min(self.position.y, 1)
return self.velocity + gravity * friction
end
function Girl:update()
self.position = self.position + self:computeVelocity()
-- Clamp y position
-- (so you don't go through ground)
self.position.y = math.max(self.position.y,0)
-- Clamp x position
self.position.x = math.max(self.position.x,-WIDTH/2)
self.position.x = math.min(self.position.x,WIDTH/2)
-- Dampen velocity
self.velocity = self.velocity * 0.98
end
function Girl:isFalling()
return self:computeVelocity().y < 0
end
function Girl:draw()
self:update()
pushMatrix()
translate(self.position.x, self.position.y)
sprite("Documents:sponge bob", 0, 0)
popMatrix()
end
--# Main
function setup()
sprite("Documents:sponge bob icon app",WIDTH/2,HEIGHT/2)
clouds = CloudLevels()
girl = Girl()
girl.position = vec2(0, 0)
end
-- This function gets called once every frame
function draw()
background(0, 234, 255, 255)
displayMode(FULLSCREEN)
-- backingMode(RETAINED)
-- Center the camera on the girl character
camPos = vec2(WIDTH/2,
math.min(HEIGHT/2 - girl.position.y, 140))
translate(camPos.x,camPos.y)
-- Draw ground
for i = 1,8 do
sprite("Documents:jelly fish", -WIDTH/2-70 + 125*i, -95)
end
clouds:update(camPos)
clouds:draw()
girl:draw()
if clouds:isColliding(girl.position) and
girl:isFalling() then
girl:jump(math.random(30,60))
end
end
function touched(touch)
if touch.tapCount == 1 and
girl.position.y == 0 then
girl:jump(40)
end
end
-- this is the eazy game and i well give you another two app
you would need toto use finite state machines. in your setup() function put:
gameState = "menu"
If you have three seperate classes for the “easy,normal, and hard” parts of your game (even if you don’t you can apply the same principles to this) then add this in the draw() function:
if gameState == "menu" then
menu()
elseif gameState == "easy" then
gameEasy:draw()
elseif gameState == "norm" then
gameNormal:draw()
elseif gameState == "hard" then
gameHard:draw()
So if you use the @dave1707 's code then instead of using the print action you would change the “gameState” part. As in:
-- print("easy option selected") <----- get rid of this and put
gameState = "easy"
Is this what you wanted?
Kid you need to put three squiggly lines before and after your code, not several times in the middle makes it hard to read
~~ ← three of these here
[CODE]
~~ three more
Sweet, it is the Lua Jump example with Spongebob graphics. Destined to be a bestseller as long as Nickelodeon doesn’t get angry. I ran out of lunch break before I could finish coding the solution, which is a bummer as I LOVE GIFTS. Maybe I will have time to get this done before anyone else gets to it. (crosses fingers.)
(I’ve edited the code post and put in the “fences” as RichGala1 explains.)
I’ve rewritten it with a menu, and even have implemented hard and medium by making the jump less powerful. I feel best answer is definitely mine, woot.
--# CloudLevels
CloudLevels = class()
CULLPADDING = 300
function CloudLevels:init() -- you can accept and set parameters here
self.clouds = {}
self.nextCloudHeight = 81
end
function CloudLevels:generateNextCloud()
cloud = Cloud()
cloud.position = vec2(math.random(-WIDTH/2,WIDTH/2), self.nextCloudHeight)
table.insert(self.clouds, cloud)
self.nextCloudHeight = self.nextCloudHeight + math.random(150,300)
end
function CloudLevels:cullClouds(floor)
for i,v in ipairs(self.clouds) do
if v.position.y < floor then
table.remove(self.clouds,i)
end
end
end
function CloudLevels:isColliding(pos)
for i,v in ipairs(self.clouds) do
if v:isColliding(pos) then
return true
end
end
return false
end
function CloudLevels:update(cam)
curHeight = -cam.y + HEIGHT + CULLPADDING
if curHeight > self.nextCloudHeight then
self:generateNextCloud()
end
self:cullClouds(-cam.y - CULLPADDING)
end
function CloudLevels:draw() -- Codea does not automatically call this method
for i,v in ipairs(self.clouds) do
v:draw()
end
end
function CloudLevels:touched(touch) -- Codea does not automatically call this method
end
--# Cloud
Cloud = class()
function Cloud:init() -- you can accept and set parameters here
self.shapes = {}
self.position = vec2(0,0)
-- Generate random cloud
numCircles = math.random(4, 5)
spacing = 30
for i = 1,numCircles do
x = i * spacing - ((numCircles/2)*spacing)
y = (math.random() - 0.5) * 30
rad = math.random(spacing, 2*spacing)
table.insert(self.shapes, {x=x, y=y, r=rad})
end
self.width = numCircles * spacing + spacing
end
function Cloud:isColliding(pos)
startp = self.position.x - self.width/2
endp = self.position.x + self.width/2
if pos.x < endp and pos.x > startp and
pos.y < (self.position.y + 30) and
pos.y > (self.position.y + 10) then
return true
end
return false
end
function Cloud:draw()
pushStyle()
pushMatrix()
translate(self.position.x, self.position.y)
noStroke()
ellipseMode(RADIUS)
fill(167, 190, 221, 255)
for i,s in ipairs(self.shapes) do
ellipse(s.x, s.y - 5, s.r)
end
fill(255, 255, 255, 255)
for i,s in ipairs(self.shapes) do
ellipse(s.x, s.y + 5, s.r)
end
popMatrix()
popStyle()
end
--# Super_sponge
Girl = class()
function Girl:init() -- you can accept and set parameters here
self.position = vec2(0,0)
self.velocity = vec2(0,0)
end
function Girl:jump(power)
sound(SOUND_JUMP)
local pow = power
if difficulty == "medium" then pow = pow - 10 end
if difficulty == "hard" then pow = pow - 15 end
self.velocity = self.velocity + vec2(0,pow)
end
function Girl:computeVelocity()
gravity = vec2(Gravity.x, math.min(Gravity.y,-1)):normalize()
gravity = gravity * 15
friction = math.min(self.position.y, 1)
return self.velocity + gravity * friction
end
function Girl:update()
self.position = self.position + self:computeVelocity()
-- Clamp y position
-- (so you don't go through ground)
self.position.y = math.max(self.position.y,0)
-- Clamp x position
self.position.x = math.max(self.position.x,-WIDTH/2)
self.position.x = math.min(self.position.x,WIDTH/2)
-- Dampen velocity
self.velocity = self.velocity * 0.98
end
function Girl:isFalling()
return self:computeVelocity().y < 0
end
function Girl:draw()
self:update()
pushMatrix()
translate(self.position.x, self.position.y)
sprite("Planet Cute:Character Boy", 0, 0)
popMatrix()
end
--# Main
function setup()
displayMode(FULLSCREEN)
sprite("Planet Cute:Icon",WIDTH/2,HEIGHT/2)
clouds = CloudLevels()
girl = Girl()
girl.position = vec2(0, 0)
gameState = "menu"
difficulty = "easy"
end
-- This function gets called once every frame
function draw()
if gameState == "menu" then
background(41, 196, 210, 255)
displayMode(FULLSCREEN)
fill(64, 64, 64, 255)
rect(WIDTH/2-100,500,200,50)
rect(WIDTH/2-100,400,200,50)
rect(WIDTH/2-100,300,200,50)
fill(255, 255, 255, 255)
text("Main Menu", WIDTH/2, 600)
text("Easy", WIDTH/2, 525)
text("Medium", WIDTH/2, 425)
text("Hard", WIDTH/2, 325)
elseif gameState == "playing" then
background(0, 234, 255, 255)
displayMode(FULLSCREEN)
-- backingMode(RETAINED)
-- Center the camera on the girl character
camPos = vec2(WIDTH/2, math.min(HEIGHT/2 - girl.position.y, 140))
translate(camPos.x,camPos.y)
-- Draw ground
for i = 1,8 do
sprite("Planet Cute:Enemy Bug", -WIDTH/2-70 + 125*i, -95)
end
clouds:update(camPos)
clouds:draw()
girl:draw()
if clouds:isColliding(girl.position) and girl:isFalling() then
girl:jump(math.random(30,60))
end
end
end
function touched(touch)
if gameState == "menu" then
if touch.state == ENDED then
if touch.y > 500 then
difficulty = "easy"
gameState = "playing"
elseif touch.y > 400 then
difficulty = "medium"
gameState = "playing"
elseif touch.y > 300 then
difficulty = "hard"
gameState = "playing"
end
end
elseif gameState == "playing" then
if touch.tapCount == 1 and girl.position.y == 0 then
girl:jump(40)
end
end
end
-- this is the eazy game and i well give you another two app
Oh, yeah, bro… Don’t forget to change the graphics back to sponge bob before releasing to the app store
I love all the helps thanks
Thank you
These is the first test
--# Main
--# CloudLevels
CloudLevels = class()
CULLPADDING = 300
function CloudLevels:init() -- you can accept and set parameters here
self.clouds = {}
self.nextCloudHeight = 200
end
function CloudLevels:generateNextCloud()
cloud = Cloud()
cloud.position = vec2(math.random(-WIDTH/2,WIDTH/2), self.nextCloudHeight)
table.insert(self.clouds, cloud)
self.nextCloudHeight = self.nextCloudHeight + math.random(92,300)
end
function CloudLevels:cullClouds(floor)
for i,v in ipairs(self.clouds) do
if v.position.y < floor then
table.remove(self.clouds,i)
end
end
end
function CloudLevels:isColliding(pos)
for i,v in ipairs(self.clouds) do
if v:isColliding(pos) then
return true
end
end
return false
end
function CloudLevels:update(cam)
curHeight = -cam.y + HEIGHT + CULLPADDING
if curHeight > self.nextCloudHeight then
self:generateNextCloud()
end
self:cullClouds(-cam.y - CULLPADDING)
end
function CloudLevels:draw() -- Codea does not automatically call this method
for i,v in ipairs(self.clouds) do
v:draw()
end
end
function CloudLevels:touched(touch) -- Codea does not automatically call this method
end
--# Cloud
Cloud = class()
function Cloud:init() -- you can accept and set parameters here
self.shapes = {}
self.position = vec2(0,0)
-- Generate random cloud
numCircles = math.random(1, 20)
spacing = 20
for i = 1,numCircles do
x = i * spacing - ((numCircles/2)*spacing)
y = (math.random() - 0.5) * 30
rad = math.random(spacing, 2*spacing)
table.insert(self.shapes, {x=x, y=y, r=rad})
end
self.width = numCircles * spacing + spacing
end
function Cloud:isColliding(pos)
startp = self.position.x - self.width/2
endp = self.position.x + self.width/2
if pos.x < endp and pos.x > startp and
pos.y < (self.position.y + 30) and
pos.y > (self.position.y + 21) then
return true
end
return false
end
function Cloud:draw()
pushStyle()
pushStyle()
pushMatrix()
translate(self.position.x, self.position.y)
noStroke()
ellipseMode(RADIUS)
fill(255, 255, 255, 255)
for i,s in ipairs(self.shapes) do
ellipse(s.x, s.y - 5, s.r)
end
fill(221, 221, 218, 255)
for i,s in ipairs(self.shapes) do
ellipse(s.x, s.y + 5, s.r)
end
popStyle()
popMatrix()
popStyle()
end
--# Super_sponge
Girl = class()
function Girl:init() -- you can accept and set parameters here
self.position = vec2(0,0)
self.velocity = vec2(0,0)
end
function Girl:jump(power)
sound(SOUND_JUMP)
sound(DATA, "ZgJAQwBAJFE8dFZiGE9hv5j2Kj+6aI0/VQA5U0JyRyM/KEBC")
sound(DATA, "ZgBAMxhIOUVPThVAP49GPdcp/T7I9gQ/VwAucS9FLUA4M0BY")
sound(DATA, "ZgBASAA2SWE/QARCRDw3v/yitT4NRLw+QABIRmNBQEEZInFs")
sound(DATA, "ZgBAQQA1USQHPnJHch1oP8oPPD9Un0M/QAA+f0BSRQdAY0t/")
sound(DATA, "ZgJAJgBAQEBAQEBAAAAAAJqZmT7NzMw+QABAf0BAQEBAQEBA")
local pow = power
if difficulty == "medium" then pow = pow - 12 end
if difficulty == "hard" then pow = pow - 10 end
self.velocity = self.velocity + vec2(0,pow)
end
function Girl:computeVelocity()
gravity = vec2(Gravity.x, math.min(Gravity.y,1)):normalize()
gravity = gravity * 13
friction = math.min(self.position.y, 1)
return self.velocity + gravity * friction
end
function Girl:update()
self.position = self.position + self:computeVelocity()
-- Clamp y position
-- (so you don't go through ground)
self.position.y = math.max(self.position.y,0)
-- Clamp x position
self.position.x = math.max(self.position.x,-WIDTH/2)
self.position.x = math.min(self.position.x,WIDTH/2)
-- Dampen velocity
self.velocity = self.velocity * 0.98
end
function Girl:isFalling()
return self:computeVelocity().y < 0
end
function Girl:draw()
self:update()
pushMatrix()
translate(self.position.x, self.position.y)
sprite("Documents:sponge bob")
popMatrix()
end
--# Main
function setup()
version = 1.6
saveProjectInfo("Description", "super sponge game")
saveProjectInfo("Author", "Mohammad abumoosa")
saveProjectInfo("Date", "17st may 2013")
saveProjectInfo("Version", version)
print("super sponge v"..version.."\
")
print("the developer mohammad abumoosa")
print("the photos maker is hassan abdulazim ")
sound(DATA, "ZgFAHxw+R0RlQFogorwGPkHdiD5vxDM/MQBPUVFlNjosSmBY")
sound(DATA, "ZgJAbwAQa3BAO3UMk8WZPG/A8z7OlA4/YAAPej9AGHs/Swxv")
sound(DATA, "ZgBAdQBAOQUzDW170XCjPq+2aj4Y+go/TQAcf0BbP2YgCGwZ")
sound(DATA, "ZgJAXQAwMzcsNzFY9KZKvnthDz8gM2k+UABqfy9AP0VWUnco")
sound(DATA, "ZgFAHxw+R0RlQFogorwGPkHdiD5vxDM/MQBPUVFlNjosSmBY")
sound(DATA, "ZgJADQBAZRZ4DEkvpEcdvEdkvD6Wy/Q+QgAyeUZAQFQxZ2Br")
sound(DATA, "ZgJA5ABdQTs/Py8FAMFOverEJj/yXZa+TAA0WD9BRz82LBtz")
sound(DATA, "ZgJAXQAwMzcsNzFY9KZKvnthDz8gM2k+UABqfy9AP0VWUnco")
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
sprite("Documents:welcome photo",WIDTH-515,HEIGHT-380)
clouds = CloudLevels()
girl = Girl()
girl.position = vec2(0, 0)
gameState = "menu"
difficulty = "eazy"
sprite("Documents:welcome photo",WIDTH-515,HEIGHT-380)
-- This function gets called once every frame
function draw()
if gameState == "menu" then
sprite("Documents:sponge bob background",WIDTH-515,HEIGHT-380)
supportedOrientations(LANDSCAPE_RIGHT)
-- background(245, 255, 0, 57)
font("Zapfino")
fontSize(60)
fill(6, 6, 6, 255)
text("Main Menu", WIDTH/2, 600)
noStroke()
ellipseMode(RADIUS)
fill(65, 141, 200, 61)
fill(0, 223, 255, 255)
rect(WIDTH -750 , 70,483,230)
font("SnellRoundhand-Black")
fill(50, 75, 175, 255)
fontSize(30)
text(" play the game", WIDTH/2 , 280)
text("credites", WIDTH/2 , 220)
text("contact the developer of the game" , WIDTH/2, 165 )
text("contact mohammad (developer) ", WIDTH/2,100 )
sprite("Documents:sandy",WIDTH-300,HEIGHT-380)
sprite("Documents:basset",WIDTH-850,HEIGHT-380)
sprite("Documents:basset",WIDTH-100,HEIGHT-600)
sprite("Documents:loaloa 2",WIDTH-850,HEIGHT-600)
sprite("Documents:loaloa",WIDTH-100,HEIGHT-400)
sprite("Documents:mrs crabs",WIDTH-175,HEIGHT-150)
sprite("Documents:mrs crabs",WIDTH-845,HEIGHT-150)
elseif gameState == "playing" then
supportedOrientations(LANDSCAPE_ANY)
sprite("Documents:sponge bob background",WIDTH-515,HEIGHT-380)
-- Center the camera on the girl character
camPos = vec2(WIDTH/2, math.min(HEIGHT/2 - girl.position.y, 144))
translate(camPos.x,camPos.y)
-- Draw ground
for i = 1,11 do
sprite("Platformer Art:Cloud 1",-WIDTH/2 -70 + 101*i, -60 )
end
clouds:update(camPos)
clouds:draw()
girl:draw()
if clouds:isColliding(girl.position) and girl:isFalling() then
girl:jump(math.random(1,89))
end
end
function touched(touch)
if gameState == "menu" then
if touch.state == ENDED then
if touch.y > 250 then
difficulty = "hard"
sound(DATA, "ZgFAMRg1Wl9BNig+vYZyPtYCnD28F18/QABzf0JedFl/MGwn")
gameState = "playing"
elseif touch.y > 200 then
difficulty = "credites"
gameState = "menu"
openURL("http" .. "://www.youtube.com/watch?v=6lEPRSJ0i9o")
sound(DATA, "ZgFAMRg1Wl9BNig+vYZyPtYCnD28F18/QABzf0JedFl/MGwn")
elseif touch.y > 150 then
difficulty = "contact the developer of the game"
gameState = "menu"
openURL("http://thedeveloperofthegame.webr.ly/")
sound(DATA, "ZgFAMRg1Wl9BNig+vYZyPtYCnD28F18/QABzf0JedFl/MGwn")
elseif touch.y > 100 then
difficulty = "contact the photos designer"
gameState = "menu"
openURL("https://twitter.com/mohd_abumoosa")
sound(DATA, "ZgFAMRg1Wl9BNig+vYZyPtYCnD28F18/QABzf0JedFl/MGwn")
end
end
elseif gameState == "playing" then
if touch.tapCount == 1 and girl.position.y == 0 then
girl:jump(50)
end
end
end
end
end