Thursday, June 3, 2021

【GAMEMAKER】Slot Machine

scriptController 

 {

 //randomize reels

reel1rnd = floor(random(3))

reel2rnd = floor(random(3))

reel3rnd = floor(random(3))


 //stop reel

 reel1.image_single = reel1rnd

 reel2.image_single = reel2rnd

 reel3.image_single = reel3rnd

 sound_play(Reel_Stop);


 //check for winner

 if(win_check()){ sound_play(Coins_In_Tray); }


}


ScriptHandle


{

 if (global.spin_enabled = true){

  

//  sound_play(Insert_Coin);

  score -= global.spin_cost

  image_single = -1


  //disable spin button

  global.spin_enabled = false


  //start reel animation

 sound_play(Reel_Spin);

 reel1.image_single = -1

 reel2.image_single = -1

 reel3.image_single = -1


  //set alarm0 on controller

  with(controller){

   alarm[0] = room_speed*global.spin_duration

   alarm[1] = room_speed*global.spin_duration + 0.5

  }

 }

}


winCheck



if (reel1rnd == 0 && reel2rnd == 0 && reel3rnd == 0){score += 1000; return true;}

if (reel1rnd == 1 && reel2rnd == 1 && reel3rnd == 1){score += 500; return true;}

if (reel1rnd == 2 && reel2rnd == 2 && reel3rnd == 2){score += 200; return true;}

if (reel1rnd == 1 && reel2rnd == 1 && reel3rnd != 1){score += 100; return true;}

if (reel1rnd == 2 && reel2rnd == 2 && reel3rnd != 2){score += 100; return true;}

return false;


Information about object: objcontroller
Sprite: controller
Solid: false
Visible: false
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Alarm Event for alarm 0:
execute script scriptController with arguments (0,0,0,0,0)
Alarm Event for alarm 1:
execute code:

{
 //checks if you can pay to play
 if (score = 0){
  str = show_question('play again?')
  if (str == false){game_end()}
  if (str == true){game_restart()}
 }

 global.spin_enabled = true
}
Other Event: Game Start:
execute code:

{
 global.spin_enabled = true
 global.spin_duration = 1
 global.spin_cost = 25
 score = 1000 

}


Information about object: reel1
Sprite: reel_animation
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

{
image_single = 0 

}


Information about object: reel2
Sprite: reel_animation
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

{
image_single = 0 

}


 Information about object: reel3

Sprite: reel_animation
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

{
image_single = 0
}

Information about object: objHandle
Sprite: Handle
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

{
  image_single = 0
  image_speed = 0.25
}
Mouse Event for Left Button:
execute code:



if (not sound_isplaying(Coins_In_Tray)) { Handle() }
Other Event: Animation End:
execute code:

{
  image_single = 0
}

No comments:

Post a Comment

[New post] All or Nothing

...