I’m trying to implement a scoring system but I can’t figure out how I should go about it. I have three questions but let me explain what I’m trying to accomplish first.
In cargo bot (example pic below) you put sprites from the toolbox to the Prog then press the play button and it carries out the order. In my code I have 3 sprites. I want to give them all values, let’s say 1,2 and 3 to be simple. Once I put them in the three big circles I want to press a button and it will add up the value of the three sprites to the score text.
So the questions are
1)how do I give my sprites a value?
2)how do I incorporate a button that waits for you to have all 3 circles filled then becomes selectable?
3)how do I make that selected button add up the 3 values of the sprites while displaying it to the score text?
If anyone has any links or tutorials that would help answer my questions post them , it will be much appreciated.
Less confusing with a visual
function setup()
displayMode(FULLSCREEN)
tab1={vec3(320,290,0),vec3(445,290,0),vec3(570,290,0)} -- position of large circles and occupied
tab2={vec2(835,335),vec2(835,265),vec2(835,195),} -- position of small circles
tab3={vec3(835,335,.5),vec3(835,265,.5),vec3(835,195,.5)} -- position of sprite and scaler value
tab4={
asset.builtin.Planet_Cute.Character_Princess_Girl,
asset.builtin.Planet_Cute.Character_Boy,
asset.builtin.Planet_Cute.Character_Cat_Girl,
}
imageSize = spriteSize(tab4[1])
tab5={}
for z=1,#tab4 do
a=math.random(#tab4)
table.insert(tab5,tab4[a])
table.remove(tab4,a)
end
scaler = .50
cnt=0
loop=0
end
function draw()
background(40, 40, 50)
sprite(asset.builtin.Cargo_Bot.Play_Button, 400,100)
pushStyle()
fontSize(30)
fill(40,40,50)
fill(40,40,50)
popStyle()
fontSize(30)
--Score text
text("0",400,400)
delay()
strokeWidth(5)
fill(128)
for a,b in pairs(tab1) do
ellipse(b.x, b.y, 100)
end
for a,b in pairs(tab2) do
ellipse(b.x, b.y, 50)
delay()
end
for z=1,cnt do
pushMatrix()
zLevel(.3)
sprite(tab5[z],tab3[z].x,tab3[z].y,imageSize*tab3[z].z)
popMatrix()
end
end
function delay()
if cnt<#tab5 then
loop=loop+1
if loop>60 then
cnt=cnt+1
loop=0
end
end
end
function touched(touch)
if touch.state==BEGAN then
pos=0
for a,b in pairs(tab3) do
if touch.x>b.x-40 and touch.x<b.x+40 and touch.y>b.y-40 and
touch.y<b.y+40 then
b.z=1 -- scaler
pos=a
for c,d in pairs(tab1) do
if b.x==d.x and b.y==d.y then
d.z=0
end
end
end
end
end
if pos==0 then
return
end
if touch.state==MOVING then
tab3[pos].x=tab3[pos].x+touch.deltaX
tab3[pos].y=tab3[pos].y+touch.deltaY
end
if touch.state==ENDED then
for a,b in pairs(tab1) do
if tab3[pos].x>b.x-55 and tab3[pos].x<b.x+55 and
tab3[pos].y>b.y-55 and tab3[pos].y<b.y+55 and
b.z==0 then
tab3[pos].x=b.x
tab3[pos].y=b.y
b.z=1
return
end
end
tab3[pos].x=tab2[pos].x
tab3[pos].y=tab2[pos].y
tab3[pos].z=.5
end
end