Engineer

Eytan I

Area of Interest

Computer Science/Computer Engineering

App Design Final

For my 11th grade app design final, we were given the task of using the code that we used all year to code engineering projects(create programs that convert between number systems, create a replication of an ideal gas, ext.) and apply it in a different way. I chose to make a display of different games.

School

SAR High School

Grade

Junior

Project Overview

On the main screen of my app, I offer the player a choice of ten different games. To pick one, you simply touch the name of the game and the game launches.

The code I am using is through an Ipad app called Codea, which uses a form of Lua which supports graphics. When the app launches and it goes to the main screen, all games are initialized, and their touch functions and variables are declared. I use a button class which I wrote to allow you to select a game.

CODE
--# Main
supportedOrientations(LANDSCAPE_ANY)
function setup()
resetAllButtons=false --declare variables
currGameChoice=0 --declare variables
gameMode=0 --declare variables
BubbleTrouble1= Button2("BubbleTrouble", vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 650),-1 , 200,60) --create button
Battleship= Button2("Battleship",vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 650), -1, 200,60) --create button
EtchSketch= Button2("EtchSketch",vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 500), -1, 200,60) --create button
Avoid= Button2("Avoid",vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 500), -1, 200,60) --create button
TicToe= Button2("Tic Tac Toe",vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 350), -1, 200,60) --create button
WackAMole= Button2("Wack A Mole",vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 350), -1, 200,60) --create button
Emoji= Button2("Emoji",vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 200), -1, 200,60)--create button
FaceMash= Button2("Face Mash",vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 200), -1, 200,60) --create button

    keepIn= Button2("Keep in",vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 50), -1, 200,60) --create button
connectFour= Button2("Connect Four",vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 50), -1, 200,60) --create button

initializeBubbleTrouble()
initializeBattleShip()
initializeEtchSketch()
initializeAvoid()
initializeTicTacToe()
initializeWackAMole()
initializeEmoji()
initializeFaceMash()
-- initialize games, the code for that is in each games code
    displayMode(FULLSCREEN)
    initializekeepIn() --must be done with full screen mode for dimension reasons
    displayMode(STANDARD)
    initializeConnect()
strokeWidth(0)
end

function draw()
strokeWidth(0) --no border
if (gameMode ==0) -- if game is not selected yet
then
        displayMode(STANDARD) 
background(36, 48, 112, 255)
sprite("Documents:bubble trouble home", WIDTH/2-150,725,80)
sprite("Documents:battleship home", WIDTH/2+150,725,80)
sprite("Documents:each sketch home", WIDTH/2-150,575,80)
sprite("Documents:Avoid backdrop", WIDTH/2+150,575,80,80)
sprite("Documents:TicTacToe", WIDTH/2-150,425,80,80)
sprite("Documents:WMSET", WIDTH/2+150,425,80)
sprite("Documents:Emoji1", WIDTH/2-150,275,80)
sprite("Documents:mash", WIDTH/2+150,275,80)
 sprite("Documents:keepIn", WIDTH/2-150,125,80)
sprite("Documents:c4", WIDTH/2+150,125,80)
--put pictures of games on screen
BubbleTrouble1:draw()
Battleship:draw()
EtchSketch:draw()
Avoid:draw()
TicToe:draw()
WackAMole:draw()
Emoji:draw()
FaceMash:draw()
        connectFour:draw()
        keepIn:draw()
--draw the buttons created earlier


        if currGameChoice ~= 0 -- if game has been selected
then
gameMode=currGameChoice --make game mode, the selected game

end

elseif gameMode==1
then
runBubbleTrouble()
elseif gameMode==2
then
runBattleShip()
elseif gameMode==3
then
runEtchSketch()
elseif gameMode == 4
then
runAvoid()
elseif gameMode == 5
then
RunTicTacToe()
elseif gameMode == 6
then
runWackAMole()
elseif gameMode == 7
then
runEmoji()
elseif gameMode == 8
then
runFaceMash()
        elseif gameMode == 9
    then
        runkeepIn()
        elseif gameMode == 10
    then
        runConnect()
end
-- if game is selected, run the game
end

function touched(touch)
--set up touch functions here
if (gameMode ==0) -- no game selected
then
BubbleTrouble1:touched(touch)
Battleship:touched(touch)
EtchSketch:touched(touch)
Avoid:touched(touch)
TicToe:touched(touch)
WackAMole:touched(touch)
Emoji:touched(touch)
FaceMash:touched(touch)
Go:touched(touch)
connectFour:touched(touch)
keepIn:touched(touch)
selectOnlyOneGameChoice(touch)
--allow buttons to be pressed
end
if (gameMode==1)
-- Bubble trouble game
then
BTReplay:touched(touch)
BTRestart:touched(touch)
--two buttons 
xloc= CurrentTouch.x
yloc= CurrentTouch.y
--make variable that go to current touch location
b1:touched(touch)
b2:touched(touch)
fire:touched(touch)
fire2:touched(touch)
Survival:touched(touch)
Highscore:touched(touch)
Go:touched(touch)
selectOnlyOneIncChoice(touch)
--buttons

