![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
IDEA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When we were told that we had to do a mini project in VRML for this course, I wanted to do something that could be used. I don't like doing projects that are just there and have no purpose, or only have a purpose for a few people. So, I started to think about making some sort of game. I have seen a few games made in VRML, some were flying games and some where role playing games (RPG's). After thinking about what I could do, I decided to keep it simple. When I mean simple I mean, something that everyone could play and with out the need of any instructions for them to read. Therefor I decided to make an Air Hockey game that you find in the amusement arcades on holiday. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DESIGN | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The design of air hockey game is quite simple. There is a playing field a puck and a playing paddle. For the moment I only made the game one player, this is due the lack of multiple user capability of COSMO. The creation of the playing field is made up of, boxes and line sets. See below The puck in the middle is a cylinder with a height of 0.1 and a radius of 0.25, The player at the bottom of the field is also a cylinder with the same attributes. What I wanted the game to do was when a user press the mouse on the black paddle the puck would start to move in a random direction every time you press the paddle. The paddle has a planeSensor attached to it so the user can move the paddle from side-to-side. Due to the limitations of the planeSensor you can only move object in the x and y coordinates. I rotated the playing field on the x axis at 33 degrees therefore without redesigning the planeSensor I had to leave the way the paddle moved. To get the objects to interact with each other I had to think about how I was going to handle collisions with the puck and the paddle and the puck with the walls. The first thing I thought of was to use a proximity sensor. BUT, they only work with the avatar and not objects in VR worlds. Therefore I had to design a javascript to handle the collisions between the objects. I will go into the javascript later on. The title and the score text are linked to a colorInterpolator which change the color of the text constantly. I did this so the user had something to look at, and it didn't make the world look dull. The next thing I had to do was, think about designing the way I would have to handle the object in the game. I first identified the things that I would have to move, or change on the fly they are: 1. The player 1 score Now I have identified the object that would interact with either the user or the world its self, I went about coding this interaction. To make the puck move I would have to change the translation of the Transform node. I decided to make the translation of both of the puck and the paddle as exposedField's so they could either be eventOuts or eventIn's. By doing this I had a bit more work to do then I would normally have to do if they were normal fields. To access the data held in the translations I had to define another PROTOTYPE within the PROTOTYPE for the object (i.e. puck and paddle). See below:
By doing the above code, I could access data in the exposedFields of the translation of the puck and the paddle. I could access and change them from within a script which would control the positioning of the objects. Also from within the GameObject PROTOTYPE
I instantiated the scores so I could change them on the fly later.
Like I said at the start the scores and the title text keep changing colour, to do this I needed a few VRML nodes. I had to use: 1. A TimeSensor The time sensor just set a field called cycleInterval to .5 which would be the time it will take to change the colour of the text. And also a loop field which specific the timer to loop it's self when it finishes.
The ColorInterpolator is the node which holds the colours to change to text to.
The key says at time fraction 0 the colour will be 1 0 0, and at time fraction .0 the colour will be 0 1 0, and at time fraction 1 the colour will be 0 0 1. What this does is changes the colour from red, to green and then to blue. The time fraction comes from the TimeSensor's fraction_changed But that doesn't happen on it's own. It needs something to activate it. This is where the Route's come in. What happens here is the fraction_changed eventOut gets routed to the ColInter's set_fraction eventIn, which starts the timer off. Then the ColInter's value_changed(which is the keyValue) gets routed to the set_diffuseColor which is part of the material node for the text.
That's about it for this section. I still have to go into how I updated the scores and handled the collisions, but I will leave this to the next section. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PROTOTYPES & SCRIPTS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In this section I will explain the PROTOTYPES that I used and also the SCRIPT that controls the whole game. The first PROTO I will explain is the Scores Prototype. The scores prototype handles the defining of the text that'll be shown in the world. In the PROTO definition I have used a few exposedFields. These fields are used so I can have control over them from within different parts of the program. For example the _Set_Player_Score and the _Set_Computer_Score fields both hold a text value which is used to display the current score in the game. To access the fields as I have shown earlier needs 2 PROTOS. One for the whole definition and one for the exposedFields that you want to access.
The Next PROTO that I will explain is the GamingObject
Prototype. From within this prototype I define the object that
interact with the user and with each other. For example the puck, the
paddle and I also instantiate the Scores from within here as well. Again
this prototype also contains exposedField which have to
be accessed from within the script and other parts of the program, so
therefore I needed to define a second prototype for them.
Now, to access these exposedFields I had to instantiate
them with the following code; As you can see I have called the prototype
and named it properties (with a lowercase p) The reason
why will become clear later.
In this PROTO I also instantiate the Scores with the following piece of code. Notice as well I have defined then instance of the score with the name theScores.
The following section of code will be the script, which controls the world.
The only other PROTO's I used were one for the playing field and one for the title
The title also changes colour while the game is playing the same method is used as in the scores prototype.
The last piece of code to talk about is the main part. This part calls t above prototypes so they can all start to interact with each other.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
IMPROVEMENTS & CONCLUSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I think over all I have made a game that will be used on the web by many people just looking for something to do. I can say that I have learnt quite a few new things from the language that I didn't know before.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
These
pages were created and designed by Jon-Paul Mulholland |