Jump to content

Programming methodology

ūüíéYueūüíé

107 views

 

When I write programming, that word makes me a lot of weight, I don't really do anything, the engine has everything I need and the only thing that is done is to give instructions that I really think is not programming, because everything is already programmed.

Well, I think I've improved a bit and I share how I'm doing things. There's probably another better way to do this, but I feel comfortable with what I'm doing.

I'm working with object-oriented programming, in this case I create a class called PickObjects. This class contains what is necessary for my character to kick boxes. 


Translated with www.DeepL.com/Translator

 

 

--################################################
--## Proyecto 	: 	Pawn.
--## Sitio Web 	: 	https://www.iris3dgames.xyz
--## Fichero 	: 	PickObjects.lua
--## Scripter   : 	Yue Rexie.
--################################################
--## Notas	:   Fichero Clase PickObjects.
--##			    Interactuar con objetos.
--################################################


PickObjects={}

function PickObjects:New(pivotRay)

	local this={}
	this.ray 	= nil
	this.pivotRay 	= nil
	this.pickInfo 	= nil 
	this.player   	= nil
	this.posPlayer	= Vec3()
	this.posPivotRay= Vec3()
	this.forceKick  = nil
	
	function this:Start(player)
		
		self.pivotRay = pivotRay
		self.player   = player


		self.pivotRay:SetParent(self.player,true )
		


	end

	function this:Update()


		self:RayObject()
		self:KickObject()
		
	end


	function this:RayObject()


		self.posPlayer   = self.player:GetPosition(true)
		self.posPivotRay = self.pivotRay:GetPosition(true)

		self.pickInfo = PickInfo()
	
		self.ray = World:GetCurrent():Pick(self.posPlayer,self.posPivotRay,self.pickInfo,0.1)
		System:Print(self.ray)
	end

	function this:KickObject()

		if self.ray then
			if self.pickInfo.entity:GetKeyValue("name") == "Cajas" then
				if 	Window:GetCurrent():KeyDown(Key.E) then 
				
					self.forceKick  = Vec3(0,1000, 500)
					self.forceKick = Transform:Vector(self.forceKick, self.player, nil)
					self.pickInfo.entity:AddPointForce( self.forceKick,self.player:GetPosition(true))
				end
			end
		end

	end


	return this

end

Already in another file called EPlayer, import this class and create an object. The EPlayer file is the one that is hooked to an entity in the map editor.

 

--################################################
--## Proyecto 	: 	Pawn.
--## Sitio Web 	: 	https://www.iris3dgames.xyz
--## Fichero 	: 	Player.lua
--## Scripter   : 	Yue Rexie.
--################################################
--## Notas	:   Fichero enganchado Al Player.
--##			    Definición del comportamiento.
--################################################


--## Class.
import "Scripts/Player/Class/Player.lua"
import "Scripts/Player/Class/HudPlayer.lua"
import "Scripts/Player/Class/PickObjects.lua"

--## Properties Script.
Script.pivotPlayer  = nil --Entity "Pivot Player"
Script.pivotCamera  = nil --Entity "Pivot Camera"
Script.cameraPlayer = nil --Entity "Camera Player"
Script.pivotRay  = nil --Entity "Pivot Ray"


function Script:Start()
	
	--## Player.
	self.Player = Player:New()
	self.Player:StartCameraOrbit(self.entity,self.pivotPlayer, self.pivotCamera,self.cameraPlayer)

	--## Hud Player.
	self.Hud = HudPlayer:New()
	self.Hud:Start()
		

	--## Pick Objects.
	self.Pick = PickObjects:New(self.pivotRay)
	self.Pick:Start(self.entity )



end



function Script:UpdateWorld()
	
	self.Player:Update()
	self.Pick:Update()


end


--[[
function Script:UpdatePhysics()
	
end
]]

--[[
--This can be used to select which objects an entity collides with.  This overrides collision types completely.
function Script:Overlap(e)
	return Collision:Collide
end
]]


function Script:Collision(entity, position, normal, speed)
	


end



function Script:Draw()
	