end
if gameMode== 2
--battleship
then
bor1:touched(touch)
-- allow board class to have class function
if touch.state == ENDED
then
for i = 1, #ships
do
if ships[i].x ~= hit.x or ships[i].y ~= hit.y and hit.x ~= nil and touch.state == ENDED
then
tries = tries-1/12
output.clear()
print (math.floor(tries).. " turns left")
print( #ships - #shipsHit  .. " ship parts to find")

circles[#circles + 1] = vec2 (bor1:left() + (hit.x -.5) * 50, bor1:bottom() + (hit.y - .5) * 50)
end
-- if hit somewhere on board with no ships, then make a circle there and lower tries
if ships[i].x == hit.x and ships[i].y == hit.y
then

shipsHit[#shipsHit +1 ] = vec2(hit.x, hit.y)
sound(SOUND_EXPLODE, 25)
--make sound and add location to ships hit array
end
end
end
BSRestart:touched(touch)
BSReplay:touched(touch)
--buttons
end
if (gameMode==3)
--etch Sketch
then
if (touch.x > WIDTH-75 and touch.y < 75) then
reset = true
end
--erase button on bottom right
if (touch.x<50 and touch.y <50)
then
col=1
asd=true
end
if touch.x>50 and touch.x <100 and touch.y <50
then
col=2
asd=true
end
if touch.x>100 and touch.x <150 and touch.y <50
then
col=3
asd=true
end
if touch.x>150 and touch.x <200 and touch.y <50
then
col=4
asd=true
end
if touch.x>200 and touch.x <250 and touch.y <50
then
col=5
asd=true
end
if touch.x>250 and touch.x <300 and touch.y <50
then
col=6
asd=true
end
if touch.x>300 and touch.x <350 and touch.y <50
then
col=7
asd=true
end
--select one of seven colors to draw with, and asd(additional selection desired) is true
if touch.y> 75 then
xjoystick= touch.x
yjoystick= touch.y
end
-- if touched above buttons, allow joystick to move with touch
if (touch.y>75 and asd== true)
then
o=touch.x
g=touch.y
xjoystick=touch.x
yjoystick= touch.y
background(0)
print("started from initial.(x,y")
asd=false
end
-- if color changed, allow new start of line at next touch location
xcurrent= touch.x
ycurrent= touch.y

if touch.state == ENDED
then
asd=true
--if pick up finger, allow new line to be drawn as well
if touch.y> 75
then
xjoystick=touch.x
yjoystick= touch.y
--needs to be placed here in code as well to optimize speed
end
end
Front:touched(touch)
Back:touched(touch)
TakePic:touched(touch)
MainMenuES:touched(touch)
--buttons
end

if gameMode == 4
--avoid the box
then
xOfMouse = CurrentTouch.x
YOfMouse= CurrentTouch.y
if (touch.state == MOVING or touch.state == BEGAN)and start1== true
then
scoreA=scoreA+.01666*2
scoreFinal=scoreA
--if you are on screen and moving, gain points
end
--tried function to do below, separate worked better
if( touch.x>0 and ( touch.x <= x +SizeOfBox/2) and (touch.x >= x -SizeOfBox/2) and (touch.y <= y +SizeOfBox/2) and (touch.y >= y - SizeOfBox/2))
--if you hit box 1
then
print ("hit")
continue1=false
end

if(( touch.x <= x2 +SizeOfBox/2) and (touch.x >= x2 - SizeOfBox/2) and (touch. y <= y2 +SizeOfBox/2) and (touch. y>= y2 - SizeOfBox/2))
-- or box 2
then
print ("hit")
continue1=false
end

if(( touch.x<= x3 +SizeOfBox/2) and (touch.x >= x3 -SizeOfBox/2) and (touch.y <= y3 +SizeOfBox/2) and (touch.y >= y3 -SizeOfBox/2))
-- or box 3
then
print ("hit")
continue1=false
end

if(( touch.x<= x4 +SizeOfBox/2) and (touch.x >= x4 -SizeOfBox/2) and (touch.y <= y4 +SizeOfBox/2) and (touch.y >= y4 -SizeOfBox/2))
-- or box 4
then
print ("hit")
continue1=false
end

if(( touch.x<= x5 +SizeOfBox/2) and (touch.x >= x5 -SizeOfBox/2) and (touch.y <= y5 +SizeOfBox/2) and (touch.y >= y5 -SizeOfBox/2))
-- or box 5
then
print ("hit")
continue1=false
end

if( touch.prevX>0 and ( touch.prevX <= x +SizeOfBox/2) and (touch.prevX >= x -SizeOfBox/2) and (touch.prevY <= y +SizeOfBox/2) and (touch.prevY >= y - SizeOfBox/2))
-- or box 6
then
print ("hit")
continue1=false
end

if(( touch. prevX <= x2 +SizeOfBox/2) and (touch.prevX >= x2 - SizeOfBox/2) and (touch. prevY <= y2 +SizeOfBox/2) and (touch. prevY>= y2 - SizeOfBox/2))
-- or box 7
then
print ("hit")
continue1=false
end

if(( touch.prevX<= x3 +SizeOfBox/2) and (touch.prevX >= x3 - SizeOfBox/2) and (touch.prevY<= y3 +SizeOfBox/2) and (touch.prevY >= y3 -SizeOfBox/2))
-- or box 8
then
print ("hit")
continue1=false
end

if(( touch.prevX<= x4 +SizeOfBox/2) and (touch.prevX >= x4 - SizeOfBox/2) and (touch.prevY<= y4 +SizeOfBox/2) and (touch.prevY >= y4 -SizeOfBox/2))
-- or box 9
then
print ("hit")
continue1=false
end

if(( touch.prevX<= x5 +SizeOfBox/2) and (touch.prevX >= x5 - SizeOfBox/2) and (touch.prevY<= y5 +SizeOfBox/2) and (touch.prevY >= y5 -SizeOfBox/2))
-- or box 10
then
print ("hit")
continue1=false
end

if continue1 == false
then
sound(SOUND_EXPLODE)
end
AvoidRestart:touched(touch)
AvoidReplay:touched(touch)
end
if (gameMode==5)
--tic tac toe
then
touchVec = vec2(touch.x, touch.y)
--current position into vec2 object
if touch.state == ENDED
then
if touchVec ~= nil
then
currentPos = vec2(getX(touchVec), getY(touchVec))
--convert pixel value into grid value
print (getY(touchVec))

if turn % 2 == 0 and spaceEmpty()
then
player1[#player1 + 1] = currentPos

if getY(touchVec)== 1
then
Row1[getX(touchVec)] =1
elseif getY(touchVec)== 2
then
Row2[getX(touchVec)] =1
elseif getY(touchVec)== 3
then
Row3[getX(touchVec)] =1
end

turn = turn + 1

elseif turn % 2 ~= 0 and spaceEmpty()
then
player2[#player2+1] = currentPos

if getY(touchVec)== 1
then
Row1[getX(touchVec)] =-1
elseif getY(touchVec)== 2
then
Row2[getX(touchVec)] =-1
elseif getY(touchVec)== 3
then
Row3[getX(touchVec)] =-1
end

turn = turn + 1
end
end
print(player2[1])
end
end
if gameMode == 6
--wack a mole
then
for i = 1, #holes
do
holes[i]:touched(touch)
end
--make each hole in class be able to be touched
WMReplay:touched(touch)
WMRestart:touched(touch)

end

if gameMode ==7
--find different emoji
then
EMReplay:touched(touch)
EMRestart:touched(touch)
if #emoji >0
then
emoji[#emoji]:touched(touch)
end
--if array of emojis class objects, allow them to be touched
Emoj1:touched(touch)
Emoj2:touched(touch)
Emoj3:touched(touch)
--emoji buttons for options
end
if gameMode==8
--face mash
then
if start8>10
then
MashReplay:touched(touch)
MashRestart:touched(touch)
b1MASH:touched(touch)
b2MASH:touched(touch)
end
        end
if gameMode==9
--keep in
        then
        if KIstartT>10
        then
            if kb1.directionM ==1 -- x plane
        then
         if touch.state==BEGAN
    then

        kgo=false
        kx1= touch.x
        ky1=touch.y
        elseif touch.state==ENDED
    then
        ky2=touch.y
        kgo=true
    end
    if ky1>ky2
--if y location is greater at end of drag than begining
    then
        r1=Ramp(kx1,ky1,kx1,ky2)
     --   make ramp object
    end
    if ky2>ky1
    then
        r1=Ramp(kx1,ky2,kx1,ky1)
     --   make ramp object
    end
        end

    if kb1.directionM ==2 -- y plane
        then
         if touch.state==BEGAN
    then

        kgo=false
        kex1= touch.x
        kyi1=touch.y
        elseif touch.state==ENDED
    then
        kex2=touch.x
        kgo=true
    end
    if kex1>kex2
    then
        r1=Ramp(kex1,kyi1,kex2,kyi1)
     --   go=true
    end
    if kex2>kex1
    then
        r1=Ramp(kex2,kyi1,kex1,kyi1)
     --   go=true
    end
        end
        KIReplay:touched(touch)
    KIRestart:touched(touch)
        end
        end
    if gameMode==10
    then
        if Cstart>10
        then
        for i = 1,8
    do
        if touch.x> ((i-1)*WIDTH/8) and touch.x < i*WIDTH/8 and touch.state== ENDED
        then
            print(i)
            if CnextAvailable(i) <9 and Cwin==false
            then
            Cy=CnextAvailable(i)
            Cpieces[#Cpieces+1] = CPieces(i,Cy)
            CBoard[i][Cy] = Cturn%2

        Cturn=Cturn+1

        end
            end
    end
            end
        if Cwin~= false
        then
        CFReplay:touched(touch)
        CFRestart:touched(touch)
            end
    end

end


function selectOnlyOneGameChoice(touch)
if BubbleTrouble1:touched(touch) and BubbleTrouble1:getState() == 1 then
currGameChoice = 1
Battleship:deselect()
EtchSketch:deselect()
Avoid:deselect()
TicToe:deselect()
WackAMole:deselect()
Emoji:deselect()
FaceMash:deselect()

        keepIn:deselect()
        connectFour:deselect()
elseif Battleship:touched(touch) and Battleship:getState() == 1 then
currGameChoice = 2
BubbleTrouble1:deselect()
EtchSketch:deselect()
Avoid:deselect()
TicToe:deselect()
WackAMole:deselect()
Emoji:deselect()
FaceMash:deselect()

        keepIn:deselect()
        connectFour:deselect()
elseif EtchSketch:touched(touch) and EtchSketch:getState() == 1 then
currGameChoice = 3
BubbleTrouble1:deselect()
Battleship:deselect()
Avoid:deselect()
TicToe:deselect()
WackAMole:deselect()
Emoji:deselect()
FaceMash:deselect()

        keepIn:deselect()
        connectFour:deselect()
elseif Avoid:touched(touch) and Avoid:getState() == 1 then
currGameChoice = 4
BubbleTrouble1:deselect()
Battleship:deselect()
EtchSketch:deselect()
TicToe:deselect()
WackAMole:deselect()
Emoji:deselect()
FaceMash:deselect()

        keepIn:deselect()
        connectFour:deselect()
elseif  TicToe:touched(touch) and TicToe:getState() == 1 then
currGameChoice= 5
BubbleTrouble1:deselect()
Battleship:deselect()
EtchSketch:deselect()
Avoid:deselect()
WackAMole:deselect()
Emoji:deselect()
FaceMash:deselect()

        keepIn:deselect()
        connectFour:deselect()
elseif  WackAMole:touched(touch) and WackAMole:getState() == 1 then
currGameChoice= 6
BubbleTrouble1:deselect()
Battleship:deselect()
EtchSketch:deselect()
Avoid:deselect()
TicToe:deselect()
Emoji:deselect()
FaceMash:deselect()

        keepIn:deselect()
        connectFour:deselect()
elseif  Emoji:touched(touch) and Emoji:getState() == 1 then
currGameChoice= 7
BubbleTrouble1:deselect()
Battleship:deselect()
EtchSketch:deselect()
Avoid:deselect()
TicToe:deselect()
WackAMole:deselect()
FaceMash:deselect()

        keepIn:deselect()
        connectFour:deselect()
elseif  FaceMash:touched(touch) and FaceMash:getState() == 1 then
currGameChoice= 8
BubbleTrouble1:deselect()
Battleship:deselect()
EtchSketch:deselect()
Avoid:deselect()
TicToe:deselect()
WackAMole:deselect()
Emoji:deselect()

        keepIn:deselect()
        connectFour:deselect()
        elseif  keepIn:touched(touch) and keepIn:getState() == 1 then
currGameChoice= 9
BubbleTrouble1:deselect()
Battleship:deselect()
EtchSketch:deselect()
Avoid:deselect()
TicToe:deselect()
WackAMole:deselect()
Emoji:deselect()
        FaceMash:deselect()
        connectFour:deselect()
        elseif  connectFour:touched(touch) and connectFour:getState() == 1 then
currGameChoice= 10
BubbleTrouble1:deselect()
Battleship:deselect()
EtchSketch:deselect()
Avoid:deselect()
TicToe:deselect()
WackAMole:deselect()
Emoji:deselect()
        FaceMash:deselect()
        keepIn:deselect()


end
end

The first game is based off of a game called bubble trouble. The game has two mode:

1) Highscore- You must shoot at the balls and prevent them from hitting the ground. Each ball you get makes you recive points.

2) Survival- The balls cannot touch you. Earn points by staying alive and destroying the balls, but now the ball can touch the floor.

CODE
function initializeBubbleTrouble()
--runs in main screen as program launches
    points = 0
    numBalls1=0
    numBalls2=0
    lost = 0
    currModeChoice= nil
    particles= {}
    balls= {}
    balls2 = {}
    print("CLICK A MODE AND THEN CLICK GO ")
    print("SURVIVAL- MOVE WITH BOTTOM BUTTONS OR TOUCH ABOVE BOTTOM BAR- DO NOT LET THE MAN BE HIT WITH THE BALL- BALL CAN TOUCH THE GROUND ")
    print("HIGH SCORE- MOVE WITH BOTTOM BUTTONS OR TOUCH ABOVE BOTTOM BAR- DO NOT LET THE BALLS HIT THE GROUND")
    g1= TheGuy(WIDTH/2)
-- class function for the shooting guy
    b1 = Button("right", Vec2(30,50), color(255,0,0), color(0,255,0), 60,30,1)
    b1.action = function() b1BtnTouched()
    end

    b2 = Button("left", Vec2(WIDTH-30,50), color(255,0,0), color(0,255,0), 60,30,1)
    b2.action = function() b2BtnTouched()
    end
    fire = Button("fire", Vec2(100,50), color(255,0,0), color(0,255,0), 60,60,2)
    fire.action = function() fireBtnTouched()
    end

    fire2 = Button("fire", Vec2(WIDTH -100,50), color(255,0,0), color(0,255,0), 60,60,2)
    fire2.action = function() fireBtnTouched()
    end

    Survival= Button2("Survival Mode", vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 500),-1 , 200,60)
    Highscore= Button2("High Score Mode",vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 500), -1, 200,60)
    Go = Button2("Go",vec2(0, 0), 20, Vec2(WIDTH/2, 50), -1, 400,120)
--two modes that can be selected

    xWorldMin = 0; xWorldMax = 350.0
    yWorldMin = 0.0; yWorldMax = 350.0
    -- screen coordinates to use entire screen
    xScreenMin = 0.0; xScreenMax = WIDTH
    yScreenMin = 0.0; yScreenMax = HEIGHT
    balls[1]= Ball(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-10), Vec2(0, -10))
    balls2[1]= Ball2(1, Vec2(WIDTH/2 * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-10), Vec2(0, -30))
   --sets initial ball for either mode
 BTRestart= Button2("Main Menu", vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 600),-1 , 200,60)
    BTReplay= Button2("Play Again", vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 600),-1 , 200,60)
