PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
B=ppscreen:size()
Bw=B.width
Bh=B.height
sin=math.sin
cos=math.cos
pi=math.pi

floor=math.floor
rand=math.random

o=ppoffscreen.new()
o:create(128,32)

o.defchar
=function(o,i,d)
local t
local dx=(i-1)*8
t="0123456789ABCDEF"
local
function f(o,dx,s,k)
  local c
  for y=0,7 do
    local r,n
    for i=0,1 do
    n=y*2+1+i
    r=s:sub(n,n)
    r=t:find(r)-1
    for x=0,3 do
      local p,z
      p=(r%2)*255
      r=floor(r/2)
      z=3-x+i*4
      c=o:pixel(z+dx,y)
      c[k]=p
      c.a=255
      o:pixel(z+dx,y,c)
    end
    end
  end
end
f(o,dx,d[1],"r")
f(o,dx,d[2],"g")
f(o,dx,d[3],"b")
end

t={
{"FFFFFFFFFFFFFFFF",
 "FFFFBFFFFFFBFFFF",
"0000000000000000"},
{"0028400040000000",
"FFFCFCF0F8E8E0C3",
"3CFEFEFEFEFC7800"},
{"0000000004001000",
"0000000000000000",
"0000400000000000"},
{"FFFDD8A9A9818181",
"FFFDF8F9F9FA8A82",
"01032675757A7A02"},
{"FFBF1B1515818181",
"FFBF1F9F9F5F5141",
"80C064AEAE5E5E40"},
{"8383878099C5CEFF",
"878F9F98FBFFFFFF",
"770F7F187B3B3100"},
{"4141E10199A373FF",
"E1F1F919DFFFFFFF",
"EEF0FE18DEDC8C00"}}

for i,d in ipairs(t)
do
  o:defchar(i,d)
end

o:hflip()
o:bind()
tex=o:texture()

function rot(r)
 local t
 t=pppoint(
  sin(r),-cos(r))
 local r
 r=pprect(0,0,1,1)
 r:pos(t*18*2)
 return r
end

p=ppoffscreen.new()
p:create(64,64)
p:tileSize(64,64)
p:fill(p:size(),g.blue)
p:pivot(16,16)
u=g:layout(p,true,true,B)
u:move(0,64)
p:pos(u)
p:move(20*32,20*32)
p.idle=function(p)
local mv
local k=ppkey
mv=""
if k.up()
then
  mv="f"
elseif k.down()
then
  mv="b"
elseif k.right()
then
  mv="r"
elseif k.left()
then
  mv="l"
end
if rbt.touch and
   lbt.touch then
  mv="f"
elseif rbt.touch
then
  mv="r"
elseif lbt.touch
then
  mv="l"
elseif #pptouch()>0
then
  mv="f"
end
if mv=="f" then
  p.x=p.x+sin(r)*2
  p.y=p.y-cos(r)*2
elseif mv=="b" then
  p.x=p.x-sin(r)*2
  p.y=p.y+cos(r)*2
elseif mv=="r" then
  p:rotate(r+0.02)
elseif mv=="l" then
  p:rotate(r-0.02)
end
end

e=ppoffscreen.new()
e:create(64,64)
e:tileSize(64,64)
e:lock()
g:scale(4)
g:tileSize(8,8)
g:put(0,0,4,tex)
g:put(8,0,5,tex)
g:put(0,8,6,tex)
g:put(8,8,7,tex)
g:scale(1)
e:unlock()
e:tile(1)
e:pos(u)
ct=pprect(
  u.x+32,u.y+32,1,1)

b=pprect(0,0,100,100)
b:move(0,Bh-100)
rbt=b

b=pprect(0,0,100,100)
b:move(Bw-100,Bh-100)
lbt=b

m=ppmap.new()
m:addLayer("layer")
m:mapSize(300,300)
m:tileSize(8,8)
m:texture(tex)
m:fill(0,0,300,300,3)
m:fill(20,20,280,280,1)
m:box(20,20,280,280,2)
for y=24,280-8,8 do
for x=24,280-8,8 do
m:fill(x,y,4,4,2)
end
end
for i=0,1000 do
 x=rand(20,280)
 y=rand(20,280)
 m:tile(x,y,2)
end
m:scale(4)

t=ppoffscreen.new()
t:create(100,100)
t:circle(50,50,50)
t:paint(50,50)
t:alpha(196)
btimg=t

function start()
  t=pptouch()
  rbt:hitCheck(t)
  lbt:hitCheck(t)
  r=p:rotate()
  x=p.x
  y=p.y
  p:idle()
  t=pppoint(p)
  m:pivot(t/4)
  m:rotate(
    pi*2-p:rotate())
  m:pos(ct-t/4)
  r=pprect(
     -17,-17,34,34)
  r:move(t/32)
  m:clip(r.x,r.y,
    r.x+r.width,
    r.y+r.height)
  m:draw()
  t=rot(
    p:rotate()-pi/4)
  t:move(p:pos())
  t1=t
  t=rot(
    p:rotate()+pi/4)
  t:move(p:pos())
  t2=t
  if m:tile(t1/32)~=1
  or m:tile(t2/32)~=1
  then
   p.x=x
   p.y=y
  end
  e:draw()
  btimg:pos(rbt)
  btimg:draw()
  g:pos(rbt)
  g:move(12,44)
  g:print(
    "RIGHT",g.blue)
  btimg:pos(lbt)
  btimg:draw()
  g:pos(lbt)
  g:move(20,44)
  g:print(
    "LEFT",g.blue)
end