PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
v=ppscreen
B=v:size()
Bw=B.width

se=ppsemml[1]

function cell(v)
local r=pprect(0,0,16,16)
r.v=v
r.draw=function(s,p,y)
  g:pos(p)
  g:move(s)
  g:move(0,y)
  g:print(s.v)
end
return r
end

function line(x,y)
local r=pprect(x,y,64,64*3)
r.d=0
r.v={}
r.sval=1
r.run=false
r.stop=true
for i=1,7 do
local c
c=cell(i)
c.y=i*16-16
r.v[#r.v+1]=c
end
r.draw=function(s)
  for i=1,8 do
  s.d=s.d+1
  if not s.run 
  and s.sval==s:ind() then
    local a
    local b
    a=math.floor((s.d-1)/16)
    b=math.floor((s.d-2)/16)
    if a~=b then
      s.d=s.d-1
      s.stop=true
    end
  end
  if s.d>#s.v*16 then
   s.d=s.d-#s.v*16
  end
  end
  v:viewport(s)
  g:scale(4)
  g:pos(s/4)
  for i,v in ipairs(s.v)
  do
    v:draw(s/4,s.d)
    v:draw(s/4,s.d-#s.v*16)
  end
  g:scale(1)
end
r.ind=function(s,i)
local t
t=#s.v-math.floor((s.d+8)/16)
t=((t+1)%#s.v)+1
return t
end
r.val=function(s,i)
return s.v[s:ind(i)].v
end
return r
end

l={}
dx=(Bw-192)/2
l[#l+1]=line(dx,32)
l[#l+1]=line(dx+64,32)
l[#l+1]=line(dx+128,32)

bt=ppbutton("STOP")
bt.height=64
p=g:layout(bt,true,true,B)
bt:pos(p)
stopbt=bt

bt=ppbutton("BET")
bt.height=64
bt.y=stopbt.y
betbt=bt

idx=4
coin=10
bet=0
run=false

function stopval()
l[1].sval=math.random(1,7)
l[2].sval=math.random(1,7)
l[3].sval=math.random(1,7)
end

function start()
v:viewport(B)
for i,v in ipairs(l) do
v:draw()
end
v:viewport(B)
local lv={}
for i,v in ipairs(l) do
if v.stop then
g:pos(v)
g:move(0,-16)
lv[i]=v:val(1)
--g:print(lv[i])
end
end
if run and #lv>=3 then
run=false
local atari=0
if lv[1]==lv[2]
and lv[2]==lv[3] then
atari=100
elseif lv[1]==lv[2] then
atari=2
elseif lv[2]==lv[3] then
atari=2
elseif lv[1]==lv[3] then
atari=2
end
coin=coin+bet*atari
bet=0
end
if stopbt:idle(pptouch()) then
  if idx>3 then
    if bet>0 and #lv==3 then
    idx=1
    for i,v in ipairs(l) do
      v.run=true
      v.stop=false
    end
    run=true
    stopval()
    lv={}
    se:play("o6cgc")
    end
  else
    l[idx].run=false
    idx=idx+1
    se:play("o7c")
  end
end
stopbt:draw()
if betbt:idle(pptouch()) then
if coin>0 and #lv==3 then
bet=bet+1
coin=coin-1
se:play("o7cd")
end
end
betbt:draw()
g:pos(0,32)
g:print(bet)
g:pos(0,64)
g:print(coin)
end