Log In  

0

does anybody know how to test what type of object and instance is?

for example I have this code

obj=
{
 x =0,
 y =0,
 w =8,
 h =8,
 dx=0,
 dy=0,
 si=0,
 st=0,
 tx=0, 
 ty=0,
 tw=8,
 th=8,
 tv=false
 cc={}
}

--create
function obj:create()
 pad.__index = self
 return setmetatable({} self)
end

--update
function obj:update()

 --get fractional value
 local pdx = self.dx - flr(self.dx) 
 local pdy = self.dy - flr(self.dy)

 --move and collide
 for i=1,flr(pnt_dist(x,y,flr(dx),flr(dy))) do
  local inst =  coll_get(self)

  self.x+=sgn(dx)
  self.y+=sgn(dy)
  if   (inst ~= nil) self:collision(inst) break end
 end 

 x =mid(0,x,127) 
 y =mid(8,y,147)
 dx=dx+pdx
 dy=dy+pdy
end

function obj:render()
 sspr(self.tx, self.ty, self.tw, self.th, self.x, self.y, self.w, self.h)
end

function bal:collision(o,n)
 if o == pad then --here I want to check if the o is of type pad
  --bounce
 end
end

bal = obj:create(63,63)

function _update()
 bal:update()
end

function _draw()
 bal:render()
end
P#48982 2018-02-04 18:05

Log in to post a comment

user:
password:

New User | Account Help
:: New User
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-02-21 03:25 | 0.207s | 1572k | Q:9