Sunday 18 April 2010

Problem... Kinda resolved but this is all I can do.

Resolved

I had the issue that the XML feed was not changing colour properly. I have been able to deal with this problem by swapping some codes around and using fill(); to help gain two of the colours I wanted. Blue will be used as slow and red is used for fast. I have also moved the raio = raio + (100 - raio)*0.025; from the void update() and have placed it into the if and else if statement.. so if the value is under a certain number, the radius of the moving circles will be smaller and blue if its above a value then it has a high radius and the colour becomes red.



I've been able to get this working and I'm proud of it!



Still can't make a timer though...

It's Complete! But with an error...

The Processing task is complete and it looks brilliant, however theres a problem with the way the xml feeds get sent to me and the way the framerates work. It's basically picking up 30 pieces of information per second from the server because of the 30 frame rate I have in place. This could bring down a server if it wasnt strong enough. So my code is basically asking the server 30 times a second: "Give me data!" This could be a problem.. But I don't know how to sort it out!

Tuesday 13 April 2010

Processing: Development Part 3

Adding the XML feeds

The most awkward task now is to effectively extract data from the Plymouth Universities ARCH-OS system and place it onto each circle to represent visual data using colour as the basis of displaying the results..

I will need to start with importing the xml from the processing libraries along with each XML Element I need to use.

import processing.xml.*;

XMLElement xml;
XMLElement[] title;
XMLElement[] pubDate;
XMLElement[] value;

Each of these elements identify titles, dates and values from the feeds.
In my void setup(){ I have to add code to string the website address and use the getChildren command to extract every piece of data from the server.

For the XML feed I have chosen windspeed. This matches my criteria because of the movement is that of a wind vane spinning. To indicate the windspeed I may choose various colours to represent the speeds.

void setup
String url ="http://x2.i-dat.org/archos/archive.rss?source=bms_.WindSpeed";
XMLElement xml = new XMLElement(this, url);
title = xml.getChildren("channel/item/title");
pubDate = xml.getChildren("channel/item/pubDate");
value = xml.getChildren("channel/item/description");

The code below displays the use of .getContent().charAt(1)) which is used to extract the numerical values needed to represent the data onto my sketch. By using another For Loop, I can simply print the data to the sketch with the help of 'println(a+" "+c)'. So this is extracting the values in a loop and producing them onto the sketch.

void update
for (int j = 0; j < 5; j++){
int a = int(title[j].getContent().charAt(1));
int b = int(pubDate[j].getContent().charAt(1));
int c = int(value[j].getContent().charAt(2));
println(a+" "+c)

Colour Changing
To represent the data onto my circles, I need to create an If/Else statement from the code above. I firstly need to create three new floats in the class Circle area which are:
float greenslow = 255;
float bluemed = 255;
float redfast = 255;

Green is slow, blue is medium and red is fast. These display the speeds of the wind depending on the winds speeds.

The code below shows the last part of the code I have used. The if/else statement is basically saying that if the value of the feed drops below 50, it changes colour to green, if it's above 50 then it will remain red showing that it's fast.

//If/Else statement: Colour changing to display speeds.
if (c <= 50) {
greenslow = 255;
bluemed = 18;
redfast = 0;
}
else if (c > 51) {
greenslow = 0;
bluemed = 0;
redfast = 255;

}
//Fill the greenslow,bluemed and redfast with colour
fill(greenslow,bluemed,redfast);

ellipse(xpos, ypos, diameter, diameter);
}
}
}

This last snippet of code shows that the greenslow, bluemed and redfast has been put into the fill to display the colours and the ellipse uses the xpos, ypos and diameters to basically make the ellipses travel in a circular motion.

Processing: Development Part 2

Let the Movement Begin

By learning about the Class construct I have been able to establish blueprints to help build the movement for the circles. The classes instance is called Circle. It will be used to describe the state of behaviour that the objects of the class all share. I have also studied trigonometry and the use of movement using xpos, ypos, speed and distance. These will all be used within a float to then be updated with the circles. Also what is added is angulo which forms as the angle using a random equation of PI times 2 divided by 2, times by two. This will be combined later in the update with raio which will class as the radius of the circle. In the same Class, the speed and diameter is declared through the float as s and d.



Void update is the most important as it constantly changes the angle and movement of the moving circles (ellipses) in the sketch. angluo is more or equal to radians which is speed determined by the speed. raio is subtracted by any number (100 is used for radius here) and is then multiplied by 0.025.

xpos is then calculated through cos which is a trigonomic function (acts as adjacent divided by hypotenuse) which will be equal to angulo which is multiplied by raio and then added by xpos' width divided by 2. (Confusing...)

ypos is calculated through sin which is yet another trigonomic function (acts as opposite divided by hypotenuse) which will be angulo which is multiplied by raio byt added with ypos' height divided by 2. (Confusing again...)

After many days of confusion and almost utter breakdown I managed to produce this pretty cool sketch I needed badly!


The image above displays the movement of each ellipse as they go along the path. They move correctly and in the areas that I wanted. The ellipses move around at various speeds (5 different settings) due to the use of the random number in the For Loop void setup. So this is highly useful for representing the idea of visualising data by creating an animative effect. All I need to do now is add the Xml feed to change the colour of the circles whenever there is a change in data.

I can increase and decrease the circles distance from the center from the 'raio = raio + (100 - raio)*0.025;' by changing the '100' it can produce some interesting displays.

Monday 12 April 2010

Processing Development Part 1

Processing Development Part 1

Now I have decided what my plan is going to be like, it is now time to experiment with various codes and see what I can do with them. The rules imply on the basis that a processing sketch must use Animation and an XML RSS feed from Plymouth's ARCH-OS websites. We are not allowed to use interactivity with the sketch so it's only visual-based.

My first stages are to basically produce the circles I need and draw them onto the sketch along with some form of animative movements using trigonometry (which is awkward). The circles can be produced like this:





The code and above displays the foundations of the 'stage' area. Starting at the top, I have created an integer which declares the name num and the number is 10 (this can be changed to any number and this will be for the amount of objects (circles) in the sketch.) It can be any number as long as it's not too big as the amount of processing will cause the computer to crash.

An array is declared to announce the name Circle and circles which are used later as a Class and in For Loops to help duplicate the circles I need.

