Minigame: Flip a Coin

Pincalibur

Coding Penguin
Member
Joined
Jan 25, 2014
Messages
7
Reaction score
8
First Language
Germany
Hi there,

this is my Flip a Coin Minigame.

Because I started learning JS two days ago, I decided to start small.

How to implement:

  • Copy the "PINC_CoinFlip.js" into your /js/plugin
  • Copy the "head.png" and "tail.png" into your /img/pictures
  • Add PINC_CoinFlip in your Plug-in-Manager
  • Edit parameters if needed
Edit:
Demo

I created a Demo for you guys, so you can see how to use the plug-in.

The coin-animation I created may be used together with the script.

Download: https://www.dropbox.com/s/w5xrjkp8jw3aogv/PINCALIBUR_COIN_FLIP.zip?dl=0

Screenshot 2015-11-15 21.12.54.png

Script only

 
/*:* @plugindesc This is a Coinflip Minigame. ** @author Pincalibur ** @help Call the Minigame with the Plug-in-command: CallCoinFlipThe Player chooses a side, which will be written into the Variable 001. (default)Value '0' for head, Value '1' for tail.If the Player guesses right, the result-value '1' will be written into the Variable: 002 (default). If he loses '0'. If the Player quits the game , it gets the value '2'.Press Left or Right to switch to head or tail. Press Enter to start or Escape to cancel the game.** @version 1.1** @param variableIDPlayerChoice* @desc The variable-ID to use for the player's choice. Can't be 0.* @default 1** @param variableIDResult* @desc The variable-ID to use for the result. Can't be 0.* @default 2** @param coinHeadLabel* @desc The shown text for the frontside.* @default Head** @param coinTailLabel* @desc The shown text for the backside.* @default Tail** @param coinHeadImageName* @desc The name for the headimage.* @default head** @param coinTailImageName* @desc The name for the tailimage.* @default tail** @param coinPosX* @desc The X value for the Coinposition* @default 385** @param coinPosY* @desc The Y value for the Coinposition* @default 310*//*-----------------------------------------------------** Parameters**----------------------------------------------------*/var parameters = PluginManager.parameters('PINC_CoinFlip');var variableNumberPlayerChoice = Number(parameters['variableIDPlayerChoice'] || 1);var variableNumberResult = Number(parameters['variableIDResult'] || 2);var coinHeadLabel = String(parameters['coinHeadLabel'] || Head);var coinTailLabel = String(parameters['coinTailLabel'] || Tail);var coinHeadImageName = String(parameters['coinHeadImageName'] || head);var coinTailImageName = String(parameters['coinTailImageName'] || tail);var coinPosX = Number(parameters['coinPosX'] || 385);var coinPosY = Number(parameters['coinPosY'] || 310);/*-----------------------------------------------------** Plugin Command "CallCoinFlip"**----------------------------------------------------*/var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command) if (command === 'CallCoinFlip') { SceneManager.push(Scene_CoinFlip); }}/*-------------------------------------------------------------* * Scene_CoinFlip** The Scene, which is acting as Coinflip-Minigame* *------------------------------------------------------------*/function Scene_CoinFlip() { this.initialize.apply(this, arguments);}Scene_CoinFlip.prototype = Object.create(Scene_Base.prototype);Scene_CoinFlip.prototype.constructor = Scene_CoinFlip;Scene_CoinFlip.prototype.initialize = function() { Scene_Base.prototype.initialize.call(this);};Scene_CoinFlip.prototype.create = function() { this.coinX = coinPosX; this.coinY = coinPosY; this.headImgName = coinHeadImageName; this.tailImgName = coinTailImageName; this.userChoice = 0; this.result = 0; this.playerChoiceVariable = variableNumberPlayerChoice; this.resultVariable = variableNumberResult; this.createBackground(); this.drawCoin(); this.drawCoinText(); Scene_Base.prototype.create.call(this);};Scene_CoinFlip.prototype.createBackground = function() { this.backgroundSprite = new Sprite(); this.backgroundSprite.bitmap = SceneManager.backgroundBitmap(); this.addChild(this.backgroundSprite);};Scene_CoinFlip.prototype.drawCoin = function() { this.coinSprite = new Sprite(); this.coinSprite.position.x = this.coinX; this.coinSprite.position.y = this.coinY; this.headBitmap = ImageManager.loadPicture(this.headImgName); this.tailBitmap = ImageManager.loadPicture(this.tailImgName); this.coinSprite.bitmap = this.headBitmap; this.addChild(this.coinSprite);};Scene_CoinFlip.prototype.drawCoinText = function() { var coinText = coinHeadLabel; this.maxWidth = Graphics.width; this.coinTextX = this.coinX - 385; this.coinTextY = this.coinY + 48; this.coinTextSprite = new Sprite(new Bitmap(Graphics.width, Graphics.height)); this.addChild(this.coinTextSprite);; this.coinTextSprite.bitmap.outlineColor = 'black'; this.coinTextSprite.bitmap.outlineWidth = 8; this.coinTextSprite.bitmap.fontSize = 48; this.coinTextSprite.bitmap.drawText(coinText, this.coinTextX, this.coinTextY, this.maxWidth, 48, 'center');};Scene_CoinFlip.prototype.start = function() { Scene_Base.prototype.start.call(this);};Scene_CoinFlip.prototype.update = function() { this.getInput(); Scene_Base.prototype.update.call(this);};Scene_CoinFlip.prototype.terminate = function() { Scene_Base.prototype.terminate.call(this);};Scene_CoinFlip.prototype.getInput = function() { if(Input.isTriggered('left')){ this.switchCoinSide(); } if(Input.isTriggered('right')){ this.switchCoinSide(); } if(Input.isTriggered('cancel')){ this.result = 2; this.saveResultInGameVariable(); this.clearGame(); } if(Input.isTriggered('ok')){ this.flipCoin(); this.savePlayerChoiceInGameVariable(); this.saveResultInGameVariable(); this.clearGame(); }};Scene_CoinFlip.prototype.switchCoinSide = function(){ if(this.userChoice === 0){ this.userChoice = 1; this.coinSprite.bitmap = this.tailBitmap; this.switchCoinText(coinTailLabel); } else { this.userChoice = 0; this.coinSprite.bitmap = this.headBitmap; this.switchCoinText(coinHeadLabel); }};Scene_CoinFlip.prototype.switchCoinText = function(coinText){ this.coinTextSprite.bitmap = new Bitmap(Graphics.width, Graphics.height); this.coinTextSprite.bitmap.outlineColor = 'black'; this.coinTextSprite.bitmap.outlineWidth = 8; this.coinTextSprite.bitmap.fontSize = 48; this.coinTextSprite.bitmap.drawText(coinText, this.coinTextX, this.coinTextY, this.maxWidth, 48, 'center');};Scene_CoinFlip.prototype.flipCoin = function(){ //0 is Head, 1 is Tail; var flipResult = Math.floor(Math.random() * 2); if (this.userChoice === flipResult){ this.result = 1; } else { this.result = 0; }} Scene_CoinFlip.prototype.savePlayerChoiceInGameVariable = function(){ $gameVariables._data[this.playerChoiceVariable] = this.userChoice;}Scene_CoinFlip.prototype.saveResultInGameVariable = function(){ $gameVariables._data[this.resultVariable] = this.result;}Scene_CoinFlip.prototype.clearGame = function(){ SceneManager.pop();}
I hope you enjoy my first Plugin!

If you want any additionally features, tell me.

I would like to be credited, if you use my ressources!

If you release a game and you use my ressources ,I would be happy to play it!

Thank you :)
 
