じ☆ve冰风 发表于 2026-7-26 08:05:08

Minigame: Flip a Coin

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



Script only

Spoiler 
/*:* @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.userChoice;}Scene_CoinFlip.prototype.saveResultInGameVariable = function(){         $gameVariables._data = 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
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7


本贴来自国际rpgmaker官方论坛作者:Pincalibur处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/minigame-flip-a-coin.50435/
页: [1]
查看完整版本: Minigame: Flip a Coin