end


--[[
function Script:DrawEach(camera)
	
end
]]


function Script:PostRender(context)
	if myMenu.guiHide == 1 then 
		self.Hud:Draw()
	end
end


--[[
--This function will be called when the entity is deleted.
function Script:Detach()
	
end
]]

--[[
--This function will be called when the last instance of this script is deleted.
function Script:Cleanup()
	
end
]]


--This function will be called upon completion of a one-shot animation played with the PlayAnimation() command.
function Script:EndAnimation(sequence)
	self.Player.forceJump = 0

	--## Init Jump.
	if sequence == 2 then 
		
		self.Player.animation = self.Player.idle
		self.typeAnim = 1
		self.Player.blend = 1500
		
		self.Player.velAnim = 0.03
		self.Player.forceJump = 7.0
	end 
	--## Falling.
	if sequence == 1 then
			self.Player.animation = self.Player.idle
			self.typeAnim = 0
			self.Player.blend = 100
	end

	
end

The previous working method helps me to have everything organized, to fragment the program into many smaller pieces and therefore it is more fun to do things.

I'm one of those who likes to start all the scripts and start from scratch, I feel I have more control over the workflow. In that case the Main.lua file is as follows:

 

--################################################
--## Proyecto 	: 	Pawn.
--## Sitio Web 	: 	https://www.iris3dgames.xyz
--## Fichero 	: 	Main.lua
--## Scripter   : 	Yue Rexie.
--################################################
--## Notas	: Fichero principal de entrada
--##			  al programa en Script Lua.
--################################################




--## Class.
import "Scripts/Class/App.lua"
import "Scripts/Class/Menu.lua" 

--## New Object App.
local myApp = App:New("Pawn 0.0 | Alpha")
myApp:InitGraphics(800,600)

--## Load Menu Level 1.
 worldMenu = myApp:CreateWorld()
myApp:LoadMap("menu")

--## Load Level 1.
 worldLevel1 = myApp:CreateWorld()
myApp:LoadMap("start")

--## New Object Menu.
myMenu = Menu:New()
myMenu:CreateGUI()
menuVisible = nil

Texture:SetDetail(0)
local myWorld = nil

--## Check World.
if myMenu.level == 0 then
	myWorld = worldMenu
elseif myMenu.level == 1 then
	myWorld = worldLevel1 
end	
myMenu.guiHide = 1
myApp:SetLightQuality(2)
myApp:FadeIn(myWorld,myMenu)





while myApp:Exit() == false and myMenu:Update(myApp,myWorld,myMenu) == false  do
	menuVisible = myMenu.guiHide -- Script Camera attach.

	--## Check World.
	if myMenu.level == 0 then
		myWorld = worldMenu
		
	elseif myMenu.level == 1 then
		--Window:GetCurrent():HideMouse()
		myWorld = worldLevel1
		worldMenu:Clear()

	end	
	

	
	myApp:UpdateWorld(myWorld)

end
--myApp:FadeOut(myWorld,myMenu)

It is the same principle, two classes are imported in the header, and objects are created on the basis of these classes.

That's all to share, my working methodology, I know it's not perfect and maybe there's another better way to do things. 

  • Like 1


0 Comments


Recommended Comments