end

function runBubbleTrouble()
    pushStyle()
    -- This sets a dark background color
    if readLocalData("highscore",0)< points
    then
        saveLocalData("highscore", points)
    end

    HighScore = readLocalData("highscore",0)
    background(40, 40, 50)
   
    if lost == 1
    then
        lose()
-if lose, go to lose screen
    elseif Go.state == -1 or currModeChoice == nil
    then
        initial()
    elseif currModeChoice == 2 and Go.state==1
    then
        playHighscore() --mode 1
    elseif currModeChoice == 1 and Go.state==1
    then
        playSurvival()
--mode 2
    end
    popStyle()
end
function lose()
--screen and settings when lose
    lost = 1
    background(0)
    textMode(CENTER)
    fill(255, 0, 0, 255)
    font("AmericanTypewriter-Bold")
    fontSize(80)
    text("YOU LOSE", WIDTH/2, HEIGHT/2)
    text("SCORE: ".. points, WIDTH/2, HEIGHT/2 -100)
    fontSize(60)
    text("HIGH SCORE: ".. math.floor(HighScore), WIDTH/2, HEIGHT/2 -200)
    popStyle()
    BTRestart:draw()
    BTReplay:draw()
    if BTRestart:getState() == 1
    then
        initializeBubbleTrouble()
        BTReplay:deselect()
        BubbleTrouble1:deselect()
        Go:deselect()
        gameMode=0
        BTRestart:deselect()
        popStyle()

        resetAllButtons=true
    end
    if BTReplay:getState() == 1
    then
        initializeBubbleTrouble()
        BTReplay:deselect()
    end

end
function initial()
    Survival:draw()
    Highscore:draw()
    Go:draw()