Last edited by a moderator:

wmbuilding

Villager
Member
Joined
Nov 1, 2015
Messages
6
Reaction score
1
First Language
english
Primarily Uses
great to see a minigame for MV already =)
 

Ghost of Christmas Kloe

Ghost of a Princess Seagull
Veteran
Joined
Nov 15, 2015
Messages
1,504
Reaction score
914
First Language
English
Primarily Uses
N/A
Yay! Demo! (Also you did  great job with the coin animation :)  ) 

May I just say that a penguin who can code a mini-game script, may just be the coolest thing ever!
 
Last edited by a moderator:

momiage

Villager
Member
Joined
Mar 12, 2015
Messages
8
Reaction score
1
First Language
Japanese
Very nice!

It would be even cooler if you were able to bet money.

(e.g. If you win, you get more money back,

but if you lose , you lose the money you bet)

But that may be too complicated. :unsure:
 

Ghost of Christmas Kloe

Ghost of a Princess Seagull
Veteran
Joined
Nov 15, 2015
Messages
1,504
Reaction score
914
First Language
English
Primarily Uses
N/A
Very nice!

It would be even cooler if you were able to bet money.

(e.g. If you win, you get more money back,

but if you lose , you lose the money you bet)

But that may be too complicated. :unsure:
Well, you sort of can. Use the demo and change the 1gold bit to 15g, and the bit where it gains one "money" item one to 20g and you have a betting system, where you bet 15g and get 30 back if you win, or nothing if you lose!
 

Pincalibur

Coding Penguin
Member
Joined
Jan 25, 2014
Messages
7
Reaction score
8
First Language
Germany
Well, you sort of can. Use the demo and change the 1gold bit to 15g, and the bit where it gains one "money" item one to 20g and you have a betting system, where you bet 15g and get 30 back if you win, or nothing if you lose!
I actually made a bet system in the demo like Kloe said.

You can add evencommand so the NPC checks if you have enough gold, then change the given or lost gold.

In my Demo the given or lost gold amount is set to 1.
 
Last edited by a moderator:

Nii Miyo

Warper
Member
Joined
Jun 16, 2016
Messages
2
Reaction score
0
First Language
Portuguese
Primarily Uses
The link to the Demo is broken for me... Please if you can, update it.
Sorry if I wrote something wrong... I don't speak English very well...
 

nahongo

Warper
Member
Joined
Nov 29, 2016
Messages
4
Reaction score
0
First Language
english
Primarily Uses
the link is dead...
 

InkPotion

I've moved accounts! Now RunePotion.
Veteran
Joined
Jun 30, 2016
Messages
82
Reaction score
51
First Language
English
Primarily Uses
RMMV
Update:
I updated my post, to provide you guys a demo version to work with.


Have fun!


Would you be able to fix the link for the demo? It seems to be broken :)  
 

dfox20

Villager
Member
Joined
Jun 21, 2012
Messages
16
Reaction score
2
First Language
English
Primarily Uses
When you are on, could you reupload the demo please? Great plugin! ^^
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Who knew modern medieval was an actual music genre? I don't know what the youtube algorithms are doing but for once they found something actually fascinating:
Yay! Got 3 new frying pans, its weird, but I'm so happy about it.
Yelp. I've discovered that I am one of those people who should not be drinking coffee. Took me a week detoxing off of coffee and switching to tea to realize how badly it was affecting me- and I've been drinking the stuff for years. Yikes!
I bought a gaiter with Meijer printed on it.

I'm still a Walmart worker, and I wore it today for work.
Trying out new carpet autotiles and I can't decide if it's working or not. Pixeling soft carpets is hard

Forum statistics

Threads
99,525
Messages
966,393
Members
131,151
Latest member
CyberRPG
Top