Pattern Muse
As I commenced the rewriting and porting of my code to Github, I felt amazed on how the heck I could have developed the game without coughing blood six months ago. All the .blend, .boo, .cs, .prefab etc files together, with all sorts of names for scripts, along with strange implementation of ideas over different scripts.
Case in point: Inside the Player_Zoid_Control script that controlled the zoid, there was one mouse event handler that handles shooting events when the right mouse button is clicked. It was supposed to shoot when the cool down period is not on and decrease the ammo count.
#Somewhere inside the script
if Input.GetMouseButton(1):
if ammo_clip[pointerpt[0]]>0 and fire_bool[pointerpt[0]] is false:
bulletprefab1= Stat.bulletlist[pointerpt[0]].Prefab
height=self.transform.position+velocity*offset
rotate=self.transform.rotation
GameObject.Instantiate(bulletprefab1, height, rotate)
ammo_clip[pointerpt[0]]-=1
fire_bool[pointerpt[0]]=true
if fire_bool[pointerpt[0]] is true and fire_count[pointerpt[0]]<Stat.bulletlist[pointerpt[0]].Delay:
fire_count[pointerpt[0]]+=1
elif fire_bool[pointerpt[0]] is true and fire_count[pointerpt[0]]>=Stat.bulletlist[pointerpt[0]].Delay:
fire_count[pointerpt[0]]=0
fire_bool[pointerpt[0]]=false
if (ammo_clip[pointerpt[0]]<=0 and tick[pointerpt[0]]<Stat.bulletlist[pointerpt[0]].Timeout):
tick[pointerpt[0]]+=1
elif (ammo_clip[pointerpt[0]]<=0 and tick[pointerpt[0]]>=Stat.bulletlist[pointerpt[0]].Timeout):
ammo_clip[pointerpt[0]]=Stat.bulletlist[pointerpt[0]].Clips
tick[pointerpt[0]]=0
Is your brain screaming for help? Mine was.
It was incredible that I actually thought of binding the weapon info into the bullet instead of the weapon since it was the zoid itself which was shooting the bullet, which then caused a great load of mayhem when I tried to manipulate the weapon itself through other scripts during play time…
Most of the scripts that I wrote was ugly hacks that just worked most of the time, so nobody said a thing, as they don’t really care about the code, they care about the product. However, the code got more and more hairy over time as I was working with it, and I had to develop even uglier hacks to cover it up. In the end there was some big ball of fluff that made me puke.
So I am rewriting it.
The terse syntax of Boo and duck typing, which is almost like Python, allowed me to test ideas and write code very quickly, so I know near immediately what went wrong with my line of thinking. Rewriting the code, when necessary, would be painless, at least in theory. Right.
Actually it was quite painless, once I understood what the heck the code was supposed to do. It took me an hour or so going through all the undocumented code…but luckily I had some sense left not to write obfuscated code.
I currently divide jobs into four different kinds of modules:
View: Provide GUI and accepts input, such as mouse clicks and keyboard presses and convert it into states of handle modules.
Handle: Has inner states to be modified to do handling of another object.
Mechs: Has outer states to do computation of player logic.
I used the module type as a postfix for the name, e.g. Player_Input.boo, mainly to remind myself not to write God Objects.
Hopefully this would work. Anyhow, while I’m not a software architect, I do think failure is a really good teacher.
Anycase, I still see myself looking back again and face palming myself again. :P