A few questions from a struggling programmer...

Hello all,

I recently started using Codea and I absolutely adore it. After creating a simple drawing game I decided to start working on a bigger project - and after a few long nights of brainstorming and cans of Mountain Dew, I started sketching out artwork for a find-the-hidden-object game. However, unlike other games of this caliber, the screen will be filled with about 100 objects (maybe more) scattered around randomly.

But the problem is, I have no clue how to do a few key things.

FIRST: How can I make sprites or artwork appear at random locations every time I open the program?
SECOND: Title screens? Any tips on those?

So really, not that many things. :"> I should have thought about what I was confused about before I started a forum post about it.

Thanks!

First: use variables for the x and y positions of your sprites and initialise them with

x=math.random(WIDTH)
Y=math.random(HEIGHT)

Second:take a look at @Reefwing’s excellent tutorials, in particular http://codeatuts.blogspot.com.au/2012/06/tutorial-4-splash-screen.html

Wow! Thanks so much!

-Feels really dumb-

.@apavey1 Maybe this will help a little.


displayMode(FULLSCREEN)

function setup()
    fontSize(40)
    updateRandom()
    screen={titleScreen,Screen1,Screen2}
    s=1
end

function draw()
    background(40, 40, 50)
    screen[s]()
end

function touched(t)
    if t.state==BEGAN then
        s=s+1
        if s>#screen then
            s=1
        end
    end
end

function titleScreen()
    background(255, 198, 0, 255)
    fill(255)
    text("Put title screen information here",WIDTH/2,HEIGHT/2)
    text("tap screen to continue",WIDTH/2,HEIGHT/2-100)
end

function updateRandom()
    tab={}
    for z=1,200 do
        table.insert(tab,vec2(math.random(WIDTH),math.random(HEIGHT)))
    end
end

function Screen1()
    background(0, 255, 189, 255)
    for a,b in pairs(tab) do
        sprite("Planet Cute:Character Pink Girl",b.x,b.y,50)
    end
    fill(255,0,0)
    text("tap screen to continue",WIDTH/2,HEIGHT/2-100)
end
      
function Screen2()
    background(0, 255, 189, 255)
    updateRandom()
    for a,b in pairs(tab) do
        sprite("SpaceCute:Star",b.x,b.y,50)
    end
    fill(255,0,0)
    text("tap screen to continue",WIDTH/2,HEIGHT/2-100)
end

We all start out feeling dumb, so don’t let that stop you.

I never stopped feeling dumb!

… and thanks @West

I felt dumb for a while, then she left, so I felt grumpy, then she left too so now I feel happy :slight_smile:

I felt pretty much all of the seven dwarfs… And don’t worry about being slow or having to reference from certain documents just to code, we all had to start there in some way or another!

@Luatee - Agreed, just cause you’ve got 20+ years under your belt doesn’t mean you can’t stop learning either - that’s one of the things I love about modern computing.