@Jarc Are you talking about the sprite information or do you want to move the sprites to a different position on the screen.
@dave1707 the sprites and the sprites info into a different table but just the sprites in the 1st row.
@Jarc You can have something like this when you press the Ready button. Any sprite that’s in the top row ( has a y2 value of 290 ), move that table entry into another table. Just make sure you set something so you’ll only do it once or you’ll move the info again.
This code goes in the touched function for the ready button.
for z=1,#show do
if show[z].y2==290 then
table.insert(tabA,show[z])
end
end
@dave1707 how do I get the score value from the 1st row to appear 1 at time, left to right instead of the total amount when the ready button is pressed.
Like if the values in the 1st row were 1,3,4,5
Then the score text would display 1 then 4 then 8 then 13 (because it’s adding each slot)
@Jarc Instead of adding all the values, move each value into a table. Instead of displaying the total, display the sum as you go through the table. Use a counter to delay the adding.
@dave1707 Thanks, I figured it out but how do I get it to score in order. From left to right.
function setup()
et=ElapsedTime
count=0
score=0
round=0
s=require("socket")
readybuttonSize=vec2(500,500)
buttonSize=vec2(500,600)
slot = { vec2(835,335), vec2(835,265), vec2(835,195), vec2(900,335), vec2(900,265), vec2(900, 195) }
gameslot = { vec3(320,290,0), vec3(445,290,0), vec3(570,290,0), vec3(695,290,0), vec3(380,180,0), vec3(505,180,0), vec3(630,180,0) }
deck = {{n=asset.builtin.Planet_Cute.Character_Princess_Girl,
v=5,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Character_Boy,
v=6,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Character_Cat_Girl,
v=8,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Gem_Green,
v=9,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Gem_Orange,
v=10,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Gem_Blue,
v=2,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Star,
v=3,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Tree_Short,
v=4,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Heart,
v=5,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Chest_Closed,
v=1,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Enemy_Bug,
v=7,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Ramp_South,
v=3,x1=0,y1=0,x2=0,y2=0,s=.5}}
pick()
imageSize = spriteSize(deck[1].n)
tabB={}
end
function pick()
st=s:gettime()
show={}
temp={}
for z=1,6 do -- temp table of small circles positions
table.insert(temp,slot[z])
end
for z=1,6 do -- pick random name and random circle
a=math.random(#deck)
b=math.random(#temp)
table.insert(show,{name=deck[a],pos=temp[b]}) -- update show table
table.remove(deck,a)
table.remove(temp,b)
end
round=round+1
print("Round ----------- "..round)
for k,v in pairs(show) do
print(v.name,v.pos)
end
for z=1,6 do
show[z].x1=show[z].pos.x
show[z].y1=show[z].pos.y
show[z].x2=show[z].pos.x
show[z].y2=show[z].pos.y
show[z].v=show[z].name.v
show[z].s=show[z].name.s
show[z].n=show[z].name.n
end
end
function draw()
background(0)
text("round 1", 200, 300)
text("round 2", 250, 200)
text("Tap next to start.",WIDTH/2,HEIGHT-50)
timer(30)
pushStyle()
fontSize(30)
fill(40,40,50)
popStyle()
fontSize(30)
if cc==4 then
rectMode(CENTER)
pushStyle()
noFill()
rect(readybuttonSize.x,readybuttonSize.y,100)
popStyle()
text("Ready",500,500)
if sc==true then
scoring()
end
end
sprite(asset.builtin.Cargo_Bot.Next_Button,buttonSize.x,buttonSize.y)
fill(128)
strokeWidth(5)
for k,v in pairs(slot) do
ellipse(v.x, v.y, 50)
end
for k,v in pairs(gameslot) do
ellipse(v.x, v.y, 100)
end
for z=1,6 do
pushMatrix()
zLevel(.3)
sprite(show[z].n,show[z].x2,show[z].y2,imageSize*show[z].s)
popMatrix()
end
end
function touched(touch)
if touch.state==BEGAN and
touch.x>readybuttonSize.x-75 and touch.x<readybuttonSize.x+75 and touch.y>readybuttonSize.y-50 and touch.y<readybuttonSize.y+50 and cc==4 then
sc=true
end
if touch.state==BEGAN and
touch.x>buttonSize.x-75 and touch.x<buttonSize.x+75 and touch.y>buttonSize.y-50 and touch.y<buttonSize.y+50 and #deck>0 and not done then
pick()
end
if touch.state==BEGAN then
if touch.x>400-50 and touch.x<400+50 and touch.y>500-50 and touch.y<500+50 then
showScore=true
end
pos=0
for a,b in pairs(show) do
if touch.x>b.x2-40 and touch.x<b.x2+40 and touch.y>b.y2-40 and
touch.y<b.y2+40 then
b.s=1 -- scaler
pos=a
for c,d in pairs(gameslot) do
if b.x2==d.x and b.y2==d.y then
d.z=0
end
end
end
end
end
if pos==0 then
return
end
if touch.state==MOVING then
show[pos].x2=show[pos].x2+touch.deltaX
show[pos].y2=show[pos].y2+touch.deltaY
end
if touch.state==ENDED then
--score=0
cc=0
showScore=false
for a,b in pairs(gameslot) do
if show[pos].x2>b.x-55 and show[pos].x2<b.x+55 and
show[pos].y2>b.y-55 and show[pos].y2<b.y+55 and
b.z==0 then
show[pos].x2=b.x
show[pos].y2=b.y
b.z=1
for c,d in pairs(show) do
if d.x1~=d.x2 and d.y1~=d.y2 then
score=score+d.v
cc=cc+1
end
end
return
end
end
show[pos].x2=show[pos].x1
show[pos].y2=show[pos].y1
show[pos].s=.5
end
end
function timer(max)
if st==nil then
return
end
if #deck>0 then
curr=s:gettime()-st
text(string.format("Time remaining %4.1f",max-curr),WIDTH/2,HEIGHT/2)
if curr>max then
pick()
end
end
end
function scoring()
if ElapsedTime-et>1 then
count = count + 1
et=ElapsedTime
end
for z=1,#show do
if show[z].y2==290 then
table.insert(tabB,show[z].v)
end
end
if count==1 then
text(tabB[1],150,500)
end
if count==2 then
text(tabB[1]+tabB[2],150,500)
end
if count==3 then
text(tabB[1]+tabB[2]+tabB[3],150,500)
end
if count==4 then
text(tabB[1]+tabB[2]+tabB[3]+tabB[4],150,500)
end
end
@Jarc I don’t know what you want to go from left to right. All you’re doing is displaying the sum of the values one at a time.
@dave1707 I know but I need the values to display from left to right in order. If the Sprites are positioned chest, bug, heart, star
And the values of the sprites are chest=1, bug=7, heart=5, star=3
I need it to show 1 then 8 then 13 then 16 so it’s in order with the positions.
Right now it’s displaying the values one at a time in a random order.
@Jarc To get them in order, you need to check for the x2,y2 value when you put them in tabB. Check x2,y2 for 320,290 then 445,290 then 570,290 then 695,290. You might have to loop through it a couple of times.
@Jarc Maybe something like this.
for z=1,#show do
if show[z].y2==290 then
if show[z].x2==320 then
tabB[1]=show[z].v
elseif show[z].x2==445 then
tabB[2]=show[z].v
elseif show[z].x2==570 then
tabB[3]=show[z].v
elseif show[z].x2==695 then
tabB[4]=show[z].v
end
end
end
@dave1707 Hey, I want the option to keep none,1 or 2 sprites after the 1st round ends(talking about the sprites in the small slots) so how would I go about doing that? Right now the unused sprites disappear when the 2nd round starts, so the keep none is figured out. Btw when you tap the NEXT Button the 2nd starts, just a recap. I know how to get the unused sprites to stay on screen but not sure how to get the 2nd round sprites to load in the unused slots and not on top of the sprites I want to keep.
Code posted below
function setup()
et=ElapsedTime
count=0
count2=0
playerscore = text
playerscoredim = vec2(150,500)
startscore=false
score=0
round=0
s=require("socket")
readybuttonSize=vec2(500,500)
readybuttonSize2=vec2(700,500)
buttonSize=vec2(500,600)
discardslot={vec2(835,100),vec2(900, 100)}
slot = { vec2(835,335), vec2(835,265), vec2(835,195), vec2(900,335), vec2(900,265), vec2(900, 195) }
gameslot = { vec3(320,290,0), vec3(445,290,0), vec3(570,290,0), vec3(695,290,0), vec3(380,180,0), vec3(505,180,0), vec3(630,180,0) }
deck = {{n=asset.builtin.Planet_Cute.Character_Princess_Girl,
v=5,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Character_Boy,
v=6,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Character_Cat_Girl,
v=8,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Gem_Green,
v=9,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Gem_Orange,
v=10,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Gem_Blue,
v=2,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Star,
v=3,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Tree_Short,
v=4,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Heart,
v=5,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Chest_Closed,
v=1,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Enemy_Bug,
v=7,x1=0,y1=0,x2=0,y2=0,s=.5},
{n=asset.builtin.Planet_Cute.Ramp_South,
v=3,x1=0,y1=0,x2=0,y2=0,s=.5}}
pick()
imageSize = spriteSize(deck[1].n)
tabA={}
tabB={}
tabC={}
tabD={}
end
function pick()
st=s:gettime()
show={}
temp={}
for z=1,6 do -- temp table of small circles positions
table.insert(temp,slot[z])
end
for z=1,6 do -- pick random name and random circle
a=math.random(#deck)
b=math.random(#temp)
table.insert(show,{name=deck[a],pos=temp[b]}) -- update show table
table.remove(deck,a)
table.remove(temp,b)
end
round=round+1
print("Round ----------- "..round)
for k,v in pairs(show) do
print(v.name,v.pos)
end
for z=1,6 do
show[z].x1=show[z].pos.x
show[z].y1=show[z].pos.y
show[z].x2=show[z].pos.x
show[z].y2=show[z].pos.y
show[z].v=show[z].name.v
show[z].s=show[z].name.s
show[z].n=show[z].name.n
end
pickR2=true
end
function draw()
background(0)
text("round 1", 200, 300)
text("round 2", 250, 200)
timer(30)
if startscore==false then
playerscore(0,playerscoredim.x,playerscoredim.y)
end
if showmidscore==true then
playerscore(tabB[1]+tabB[2]+tabB[3]+tabB[4],playerscoredim.x,playerscoredim.y)
end
fontSize(30)
if cc==4 then
rectMode(CENTER)
pushStyle()
noFill()
rect(readybuttonSize.x,readybuttonSize.y,100)
popStyle()
text("Ready",500,500)
if sc==true then
scoring()
end
end
if pickR2==true and cc==3 and sc==true then --Round 2 scoring
rectMode(CENTER)
pushStyle()
noFill()
rect(readybuttonSize2.x,readybuttonSize2.y,100)
popStyle()
text("Ready",700,500)
if sc2==true then
scoring2()
end
end
sprite(asset.builtin.Cargo_Bot.Next_Button,buttonSize.x,buttonSize.y)
fill(128)
strokeWidth(5)
for k,v in pairs(slot) do
ellipse(v.x, v.y, 50)
end
for k,v in pairs(gameslot) do
ellipse(v.x, v.y, 100)
end
for z=1,6 do
pushMatrix()
zLevel(.3)
sprite(show[z].n,show[z].x2,show[z].y2,imageSize*show[z].s)
popMatrix()
end
if boardstay==true then
for z=1,#tabA do
pushMatrix()
zLevel(.3)
sprite(tabA[z].n,tabA[z].x2,tabA[z].y2,imageSize*tabA[z].s)
popMatrix()
end
end
end
function touched(touch)
if touch.state==BEGAN and --READY BUTTON
touch.x>readybuttonSize.x-75 and touch.x<readybuttonSize.x+75 and touch.y>readybuttonSize.y-50 and touch.y<readybuttonSize.y+50 and cc==4 then
sc=true
board()
end
if touch.state==BEGAN and --READY BUTTON FOR ROUND 2
touch.x>readybuttonSize2.x-75 and touch.x<readybuttonSize2.x+75 and touch.y>readybuttonSize2.y-50 and touch.y<readybuttonSize2.y+50 and cc==3 then
sc2=true
end
if touch.state==BEGAN and --NEXT BUTTON
touch.x>buttonSize.x-75 and touch.x<buttonSize.x+75 and touch.y>buttonSize.y-50 and touch.y<buttonSize.y+50 and #deck>0 and not done then
pick()
end
if touch.state==BEGAN then
if touch.x>400-50 and touch.x<400+50 and touch.y>500-50 and touch.y<500+50 then
showScore=true
end
pos=0
for a,b in pairs(show) do
if touch.x>b.x2-40 and touch.x<b.x2+40 and touch.y>b.y2-40 and
touch.y<b.y2+40 then
b.s=1 -- scaler
pos=a
for c,d in pairs(gameslot) do
if b.x2==d.x and b.y2==d.y then
d.z=0
end
end
end
end
end
if pos==0 then
return
end
if touch.state==MOVING then
show[pos].x2=show[pos].x2+touch.deltaX
show[pos].y2=show[pos].y2+touch.deltaY
end
if touch.state==ENDED then
cc=0
showScore=false
for a,b in pairs(gameslot) do
if show[pos].x2>b.x-55 and show[pos].x2<b.x+55 and show[pos].y2>b.y-55 and show[pos].y2<b.y+55 and b.z==0 then
show[pos].x2=b.x
show[pos].y2=b.y
b.z=1
for c,d in pairs(show) do
if d.x1~=d.x2 and d.y1~=d.y2 then
score=score+d.v
cc=cc+1
end
end
return
end
end
show[pos].x2=show[pos].x1
show[pos].y2=show[pos].y1
show[pos].s=.5
end
end
function timer(max)
if st==nil then
return
end
if #deck>0 then
curr=s:gettime()-st
text(string.format("Time remaining %4.1f",max-curr),WIDTH/2,HEIGHT/2)
if curr>max then
pick()
end
end
end
function scoring() --SCORING FOR ROUND 1
startscore=true
if ElapsedTime-et>1 then
count = count + 1
et=ElapsedTime
end
for z=1,#show do
if show[z].y2==290 then
table.insert(tabB,show[z].v)
end
end
for z=1,#show do
if show[z].y2==290 then
if show[z].x2==320 then
tabB[1]=show[z].v
elseif show[z].x2==445 then
tabB[2]=show[z].v
elseif show[z].x2==570 then
tabB[3]=show[z].v
elseif show[z].x2==695 then
tabB[4]=show[z].v
end
end
end
if count==1 then
playerscore(tabB[1],playerscoredim.x,playerscoredim.y)
end
if count==2 then
playerscore(tabB[1]+tabB[2],playerscoredim.x,playerscoredim.y)
end
if count==3 then
playerscore(tabB[1]+tabB[2]+tabB[3],playerscoredim.x,playerscoredim.y)
end
if count>=4 then
playerscore(tabB[1]+tabB[2]+tabB[3]+tabB[4],playerscoredim.x,playerscoredim.y)
end
if count>5 then
boardstay=true
showmidscore=true
end
end
function board()
for z=1,#show do
if show[z].y2==290 then
table.insert(tabA,show[z])
end
end
for z=1,#tabA do
print(tabA[z])
end
if boardstay==true then
for z=1,#tabA do
tabA[z].x1=gameslot[z].x
tabA[z].y1=gameslot[z].y
tabA[z].x2=gameslot[z].x
tabA[z].y2=gameslot[z].y
end
end
end
function scoring2() -- SCORING FOR ROUND 2
showmidscore=false
if ElapsedTime-et>1 then
count2 = count2 + 1
et=ElapsedTime
end
for z=1,#show do
if show[z].y2==180 then
table.insert(tabD,show[z].v)
end
end
for z=1,#show do
if show[z].y2==180 then
if show[z].x2==380 then
tabD[1]=show[z].v
elseif show[z].x2==505 then
tabD[2]=show[z].v
elseif show[z].x2==630 then
tabD[3]=show[z].v
end
end
end
if count2==1 then
playerscore(tabD[1]+tabB[1]+tabB[2]+tabB[3]+tabB[4],playerscoredim.x,playerscoredim.y)
end
if count2==2 then
playerscore(tabD[1]+tabD[2]+tabB[1]+tabB[2]+tabB[3]+tabB[4],playerscoredim.x,playerscoredim.y)
end
if count2==3 then
playerscore(tabD[1]+tabD[2]+tabD[3]+tabB[1]+tabB[2]+tabB[3]+tabB[4],playerscoredim.x,playerscoredim.y)
end
if count2>=4 then
playerscore(tabD[1]+tabD[2]+tabD[3]+tabB[1]+tabB[2]+tabB[3]+tabB[4],playerscoredim.x,playerscoredim.y)
end
end
Just one quick question : is the shortcut for math.randon ; RND ?..
Only if you do this:
function setup()
RND=math.random
print(RND(100))
end
Edited* Disregard