Skip to content

Instantly share code, notes, and snippets.

@wertgit
Created January 25, 2017 05:20
Show Gist options
  • Save wertgit/8b0ed4c89cf944d9915a916488607895 to your computer and use it in GitHub Desktop.
Save wertgit/8b0ed4c89cf944d9915a916488607895 to your computer and use it in GitHub Desktop.
Diamond
// List of total cards to swipe for a diamond
// Minimum being 3 and Maximum being 13
var diamond_targets = [3,8,5,7,9,10,4,12,13,6];
// Sets the total ammount of cards to solve
function set_total_cards_to_solve_for_diamond() {
// a random number from the list
var random
random = Math.floor((Math.random() * diamond_targets.length) + 0)
total_cards_to_solve_for_diamond = diamond_targets[random]; // set the value for the total number to solve
diamond_counter = 0 // reset the diamond counter
}
function offerDiamond(){
// only offer a limited number of diamonds between each mode in this case 3
// total_diamonds_given_fastmode is the total we have given out so far per fast mode session.
if(total_diamonds_given_fastmode < 1 && piano_sfx_counter > 2){
var offeraDiamond = Math.floor((Math.random() * 2) + 0)
if(offeraDiamond === 1) return true
else return false
//return true
}else return false
}
// Checks if we can display a diamond.
function showaDiamond() {
// During Fast Mode we award the player 2 Diamonds on Completion
// We also award one diamond randomly.
if (in_fast_mode) {
// We re-set the total cards to solve for diamond during this mode
set_total_cards_to_solve_for_diamond()
// piano_sfx_counter is counter for the piano roll.
//
if(piano_sfx_counter < 12){
// we check if we can offer player a random diamond
var offer = offerDiamond()
if(offer || piano_sfx_counter == 10){ // on the 10 position is the end of the piano roll
// We do not want to offer diamond right at the start of the fast mode so
// we skip the first 2 cards.
if(!(piano_sfx_counter === 0) && !(piano_sfx_counter === 1) )
{
total_diamonds_given_fastmode++ // increment total we have given out so far per fast mode session.
// set the total to collect. if piano sfx is at end 10, offer 2 else offer 1
diamondObject.no_of_diamonds_to_collect = piano_sfx_counter == 10 ? 2:1
showDiamonds() // show the diamond on the card starts the show diamond animation
makeDiamondsIdle() // start the diamond Idle animation
diamondObject.award_a_Diamond = true // we can award the diamond.
}
}
}
} else { /// In Slow Mode
// diamond_counter should be equal to the total cards to solve to show diamond.
if(diamond_counter === total_cards_to_solve_for_diamond)
{
// set the total to collect. offer 1
diamondObject.no_of_diamonds_to_collect = 1
showDiamonds() // show the diamond on the card starts the show diamond animation
makeDiamondsIdle() // start the diamond Idle animation
diamond_counter = 0 // reset diamond counter.
// set a boolean to collect a diamond
diamondObject.award_a_Diamond = true
}
}
}
function awardDiamond(){
idle_animation.stop() // Stop the Idle Animation
incrementDiamonds() // This makes the diamonds fly to the diamond HUD position.
set_total_cards_to_solve_for_diamond()
diamondObject.award_a_Diamond = false
}
function incrementDiamonds(){
// we set how many diamonds are to fly to the diamondHUD
var i
for (i = 0; i < no_of_diamonds_to_collect; i++) {
entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("Score.qml"), {"text_color": "RED","text_value": "+"+0,"x_value": x_cord_diamond_HUD,"y_value": y_cord_diamond_HUD,"from_x_value": 110,"from_y_value": 210});
}
// The animation works like
// we set a random duration for the diamond flying animation
//
ParallelAnimation {
id: diamond_fly_to_HUD
PropertyAnimation { target: diamondObject; property: "y"; from: 350; to: y_value; easing.type: Easing.Linear; duration: utils.generateRandomValueBetween(500, 720) }
PropertyAnimation { target: diamondObject; property: "x"; from: 130; to: x_value+61; easing.type: Easing.OutBack; duration: utils.generateRandomValueBetween(500, 720) }
PropertyAnimation { target: diamondObject; property: "opacity"; to: 1; easing.type: Easing.Linear; duration: 100 } // its starts when transparent
onStopped: {
removeEntity()
/// Once the cards reach the Diamond HUD.
if(reachedHUD){
// grab the total diamonds of player and add the total ammount of diamonds collected
totalDiamonds += diamondObject.no_of_diamonds_to_collect
saveDiamonds() // save the total diamonds in local storage.
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment