Hello.
For an assignment piece I am coding an app that controls many of the annoying bits of a board game I have made - not important but background info.
Basically, I had a menu set up but I didn’t like it and I am now redesigning it.
Here is the main code chunk:
-- BoardGame
-- Use this function to perform your initial setup
aa = math.random(8)
bb = math.random(8)
cc = math.random(8)
dd = math.random(8)
sw = 1024
crysis = 255
hamish = 60
sh = 768
sniper = 0
watch = 0
--beginning
a = 1
--menu
b = 2
--good
c = 3
--one disk, reshuffle, roll of a dice
d = 4
--what is it, how to play, victory, aligning rings
e = 5
--good
f = 6
--right
g = 7
--wrong
h = 9
--evil
i = 10
--one disk
j = 11
--what is it
k = 12
--roll of a dice
l = 13
m = 14
n = 15
o = 16
p = 17
q = 18
dir1 = "x"
dir2 = "x"
dir3 = "x"
dir4 = "x"
mainfont = 100
secfont = 70
thirfont = 5
country = 0
land = 0
object = 0
poss = 0
cmessage = 1
bmessage = 0
ore = "x"
dice = "x"
memprev = b
GAME_STATE = a
gconseq = 0
gending = 0
gresult = 0
econseq = 0
eending = 0
eresult = 0
rconseq = 0
rending = 0
rresult = 0
wconseq = 0
wending = 0
wresult = 0
touch = t
--'Roll again'
--'Switch positions with anyone on the board if you desire so'
--'Turn a disk as many spaces as you like'
--'Move back to where you were at the beginning of this turn'
--'Miss a turn'
--'The player to your left can turn a disk as many spaces as they like'
function setup()
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
end
function draw()
gresult = math.random(3)
if gresult == 3 then
gconseq = 'Switch positions with anyone on the board if you desire so'
elseif gresult == 2 then
gconseq = 'Roll again'
elseif gresult == 1 then
gconseq = 'Turn a disk as many spaces as you like'
end
eresult = math.random(3)
if eresult == 3 then
econseq = 'Move back to where you were at the beginning of this turn'
elseif eresult == 2 then
econseq = 'Miss a turn'
elseif eresult == 1 then
econseq = 'The player to your left can turn a disk as many spaces as they like'
end
wresult = math.random(4)
if wresult == 1 or wresult == 2 then
wconseq = 'Move back to where you were at the beginning of this turn'
elseif wresult == 3 or wresult == 4 then
wconseq = 'Miss a turn'
end
rresult = math.random(4)
if rresult == 1 or rresult == 2 then
rconseq = 'Turn a disk as many spaces as you like'
elseif rresult == 3 or rresult == 4 then
rconseq = 'Roll again'
end
bmessage = math.random(3)
mainfont = 100
secfont = 70
thirfont = 400
country = math.random(16)
if country == 1 then
country = 'Australia'
elseif country == 2 then
country = 'the United States'
elseif country == 3 then
country = 'Pakistan'
elseif country == 4 then
country = 'India'
elseif country == 5 then
country = 'Russia'
elseif country == 6 then
country = 'Japan'
elseif country == 7 then
country = 'Thailand'
elseif country == 8 then
country = 'Syria'
elseif country == 9 then
country = 'South Africa'
elseif country == 10 then
country = 'Germany'
elseif country == 11 then
country = 'France'
elseif country == 12 then
country = 'Scotland'
elseif country == 13 then
country = 'England'
elseif country == 14 then
country = 'New Zealand'
elseif country == 15 then
country = 'Canada'
else
country = 'Argentina'
end
poss = math.random(16)
if poss == 1 then
poss = 'carrots'
elseif poss == 2 then
poss = 'gold'
elseif poss == 3 then
poss = 'iron'
elseif poss == 4 then
poss = 'grain'
elseif poss == 5 then
poss = 'pearls'
elseif poss == 6 then
poss = 'marble'
elseif poss == 7 then
poss = 'money'
elseif poss == 8 then
poss = 'drumsticks'
elseif poss == 9 then
poss = 'weapons'
elseif poss == 10 then
poss = 'vehicles'
elseif poss == 11 then
poss = 'wheel barrows'
elseif poss == 12 then
poss = 'iPads'
elseif poss == 13 then
poss = 'pencils'
elseif poss == 14 then
poss = 'bananas'
elseif poss == 15 then
poss = 'cattle'
else
poss = 'cotton'
end
--oscillating alpha
crysis = crysis + (sniper)
if crysis == 255 then
sniper = -5
end
if crysis == 0 then
sniper = 5
end
hamish = hamish + (watch)
if hamish == 60 then
watch = -5
end
if hamish == 0 then
watch = 5
end
if GAME_STATE == a then
background(91, 45, 81, 255)
fill(255, 255, 255, 255)
fontSize(mainfont)
font("AmericanTypewriter-Bold")
text('CIRCUMFERENCE', sw/2, sh/2+100)
fontSize(secfont)
fill(196, 196, 196, 255)
rect(sw/2-270, sh/2-150, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2-270+5, sh/2-150+5, 530, 90)
fill(196, 196, 196, crysis)
text('Touch To Start', sw/2, sh/2-100)
end
--MENU SCREEN
if GAME_STATE == b then
background(91, 45, 81, 255)
fontSize(50)
fill(196, 196, 196, 255)
rect(sw/2-580, sh/2+250, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2-575, sh/2+255, 530, 90)
fill(255, 255, 255, 255)
text('Good', sw/2-250, sh/2+300)
fill(196, 196, 196, 255)
rect(sw/2-580, sh/2+100, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2-575, sh/2+105, 530, 90)
fill(255, 255, 255, 255)
text('Right', sw/2-250, sh/2+150)
fill(196, 196, 196, 255)
rect(sw/2-580, sh/2-50, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2-575, sh/2-45, 530, 90)
fill(255, 255, 255, 255)
text('Wrong', sw/2-250, sh/2)
fill(196, 196, 196, 255)
rect(sw/2-580, sh/2-200, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2-575, sh/2-195, 530, 90)
fill(255, 255, 255, 255)
text('Evil', sw/2-250, sh/2-150)
fill(196, 196, 196, 255)
rect(sw/2-580, sh/2-350, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2-575, sh/2-345, 530, 90)
fill(255, 255, 255, 255)
text('Dice Roll', sw/2-250, sh/2-300)
fill(196, 196, 196, 255)
rect(sw/2+40, sh/2+250, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2+45, sh/2+255, 530, 90)
fill(255, 255, 255, 255)
text('What is it?', sw/2+310, sh/2+300)
fill(196, 196, 196, 255)
rect(sw/2+40, sh/2+100, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2+45, sh/2+105, 530, 90)
fill(255, 255, 255, 255)
text('How to Play', sw/2+310, sh/2+150)
fill(196, 196, 196, 255)
rect(sw/2+40, sh/2-50, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2+45, sh/2-45, 530, 90)
fill(255, 255, 255, 255)
text('Aligning Disks', sw/2+310, sh/2)
fill(196, 196, 196, 255)
rect(sw/2+40, sh/2-200, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2+45, sh/2-195, 530, 90)
fill(255, 255, 255, 255)
text('Victory', sw/2+310, sh/2-150)
fill(196, 196, 196, 255)
rect(sw/2+40, sh/2-350, 540, 100)
fill(0, 0, 0, 255)
rect(sw/2+45, sh/2-345, 530, 90)
fill(255, 255, 255, 255)
text('Shuffle', sw/2+310, sh/2-300)
end
end
function touched(t)
--taptoplay
if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
and CurrentTouch.y > sh/2-145 and CurrentTouch.y < sh/2-145+90 and GAME_STATE == a then
GAME_STATE = b
end
--back button
if CurrentTouch.x > sw/2+305 and CurrentTouch.x < sw/2+305+90
and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE ~= b then
GAME_STATE = b
end
--good
if CurrentTouch.x > 0 and CurrentTouch.x < sw/2-40
and CurrentTouch.y > sh/2+255 and CurrentTouch.y < sh/2+345 then
GAME_STATE = c
Good:draw()
end
end
I put most of it in the main tab, but right at the bottom you will notice there is a class call (will include class in reply) but whenever I call it, instead of blocking out the screen with delightful green, a quick tap brings a fast flickering image, a held tap lowers the rate and after a few seconds of hold it will then be blocked in.
I know there is a bunch of problems with the code like variables that do not make sense and all the rest - it is okay. I have them all in a scrap tab which was the old version I am converting (will include). If anyone can help with this flickering it would be much appreciated!