ユーザ用ツール

サイト用ツール


lua:managerclass

文書の過去の版を表示しています。


概要

  • Managerクラスを作りたい。
  • 余談ですが、これいつも自分が作るゲームフレームワークをLuaに書き直した形です。
  • ガバッと配列を確保して作る感じですね。
  • 種類ごとにマネージャクラスを作る考えです。
  • C言語ならポインタでリンクリストっぽくして作るとかはできるし無駄がないんですが、管理が煩雑になるのと、当たり判定がないオブジェクトが存在するんだからそういうオブジェクトのための構造も用意しておくほうが無駄がないという考えでこうなってます。

実装

chr ={
  cnt=400,
  x={},
  y={},
  dx={},
  dy={},
  life={},

  init = function(self)
    for i=1,self.cnt do
      self.x[#self.x+1]=0
      self.y[#self.y+1]=0
      self.dx[#self.dx+1]=0
      self.dy[#self.dy+1]=0
      self.life[#self.life+1]=0
    end
  end,

  set = function(self)
    for i=1,self.cnt do
      if self.life[i] == 0 then
        self.x[i]=120
        self.y[i]=68
        self.dx[i] = math.random(-1000,1000)*0.0001
        self.dy[i] = math.random(-1000,1000)*0.0001
        self.life[i]=1
        break
      end
    end
  end,

  move = function(self)
    for i=1,self.cnt do
      if self.life[i] > 0 then
        self.x[i]=self.x[i]+self.dx[i]
        self.y[i]=self.y[i]+self.dy[i]
      end
    end
  end,
  
  draw = function(self)
    for i=1,self.cnt do
      if self.life[i] > 0 then
        spr(1,self.x[i],self.y[i],
            14,1,0,0,1,1)
      end
    end
  end
}
t=0
function BOOT()
  chr:init()
  chr:set()
end

function TIC()
  cls(13)
  chr:move()
  chr:draw()
  t=t+1
end
lua/managerclass.1751957860.txt.gz · 最終更新: by machiaworx