end
function playHighscore()
    g1:move()
    g1:draw()

    b2:draw()
    -- This sets the line thickness
    strokeWidth(5)
    b1:draw()
    fire:draw()
    fire2:draw()
    -- Do your drawing here
    --   p1:move(1/60)
    --    p1:draw()
    if #balls > 0
    then
        for i = 1, #balls
        do
            balls[i]:move(1/60)
            balls[i]:draw()
        end
    end
    if #particles > 0----
    then
        for i = 1, #particles
        do
            particles[i]:move(1/60)
            particles[i]:draw()
        end
    end
    --   for i = 1, #balls
    --   do
    if balls[1].next == true and points < 10
    then
        balls[1] = nil
        balls[#balls + 1]= Ball(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-20,-10)))
        balls[1].next = false
        numBalls1 = numBalls1 + 1
    end
    if #balls == 1 then
        if balls[1].next == true --and balls[2].next == true
        and points >= 10
        then
            balls[1] = nil
            balls[1]= Ball(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-20,-10)))
            --   balls[1].next = false
            numBalls1 = numBalls1 + 1

            balls[2] = nil
            balls[2]= Ball(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-20,-10)))
            --    balls[i].next = false
            numBalls1 = numBalls1 + 1
            ba =  #balls
            balls[1].next = false
            balls[2].next = false
        end
    end

    if #balls > 1 then
        if balls[1].next == true and balls[2].next == true
        and points >= 10
        then
            balls[1] = nil
            balls[1]= Ball(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-20,-10)))
            --   balls[1].next = false
            numBalls1 = numBalls1 + 1

            balls[2] = nil
            balls[2]= Ball(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-20,-10)))
            --    balls[i].next = false
            numBalls1 = numBalls1 + 1
            ba =  #balls
            balls[1].next = false
            balls[2].next = false
        end
    end
    --    end
    --level 2
    if points >= 5 and points <= 10
    then
        print("LEVEL 2")
        balls[1].fnet = Vec2(0,math.random(-40,-20))
    end
    if points > 10 and points <= 15
    then
        print("LEVEL 3")
        for i = 1, #balls
        do
            balls[i].fnet = Vec2(0,math.random(-40,-20))
        end
    end

    if points > 15-- and points < 15
    then
        print("LEVEL 4")
        for i = 1, #balls
        do
            balls[i].fnet = Vec2(0,-40)
        end
    end

    --   end
    if #balls == 1 then
        if balls[1].lost == true --or balls[2].lost == true
        then
            --[[background(0)
            textMode(CENTER)
            fill(255, 0, 0, 255)
            font("AmericanTypewriter-Bold")
            fontSize(80)
            text("YOU LOSE", WIDTH/2, HEIGHT/2)
            text("SCORE: ".. points, WIDTH/2, HEIGHT/2 -100)
            popStyle()]]
            lose()
        end
    elseif #balls == 2
    then
        if balls[1].lost == true or balls[2].lost == true
        then
            --[[background(0)
            textMode(CENTER)
            fill(255, 0, 0, 255)
            font("AmericanTypewriter-Bold")
            fontSize(80)
            text("YOU LOSE", WIDTH/2, HEIGHT/2)
            text("SCORE: ".. points, WIDTH/2, HEIGHT/2 -100)
            popStyle()]]
            lose()
        end
    end
    if lost ==0
    then
        pushStyle()
        fill(255, 0, 0)
        textMode(CENTER)
        font("AmericanTypewriter-Bold")
        fontSize(100)
        text(points, WIDTH/2, HEIGHT/2)
        popStyle()
    end
end
function playSurvival()
    g1:move()
    g1:draw()

    b2:draw()
    -- This sets the line thickness
    strokeWidth(5)
    b1:draw()
    fire:draw()
    fire2:draw()
    -- Do your drawing here
    --   p1:move(1/60)
    --    p1:draw()

    if #balls2 > 0
    then
        for i = 1, #balls2
        do
            balls2[i]:move(1/60)
            balls2[i]:draw()
        end
    end
    if #particles > 0
    then
        for i = 1, #particles
        do
            particles[i]:move(1/60)
            particles[i]:draw()
        end
    end
    if balls2[1].next == true and points < 10
    then
        balls2[1] = nil
        balls2[#balls2 + 1]= Ball2(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-40,-10)))
        balls2[1].next = false
        --numBalls2 = numBalls2 + 1
    end
    if #balls2 == 1 then
        if balls2[1].next == true --and balls[2].next == true
        and points >= 10
        then
            balls2[1] = nil
            balls2[1]= Ball2(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-50,-10)))
            --   balls[1].next = false
            --numBalls1 = numBalls1 + 1

            balls2[2] = nil
            balls2[2]= Ball2(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-50,-10)))
            --    balls[i].next = false
            -- numBalls1 = numBalls1 + 1
            -- ba =  #balls
            balls2[1].next = false
            balls2[2].next = false
        end
    end

    if #balls2 > 1 then
        if balls2[1].next == true and balls2[2].next == true
        and points >= 10
        then
            balls2[1] = nil
            balls2[1]= Ball2(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-50,-10)))
            --   balls[1].next = false
            --    numBalls1 = numBalls1 + 1

            balls2[2] = nil
            balls2[2]= Ball2(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-50,-10)))
            --    balls[i].next = false
            --numBalls1 = numBalls1 + 1
            --   ba =  #balls
            balls2[1].next = false
            balls2[2].next = false
        end
    end
    for i = 1, #balls2
    do
        --[[ if balls2[i].next == true-- and #balls2 < 3
        then
        balls2[#balls2+1]= Ball2(1, Vec2(math.random(100,WIDTH - 100) * (350/WIDTH), HEIGHT* (350/WIDTH)), Vec2(0,-20), Vec2(0, math.random(-20,-10)))
        balls2[i].next = false

    end
        --level 2
        print(balls2[i].p:getX() .. " " .. g1.locx *( 350/WIDTH))
        if points > 5
        then
        balls2[i].fnet = Vec2(0,math.random(-40,-20))
    end
        ]]
        if math.abs(balls2[i].p:getX() - (g1.locx * 350/WIDTH)) < (balls2[i].size/2 * (350/WIDTH)) + 10 and balls2[i].p:getY()< 80
        then
            lost = 1

        end
    end
    -- print(xloc)
    if points > 5 and points < 10
    then
        print("LEVEL 2")
        balls2[1].fnet = Vec2(0,math.random(-40,-20))
    end
    if points > 10 and points < 15
    then
        print("LEVEL 3")
        for i = 1, #balls2
        do
            balls2[i].fnet = Vec2(0,math.random(-40,-20))
        end
    end

    if points > 15-- and points < 15
    then
        print("LEVEL 4")
        for i = 1, #balls2
        do
            balls2[i].fnet = Vec2(0,-40)
        end
    end
    if lost ==0
    then
        pushStyle()
        fill(255, 0, 0)
        textMode(CENTER)
        font("AmericanTypewriter-Bold")
        fontSize(100)
        text(points, WIDTH/2, HEIGHT/2)
        popStyle()
    end
    pushStyle()
end

function b1BtnTouched()
    g1.locx = g1.locx + 10
end
function b2BtnTouched()
    g1.locx = g1.locx - 10
end
function fireBtnTouched()
    local x = g1.locx * (350/WIDTH)
    particles[#particles + 1] = Particle(1,Vec2(x,50), Vec2(0,100), Vec2(0,1))
end

function selectOnlyOneIncChoice(touch)
    if Survival:touched(touch) and Survival:getState() == 1 then
        currModeChoice = 1
        Highscore:deselect()
    elseif Highscore:touched(touch) and Highscore:getState() == 1 then
        currModeChoice = 2
        Survival:deselect()


    end
end

function map(value, x1, x2, y1, y2)
    m = (y2 - y1) / (x2 - x1)     -- slope
    b = y1 - m * x1               -- y-intercept
    return (m * value + b)
end
function worldToScreen(xW, yW)
    local xS = map(xW, xWorldMin, xWorldMax, xScreenMin, xScreenMax)
    local yS = map(yW, yWorldMin, yWorldMax, yScreenMin, yScreenMax)
    return xS, yS
end
function worldToScreenX(xW)
    local xS = map(xW, xWorldMin, xWorldMax, xScreenMin, xScreenMax)

    return xS
end

Survival Mode:

High Score Mode:

My second game is battleship. When the game initializes, 4 ships are placed at random: 1 four piece ship, 2 three piece ships, and 1 two piece ship. You have 25 chances to find all parts of the ships.

CODE
--# Main
-- Battleship

-- Use this function to perform your initial setup
function initializeBattleShip()


    circles = {}
    boardBS = 7
    bor1= Board(boardBS,1)
    bor2 = Board(boardBS,2)
    bor3 = Board(boardBS,3)
    ships = {}

    win = false

    buildShip(3)
    buildShip(3)
    buildShip(4)
    buildShip(2)
    hit = vec2 (0,0)
    shipsHit= {}
    tries= 26
    ready = -1 * #ships
    qwerty=0 -- variable that makes it restart until no overlap
    parameter.boolean("hint", false)
    print("Welcome to BattleShip. You have 3 ships to find. One 4 units, one 3, and one 2. You have " .. tries-1 .. " guesses")
    print("Feel free to ask for a hint. The first time you do so you will lose 5 guesses. Then you could do it unlimited times")
    parameter.boolean("reveal",false)
    k= #ships
    BSRestart= Button2("Main Menu", vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 600),-1 , 200,60)
    BSReplay= Button2("Play Again", vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 600),-1 , 200,60)
