How is my programming format

Started by
7 comments, last by mholmes 11 years, 3 months ago
I tend to be a bit picky as to how I format my code. Just wondering if all this is necessary and also if the some what obvious functions like ApplyGravityForce() and HandleEvents() are even worth while?
class TwoDPlatformController ( MonoBehaviour ): 	
	public walkSpeed   as single     = 6.0F
	public runSpeed	   as single     = 10.0F
	public jumpSpeed   as single     = 8.0F
	public gravity     as single     = 20.0F
	public doubleJump  as bool       = true
	public midAirJumps as int 		 = 2
	
	private moveDirection as Vector3 = Vector3.zero
	private curNumJump as int        = 1
	private controller as CharacterController
	
	def Update():
		PlayerMovement()
		HandleEvents()
		
	def PlayerMovement ():
		controller = GetComponent(CharacterController)
		
		// While character is grounded allow to jump and horizontal movement
		// Player is restricted in jump movement.  One way jump if double jump disabled
		if controller.isGrounded:
			moveDirection = Vector3( -1 * Input.GetAxis('Horizontal')*walkSpeed, 0, 0 )
			SingleJump()
		
		//Player is in the air
		else:
			ExtraJump()
			
				
		ApplyGravityForce()
		
		controller.Move( moveDirection * Time.deltaTime )
		
	def SingleJump ():
	// Immediately present number of allowed mid air jumps when landed
	// Allow player to jump
		
		curNumJump = 1	
		if Input.GetButton( 'Jump' ) or Input.GetKeyDown( 'w' ):
			moveDirection.y = jumpSpeed
			
	def ExtraJump ():
	// Allow player the capability to jump multiple times in mid air
	//  Number of times is based on 'midAirJumps'
	//  Once limit is reach player must land before jumping again
	// When jumping horizontal movement is unlocked for that jump then it will be locked again
	
		if (Input.GetButtonDown( 'Jump' ) or Input.GetKeyDown( 'w' )) and doubleJump:
			//Player has not met his extra jumping limit
			if curNumJump < midAirJumps:
				moveDirection = Vector3( -1 * Input.GetAxis('Horizontal')*walkSpeed, 0, 0 )
				moveDirection.y = jumpSpeed
				curNumJump += 1	
	def ApplyGravityForce ():
		moveDirection.y -= ( gravity * Time.deltaTime )
		
	def HandleEvents ():
	// Events taken place are of action types: shooting, special attacks, interactable object, etc
		pass
Advertisement

Hi Cdrandin,

First of all let me tell you I don't program unity but do program python, c#, c++, etc. Looking at the format I personally think it looks really clean. Only thing I would change myself (if possible) is put the description of the function above the function. Also I am missing a simple outline for the class (meaning a bit of comments explaining what this class is for).

As for the rest of the code I think it looks pretty nice.

With kind regards,

StaticCUbe

I'm not personally for spaces before or after brackets, but at a high level I find the code to be actually readable. The comments are useful and relevant, it's clean. Maybe try and be a bit more consistent with newlines.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Looks good, I would however recommend learning something more powerful than VB if you expect to make responsive high paced games that those of us with older computers (You know the majority of your potential players) can play. Yes the obvious functions are always better to have.

Dan Mayor

Professional Programmer & Hobbyist Game Developer

Seeking team for indie development opportunities, see my classifieds post

Looks good, I would however recommend learning something more powerful than VB if you expect to make responsive high paced games that those of us with older computers (You know the majority of your potential players) can play. Yes the obvious functions are always better to have.
That's not VB, I think it's Boo.
Looks good, I would however recommend learning something more powerful than VB if you expect to make responsive high paced games that those of us with older computers (You know the majority of your potential players) can play. Yes the obvious functions are always better to have.
That's not VB, I think it's Boo.

Well that might just negate my comment. If it's a scripting language particular to the engine than it probably is among the best performance you would get with the entire kit. Just noticed the lack of ; and {} which immediately makes me thing VB or even worse Python :-o

Dan Mayor

Professional Programmer & Hobbyist Game Developer

Seeking team for indie development opportunities, see my classifieds post

<blockquote class="ipsBlockquote" data-author="Dan Mayor" data-cid="5018658"><p><br /></p><blockquote class="ipsBlockquote" data-author="Mussi" data-cid="5018581"><p><br /></p><blockquote class="ipsBlockquote" data-author="Dan Mayor" data-cid="5018578"><p>Looks good, I would however recommend learning something more powerful than VB if you expect to make responsive high paced games that those of us with older computers (You know the majority of your potential players) can play. Yes the obvious functions are always better to have.</p></blockquote>That's not VB, I think it's Boo.<p><br /></p></blockquote>&nbsp;<br />Well that might just negate my comment. &nbsp;If it's a scripting language particular to the engine than it probably is among the best performance you would get with the entire kit. &nbsp;Just noticed the lack of ; and {} which immediately makes me thing VB or even worse Python :-o<br />&nbsp;<br /><p><br /></p></blockquote><br />Both VB.Net and IronPython runs pretty darn fast (performance is comparable to what you get with normal C# code), and that is indeed Boo (Which is a .Net language similar to Python). (The only really slow Python implementation i can think of is CPython, but even that is fast enough if you got an engine that does the heavy lifting for you)<br /><br />Also, what do you have against Python ? you are probably the first programmer i've seen who say that python is worse than VB (I don't think it is even possible for a language to be worse than VB, (COBOL or Brainfuck might possibly manage it, but even that is debatable)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

I personally think it looks clean. I used to smash all of my code into one place (e.g. all logic in the Update() function in Unity) and use "folding comments" to organize it, but now I'm starting to prefer separating them into functions and applying that to all my latest code.

I'm not sure if this actually works with Boo, but if you're using the text editor that comes with Unity, called UniSciTE, then it allows you to make "folding comments" like so:


//{Movement:
//Movement code goes here
//}
//{Jumping:
//Jumping code goes here
//}

These are like 'regions'. I'm not sure if regions are applicable to other languages/IDEs, because I've only used them in Visual Studio C#, but I know they don't work in UniSciTE.

Anyway, they make it so that you can fold the selection, and hide everything but the first comment with the starting brace in it, like "//Jumping:"

I think there are a lot of people who are against the idea of folding up your code with regions (or "folding comments"), but I just wanted to let you know about them if you wanted to use them. They're pretty much the only way to fold stuff up in UniSciTE manually, without that something being a function, class, etc.

Anyway, as I said, you might not want to use this technique and it might not even work with Boo, but too bad because knowing about it is already taking up space in your brain!

[twitter]Casey_Hardman[/twitter]

Very nice but comment your functions, 6 months from now you wont remember what you wrote so u need to leave your self notes or someone else notes.

This topic is closed to new replies.

Advertisement