Help

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

Any Sugestions?

Sorry about how wot looks I couldn’t figure put how to make it look normal

try posting it between

code...

and close the pre here...

Put 3 ~ like:

This is what it does:

function setup()
tildes = true
if tildes = true then
close()
end
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.

That is true @mark

@codea noob, where does that piece of a code go

What do you mean @stevon8ter

@abrown18 @CodeaNoob’s code doesn’t do anything, it was just an example of code formatting.

Like this:

~~~

Your code

~~~

And @stevon8ter posted a different way, with a bit of HTML. That one has syntax highlighting. Here’s a text file on my Dropbox that shows the usage, I can’t get it to format properly here. Link: https://www.dropbox.com/s/1h6g2ikc9nv7psy/Code%20formatting%20syntax.txt

The ~~~ method looks like:

abc = 123
print("Hello World!")

The pre method looks like:

abc = 123
print("Hello World!")

```

@ Mark I have done that before on that code

@abrown18 Here’s a suggestion.


-- 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

@skythecoder thx for making that more clear :wink:

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…

Does anyone know how I can make the space ship collide with anything

Make it a physics.body

What do u mean

I’ve done tutorials on this, have a look on the wiki link above

Create a shape(body) that is applicable to physics

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.