end

-- This function gets called once every frame
function runBattleShip()
    pushStyle()
    if qwerty <10
    then
        shipsHit={}
        circles={}
        print("hi")
    end
    qwerty=qwerty+1
    for i = 1, #ships
    do
        if ships[i] == ships[i+1] or ships[i] == ships[i+2] or ships[i] == ships[i+3] or ships[i] == ships[i+4]or
        ships[i] == ships[i+5] or ships[i] == ships[i+6] or ships[i] == ships[i+7]or ships[i] == ships[i+8] or ships[i] == ships[i+9] or ships[i] == ships[i+10] or ships[i] == ships[i+11] or ships[i] == ships[i-1] or ships[i] == ships[i-2] or ships[i] == ships[i-3] or ships[i] == ships[i-4]or
        ships[i] == ships[i-5] or ships[i] == ships[i-6] or ships[i] == ships[i-7]or ships[i] == ships[i-8] or ships[i] == ships[i-9] or ships[i] == ships[i-10] or ships[i] == ships[i-11]
        then
            ships={}
            buildShip(3)
            buildShip(3)
            buildShip(4)
            buildShip(2)
        end
    end
    
    background(40, 40, 50)
    bor1:draw()


    -- This sets the line thickness
    strokeWidth(5)

    for i = 1, #circles
    do

        pushStyle()
        noStroke()
        fill(0)
        ellipse(circles[i].x, circles[i].y, 20)
        popStyle()

    end

    if #shipsHit > 0
    then
        for i = 1, #shipsHit
        do
            fill(255,0,0)
            noStroke()
            rect(bor1:left() + (shipsHit[i].x -.5) * 50, bor1:bottom() + (shipsHit[i].y - .5) * 50, bor1.size * 50/ bor1.size)
        end
    end


    if tries <= 1 -- if lose
    then
        background(0)
        pushStyle()
        fill(255, 0, 0)
        textMode(CENTER)
        font("AmericanTypewriter-Bold")
        fontSize(100)
        text("YOU LOSE", WIDTH/2, HEIGHT/2)
        popStyle()
        bor2:draw()
        for i = 1, #ships
        do
            fill(255,0,0)
            noStroke()
            rect(bor2:left() + (ships[i].x -.5) * 50, bor2:bottom() + (ships[i].y - .5) * 50, bor2.size * 50/ bor2.size)
        end
        for i = 1, #shipsHit
        do
            fill(0, 255, 82, 255)
            noStroke()
            rect(bor2:left() + (shipsHit[i].x -.5) * 50, bor2:bottom() + (shipsHit[i].y - .5) * 50, bor2.size * 50/ bor2.size)
        end
    elseif #shipsHit == k
    then
        background(0)
        pushStyle()
        fill(255, 0, 0)
        textMode(CENTER)
        font("AmericanTypewriter-Bold")
        fontSize(100)
        text("YOU WIN!!", WIDTH/2, HEIGHT/2)
        popStyle()
        win = true
        reveal= false
    end
    if reveal ==true
    then
        bor3:draw()


        for i = 1, #ships
        do
            fill(255,0,0)
            noStroke()
            rect(bor3:left() + (ships[i].x -.5) * 50, bor3:bottom() + (ships[i].y - .5) * 50, bor3.size * 50/ bor3.size)
        end
        for i = 1, #shipsHit
        do
            fill(0, 255, 82, 255)
            noStroke()
            rect(bor3:left() + (shipsHit[i].x -.5) * 50, bor3:bottom() + (shipsHit[i].y - .5) * 50, bor3.size * 50/ bor3.size)
        end
    end

    sprite("Documents:battleship",WIDTH/2,700,WIDTH - 200,100)

    BSRestart:draw()
    BSReplay:draw()
    if BSRestart:getState() == 1
    then
        initializeBattleShip()
        BSReplay:deselect()
        Battleship:deselect()
        Go:deselect()
        gameMode=0
        BSRestart:deselect()
        popStyle()

        resetAllButtons=true
    end
    if BSReplay:getState() == 1
    then
        initializeBattleShip()
        BSReplay:deselect()
    end
    popStyle()
end


vert = 1
hor = 2
function buildShip(size)
    position = math.random (1,2)
    if position == 1
    then
        x = math.random ( 1,boardBS)

        y = math.random(1,boardBS-size+1)
    elseif position == 2
    then
        x = math.random ( 1,boardBS-size+1)

        y = math.random(1,boardBS)
    end
    for i = 1,size
    do
        if position == 1
        then
            ships [#ships+1] = vec2(x,y+i -1)
        elseif  position == 2
        then
            ships [#ships+1] = vec2(x+i-1,y)
        end
    end
end

function shipHit(ship)
    for i = 1 , k
    do
        if shipsHit[i].x == ship.x and shipsHit[i].y == ship.y
        then
            return true
        else
            return false
        end
    end
end

Battleship

In Etch-A-Sketch, there are two ways to draw. First, one has the option to draw using the parameters on the side. Additionally, one can draw with their fingers. The color could be changed by clicking on the colors on the bottom, and it could be erased by pressing the bottom right corner, or shaking the device. Additionally, you could put a picture on the screen by pressing the camera button.

CODE
local function deviceShaking() -- function that recognizes shaking
    local acceleration = UserAcceleration
    local intensity    = 1 -- adjust min. shaking intensity to trigger this event!
    if UserAcceleration.x > intensity or acceleration.y > intensity or acceleration.z > intensity then
        _deviceShakeUpdatedAt = ElapsedTime
        _deviceShakeBegunAt   = _deviceShakeBegunAt or ElapsedTime

        -- first shake triggers listening process
        -- listen if shaking continues for [x] seconds then device is considered shaking on purpose
        if (ElapsedTime - _deviceShakeBegunAt) >= .5 then return true end
    end
    if _deviceShakeUpdatedAt and (ElapsedTime > (_deviceShakeUpdatedAt + .5)) then
        _deviceShakeBegunAt   = nil
        _deviceShakeUpdatedAt = nil
    end
    return false
end



function initializeEtchSketch()
    FrontCam() -- turns camera on because one could input live picture into app

    local camWidth, camHeight = spriteSize( CAMERA )
    asd=true -- in order to make it start at current touch later
    new=false
    x= WIDTH
    col=0 --color
    y=HEIGHT
    o=0 --joystick x
    g=0 --joystick y
    reset = false
 

    parameter.integer("xjoystick",1,x)
    parameter.integer("yjoystick",1,y)

    -- Creates a button to clear the output

    parameter.integer("startmiddle",1,2)
    parameter.integer("drawCircle",1,2)
    parameter.integer("radius",1,200)
    radius=50

    backingMode(RETAINED)

    print("Slide so can see all parameters. This is an etch-a-sketch! if you wish to start in the middle, switch the startmiddle button to the right, then back. if you wish to reset, switch swipetoreset to the right then back. if you wish to draw a circle, pick a radius then swipe drawcircle to the right then back. Enjoy!")
    Front= Button("Front Camera", vec2(WIDTH/2-275, HEIGHT-30), color(255,0,0), color(0,255,0), WIDTH/4,60,1)
    Front.action =  function() FrontCam()
    end
    Back= Button("Back Camera", vec2(WIDTH/2-86, HEIGHT-30), color(255,0,0), color(0,255,0), WIDTH/4,60,1)
    Back.action=  function() BackCam()
    end
    TakePic= Button("Take Pic", vec2(WIDTH/2+103, HEIGHT-30), color(255,0,0), color(0,255,0), WIDTH/4,60,1)
    TakePic.action=  function() takePhoto()
    end

    MainMenuES= Button("Main Menu", vec2(WIDTH/2+290, HEIGHT-30), color(255,0,0), color(0,255,0), WIDTH/4-30,60,1)
    MainMenuES.action=  function() MainMenu1()
    end
end

function runEtchSketch()
    displayMode(STANDARD)
    if o== nil
    then
        o=xjoystick
    end
    pushStyle()
    displayMode(STANDARD)
    local camWidth, camHeight = spriteSize( CAMERA )
    if asdf < 10
    then

        asd= true
        xjoystick= nil
        yjoystick = nil
        reset = true
        reset = false
        background(0)
    end
    Front:draw()
    Back:draw()
    TakePic:draw()
    MainMenuES:draw()
    asdf=asdf+1
    if (col==0)  then --set color of line based on touch
        stroke(255)
    elseif (col ==1) then
        stroke(255,0,0)
    elseif (col ==2) then
        stroke(255, 255, 255, 255)
    elseif (col ==3) then
        stroke(0,0,255)
    elseif (col ==4) then
        stroke(0,255,0)
    elseif (col ==5) then
        stroke(255, 0, 222, 255)
    elseif (col ==6) then
        stroke(249, 255, 0, 255)
    elseif (col ==7) then
        stroke(141, 0, 255, 255)
    end
    if (col==0)  then
        fill(255)
    elseif (col ==1) then
        fill(255,0,0)
    elseif (col ==2) then
        fill(255, 255, 255, 255)
    elseif (col ==3) then
        fill(0,0,255)
    elseif (col ==4) then
        fill(0,255,0)
    elseif (col ==5) then
        fill(255, 0, 222, 255)
    elseif (col ==6) then
        fill(249, 255, 0, 255)
    elseif (col ==7) then
        fill(141, 0, 255, 255)
    end


    strokeWidth(10)
    if xjoystick~= nil and startmiddle==1
    then
--draw
        line(o, g, xjoystick, yjoystick)
    end

    o=xjoystick
    g=yjoystick
    if (swipeToReset==2) then
        background (0)
        xjoystick=xcurrent
        yjoystick=ycurrent
        radius=50
    end
    if (startmiddle==2) then
        xjoystick= 375
        yjoystick = HEIGHT/2
        background(0)
    end
    if (drawCircle == 2)
    then
        noStroke()
        ellipse(xjoystick,yjoystick,radius)
    end
    noStroke()
    rectMode(CORNER)
    fill(255)
    ellipse(WIDTH-25, 25, 40)
    fill(255,0,0)
    rect(0,0,50,50)
    fill(255, 255, 255, 255)
    rect(51,0,50,50)
    fill(0,0,255)
    rect(102,0,50,50)
    fill(0,255,0)
    rect(153,0,50,50)
    fill(255, 0, 222, 255)
    rect(204,0,50,50)
    fill(249, 255, 0, 255)
    rect(255,0,50,50)
    fill(141, 0, 255, 255)
    rect(306,0,50,50)

    if reset == true or deviceShaking()
    then
        background(0)
        swipeToRestart=2
        reset = false
        swipeToRestart=1
        col=0
        asd= true
        xjoystick= nil
    end

    if capturedImage ~= nil and a1 == true then
        pushStyle()
        spriteMode(CORNER)
        -- rotate(90)
        sprite(capturedImage, 0, 0, WIDTH,HEIGHT)
        popStyle()
        a1=false
    end
    popStyle()
end

function takePhoto()
    -- supportedOrientations(LANDSCAPE_ANY)
    capturedImage = image(CAMERA)
    a1=true
end
function FrontCam()
    cameraSource(CAMERA_FRONT)
    print("front")
end

function BackCam()
    cameraSource(CAMERA_BACK)
end
function TakePicCam()
    takephoto()
end
function MainMenu1()
    initializeEtchSketch()
    EtchSketch:deselect()
    Go:deselect()
    gameMode=0
    popStyle()

    resetAllButtons=true
end

Etch-A-Sketch

In this game, one must hold their finger against the screen, and avoid all boxes. If they hit a box, they lose.

CODE
-- Avoid

function initializeAvoid()
    print("Hello World!")
    xOfSquare=0
    x=0 --starting of square 1
    y=0
    x2=WIDTH -- starting of sqaure 2
    y2=HEIGHT
    x3=WIDTH/2 -- starting of square 3
    y3=0
    x4= WIDTH/2
    y4= HEIGHT
    x5=0
    y5=HEIGHT/2
    scoreA=0
    continue1=true -- when true game mode is on
    start1=true -- does not start until switch
    parameter.integer("numsquares", 1,5) -- num of moving squares
    parameter.integer("SizeOfBox",50,150)
    parameter.boolean("start",false) -- starts game
    parameter.boolean("restart",false) -- restarts game ]]
    numsquares=4 -- initial num squares
    Level =6
    SizeOfBox=75
    AvoidRestart= Button2("Main Menu", vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 600),-1 , 200,60)
    AvoidReplay= Button2("Play Again", vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 600),-1 , 200,60)
    AvoidPrep=0
end