There are no comments to display.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Blog Entries

    • By Haydenmango in Snowboarding Development Blog 6
      So I've been researching snowboarding lately to get an idea of what animations and mechanics I need to create for my game.  I have learned lots of interesting things since I've only seen snow once or twice in my entire life and have never even tried snowboarding or any other board sports (skateboarding, surfing, etc.) for that matter.
       
      Snowboarding tricks are quite interesting as they are mostly derived from skateboarding.  Snowboarding tricks pay homage to their equivalent skating tricks by sharing many concepts and names.  For example basic grabs in snowboarding share the same concepts and names as skateboarding: indy, mute, method, stalefish, nosegrab, and tailgrab.  Something interesting to note is in snowboarding you can grab Tindy or Tailfish but this is considered poor form since these grabs can't be done on a skateboard (due to the board not being attached to the skaters feet) and grabbing these areas is generally something a novice snowboarder does when failing or "half-assing" a normal grab.  Check out this diagram to see how grabs work -
       
       
      So, after reading lots of text descriptions for tricks I was still confused by what all these terms meant and how they were actually applied.  So my next step was to look up these tricks actually being done and I found some really cool videos showing off how to do various tricks.  This video in particular is the best reference material I've found as it contains nearly every trick back to back with labeled names and some tweaks -
       
      Sadly my rigged model doesn't handle leg animations with the snowboard that well so I can't animate as many tricks as I want to.  Regardless there will still be around 15 total grab/air tricks in the game.  Now it's time for me to stop procrastinating and start animating!  
    • By jen in jen's Blog 3
      I thought I would share my experience on this; if you're working on Multiplayer, you will need to protect your packets. The solution is simple, let's go through how we can achieve this by implementing what Valve calls "challenge codes". (Some reading on the topic from Valve here: https://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol#Challenge_response).
      Disclaimer: this doesn't cover other security techniques like authoritative server or encryption.
      So, I've worked on Border Recon last year (I think) and I needed a way to protect my server/client packets. There was no need for me to re-invent the wheel, I just had to copy what Valve has had for a  long time - challenge  codes.
      The idea behind challenge codes is similar to Captcha, but not exactly. Think of it like this: for every packet submitted to the server, it must be verified - how? By requiring the client to solve challenges our server provides.
      To implement this we need to have the following:
      A randomised formula in the server i.e.: a = b * c / d + e or a = b / c + d - e, be creative - it can be any combination of basic arithmetic or some fancy logic you like and can be however long as you want - do consider that the longer the formula, the more work your server has to do to make the computation.  Copy the same formula to the client. A random number generator.  So the idea here is:
      (Server) Generate a random number (see 3 above) of which the result would become the challenge code, (Server) run it through our formula and record the result. (Client) And then, we hand over the challenge code to the client to solve (an authentic client would have the same formula implemented in its program as we have on the server). For every packet received from the player, a new challenge code is created (and the player is notified of this change by the server in response). For every other packet, a new challenge code is created. (Client) Every packet sent to the server by the client must have a challenge code and its answer embedded.  (Server receives the packet) Run the challenge code again to our formula and compare the result to the answer embedded on the client's packet. (Server) If the answers are different, reject the packet, no changes to the player's state. The advantage(s) of this strategy in terms of achieving the protection we need to secure our server:
      - For every packet sent, new challenge code is created. Typically, game clients (especially FPS) will update its state in a matter of ms so even if a cheater is successful at sniffing the answer to a challenge code it would be invalidated almost instantaneously. 
      - Lightweight solution. No encryption needed. 
      Disadvantage(s):
      - The formula to answering the challenge code is embedded to the client, a cheater can de-compile the client and uncover the formula. Luckily, we have other anti-cheat solutions for that; you can implement another anti-cheat solution i.e. checking file checksums to verify the integrity of your game files and more (there are third-party anti cheat solutions out there that you can use to protect your game files).
       
       
       
    • By Josh in Josh's Dev Blog 4
      New commands in Turbo Engine will add better support for multiple monitors. The new Display class lets you iterate through all your monitors:
      for (int n = 0; n < CountDisplays(); ++n) { auto display = GetDisplay(n); Print(display->GetPosition()); //monitor XY coordinates Print(display->GetSize()); //monitor size Print(display->GetScale()); //DPI scaling } The CreateWindow() function now takes a parameter for the monitor to create the window on / relative to.
      auto display = GetDisplay(0); Vec2 scale = display->GetScale(); auto window = CreateWindow(display, "My Game", 0, 0, 1280.0 * scale.x, 720.0 * scale.y, WINDOW_TITLEBAR | WINDOW_RESIZABLE); The WINDOW_CENTER style can be used to center the window on one display.
      You can use GetDisplay(DISPLAY_PRIMARY) to retrieve the main display. This will be the same as GetDisplay(0) on systems with only one monitor.
√ó
√ó
  • Create New...