SHOW:
|
|
- or go back to the newest paste.
| 1 | #------------------------------------------------------------------------------- | |
| 2 | - | # Ultim1337Gamer's Simple Rock-Paper-Scissors |
| 2 | + | # U1G Engine - Simple Rock-Paper-Scissors System V.1.2 |
| 3 | - | # By : Ultim1337Gamer |
| 3 | + | # By : Ultim1337Gamer |
| 4 | - | # |
| 4 | + | # |
| 5 | - | #This script allows you to add a Rock-Paper-Scissors Scene to your game |
| 5 | + | # This easy-to-use script adds a Rock-Paper-Scissors scene in your game. |
| 6 | #------------------------------------------------------------------------------- | |
| 7 | - | #================================TERMS OF USE(READ)============================# |
| 7 | + | #================================HOW TO USE====================================# |
| 8 | - | # Free for all projects (Commercial & Non-Commercial)As long as I'm credited : |
| 8 | + | # -Plug & Play.Edit if needed. # |
| 9 | - | #"Ultim1337Gamer". |
| 9 | + | # -Call the scene using the script call SceneManager.call(Scene_RPS) # |
| 10 | - | #=============================SCRIPT STARTING==================================# |
| 10 | + | # -NOTE : DON'T edit outside editable zones UNLESS you KNOW what you're doing. # |
| 11 | - | #Don't edit outside editable zones unless you know what you're doing. |
| 11 | + | # -NOTE :Don't edit Non-Commented code UNLESS you KNOW what you're doing. # |
| 12 | #==============================================================================# | |
| 13 | - | #To call the scene,Use :"SceneManager.call(Scene_RPS)"Without quotation marks |
| 13 | + | #===============================CHANGELOG======================================# |
| 14 | - | |
| 14 | + | # V.1.1 : Beta # |
| 15 | - | # Main Scene |
| 15 | + | # V.1.2 : Cleaned & made the code easily readable,Added background,polished # |
| 16 | - | class Scene_RPS < Scene_Base |
| 16 | + | # editable zone looks,fixed bugs and other stuff... # |
| 17 | - | # Scene Starting |
| 17 | + | |
| 18 | - | def start |
| 18 | + | # CREDITS & TERMS OF USE |
| 19 | - | super |
| 19 | + | #-Free for both Commercial and Non-Commercial Projects as long as I'm credited |
| 20 | # "Ultim1337Gamer" | |
| 21 | #----------------------------------CREDITS-------------------------------------- | |
| 22 | #-My Brain and Hands : For thinking and typing this script. | |
| 23 | #-DiamondandPlatinium3 : For his awesome RGSS3 Tutorials | |
| 24 | #-Euphoria : For helping | |
| 25 | - | # Creates Title |
| 25 | + | #-Napoleon : For helping |
| 26 | - | def create_title |
| 26 | + | #-Venka : For LOTS and LOTS of helping. |
| 27 | #-FenixFyreX : For helping and suggestions. | |
| 28 | - | Audio.bgm_play("Audio/BGM/Battle1", 100, 100)#EDITABLE#
|
| 28 | + | |
| 29 | - | @title.set_text("Rock-Paper-Scissors!")#EDITABLE#
|
| 29 | + | # Editable Zone Starting : |
| 30 | #=============================================================================== | |
| 31 | - | # Creates Selection Window |
| 31 | + | module U1GRPS |
| 32 | - | def create_commands |
| 32 | + | BG_Image = "RPSBackground" # The image that'll serve as a background |
| 33 | Music = ["Battle1", 100, 100] # The BGM that'll play in the scene. | |
| 34 | - | @window_selection.set_handler(:rock, method(:rock))#EDITABLE |
| 34 | + | Title_Text = "Rock-Paper-Scissors!" # Text to display as a title. |
| 35 | - | @window_selection.set_handler(:paper, method(:paper))#EDITABLE |
| 35 | + | Win_Text = "Win!" # Message to diplay in case of winning |
| 36 | - | @window_selection.set_handler(:scissors, method(:scissors))#EDITABLE |
| 36 | + | Tie_Text = "Tie!" # Message to diplay in case of tie |
| 37 | Loss_Text = "Loss!" # Message to display in case of a loss | |
| 38 | - | # Generates COM Choice. |
| 38 | + | Rock_Command = "Rock" # Weapon name in Choice window. |
| 39 | - | def generate_choice |
| 39 | + | Paper_Command = "Paper" # Weapon name in Choice window. |
| 40 | - | list_weapons = [:rock, :paper, :scissors] |
| 40 | + | Scissors_Command = "Scissors" # Weapon name in Choice window. |
| 41 | - | @computer_choice = list_weapons.sample |
| 41 | + | end |
| 42 | #=============================================================================== | |
| 43 | - | def create_window_message |
| 43 | + | # End of Editable Zone.Editing past this point will cause brain explosion. |
| 44 | #=============================================================================== | |
| 45 | # SCRIPT STARTING # | |
| 46 | class Scene_RPS < Scene_Base | |
| 47 | - | # Shows Message |
| 47 | + | #------------------------------------------------------------------------------# |
| 48 | - | def display_message(text, number) |
| 48 | + | # Start the Scene |
| 49 | def start | |
| 50 | - | message = "Win!"#EDITABLE |
| 50 | + | super() |
| 51 | create_background | |
| 52 | - | message = "Tie!"#EDITABLE |
| 52 | + | |
| 53 | create_commands | |
| 54 | - | message = "Loss!"#EDITABLE |
| 54 | + | |
| 55 | end | |
| 56 | #------------------------------------------------------------------------------# | |
| 57 | # Creates Background | |
| 58 | def create_background | |
| 59 | - | # IF rock |
| 59 | + | @background_sprite = Sprite.new |
| 60 | - | def rock |
| 60 | + | @background_sprite.bitmap = Cache.picture(U1GRPS::BG_Image) |
| 61 | - | if @computer_choice == :rock |
| 61 | + | @background_sprite.x = 0 |
| 62 | - | display_message("You : Rock,COM : Rock", 0)
|
| 62 | + | @background_sprite.y = 0 |
| 63 | - | SceneManager.call(Scene_RPS) |
| 63 | + | @background_sprite.zoom_x = 544.0 / @background_sprite.bitmap.width |
| 64 | - | elsif @computer_choice == :paper |
| 64 | + | @background_sprite.zoom_y = 414.0 / @background_sprite.bitmap.height |
| 65 | - | display_message("You : Rock,COM : Paper", 1)
|
| 65 | + | |
| 66 | - | SceneManager.call(Scene_Map) |
| 66 | + | #----------------------------------------------------------------------------# |
| 67 | - | else |
| 67 | + | # Creates Title |
| 68 | - | display_message("You : Rock,COM : Scissors", 2)
|
| 68 | + | def create_title |
| 69 | - | SceneManager.call(Scene_RPS) |
| 69 | + | |
| 70 | BattleManager.save_bgm_and_bgs | |
| 71 | RPG::BGM.new(*U1GRPS::Music).play | |
| 72 | - | # IF paper |
| 72 | + | @title.set_text(U1GRPS::Title_Text) |
| 73 | - | def paper |
| 73 | + | |
| 74 | - | if @computer_choice == :paper |
| 74 | + | #----------------------------------------------------------------------------# |
| 75 | - | display_message("You : Paper,COM : Paper", 0)
|
| 75 | + | # Creates Commands |
| 76 | - | SceneManager.call(Scene_RPS) |
| 76 | + | def create_commands |
| 77 | - | elsif @computer_choice == :scissors |
| 77 | + | |
| 78 | - | display_message("You : Paper,COM : Scissors", 1)
|
| 78 | + | @window_selection.set_handler(:ok, method(:choose_rps)) |
| 79 | - | SceneManager.call(Scene_Map) |
| 79 | + | @window_selection.set_handler(:cancel, method(:return_scene)) |
| 80 | - | else |
| 80 | + | |
| 81 | - | display_message("You : Paper,COM : Rock", 2)
|
| 81 | + | #----------------------------------------------------------------------------# |
| 82 | - | SceneManager.call(Scene_RPS) |
| 82 | + | # Creates Window Message |
| 83 | def create_window_message | |
| 84 | @message = Window_Base.new(132, 168, 280, 80) | |
| 85 | - | # IF scissors |
| 85 | + | |
| 86 | - | def scissors |
| 86 | + | |
| 87 | - | if @computer_choice == :scissors |
| 87 | + | #----------------------------------------------------------------------------# |
| 88 | - | display_message("You : Scissors,COM : Scissors", 0)
|
| 88 | + | # Determine player selection |
| 89 | - | SceneManager.call(Scene_RPS) |
| 89 | + | # This is FenixFyreX's suggestion |
| 90 | - | elsif @computer_choice == :rock |
| 90 | + | def choose_rps |
| 91 | - | display_message("You : Scissors,COM : Rock", 1)
|
| 91 | + | |
| 92 | - | SceneManager.call(Scene_Map) |
| 92 | + | case @window_selection.current_symbol |
| 93 | - | else |
| 93 | + | when :rock; rock |
| 94 | - | display_message("You : Scissors,COM : Paper", 2)
|
| 94 | + | when :paper; paper |
| 95 | - | SceneManager.call(Scene_RPS) |
| 95 | + | when :scissors; scissors |
| 96 | end | |
| 97 | @window_selection.activate | |
| 98 | - | # Waiting to press C button |
| 98 | + | |
| 99 | - | def pre_terminate |
| 99 | + | #----------------------------------------------------------------------------# |
| 100 | - | super |
| 100 | + | # Generate Choice |
| 101 | - | loop do |
| 101 | + | def generate_choice |
| 102 | - | Graphics.update |
| 102 | + | @weapon_list = ["Rock", "Paper", "Scissors"] |
| 103 | - | Input.update |
| 103 | + | @computer_choice = @weapon_list.sample |
| 104 | - | break if Input.trigger?(:C) |
| 104 | + | |
| 105 | #----------------------------------------------------------------------------# | |
| 106 | # Choice : Rock | |
| 107 | def rock | |
| 108 | - | |
| 108 | + | text = "You: #{U1GRPS::Rock_Command} - COM: #{@computer_choice}"
|
| 109 | - | # "Weapon" Selection Window |
| 109 | + | case @computer_choice # Get the result number |
| 110 | - | class Window_RPS < Window_Command |
| 110 | + | when @weapon_list[0]; result = 0 # Rock |
| 111 | - | # Choice window Creation. |
| 111 | + | when @weapon_list[1]; result = 1 # Paper |
| 112 | - | def make_command_list |
| 112 | + | when @weapon_list[2]; result = 2 # Scissors |
| 113 | - | add_command("Rock", :rock)#EDITABLE#
|
| 113 | + | |
| 114 | - | add_command("Paper", :paper)#EDITABLE#
|
| 114 | + | display_message(text, result) |
| 115 | - | add_command("Scissors", :scissors)#EDITABLE#
|
| 115 | + | |
| 116 | #----------------------------------------------------------------------------# | |
| 117 | # Choice : Paper | |
| 118 | - | #==============================END OF SCRIPT================================== |
| 118 | + | def paper |
| 119 | # Set the text string just the one time. | |
| 120 | text = "You: #{U1GRPS::Paper_Command} - COM: #{@computer_choice}"
| |
| 121 | case @computer_choice # get the result number | |
| 122 | when @weapon_list[0]; result = 2 # Rock | |
| 123 | when @weapon_list[1]; result = 0 # Paper | |
| 124 | when @weapon_list[2]; result = 1 # Scissors | |
| 125 | end | |
| 126 | display_message(text, result) | |
| 127 | end | |
| 128 | #----------------------------------------------------------------------------# | |
| 129 | # Choice : Scissors | |
| 130 | def scissors | |
| 131 | # Set the text string just the one time. | |
| 132 | text = "You: #{U1GRPS::Scissors_Command} - COM: #{@computer_choice}"
| |
| 133 | case @computer_choice # get the result number | |
| 134 | when @weapon_list[0]; result = 1 # Rock | |
| 135 | when @weapon_list[1]; result = 2 # Paper | |
| 136 | when @weapon_list[2]; result = 0 # Scissors | |
| 137 | end | |
| 138 | display_message(text, result) | |
| 139 | end | |
| 140 | #----------------------------------------------------------------------------# | |
| 141 | # Shows Message | |
| 142 | def display_message(text, number) | |
| 143 | @message.contents.clear | |
| 144 | @message.draw_text(0, 0, 280, 38, text) | |
| 145 | message = U1GRPS::Win_Text | |
| 146 | if number == 0 | |
| 147 | message = U1GRPS::Tie_Text | |
| 148 | elsif number == 1 | |
| 149 | message = U1GRPS::Loss_Text | |
| 150 | end | |
| 151 | @message.draw_text(0, 20, 280, 38, message) | |
| 152 | @message.show | |
| 153 | end | |
| 154 | #----------------------------------------------------------------------------# | |
| 155 | # Quitting the Scene : | |
| 156 | def terminate | |
| 157 | super() | |
| 158 | @background_sprite.bitmap.dispose() if @background_sprite.bitmap | |
| 159 | @background_sprite.dispose() if @background_sprite | |
| 160 | BattleManager.replay_bgm_and_bgs | |
| 161 | end | |
| 162 | end | |
| 163 | ||
| 164 | # "Weapon" Selection Window | |
| 165 | class Window_RPS < Window_Command | |
| 166 | # Choice Window Creation (Don't Edit yellow text!!" | |
| 167 | def make_command_list | |
| 168 | add_command(U1GRPS::Rock_Command, :rock) | |
| 169 | add_command(U1GRPS::Paper_Command, :paper) | |
| 170 | add_command(U1GRPS::Scissors_Command, :scissors) | |
| 171 | end | |
| 172 | end |