-- This function gets called once every frame
function runAvoid()
    if AvoidPrep == 0
    then
        AvoidReplay:setState(1)
        AvoidReplay:setState(-1)
    end
    AvoidPrep=1
    pushStyle()
    rectMode(CENTER)
    if scoreA > 25
    then
        level = 8
        numsquares=5
        print("level 2")
    end

    if start1 ==true
    then
        displayMode(FULLSCREEN)
    end

    if continue1 == false
    then
        start1=false
        displayMode(STANDARD)
    end
    if x<WIDTH-SizeOfBox and continue1 == true and start1==true -- if square didnt reach end of screen
    then
        background(0)
        fill(255, 0, 0, 255)
        fontSize(200)
        textMode(CENTER)
        text(math.floor(scoreA).. " Points",WIDTH/2,HEIGHT/2)
        fill(255)
        rect(x,y,SizeOfBox,SizeOfBox)
        -- move box
        x=x+Level
        y=y+Level
    else
        fill(0)
        rect(WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
        x=0
        y=math.random(0,HEIGHT- 300)
    end
    if x2>SizeOfBox and continue1==true and start1==true and numsquares>= 2
    then
        fill(255)
        rect(x2,y2,SizeOfBox,SizeOfBox)
        x2=x2-Level
        y2=y2-Level
    else
        fill(0)
        x2=math.random(WIDTH-100,WIDTH)
        y2=math.random(100, HEIGHT)

    end

    if y3< HEIGHT-SizeOfBox and continue1==true and start1==true and numsquares>= 3
    then
        fill(255)
        rect(x3,y3,SizeOfBox,SizeOfBox)
        y3=y3+ 2*Level
    else
        fill(0)
        x3=math.random(0,WIDTH)
        y3=0

    end
    if y4> SizeOfBox and continue==true and start1==true and numsquares>= 4
    then
        fill(255)
        rect(x4,y4,SizeOfBox,SizeOfBox)
        y4=y4- 2*Level
    else
        fill(0)
        x4=math.random(0,WIDTH)
        y4=HEIGHT
    end

    if x5<WIDTH-SizeOfBox and continue1==true and start1==true and numsquares>= 5
    then
        fill(255)
        rect(x5,y5,SizeOfBox,SizeOfBox)

        x5=x5+Level
        y5=y5

    else
        fill(0)

        x5=0
        y5=math.random(0, HEIGHT)

    end

    if continue1 == false
    then
        background(255, 0, 0, 255)
        textSize(200)

        fill(0)
        fontSize(100)
        text("YOU LOSE", WIDTH/2,HEIGHT/2)
        fontSize(50)
        text("Final Score:" .. math.floor(scoreFinal) ,WIDTH/2, HEIGHT/2-80)
        text("Time Ellapsed " .. math.floor((scoreFinal)/2) .. " Seconds", WIDTH/2, HEIGHT/2+80)
        scoreA=0
        AvoidRestart:draw()
        AvoidReplay:draw()
        if AvoidRestart:getState() == 1
        then
            start1=true
            continue1= true
            AvoidReplay:deselect()
            Avoid:deselect()
            Go:deselect()
            gameMode=0
            AvoidRestart:deselect()
            popStyle()

        resetAllButtons=true
        end
        if AvoidReplay:getState() == 1
        then
            start1=true
            continue1= true
            AvoidReplay:deselect()
        end
    end
    if restart == true
    then
        continue1=true
        restart=false
        start1= false
    end
    if xOfSquare>0 and continue == true
    then
        pushStyle()
        fill(255, 255, 255, 255)
        ellipse(xOfSquare,YOfSquare,30)
        popStyle()
    end
    popStyle()
en

AVOID

Classic game of tic-tac-toe

CODE
-- Tic Tac Toe Final
function initializeTicTacToe()
    b1T= TTTboard()
    V1 = Vec2(80,200)
    player1= {}
    player2= {}
    turn = 0
    Row3 = {0, 0, 0}
    Row2 = {0, 0, 0}
    Row1 = {0, 0, 0}
    board = {Row1, Row2, Row3}
--board is array of arrays
    winning1=nil
    winning2=nil
    makesure= 0
    TTTRestart= Button2("Main Menu", vec2(0, 0), 20, Vec2(WIDTH/2 -150 , 600),-1 , 200,60)
    TTTReplay= Button2("Play Again", vec2(0, 0), 20, Vec2(WIDTH/2 +150 , 600),-1 , 200,60)
    makesure2=0
end


function RunTicTacToe()

    -- This sets a dark background color
    background(40, 40, 50)
    stroke(0)
    noStroke()

    if makesure <20 --once launched properly
    then
        player1= {}
        player2= {}
        turn = 0
        Row3 = {0, 0, 0}
        Row2 = {0, 0, 0}
        Row1 = {0, 0, 0}
        board = {Row1, Row2, Row3}
    end

    makesure=makesure+1
    b1T:draw()
    for i = 1, #player1
    do
        if player1[i] ~= player2[i-1] and player1[i] ~= player2[i-2] and player1[i] ~= player2[i-3] and player1[i] ~= player2[i-4] and player1[i] ~= player2[i-5]
        then
            pushStyle()
            fill(255, 255, 255, 255)
            ellipseMode(CENTER)
            ellipse(player1[i].x * WIDTH/3 - .5* WIDTH/3, player1[i].y *  HEIGHT/3 - .5* WIDTH/3, 100)
            --    print("hi")
            popStyle()
        end
    end
--if new location, drop piece
    for i = 1, #player2
    do
        if player2[i] ~= player1[i-1] and player2[i] ~= player1[i-2] and player2[i] ~= player1[i-3] and player2[i] ~= player1[i-4] and player2[i] ~= player1[i-5]
        then
            pushStyle()
            noStroke()
            fill(255, 0, 0, 255)
            ellipseMode(CENTER)
            ellipse(player2[i].x * WIDTH/3 - .5* WIDTH/3, player2[i].y *  HEIGHT/3 - .5* WIDTH/3, 100)
            --    print("hi")
            popStyle()
        end
    end --if new location, drop piece
   
    if xWin()
    then
        background(0)
        pushStyle()
        fill(255, 0, 0)
        textMode(CENTER)
        font("AmericanTypewriter-Bold")
        fontSize(80)
        text("PLAYER 1 WINS!", WIDTH/2, HEIGHT/2)

        stroke(255,0,0)
        popStyle()
        --strokeWidth(10)
        if makesure2>20
        then
            TTTRestart:draw()
            TTTReplay:draw()
        end
        makesure2=makesure2+1
        if TTTRestart:getState() == 1
        then
            initializeTicTacToe()
            TTTReplay:deselect()
            TicToe:deselect()
            Go:deselect()
            gameMode=0
            TTTRestart:deselect()

            resetAllButtons=true
        end
        if TTTReplay:getState() == 1
        then
            initializeTicTacToe()
            TTTReplay:setState(0)
        end

    end

    if oWin()
    then
        background(0)
        pushStyle()
        fill(255, 0, 0)
        textMode(CENTER)
        font("AmericanTypewriter-Bold")
        fontSize(80)
        text("PLAYER 2 WINS", WIDTH/2, HEIGHT/2)
        popStyle()
        if makesure2>20
        then
            popStyle()
            TTTRestart:draw()
            TTTReplay:draw()
        end
        makesure2=makesure2+1
        if TTTRestart:getState() == 1
        then
            initializeTicTacToe()
            TTTReplay:deselect()
            TicToe:deselect()
            Go:deselect()
            gameMode=0
            TTTRestart:deselect()
            popStyle()

            resetAllButtons=true
        end
        if TTTReplay:getState() == 1
        then
            initializeTicTacToe()
            TTTReplay:setState(0)
            popStyle()
        end
    end

    if #player1 ==5 and xWin ~= true
    then
        background(0)
        pushStyle()
        fill(255, 0, 0)
        textMode(CENTER)
        font("AmericanTypewriter-Bold")
        fontSize(80)
        text("TIE", WIDTH/2, HEIGHT/2)
        popStyle()
        if makesure2>40
        then
            TTTRestart:draw()
            TTTReplay:draw()
        end
        makesure2=makesure2+1
        if TTTRestart:getState() == 1
        then
            initializeTicTacToe()
            TTTReplay:deselect()
            TicToe:deselect()
            Go:deselect()
            gameMode=0
            TTTRestart:deselect()
        end
        if TTTReplay:getState() == 1
        then
            initializeTicTacToe()
            TTTReplay:setState(0)
        end
    end
end

function spaceEmpty()
    empty= true
    for i = 1,100
    do
        --  if currentPos ~= player1[i] or
        if currentPos == player2[i] or currentPos == player1[i]
        then
            empty = false

        end
    end
    return empty
end

function xWin()
    -- check all combinations for a win and if one is met, return true

    if board[1][1] == board[1][2] and board[1][2] == board[1][3] and board[1][1] == 1 then      -- bottom row
        winning1= vec2(1,1)
        winning2= vec2(3,1)
        return true

    elseif board[2][1] == board[2][2] and board[2][2] == board[2][3] and board[2][1] == 1 then  -- middle row
        winning1= vec2(1,2)
        winning2= vec2(3,2)
        return true

    elseif board[3][1] == board[3][2] and board[3][2] == board[3][3] and board[3][1] == 1 then  -- top row
        winning1= vec2(1,3)
        winning2= vec2(3,3)
        return true

    elseif board[1][1] == board[2][1] and board[2][1] == board[3][1] and board[1][1] == 1 then  -- left column
        winning1= vec2(1,1)
        winning2= vec2(1,3)
        return true
    elseif board[1][2] == board[2][2] and board[2][2] == board[3][2] and board[1][2] == 1 then  -- center column
        winning1= vec2(2,1)
        winning2= vec2(2,3)
        return true
    elseif board[1][3] == board[2][3] and board[2][3] == board[3][3] and board[1][3] == 1 then  -- right column
        winning1= vec2(3,1)
        winning2= vec2(3,3)
        return true
    elseif board[1][1] == board[2][2] and board[2][2] == board[3][3] and board[1][1] == 1 then  -- diagonal (+slope)
        winning1= vec2(1,1)
        winning2= vec2(3,3)
        return true
    elseif board[1][3] == board[2][2] and board[2][2] == board[3][1] and board[3][1] == 1 then  -- diagonal (-slope)
        winning1= vec2(1,3)
        winning2= vec2(3,1)
        return true
    else
        return false
    end
    print("x")
end

function oWin()
    -- check all combinations for a win and if one is met, return true

    if board[1][1] == board[1][2] and board[1][2] == board[1][3] and board[1][1] == -1 then      -- bottom row
        return true
    elseif board[2][1] == board[2][2] and board[2][2] == board[2][3] and board[2][1] == -1 then  -- middle row
        return true
    elseif board[3][1] == board[3][2] and board[3][2] == board[3][3] and board[3][1] == -1 then  -- top row
        return true
    elseif board[1][1] == board[2][1] and board[2][1] == board[3][1] and board[1][1] == -1 then  -- left column
        return true
    elseif board[1][2] == board[2][2] and board[2][2] == board[3][2] and board[1][2] == -1 then  -- center column
        return true
    elseif board[1][3] == board[2][3] and board[2][3] == board[3][3] and board[1][3] == -1 then  -- right column
        return true
    elseif board[1][1] == board[2][2] and board[2][2] == board[3][3] and board[1][1] == -1 then  -- diagonal (+slope)
        return true
    elseif board[1][3] == board[2][2] and board[2][2] == board[3][1] and board[3][1] == -1 then  -- diagonal (-slope)
        return true
    else
        return false
    end
    print("o")
end

Tic-Tac-Toe

This game is modeled after the classic wack-a-mole game at arcades. You have 30 seconds to hit as many moles as you could.

CODE
-- Wackamole

-- Use this function to perform your initial setup
function initializeWackAMole()
    nextHole= true
    Wackscore = 0
    lastHole=3
    WMDone=false
    holes= {}
    holes[1]= Hole(150,100,120,60,1)
    holes[2]= Hole(WIDTH/2,100,120,60,1)
    holes[3]= Hole(WIDTH/2+ (WIDTH/2 -150),100,120,60,1)
    holes[4]= Hole( 150+ (WIDTH/2 -150)/2,400,100,50,1)
    holes[5]= Hole( WIDTH/2+ (WIDTH/2 -150)/2,400,100,50,1)
    holes[6]= Hole( WIDTH/2,650,80,40,1)
--make all holes
    time=30
    WMRestart= Button2("Main Menu", vec2(0, 0), 20, Vec2(WIDTH/2 -300 , 600),-1 , 200,60)
    WMReplay= Button2("Play Again", vec2(0, 0), 20, Vec2(WIDTH/2 +300 , 600),-1 , 200,60)
end
-- This function gets called once every frame
function runWackAMole()

    pushStyle()
    if readLocalData("highscoreWack",0)< Wackscore
    then
        saveLocalData("highscoreWack", Wackscore)
    end
    HighScoreWack = readLocalData("highscoreWack",0)
--show highscore
    time = time - (1/60)
   
    background(13, 250, 32, 255)
    
    fill(255, 0, 0, 255)
    fontSize(50)
    textMode(CENTER)
    text(math.floor(Wackscore).. " Points",WIDTH/2+200,HEIGHT-40)
    text(math.floor(time).. " seconds",WIDTH/2-200,HEIGHT-40)


    for i = 1, #holes
    do
        holes[i]:draw()
    end
    -- Do your drawing here

    if nextHole == true -- if pressed on mole
    then
        numHole = math.random(1,#holes)
        for i =1,7
        do
            if numHole == lastHole -- different than previous
            then
                numHole = math.random(1,#holes)
            end
        end
        lastHole=numHole
        holes[numHole]:setState(2)
        nextHole= false
    end

    i = i +1 --score
    if time<0
    then
        WMDone= true
        background(0, 101, 255, 255)
        textSize(200)

        fill(118, 58, 58, 255)
        fontSize(100)
        --text("YOU LOSE", WIDTH/2,HEIGHT/2)
        -- fontSize(50)
        text("Final Score:" .. math.floor(Wackscore) ,WIDTH/2, HEIGHT/2)
        fontSize(60)
        text("High Score:" .. math.floor(HighScoreWack) ,WIDTH/2, HEIGHT/2 -100)
        -- text("Time Ellapsed " .. math.floor((scoreFinal)/2) .. " Seconds", WIDTH/2, HEIGHT/2+80)
        WMReplay:draw()
        WMRestart:draw()
    end

    if WMRestart:getState() == 1
    then
        initializeWackAMole()
        WMReplay:deselect()
        WackAMole:deselect()
        Go:deselect()
        gameMode=0
        WMRestart:deselect()
        popStyle()

        resetAllButtons=true
    end
    if WMReplay:getState() == 1
    then
        initializeWackAMole()
        WMReplay:deselect()
    end
    WMReplay:draw()
    WMRestart:draw()
    popStyle()
end

Wack-a-mole

Pick one of three emojis to find among the tongue out emoji. Every time you find i you get more time and more points.

CODE
function initializeEmoji()
    EMOx="😛" --apple version of emoji
    print(EMOx)

    nextEmoji = true
    emoji= {}
    pointsEmo=0
    Emoj1= Button2E("😇", vec2(0, 0), 20, Vec2(WIDTH/2 -300 , 500),-1 , 150,60)
    Emoj2= Button2E("😂",vec2(0, 0), 20, Vec2(WIDTH/2  , 500), -1, 150,60)

    Emoj3= Button2E("😩",vec2(0, 0), 20, Vec2(WIDTH/2 + 300 , 500), -1, 150,60)
    start=false
    EMOJItime = 10
    EMRestart= Button2("Main Menu", vec2(0, 0), 20, Vec2(WIDTH/2 -300 , 600),-1 , 200,60)
    EMReplay= Button2("Play Again", vec2(0, 0), 20, Vec2(WIDTH/2 +300 , 600),-1 , 200,60)
    --fill(255,0,0)
end

-- This function gets called once every frame
function runEmoji()


    if start == false
    then
        background(0)
        Emoj1:draw()
        Emoj2:draw()
        Emoj3:draw()
--if no emoji picked, allow user to pick
        if Emoj1:getState() == 1
        then
            EMOx ="😇"
            start=true
        end
        if Emoj2:getState() == 1
        then
            EMOx ="😂"
            start=true
        end
        if Emoj3:getState() == 1
        then
            EMOx ="😩"
            start=true
        end
    else
        if EMOJItime>0
        then
            EMOJItime = EMOJItime - 1/40
        end
        if nextEmoji == true
        then
            emoji[#emoji +1] = Otherdude()
            nextEmoji = false
            EMOJItime= 10
        end
        -- This sets a dark background color
        background(40, 40, 50)

        --[[for i =1,WIDTH
        do
        for k = 1,HEIGHT
        do
        --  strokeWidth(5)
        --   fill(255, 0, 0, 255)
        --     fontSize(50)
        textMode(CENTER)
        text(x,i,k)
    end
    end]]
        -- This sets the line thickness
        for i = 5,WIDTH,20
        do
            for k = 5,HEIGHT-20,20
            do
                drawMessage("😛",i,k)
            end
        end

        emoji[#emoji]:draw()
        print(pointsEmo)
    end
    if EMOJItime<=0
    then
        EMOJItime= 0
        background(0)
        pushStyle()
        textMode(CENTER)
        fill(255)
        font("AmericanTypewriter")
        fontSize(22)
        text("LOSE", WIDTH/2, HEIGHT/2)
        text("Score is " .. pointsEmo, WIDTH/2, HEIGHT/2 -20)
        popStyle()
        EMReplay:draw()
        EMRestart:draw()
    end
    pushStyle()
    textMode(CENTER)
    fill(255)
    font("AmericanTypewriter-Bold")
    fontSize(10)
    text("Time Left: ".. math.floor(EMOJItime), WIDTH/2, HEIGHT-10)
    popStyle()

    if EMRestart:getState() == 1
    then
        initializeEmoji()
        EMReplay:deselect()
        Emoji:deselect()
        Go:deselect()
        gameMode=0
        EMRestart:deselect()
        popStyle()
        resetAllButtons=true
    end
    if EMReplay:getState() == 1
    then
        initializeEmoji()
        EMReplay:deselect()
    end

end



function drawMessage(str, x, y)
    pushStyle()
    --   fill(255, 0, 0)
    textMode(CENTER)
    font("AmericanTypewriter-Bold")
    fontSize(20)
    text(str, x, y)
    popStyle()
end

Emoji Game

Mouse doesn’t show so I circled the emoji with assist touch

Start typing and press Enter to search