Hello everyone I am a 8th grader who is just starting to code and was wondering if I could get help with mine.
I have a backround on the code and every time I take it off the code glitches.
Here is the code:
-- Rocket Run
-- Use this function to perform your initial setup
function setup()
spx = 600
spy = 400
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(255, 255, 255, 255)
-- This sets the line thickness
strokeWidth(5)
end
function draw()
-- Do your drawing here
sprite("SpaceCute:Background",374,500,1505,1005)
sprite("SpaceCute:Rocketship",spx,spy)
end
function touched(touch)
spx = touch.x
spy = touch.y
end
function instructions()
w=WIDTH/2
fill(242, 242, 242, 255)
fontsize(25)
text("this is a game made by Andrew Brown",w,650)
text("You have to dodge the boxes to get to the next level",w,600)
end
It looks like, from what’s posted above, you have two draw functions… which certainly makes it hard to tell what’s really being executed. Try something like this:
-- Rocket Run
function setup()
spx = 600
spy = 400
end
function draw()
background(255, 255, 255, 255)
sprite("SpaceCute:Background",374,500,1505,1005)
sprite("SpaceCute:Rocketship",spx,spy)
end
function touched(touch)
spx = touch.x
spy = touch.y
end
If you remove the background command, the image will not start ‘fresh’ each time, but will draw on top of the existing image. This can be used for interesting effects, but is probably not what you are after.
-- Rocket Run
displayMode(FULLSCREEN)
function setup()
w=WIDTH/2
h=HEIGHT/2
instr=true
end
function draw()
background(255, 255, 255, 255)
strokeWidth(5)
if instr then
instructions()
else
sprite("SpaceCute:Background",w,h,WIDTH,HEIGHT)
sprite("SpaceCute:Rocketship",spx,spy)
end
end
function touched(touch)
instr=false
spx = touch.x
spy = touch.y
end
function instructions()
fill(224, 149, 129, 255)
fontSize(25)
text("This is a game made by Andrew Brown",w,650)
text("You have to dodge the boxes to get to the next level",w,600)
fontSize(20)
text("Tap screen to start.",w,500)
end
on topic: @dave1707’s code is a nice example… that’s a good start for you game, notice that he calls a ‘instructions’ function that start before your actual game…
You should go like that all the way, so instead of doing all your code inside your draw, call functions from there, that’s less messy and eventually easyer if you want to use it in one of your other projects…
Setting up physics bodies just for collisions is overkill in this program. Especially since he said he was just starting to code. I sent him a copy of code that checked for collisions based on distance between the objects. That should be enough to get him going.