💎Yue💎 306 Posted November 15 Lua is a programming language that has the option of simulating the object-oriented programming paradigm. At this point the work method implemented is to work with classes that are implemented through the use of tables. For example in the project I have a file that simulates a class called HudPlayer The content of this file refers to the player's hud, such as his image shown on the bottom right and the respective health, energy, and oxygen bars. And the content of that file is as follows: Hud = {} function Hud:Create() local this = {} this.context = nil this.window = nil this.imgPlayer = nil this.damage = nil this.dEnergy = nil function this:Start() self.context = Context:GetCurrent() self.window = Window:GetCurrent() self.imgPlayer = Texture:Load("Imagenes/HudPlayer.tex") self.damage = 0 self.dEnergy = 0 end this:Start() function this:Draw() self:DrawBarHealth() self:DrawBarEnergy() self:DrawBarOxigen() self:DrawImgPlayer() end function this:DrawImgPlayer() self.context:SetBlendMode(Blend.Alpha) self.context:SetColor(0.941, 0.521, 0.2) self.context:DrawImage(self.imgPlayer,self.window:GetWidth()-185,self.window:GetHeight()-243,339/2,410/2) self.context:SetBlendMode(Blend.Solid) self.context:SetColor(1,1,1) end function this:DrawBarHealth() self.context:SetColor(0.941, 0.321, 0.2) self.context:DrawRect(self.window:GetWidth()-327, self.context:GetHeight()-50,200,50) self.context:SetColor(0.556, 0.082, 0.082) self.context:DrawRect(self.window:GetWidth()-322, self.context:GetHeight()-45,190,40) self.context:SetColor(0.2, 0.2, 0.2) self.context:DrawRect(self.window:GetWidth()-322, self.context:GetHeight()-45,self.damage,40)--Max 190 self.context:SetColor(1,1,1) end function this:DrawBarEnergy() self.context:SetColor(0.133, 0.886, 0.156) self.context:DrawRect(self.window:GetWidth()-322,self.window:GetHeight()-49,190,5) self.context:SetColor(0,0,0) self.context:DrawRect(self.window:GetWidth()-322,self.window:GetHeight()-49,self.dEnergy,5) self.context:SetColor(1,1,1) end function this:DrawBarOxigen() self.context:SetColor(0.176, 0.901, 0.898) self.context:DrawRect(self.window:GetWidth()-322,self.window:GetHeight()-84,190,5) self.context:SetColor(0,0,0) self.context:DrawRect(self.window:GetWidth()-322,self.window:GetHeight()-84,10,5) self.context:SetColor(1,1,1) end function this:AddDamage(damage) self.damage = damage end function this:AddDamageEnergy( energy ) if self.dEnergy < 190 then self.dEnergy = self.dEnergy + energy end end function this:RecoverEnergy( energy ) if self.dEnergy > 0 then self.dEnergy = self.dEnergy - energy end end return ( this ) end So the way to work is to create these files to attach to the project. For example a particle system to simulate a storm on Mars, or similar things. 1 Share this post Link to post Share on other sites
khotan 32 Posted November 22 Interesting and thank you for sharing the code 1 Share this post Link to post Share on other sites