PicoPicoGameEngine

Quick Links

ピコピココード

g=ppgraph
sin=math.sin
cos=math.cos
atan2=math.atan2
pi=math.pi
B=ppscreen:size()
rand=math.random

p=ppoffscreen.new()
p:create(5,5)
p:pivot(2.5,2.5)
p:fill(1,2,3,4,g.cyan)
p:fill(2,0,1,2,g.cyan)
p:fill(2,2,1,2,g.blue)
p:fill(0,4,5,1,g.cyan)
p:scale(8,8)
p:pos(
 g:layout(
   p:size(),true,true,B))
p:move(p:pivot()*10)
my=p

cur=ppoffscreen.new()
cur:create(48,48)
cur:circle(24,24,8,g.white)
cur:pivot(24,24)

col={
  g.red,
  g.blue,
  g.green,
  g.yellow
}

local star={}
for i=1,100 do
  local w=2
  local t=pprect(0,0,w,w)
  t.z=rand(10,50)/50
  t.x=rand(0,B.width-w)
  t.y=rand(0,B.height-w)
  t.col=col[rand(1,#col)]
  t.d=pppoint()
  table.insert(star,t)
end

function movestar()
  local r=my:rotate()
  q=pppoint()
  q.x=sin(r)
  q.y=-cos(r)
  for i,v in ipairs(star)
  do
    v:move(-q*4*v.z+v.d)
    if v.x<-v.width then
      v.x=B.width
    end
    if v.y<-v.height then
      v.y=B.height
    end
    if v.x>B.width then
      v.x=-v.width
    end
    if v.y>B.height then
      v.y=-v.height
    end
    g:fill(v,v.col)
  end
end

function start()
  dir=ppvkey:dir(4)
  delta=ppvkey:delta()
  q=delta
  d=q:length()
  if d~=0 then
    q=q/q:length()
    q=atan2(q.y,q.x)
    my:rotate(q+pi/2)
  end
  cur:pos(my:pos())
  cur:move(my:pivot())
  cur:move(delta/2)
  cur:move(-cur:pivot())
  if dir>=0 then
    cur:draw()
  end
  movestar()
  my:draw()
end