I have then created a void setup(){ to produce some of the extra features of the sketch such as adding smoothing, establishing the size of the sketch along with adding the frame rate which is set to 30. A for loop begins here which sets up circles I need for the sketch, int i is declared and is used as a new circle to create a Random generation of circles (in this code there is 5 variations of movement for the circles). The size of each circle is set to 15.

I then established a void draw(){ which projects everything onto the sketch. I have currently provided a basic shape such as an ellipse to draw as my boundary. This will be filled to become a dark background. The ellipse and it's fill doesn't need to be there but when the trigonometry it will be needed to check if the moving circles are in the right path. Another For Loop statement is used as an 'Updater' to constantly update the position of the moving circles on the drawed sketch. The circles[i] is used from For Loop in the void setup(){ to produce the sketch.

Thursday 11 March 2010

Processing

Processing is a computer program that uses Java as the sole purpose of it's language. I have found it more difficult compared to the likes of Actionscript 3.0. It's a very confusing language but has to be studied for a long time in order to understand what it wants and what you want out of it as a final product.

The assignment is to base RSS feeds from an Arch OS system and use them to make a visual representation of what they would look like in Processing. I have drawn up some plans which maybe useful to my designs.

The design that I have come up with is based on simple circles that rotate in either different positions or closeby each other in the same moving path. Each circle will be based on the various data from the feeds and will be different colours depending on how high or low they are.

Monday 1 February 2010

Final Flash Game Product

Lee Cunnington.co.uk/Fun

Here is the final version of the Flash game which I have created. The current errors which were troubling me have been changed and removed, so it is now a 100% clean working Flash Game.

http://www.leecunnington.co.uk/Fun

Saturday 30 January 2010

Development

Development
Software

The software that I will be using for creating the maze is Adobe Flash CS4, it's specially designed for the job of creating animations, animated movies and games. It also uses a coding language named ActionScript 3.0, it's similar to Javascript but uses KeyListeners and Events to identify each movie clip object. It relies on coordinates through x and y to complete animation of rotating objects and moving ones.

Stage One

I will be designing a Cursor maze game, where the user will use their original mouse cursor to guide through the maze to the indicated exit without touching the maze walls or moving obstacles throughout the game. They will be timed on their progress to see how long they last for in the maze, they will be given a random experience when they fail the level, they will be able to pick their starting location to see if they can beat the game.

Update: The reason why I'm not using an object and keyboard commands in the maze because of hit testing. I found difficulty trying to 'End the game' when the object the player uses comes into contact with walls. The object simply passes through the walls and obstacles, destroying the whole point of the game. I spent a whole week trying to do hit testing with various codes, but none seemed to function correctly.

Designing Menu's

A menu is important for the majority of games. Through researching various puzzle games just like the maze I'm going to create all have a menu giving the user various instructions on how to play the game and how to achieve the objective. Some have other features like choosing difficulty levels, an option to reduce music and sound effects. I am going to design a menu which is quick and simple so the users can get in and out of the game whenever they request to. To match the house style of my website (Primarily Blue and White), I will try to achieve the same as this.



I have currently kept it very basic with the Blue background and White text. I have also added the first button which will be programmed to begin the game. Using the Primitive rectangle tool I have designed the shape of the button along with rounding off the edges to create smoothness.

The actionscript code which I have used to begin the game goes as follows:

('start' is the instance name of the button.)
stop();

start.addEventListener(MouseEvent.CLICK, startGame)
function startGame(event:MouseEvent){
gotoAndStop("2");
}

This section of code basically tells the button to go to Frame 2 (this is where the maze will be).

Losing The Game

When the users character touches an obstacle, then it's game over, simple as that. The code is very similar to the button command, however it uses a Mouse Event Rollover instead, so as the mouse cursor rolls over the obstacle, then it instantly sends the user to the game over screen.

('walls' is the instance name for the maze walls.)

walls.addEventListener(MouseEvent.MOUSE_OVER, overwalls)
function overwalls(Event:MouseEvent){
gotoAndStop("End Game");
trace("Complete");
}

When the game is declared over, the user will have the option to go back to the start menu or simply go back into the game again.

When the game develops overtime, I will be able to code other obstacles that are animated (rotating, moving) to create the same effect when the player hits it.



Winning The Game

When the user finally touches the 'Exit', the user will be sent to the Winner frame. They will be congratulated and will be given a balloon. Which can be controlled using the up, down, left, right arrow keys. Just as a little amusement for the user.
The AS3 code to generate the Winner frame is very similar to the Game Over code above. The mouse rollover events are very useful in doing this as it's quick and tidy.





Update: Trying Again

Going back through thinking about improvements, and I thought of the idea to give the user the chance to try again, instead of getting a blunt 'Game Over'. This new menu allows the user to choose their location from Five different points which I have arranged. Simply clicking on one of the small white rounded squares will take them back into the game to try again. This will give the player a new experience everytime they join back into the game, bringing more fun and experiences to it.



Update:Improvement

Instead of the plain blue background in each menu I have used the original background from my website (the sky background). This will give it better presentation and will attract users to play the game. It looks more professional and makes it look worth while compared to the blue background I originally planned out.





Stage Two
Designing The Maze

Because I have to add this to my website I have ensured that the colours match my websites house styles. So the floor of the maze is blue. However, for the maze walls they are currently a dull grey to match a 'prison' level where the user has to escape from the prison walls to the finish location. This is due to change, I'm thinking about changing it to White to make it more brighter and make it like a snow prison.



The walls are designed and coded not to be touched by the user. If the user touches any obstacle with the escaping character, then it's an instant game over. This will bring a new challenge to the player as it test their patience and accuracy of movement using the keyboard or mouse (currently not decided).

Rotating Objects and Traps
I have devised a plan to create some rotating obstacles and a trap which will be designed to coincide with each other. When the users cursor moves over a certain location in the maze, it will trigger the command for the objects to start rotation. Using Mouse rollover events, I will be able to achieve functionality of the rotating objects. I will also add some 'Security' characters which will act as security guards and when the users cursor comes into contact with them, it will be game over.

Rotating Obstacle (Version 1)


Guard (Version 1)


Developing The Rotating Obstacles and The Trap

The image below is the trap that I'm going to use with AS3 to trigger a trap to spawn the movement of the rotating obstacles. This will make the game more challenging to the users. They can choose not to go near the trap and they can simply move past. This will bring new experience to the game because they can experiment with surviving the maze with the trap activated or not.




Rotating Obstacle (Improved)



The code below displays the rotating obstacles and the traps characteristics and shows them linking together to work. The rotate_btn is effective the tiny dot in the maze so when the mouse rolls over this dot, it will start the command to rotate the objects. When this has started, each of the objects will be 'told' to begin rotation from the event listener. I have also added a dynamic text box which handles the output of "Its a Trap!" when the mouse rolls over the trap. This indicates what the user has got themselves into.

// Add Listener to the Rotate Trap 'Button'
rotate_btn.addEventListener(MouseEvent.MOUSE_OVER, rotateButtonOver);

function rotateButtonOver(evt:MouseEvent):void {
// Event Listener declared to start rotation
addEventListener(Event.ENTER_FRAME, startRotate);
trace("Trap Clicked");
}

function startRotate(evt:Event):void {
// Call function rotateSquare
rotateSquare();
}

function rotateSquare():void {
// Rotate the MovieClip
mcRotate.rotation += 20;
mcRotate2.rotation -= 20;
mcRotate3.rotation -= 10;

// Display message
output_txt.text = "Its a Trap!";
}

Developing The Guard

The guard is made by two to three shapes, a circle and a triangle basically stuck together into a movie clip. The circle is used to act as a guard with a flash light or the sight it has over the maze map. The bigger the triangle, the more radius the guard can see. So when the users cursor moves into the perimeter of the guard, then its game over (because they have been spotted). I have dotted guards around the maze in certain places to give the users more of a challenge not to be detected by the radius perimeters. The guards are different sizes, the bigger the guard, the more difficult it is to pass through.

Rotation

The guards rotate at various speeds, to give the chance for the users to pass through the various paths in the maze, but what goes around, comes around. So the user must quickly pass through undetected.

//Security rotates automatically
Security1.addEventListener(Event.ENTER_FRAME, rotateMoveClip);
Security2.addEventListener(Event.ENTER_FRAME, rotateMoveClip);
//Add more Security guards

// the rotateMoveClip function
function rotateMoveClip(e:Event)
{
// e.target is the reference to the MovieClip calling the event
e.target.rotation += 0.5;
}

The code above is based on rotation events. The security rotate clockwise at 0.5px.

Guard (Improved)

The improved guard works the same as before, however, the little circle is hidden under the big static circle object above. So it makes it look more of a security tower building compared to just a guard spinning around with a flashlight. This idea looks better and realistic compared to its predecessor.



Developing The Moving Obstacles





The code below makes the two moving obstacles move left to right using x and y coordinates. xRate is the speed of the obstacle that makes it travel from y to x. The obstacles will move to the width of the stage so every time they move from one side to the other, they will effectively bounce off the corner of the stage and will stay within the maze.

function moveObstacles(event:Event) {
mcObstacle.x -= xRate;
mcObstacle1.x += xRate;

if (mcObstacle.x > (stage.stageWidth - 10) || mcObstacle.x < 10 || mcObstacle1.x < 10) {
xRate = xRate * -1;
}
}

The Timer

The Timer is very important to maze game, it can be used as a psychological method to make the user panic and hurry up to complete the maze game in the fastest time possible. The more pressure the user has to beat his/her older records, the chances of failing the game are more likely than expected.

The code below shows how the timer works, it starts at 0 and basically adds a digit by 1 everytime. Using a dynamic textbox called countTxt.text as the output helps this function to visualise the counting up.

//Timer
var count:Number = 0;
var myTimer:Timer = new Timer(1000,count);
myTimer.addEventListener(TimerEvent.TIMER,countup);
myTimer.start();

function countup(event:TimerEvent):void
{
countTxt.text = String((count)+myTimer.currentCount);
}



The Timer is located in the top right corner of the maze, it will appear once the game has started.

Adding Sounds

To add sounds or music, I must import the sound files (preferably MP3) into the library. The screenshot below shows after adding the sound file into the library, I have to check its properties to create linkage to the frames for the game. Checking the tick box, it ensures this and allows the sound to be involved in the actionscript codes.





//Sound
var snd:Sound = new FFX();
var channel:SoundChannel;

channel = snd.play();

//Stop Button
btnStop.addEventListener(MouseEvent.CLICK, onClickStop);

function onClickStop(e:MouseEvent):void{
channel.stop();
}

//Play Button
btnPlay.addEventListener(MouseEvent.CLICK, onClickPlay);

function onClickPlay(e:MouseEvent):void{
channel = snd.play();
}

Issue With Sound

When originally using this code:

var snd:Sound = new FFX();
var channel:SoundChannel;
channel = snd.play();

I had problems with the song from the main menu constantly playing throughout the game, so I had to create two sound buttons which represent Play and Stop. So the user can happily choose to play the music throughout the game or not. The code above displays what I had to do to declare the buttons into functions and make events, so when the user clicks the button, then the sound plays on or off.

Shortening The Code (Efficiency)
I have noticed that some of my actionscript 3.0 code can be shortened for easier maintenance when going back to improve aspects of the game. The game needs efficiency, so shortening the code will mean less loading times and lesser problems for future usage.

Here are some examples of what I am about to change:

Rotating Obstacles

The code below shows that when the users cursor touches the obstacles, its an instant game over. Each of these functions repeat the same thing, so I will change this to make it smaller and easier to understand and maintain of course.

mcRotate.addEventListener(MouseEvent.MOUSE_OVER, doom1)
function doom1 (Event:MouseEvent){
gotoAndStop("End Game");
trace("Complete");
}

mcRotate2.addEventListener(MouseEvent.MOUSE_OVER, doom2)
function doom2 (Event:MouseEvent){
gotoAndStop("End Game");
trace("Complete");
}

mcRotate3.addEventListener(MouseEvent.MOUSE_OVER, doom3)
function doom3 (Event:MouseEvent){
gotoAndStop("End Game");
trace("Complete");
}

Improved

The code below shows the improvement of shortening the code, each instance of the object uses the same function to be used under the same command. So whenever any of these obstacles are touched by the users cursor, then it's game over. This code is now easier to maintain and I will be able to add more onto this!

mcRotate.addEventListener(MouseEvent.MOUSE_OVER, doom1)
mcRotate2.addEventListener(MouseEvent.MOUSE_OVER, doom1)
mcRotate3.addEventListener(MouseEvent.MOUSE_OVER, doom1)

function doom1 (Event:MouseEvent){
gotoAndStop("End Game");
trace("Complete");
}

I can repeat similar steps to this for other objects such as the moving obstacles.

Extras: Moving Balloon (Reward For Winning)
I have added the balloon in the You Win scene which has been coded to take up, down, left, right arrow key commands. The code below displays each command from clicking on the balloon to 'activate' it to pressing the arrow keys to begin movement.


start3.addEventListener(MouseEvent.CLICK, startGame0)
function startGame0(event:MouseEvent){
gotoAndStop("2");
}

var big_step = 20;

balloon.tabEnabled = true;

balloon.addEventListener(MouseEvent.CLICK, change_focus);
function change_focus(ev:MouseEvent) {

balloon.addEventListener(KeyboardEvent.KEY_DOWN, balloon_control);

function balloon_control(event:KeyboardEvent):void {

move_it(event);
}
function move_it(event){

var key = event.keyCode;
var target = event.target;

switch (key) {
case Keyboard.LEFT :
target.x -= big_step;
break;

case Keyboard.RIGHT :
target.x += big_step;
break;

case Keyboard.UP :
target.y -= big_step;
break;

case Keyboard.DOWN :
target.y += big_step;
break;
}
}
}



When the mouse is clicked, the focus of the stage is directed at the balloon, so the arrow key commands can be used preventing the screen from rolling up (when on my website). The switch and case statements identify each key stroke moving up, down, left or right.

Balloon Collision

I have added an animated wall which travels across the stage from side to side. When the balloon comes into contact with the wall, it simply changes colour displaying that it has collided with it.



//Collision Detection

import flash.geom.ColorTransform;
stage.addEventListener(Event.ENTER_FRAME,hit);

function hit(evt:Event)
{
var c:ColorTransform = new ColorTransform();
if(balloon.hitTestObject(mcWall)) {
c.color = 0x0033CC;
balloon.transform.colorTransform = c;
trace("hit a wall");
} else {
c.color = 0xFFFFFF;
balloon.transform.colorTransform = c;
}
}

So when the balloon collides with the wall it changes colour but when it's away from the wall then it returns to it's usual colour.


Further Improvements

Further Improvements I have made is specifically on the Main Menu, I have initially added moving objects which bounce off the edges of the stage. Just to improve visual quality and make it look more 'busy'. It uses the same code as the moving obstacles (above) but also uses y axis usage for one of the obstacles so instead of moving across, it moves up and down the stage.



Final Maze Floor

Below is the screenshot of the completed maze floor. It's full of traps, moving objects and security guards that have one mission: To stop the user from getting to the exit. As you can see all the objects are moving in this still image. The trap has been set as well to activate the rotating obstacles. The moving obstacles and guards already move automatically without any commands from the trap. As promised I have added optionality and different experiences for the users as they can choose not to touch the trap or not; they can also choose their location if they got game over the first time, so it gives them a chance to start again in a new part of the maze to try and get to the exit.

Planning

Design Brief

The specifications of my maze game will be determined by the users themselves. What they want is what they deserve to get.

Casual gamers these days require quick entertainment whilst on the go, simple games which require less work in order to feel that they have succeeded something. My approach to this requirement is to create a game which will match this but will also give the user a challenge at the same time. Users also want new experiences everytime they go back to play the game, so I must find a way of dealing with this concept.

Some features that my game will require...

- Fast Pace
- Efficient
- Rewarding
- Fast Loading Times
- Challenges
- Random Experience
- Optional Features within gameplay. (Changing Difficulty)

My decision with choosing a Maze game approach is an ideal way to test the challenges that modern day gamers want. This is because a maze will provide a challenge for the users and will give them a random experience every time with different 'spawn points'. So the object that needs to get to the destination will be in a brand new place so the user can try and reach the goal.

Targetting all ages groups is a main feature that needs to be addressed for my game design. It needs to be colourful, fun and needs to be a serious game for all ages to enjoy. This can be achieved easily for users who enjoy puzzles, escape and stealth games.

Wednesday 27 January 2010

Narrowing Down

I have narrowed down the options to making these 3 genres of games.

- Maze
- Tower Defense
- Stealth

These game genres are very common in the Flash gaming world, I have been thinking about incorporating each of these ideas together to create a game which makes the user the 'creep' attacking the defense, whilst the AI (computer) simply uses turrets to shoot at you.

Using the arrow keys, the user could move around the maze to get through to the exit without being hit by the defending turrets.

Sunday 17 January 2010

Flash Game

Flash Game

Welcome to Term 2's edition of IDAT102, during the Christmas holidays I have been coming up with ideas of game genres which could be explored when coming to build the Flash Game.

List of Game Genres

Shooting
- Sniping
- Zombie
- Tower Defense
- Free Roaming
- Target Based (Assignments)
- Assassin
- Stealth

Maze
- Escape
- Dodge
- Collect (Certain items to open doors)
- Time Trial

Adventure
- Crash Bandicoot Based

Puzzle
- Guessing Games
- Quiz
- 'Impossible' Quiz

War
- Trench Warfare
- Free Roaming
- Military Vehicles
- Aircraft

Strategy
- Command & Conquer Based

Fighting
- Tekken Based

RPG (Role Playing Game)
- Final Fantasy Based

Driving
- Destruction Derby
- F1
- Touring


In the next few days I will need to come up with a decision between these different types of genres to base my Flash Game on.