设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 101|回复: 0

[转载发布] Minigame: Flip a Coin

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    8259

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    30525
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    39678

    灌水之王

    发表于 6 天前 | 显示全部楼层 |阅读模式
    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

    [url=https://forums.rpgmakerweb.com/attachments/screenshot-2015-11-15-21-12-54-png.26139/][/url]

    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.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  



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

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 18:50 , Processed in 0.149720 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表