Thursday 25 February 2016

BlackJack: 3 in one gaming assessment




Assessment 2: 3 in one gaming


Sprites:

Deck (spr_deck)
Contains all of the cards sprites.
Deal Button (spr_dealbutton)
Used to deal the cards.

Twist (spr_twist_button)
Used to allow the player to spawn a card.
Stick (spr_stick_button)
Allows the player to pass the turn.
Restart (spr_restart) 
The restart button was there so that I could restart the game to check if everything was working each time I played. 

Objects:

Controller (controller)
Player (obj_player)

AI1 (obj_AI1)
AI2 (obj_AI2)
Dealer (obj_dealer)
Deck (obj_deck)
Twist (obj_twist)
Stick (obj_stick)

Controller:
(Create Event):
Contains and initialises all of the global variables which are used in game. It also contains code for the ini file. The ini file code is:

ini_open("scores.sav")   (Doesn't create it, gets it ready)


if !(ini_key_exists("player", "wins")) then {              
     ini_write_real("player", "wins", 0)
}

ini_close()

If there isn't "player" and "wins" there then create it in the ini file "scores.sav" and the ini_close, closes the file it has been written/checked its been written.




(Step Event):
In the step event of the controller contains code which checks whether all the players have hit more than 21. When it checks through each if statement, its checking to see whether the player is over 21, and if they are, the global.turn changes to 1000. The reason behind why it changes to 1000 because is so it is a value which I know I won't use to activate anything important. The global.turnTo is a variable which is used to change who's turn it is. When it changes integer, that when it is the next person/AI turn.

(Draw Event):
The code within the draw event is just repeated code. The main mechanism behind it is, if the variable "finish"is 0, which is the state where the game is in play, then it checks to see whether the value of their cards added up is over 21. If they are over 21, (which in the step event, if they are over 21 it switches to 1000) then it activates the else statement and displays the word "bust".
This code is repeated for all of the AIs as they use similar coding.

Further down is the code in which displays whether the players have won or the dealer has won. The code is repeated for the AIs as they use similar code. So the first part of the code is checking whether the game has finished, if it is equal to 1 then the game has finished. Then it checks whether the playervalue is NOT 1000 and the player cards value is  more or equal to the dealers card value or dealers value is equal to 1000 then the player wins and it displays the words "You won!". Additionally, it opens the ini file, reads the current amount of wins, then the next part which is "if global.save = 0 then...." this section checks whether a new score needs to be saved and then adds 1 if the player has won. Within this global.saved if statement, it will read the ini file and display the current amount of wins when you have won. The else statement checks whether the cards value in hand = 1000 or the playervalue is less than the dealers then it will say the player has lost.
The dealer code for this is different. The wins don't get saved when the dealer wins. What happens is, when the dealer value is not a 1000 (a value which is used generically) it displays the current card value in the dealers hand, else when the dealer value is 1000 then the total display changes to "bust".




(press F key Event)
This event comes into play when the player wants to access full screen mode. The screenstate is setting acts as an on and off switch for when activating the full screen mode.







obj_player:
There is not much code in the player object as a lot of the mechanisms for the player have already been predefined in the controller object.

(Create Event): (similar coding for all AI/Dealer)

Depth = -global.player_card_xpos - this piece of code defines where the placement of the cards of going.

global.player_card_xpos += 80 - This adds 80 pixels onto where the previous card has been displayed and then places a new a card.

image_speed = 0 - We want the card to not cycle through all the image index so we have it set to 0.

image_index = ds_list_find_value(global.deck,0) - Sets the image index to the values in the ds list.

cardValue = ds_list_find_value(global.deck,0) - Finds the value chosen for that card.

ds_list_delete(global.deck,0) - Removes the selected card from the ds_list deck.




obj_dealer:
(Create Event):
Similar code to player, just different variables used.





(Alarm 0):
There are only two lines of code within this event.

global.turn = 3 - This line of code is a variable change so it can activate another persons turn.

show_debug_message("Alarm countdown works333") - This allows me to see if the alarm has worked by showing a debug a message.





(Step Event):
The step event contains 3 if statements (one nested).

if global.turnTo = 3 then {
    show_debug_message("Alarm works3333")
    alarm[0] = 100
    global.turnTo = 1000
}

This first section above is checking whether the turnTo variable is 3. Once it is 3, the alarm will activate and then the turnTo variable is set to the common number of 1000, one we don't use to activate anything.

if global.turn = 3 then {
    if global.DealerValue < 17 then {
        instance_create(global.dealer_card_xpos, 145, obj_dealer)
        global.turn = 1000
        global.turnTo = 3
    }

    if global.DealerValue >= 17 then {
        global.turn = 1000
        global.turnTo = 1000
        global.finish = 1
    }
}


This second section checks whether the variable "turn" has changed to 3 (in which is has because of the alarm event) activates the nested if statement. The nested if statement checks whether the dealers overall cards in hand are less than 17 then it will automatically produce another card for the dealer.
If it is more than 17, the dealer is not allowed anymore cards.



obj_AI1/obj_AI2:
(Create Event):
The create event uses similar code to the dealer and player object, the only difference is the variables used. 






(Alarm Event):
The alarm event uses similar code to the dealer and player object alarm events, the only difference is what the variables are equal to.





(Step Event):
The step event is the event which holds the probability code.  I am going to break this code into sections and explain what this does.

if global.turn = 1 then {
    if global.AI1Value = 21 then {
        global.turn = 1000
        global.turnTo = 2
        exit

    }

This small section defines whether the AI has definitely hit 21 or not. If they have definitely got 21 then the turns have to increment by one. 

if global.AI1Value < 16 then {
        instance_create(global.AI1_card_xpos, 457.5, obj_AI1)
        show_debug_message("AI1 Value less than 16 therefore card")
        global.turn = 1000
        global.turnTo = 1

  

This section is the first third of the probability code used. This is checking whether the cards in hand for AI1 is less than 16, if so a card will definitely spawn in for them and add on to the current overall value. (The turn and turnTo variables are there just to make sure the turn doesn't change). 

} else if global.AI1Value >= 16 then {
        if irandom(global.AI1Value - 16) = 0 then {
            instance_create(global.AI1_card_xpos, 457.5, obj_AI1)
            show_debug_message("AI1 Value greater than 16 therefore probs card")
            global.turn = 1000
            global.turnTo = 1

            exit

This is the second third of the probability code used. If the current cards in hand for AI1 add up to more than 16 or is 16 then an if statement is carried out. The irandom is used so that it picks a random number between whatever the current value in hand is - 16 and 0. For example, if the AI1 cards add up to 18, then it run through the code, minus 16 from 18 (which leaves 2) and picks the number 2, 1 or 0. If the number is 0 then it will spawn in another card, keep the turn as 1 (which allows it to take another go) and runs through the code again.

  } else {
            global.turn = 1000
            global.turnTo = 2
            show_debug_message("AI1 Value greater than 16 therefore probs no card")
            exit
        }
    }
}

This is the last third of the probability code used. If the irandom number chosen is not 0 then the turn goes to the next player and a debug message is shown, allowing me to check that the turn has definitely been passed on.




obj_deck:
(Create event):

global.deck = ds_list_create()
for(k = 0; k < 52; k += 1) {
    ds_list_add(global.deck, k)
}
randomize()
ds_list_shuffle(global.deck)

The "randomize" code randomises the random seed every time, so that when the deck shuffles, it will not have the same shuffle every time.
This section of code create the ds_list which is used for deck.
What the ds_list looks like right now is:

index: 0 1 2 3 4 5 6 7 8 9 10 ...
value: 1 2 3 4 5 6 7 8 9 10 11...

The index is the location, where the values are stored.

global.deckValue = ds_list_create()
for(k = 2; k < 11; k += 1) {
    ds_list_add(global.deckValue, k)
}
ds_list_add(global.deckValue, 10)
ds_list_add(global.deckValue, 10)
ds_list_add(global.deckValue, 10)
ds_list_add(global.deckValue, 1)

The section of code is where i add the values to the card deck. Where "k" is equal 2 and is less than 11, this is where the value will align with the index numbers. The increment of 1 makes sure that the values will definitely go up by one.  It will look a little like this;

index: 0 1 2 3 4 5 6 7 8
value: 2 3 4 5 6 7 8 9 10

The ds_list_add section adds the numbers 10 3 times and 1 for the Jack, Queen, King and Ace after the value numbers 2-10. So now the value will look like:

index: 0 1 2 3 4 5 6 7   8   9  10 11 12 13
value: 2 3 4 5 6 7 8 9 10 10 10 10 1

This now covers a whole suit of cards. This first suit of cards is most likely spades as that is the first suit seen in the image index. This section of code is repeated another 3 times for the other 3 suits.




(Left button event):

if mouse_check_button_pressed(mb_left) && global.dealDone = 0 {
// Deal button event

instance_create(global.dealer_card_xpos, 145, obj_dealer)
instance_create(global.dealer_card_xpos, 145, obj_dealer)
instance_create(global.player_card_xpos, 745, obj_player)
instance_create(global.player_card_xpos, 745, obj_player)
instance_create(global.AI1_card_xpos, 457.5, obj_AI1)
instance_create(global.AI1_card_xpos, 457.5, obj_AI1)
instance_create(global.AI2_card_xpos, 457.5, obj_AI2)
instance_create(global.AI2_card_xpos, 457.5, obj_AI2)
global.turn = 0
global.dealDone = 1
exit
}

if mouse_check_button_pressed(mb_left) && global.dealDone = 1 {
game_restart()
exit
}

This code is fairly simple, what happens is when the player left clicks on the card deal sprite, it will instantly deal the cards to the desired positions. Then the turn is set to 0 which means the first player can take their turn and dealDone is a variable used to make sure that the deal has been successful.
The bottom if statement checks whether the left button has been pressed over the sprite and checks if the deal was successful and then the game will restart.



obj_twist:
(Left button event):

if mouse_check_button_pressed(mb_left) {
    switch(global.turn) {
    case 0:
        instance_create(global.player_card_xpos, 745, obj_player)
    break
    case 1:
    show_message("You must wait for Player 1 to end their turn")
    break
    case 2:
    show_message("You must wait for Player 2 to end their turn")
    break
    }
}

When the left button is pressed, the player is able to add another card to their hand of cards to get close to the objective of the game, getting "blackjack"/21. If the player becomes bust or tries to use the twist button whilst it is someone else turns, a message will pop up dependent on which global.turn it is on. If the turn is on 0 then the player is still able to take their turn.



obj_stick:
(Left button event):

if mouse_check_button_pressed(mb_left) {
    switch(global.turn) {
    case 0:
        global.turnTo = 1
        global.turn = 1000
    break
    case 1:
    show_message("You must wait for Player 1 to end their turn")
    break
    case 2:
    show_message("You must wait for Player 2 to end their turn")
    break
    }
}

The code used for the stick button is very similar to the twist button. The code uses a switch statement instead of a bunch of if statements as it is easier and tidier to use. If the turn is on 0 and the player clicks on "stick" then the turnTo is activated and activates code for the AI player and your turn is over.



Sound:
I only have one sound for this game which is used for when the cards have been dealt. This sound lasts for a few seconds. The only reason why I only have one sound is because I have mainly been focusing on the coding for the game to make sure that everything works in harmony with one another. The sound code will be shown in a testing video (done by me) showing what sound I chose and showing it working.

Management:


Testing: 

Luke Anderson: The game was good with the dealing and the AI but I was able to restart the game when ever I want.

{The image below displays him typing up his thoughts on the game into my blogger.}




{The image below displays his game play when he pressed the deal button (back of card)}



{The image below displays his game play, after he has taken his turn and the AI's have taken their turn}


The reason behind why it says he has won "3" times is because that is how many times he has won on this computer.

Morgan Proffitt:

https://www.youtube.com/watch?v=GyccyeSxVM0&feature=youtu.be





Me:

https://www.youtube.com/watch?v=hr4fJiuUgRI&feature=youtu.be



Monday 8 February 2016

Assignment 1 Unit 73: Understanding the use of music within games and the methodology of recording and production.

Level 3 Btec Extended Diploma in Games Development
Unit 73: Sound for Computer Games

Assignment 1 - Understanding the use of music within games and the methodology of recording and production.

Task 1:Compare and contrast the following Console game music. You can consider other pieces of music/FX from the same game

Task 2: Using the clips above discuss the methods which could have been used to record and produce the music and why.

The Last of Us:



I have merged the two tasks together as I have found it easier this way to talk about the music tracks emotionally and technically. The Last of Us main theme song was originally composed by Gustavo Santaolalla and his instruments. One of the instruments which was used was a ronroco. This video shows evidence of the songs created for The Last Of Us were original developed made from instruments in a recording studio. I believe that what audio recording system they used is multi-track recordings. The reason behind why I believe that this song was created by multi-track recordings was so that Gustavo Santaolalla could listen to the orchestra separately from his guitar tune to create the perfect sound and then added his guitar to the orchestra track. Furthermore, with the orchestra, it is most likely that they would of recording the groups of instruments separately, for example; percussion, string, woodwind, brass etc. In this video https://www.youtube.com/watch?v=Ejdjcun2Jo4 around 1:10 - 1:30, this is where we see Gustavo Santaolalla taking control of how he wants the orchestra to play their instruments to gain the desired result.




When the music shifts into a softer tone, it creates a relaxed atmosphere and I feel this is where the perspective of the world around these characters has changed. It almost as if we see the beautiful side of this world, where nature has taken over the buildings. For example, where Joel and Ellie find the giraffe at the edge of a building and Ellie strokes its head. Furthermore, it gives a sense of hope as if they will see the end to this apocalyptic plague. Both of these images link in with my idea of the relaxed atmosphere the song creates.




When the bridge part of the song is over, it's almost as if we have been pulled back into the harsh reality of the world the characters live in, the post-apocalyptic world. The end of the track becomes very loud and harsh. The amplitude here would be large. The reason for this is because amplitude is the size of vibrations and the larger the vibration the louder the sound, this also meaning the decibel level would be very high. The wavelength of  the higher pitch parts would a have shorter wavelengths than deeper pitch parts, when it comes to louder and quieter sounds, the wavelength stays the same but the amplitude changes. The image below shows the difference in wavelengths and amplitude, dependent on the sound. This supports my idea of what the wavelength and amplitude would be like in certain parts of the track.








The Last Of Us main theme contrasts against the genre of the game. The genre of the game is survival horror and this song pushes away from the typical high pitch sounds and fast paced tune which is used for a horror games sound track. This track symbolises how the characters perceive the current world they live in. It symbolises a wasteland which carries on beyond the horizon in which the characters are exploring. The image to the right is an in game image showing the two main characters stood in an abandoned street. A lot of the areas which are explored are deserted. I think that what is most relative between this image and song is the warm tones from the sunset/dawn used to illuminate the abandoned streets. These warm tones from the sun illuminating the wasteland of the world tie in with the western theme, the theme of deserted lands and a rustic theme. Additionally, this particular scene fits in well with a mexican showdown as they are usually taken place at dawn in which fits in with the western theme. The finger plucked sounds created by using a guitar at a high pitch gives the song its western theme and contrasts against the deep pitched strums of guitar which create the song. This track is made for surround sound as the game was made for the PS4 (and PS3 but remastered for the PS4) and the disc used would be Blu-ray. As the format of the disc is Blu-ray, that means the sound file would actually be uncompressed due to the amount of space a Blu-ray contains. Blu-rays are made with 96KHz/192KHz sample rate and 24-bit-depth. So if this song had 96KHz sample rate and 24-bit-depth, then the file size of this would be 2.025GB taken up already on the Blu-ray disc. It is likely that they used a .WAV file format for the music as this is the most commonly used uncompressed file type. They most likely would of used PCM to determine what the bit-depth and sample rate is. Working this out is very helpful if they wanted to save some space. Having a song with double the sample rate can effectively double the overall size of a sound, due to the fact that there is now double the amount of samples to store, meaning that the file size is going to be bigger. When they were making this song, it is most likely that they used up more RAM compared to what Halo 2 composers did. For example, to create and edit the Halo 2 music overall, they may have had 4-8GB of RAM in their computers whereas, The Last of Us music may have had 8-16GB of RAM.

Halo 2:



The beginning of the song (when wearing headphones) really emphasis's on this song being made for stereo sound. The gospel voices which are used creates an atmosphere of the player entering sacred ground. Then, the increasing sound of the beat and the instruments in which are being added at the beginning of the song, create an atmosphere of a triumphant battle which is about to begin, as if you, the player, is approaching the battle ground. The increasing tone of the guitar and beat builds up a lot of tension and pressure on the player, but also, it makes the player feel dauntless and heroic. The added violin which plays with the guitar really adds emphasis on the guitar and pushes forth the atmosphere of this tense final battle. The rush of how quickly the instruments are put together beautifully and the speed of which the instruments are played at adds chaos to the atmosphere. This image is an in-game image of a battle in Halo 2 and I think it shows the chaotic battlefield which fits in with the music. The end of the main theme song almost replicates the beginning of the song, however with the fading sound of the guitar emphasis's the end of the battle. When the music shifts massively at the end of the track, the amplitude would be very low at this point, creating that quieter, softer tone. Same with the beginning of the track, with the voices. From 0:47 - 1;10, this video clips shows tense moments in Halo 2 where the player is in battle against another player, you can see that he finds it difficult to kill the other player and switches his weapon and jumps about.This image below is a screenshot of the Halo 2 gameplay in which I believe fits in well with the music.                                                          https://www.youtube.com/watch?v=tQRPH0PT4JA








It sounds as if, to create this track they used the audio recording system, multi-track recording. The reason behind why I think this is because it sounds like they have recorded the orchestra separate from the guitar. Also, it sounds like they recorded the violin separately away from the guitar and orchestra and then used multi-track recording to line up the tracks for the desired result. As they have used real instruments, this pushes away from them using software plug-ins and everything was originally developed.  This game was made for the original Xbox which means the disc they used to store all of the games data and such, was a dual-layer DVD disc meaning it has smaller capacity.The image above displaying CD, DVD and Blu-ray shows the different sized data they can all withstand and what the data layers look like.  A lot less compared to the size of a Blu-ray disc which was used for "The Last of Us". Its most likely that they would have compressed the sound files due to the amount of storage on the disc. The sound file they could have used is .WAV, a raw .WAV sound file has the sample rate of 44,100 kHz and 16-bit-depth. WAV files can be compressed, however when the WAV file is compressed, the only thing that is most likely to bit reduced is the bit depth. With the example above, the sample rate would still be 44,100 kHz and the bit depth would be reduced down to 4.  The audio limitation of this sound file would be that it had to be compressed due to the size of the DVD disc. As the sound file is compressed this means that the quality of music will be reduced from its original state. Furthermore, WAV files must be decompressed if compressed to listen to them. It is most likely they might have chosen a different file format due to wanting to save space such as MP3 or AAC. MP3 files is the most common file format and is the most compatible, however it is said that it is not efficient. An AAC file has the same the same quality as an MP3 file and is more efficient. This image below displays the file size and compatibility comparison between MP3 and AAC.




When it comes to comparing both pieces of music, they have a few things in common. What they have in common is that they are both main music themes for that particular game. They both give the game an overall feeling of what it is about. Another similarity is that both pieces of game music use similar techniques, using analogue and using computers and programs to process their music through.
The differences is that both games are on different platforms and the time around when they were made. When Halo 2 was released, it was made for the original Xbox. This gaming console used regular DVD disc for their games due to the specifications of the original Xbox. When The Last of Us was made, it was originally made for PS3. Technology had moved on since then dramatically, the PS3 had near enough the same specifications as the newer Xbox 360's. The PS3 and PS4 used blu-ray discs, this allowing them to use uncompressed file formats for the sound track. This kept the quality of the original soundtrack.

Composers can sell their music to a game company. When composers do this, they still have property rights. When a composers music has been put into a game, they receive "royalties". However, game company royalties are different to the music industry royalties. Music industry royalties often give the composers money in quarterly instalments, however with game companies, they decide to do something different. What game companies do is they work out a percentage which is a payment that have been calculated from net profits and they pay the composer.
If the game the composer has worked on has now been chosen to be developed for other platforms, the composer then receives extra money for their work.
When it comes to copyrighting the music in a games company, the developer will almost always demand to own the music. The reason for this is so that the developer can then use the same music or sound FX in the sequel of that game or they can re-use it on different platforms. Its most likely that with both games, the composers have agreed to the copyright regulations and agreed to the format of the royalties. In which is very different form from what Gustavo Santaolalla is used to.
If the game company believes that buying you out-right (meaning paying your wished amount is too high), you may offer a license to them. This license allows them to use your music in their game. With your music only being licensed, this means that you still have full ownership of your music and you able to re-sell it if you wanted to. However, game companies usually have a license agreement where the song that they have licensed to used, is only allowed to be used for that game in particular until a certain amount of time has passed and then your music can be used for another game.
It is most likely that all the composers involved within both games have accepted these terms and legal rights in order to start creating the music.