Jump to content
๐Ÿ’ŽYue๐Ÿ’Ž

Working method for programmers

Recommended Posts

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
image.png.4343b9dc6517e0ec24ef49cf072e5308.png

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.



image.png.7608cc400ea47a90ecd606f6b0c2fffe.png

ย 

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.ย 

ย 

  • Like 1

Share this post


Link to post
Share on other sites

ร—
ร—
  • Create New...