Tuesday, January 28, 2014

Average, Normal, Ordinary, Everyday...Regular Expressions

This week I began a new Software Engineering class in which I am learning Ruby on Rails. I started watching the introductory tutorials on the new language, and I immediately discovered a shortcoming in my education-to-date. I realized I know next to nothing about regular expressions. I was unable to decipher which of the characters I was seeing belonged to these regular expressions, and which were syntactical requirements of Ruby. If anyone else is experiencing similar difficulties, I hope to help your understanding by providing a quick introduction here as well as some resources for further study. Because my background is in Java, I will start there, then transition into Ruby formatting. So without further adieu...

What is a Regular Expression?
This is a way of matching patterns within sequences of characters. For example, I could search a string such as "How much wood could a woodchuck chuck?" for the string "wood." I could do several things...I could find out if the pattern existed at all, I could count the number of occurrences within the string, I could perform the search based on capital letters or lowercase letters, or even a combination. It is even possible to "find and replace" matching patterns.

Why Regular Expressions?
It is simple to consider potential uses of "find and replace" functionality, from simple misspellings of a single word to intricate changes in long documents, such as new contact information for Congress members after post-election. Even more simply, we might just want to search a small amount of input for a particular set of characters. If we were to write basic "beginner" Java code to search the above input string for "wood," it would involve nested loops and if-else statements and storing and backtracking and...well, suffice it to say regular expressions not only condense the amount of code, but also are simpler to understand as they are a higher level way of scripting, thus closer to the way we think.

Java: regex
In Java, the java.util.regex and java.util.matcher packages contain the classes needed to utilize this functionality. To implement you would first build the pattern you want to match, then the test string, and finally the test statement:
Pattern pattern = Pattern.compile("\\d{5}");
Matcher m = pattern.matcher("90210");
boolean bool = m.matches(); 
This defines our pattern as five digits (0-9). Then, builds the test string (90210), and finally tests to see if the test string matches the pattern. This is the equivalent of testing a field to see if it could potentially be a zip code.

Ruby: Regexp
In Ruby, the regular expression looks very similar. Instead of being enclosed in quotation marks, it is enclosed in two forward slashes:
/\d{5}/
Additionally, instead of calling .matcher, you simply call .match.  I'm beginning to like the simplicity already!

I Want to Know More
As I mentioned, these are just the basics. There are much more intricate uses of regular expressions. For more on either language, here are some resources:

Javadoc Tutorial on Regular Expressions
Java Regex Tutorial by vogella.com
Ruby-doc on Regexp

If you have any corrections, suggestions, or questions, please feel free to share your wisdom in the comments!

Sunday, December 15, 2013

It's Finally Final!

After a fantastic semester of playing with Stencyl, gaming.js, and Unity, I have finally put together a basic pinball game. It isn't perfect...the game never actually ends, and the physics have some more tweaking, but...it plays. There have been a lot of changes since the last prototype. In addition to basic bumpers, I have added triangle bumpers, a plunger simulator, drop targets, and lanes for the ball. Also, the game now keeps score, and it counts down your remaining balls. I have learned so much this semester, but as you can see, I have only touched on the basics of writing this game. The world of battles and levels and wormholes I envisioned isn't quite here, but now that I have the foundation, I can continue building upon this fantasy world of which I dream.

In the following video, I discuss my vision and strategy as I build the game, and there is a brief clip at the end of the game in action:


If you would like to try the game for yourself, please feel free to play it online.

I hope you enjoy, and Happy Holidays!!

Thursday, December 12, 2013

Pinball Masters, Prototype #4

I have finally gotten my flippers working in Unity! It took a while, and after trying "Lerp"ing and "Slerp"ing (and maybe even a little twerking!?), I found a YouTube video from PushyPixels that simply utilized "rotateAround".  Since I am working in JavaScript, variable declaration was done a little differently, but nothing too difficult to figure out. The next issue I had was that they were using the mouse as a controller, and I wanted to use "D" for the left flipper and "K" for the right flipper, so I gave the object tags, and paired them with the GetKeyUp and GetKeyDown events. Finally, I stopped watching at the point in the video where they were still struggling with trying to get the left flipper to move correctly. I simply utilized their script, changing the positive/negative values on "maxAngle" throughout the code for the left flipper, and it worked swimmingly.

So here it is, prototype number four

And if you would like to check out the video by PushyPixels, you can find it here.


Sunday, November 17, 2013

Pinball Battle: The Multiplayer Version of Pinball Masters

If you're already excited about Pinball Masters, wait until you hear about the multiplayer version! Imagine sitting down across from your best friend at a long, flat pinball table. Each of you have your own set of flippers, but you share a ball as you try to force the opponent into three ball losses. You have targets you can hit on your own side to earn points, which will allow you to buy equipment, such as temporary stoppers to prevent the ball from exiting your side, and one-way doors, which will reflect the ball back onto the opponent's side of the table, while allowing it through when you send it across to the other side. Once your opponent has lost three balls down their side of the table, you clench your victory!

Tuesday, November 12, 2013

Switching to Unity

Greetings! This week I have begun making the switch to using Unity3D as the development tool for my pinball game. It has a lot of incredible functionality, which means there is a lot to learn! So far, I have the main game components added to the screen, but no flipper motion yet. Here's a quick clip of the game:


Monday, November 4, 2013

"Just One Minute": A Pinball Masters Gameplay Excerpt

The player pulls back the plunger, exhales, and launches the ball onto the table. The ball speeds through the launch ramp and into the gameplay area. The player can hear the ball as it ricochets back and forth between the bumpers, causing lights to flash and points to build. Watching intently as the ball makes its way down the table, the player tries to anticipate its arrival. Noting the ball traveling directly down the center, the player attempts to gently tilt the table. Unfortunately, the ball still escapes down the drain, but is saved and automatically relaunched. This time, the player manages to activate the flipper in time to send the ball back onto the field. As the player continues to bounce the ball around the table, a series of flags are triggered, and the player is given his first mission. A friendly assistant offers to grant shielding if the player shoots the ball up the left ramp in the next 30 seconds. A skill shot launches the ball up the ramp just in time to earn a basic shield in his inventory. The player decides not to use the shield at the moment, but to wait until he has to fight the next enemy. Hopefully he can also earn some healing and weaponry by completing other missions before he has to battle THE PINBALL MASTER!

Wednesday, October 30, 2013

Pinball Prototype v1.1

The next set of steps in building the game took quite a bit more study, but I have finally added some physics components, and the ball bounces around the screen and off the bumpers and flippers. I've added a splash of color as well as a scoreboard with instructions. I do recognize there is a LOT of work to be done to make this game what I want it to be, and I'm rather excited about the upcoming modifications. In the meantime, please feel free to check out my game and let me know what you think!

Pinball Prototype Screenshot