starter game

Some of the new coders want to write games, but they don’t know where to start. Here is some code the anyone can take and make into something more interesting. It’s kind of barebones, but it’s a start for someone willing to improve on it. The object is to tilt the ipad and move the blue circle around the screen hitting the numbered white circles. If you hit the circles in the correct order they will turn red. If you complete the order, the next round will have 3 more circles to hit. If you hit a circle out of order, they all turn white and you start that round again. As I said, this is a starter, so what else you want to add to make it more interesting is up to you. Start the game with the ipad laying flat.

``````
displayMode(FULLSCREEN)

function setup()
ball=vec2(WIDTH/2,HEIGHT/2)
createTarget()  -- create circles to hit
end

function createTarget()
target={}   -- create table for targets
for z=1,count do    -- create number of count circles
-- x,y,number,0=not hit 1=hit
table.insert(target,vec4(math.random(100,WIDTH-100),
math.random(100,HEIGHT-100),z,0))
end
nbr=1   -- starting circle number
match=0 -- number of circle being hit
end

function draw()
background(40,40,50)    -- background color
fill(0, 52, 255, 255)   -- ball color
ellipse(ball.x,ball.y,50)   -- draw blue ball
ball.x = ball.x + Gravity.x*40  -- move in x direction
ball.y = ball.y + Gravity.y*40  -- move in y direction
for a,b in pairs(target) do -- draw circles
if b.w==1 then  -- should it be red
fill(255,0,0)   -- set red color
end
ellipse(b.x,b.y,50) -- draw circle
fill(0, 115, 255, 255)  -- color for numbers on circles
text(a,b.x,b.y) -- draw numbers on circles
end
hit()   -- check which circle is hit
end

function hit()
v1=ball -- vector info for distance calculation
overlap=false   -- no circle is being hit
for a,b in pairs(target) do -- loop thru target table
d=v1:dist(vec2(b.x,b.y))-- distance between blue ball and circles
if d<50 then    -- less than 50
overlap=true    -- ball and circle are touching
match=b.z   -- number of circle being touched
end
end
if not overlap then -- no overlap happening
if match>0 then  -- was a circle being overlapped
nbr=nbr+1   -- add 1 for next circle
match=0 -- clear variable
end
end
if match>0 then -- circle being overlapped
if match==nbr then  -- correct circle
target[match].w=1   -- set flag for red color
if match==#target then  -- last circle being touched
count = count + 3   -- add 3 to circle count
createTarget()  -- create new circles
end
else
createTarget()  -- wrong circle touched, redraw circles
end
end
end

``````

Nice and holy cow thats compact.

@Goatboy76 Thanks. I was working on something else and this came to mind. Since I don’t play games, I thought I would get it started for someone else to improve on if they want.

Has anyone done a game for children? When I was first learning C I made a simple maze puzzle for my kids and they loved it. It was randomly generated, and they used the arrow keys to navigate from start to finish. I think something like this (with a more modern interface - touching the screen) might be fun. It was fun to for me, anyway…

I’ve done a simple jigsaw game for my 2 year old - dragging cut out shapes into predefined locations. I personalised it by making the images her and her friends and have used some of the sounds which shipped with codea 2 which she loves!

Tanks, this code is usefull, You´re really a good mentor for beginners in Codea like me

@richardmike4 Thanks for the comment, but this forum is loaded with great examples from a lot of people. There are several years worth of code here just waiting for anyone to use it.

Just wanted to let you know that when I started with Codea, I played around with this source. I made the balls move at slightly different speeds, using their numbers. Then I encountered an issue of them all moving together making the slower ones impossible to reach. So I added a little bit of randomization and ended up with a more difficult version of your game.

It wasn’t much but I enjoyed learning from and working with your source. Thanks for sharing!

@RiverForge Thanks for the comment.