1 /**********************************************************************************
2 * Copyright (c) 2008, 2009 Derek Yu and Mossmouth, LLC
3 * Copyright (c) 2010, Moloch
4 * Copyright (c) 2018, Ketmar Dark
6 * This file is part of Spelunky.
8 * You can redistribute and/or modify Spelunky, including its source code, under
9 * the terms of the Spelunky User License.
11 * Spelunky is distributed in the hope that it will be entertaining and useful,
12 * but WITHOUT WARRANTY. Please see the Spelunky User License for more details.
14 * The Spelunky User License should be available in "Game Information", which
15 * can be found in the Resource Explorer, or as an external file called COPYING.
16 * If not, please obtain a new copy of Spelunky from <http://spelunkyworld.com/>
18 **********************************************************************************/
19 class MonsterTunnelMan['oTunnelMan'] : MapObject;
33 int udHoldCounter = 0;
34 const int udHoldCounterFirst = 15;
35 const int udHoldCounterMax = 4;
37 bool upPressed, downPressed, payPressed;
38 bool upHold, downHold;
42 int helpMessageShown = 0;
45 override bool initialize () {
46 if (!::initialize()) return false;
47 setSprite('sTunnelManLeft');
48 setCollisionBoundsFromFrame();
54 setSprite('sTunnelManRight');
58 void playerMovedAway () {
65 //writeln("player moved away; talk=", talk);
66 if (talk != TalkState.Silent) {
67 if (!donated) talk = TalkState.Complaining;
68 //playerGoAway = true;
76 talk = TalkState.Hello;
81 if (talk == TalkState.Hello) {
82 level.osdMessageTalk("HEY THERE! I'M THE TUNNEL MAN!\nI DIG SHORTCUTS.", replace:true, timeout:999999, inShopOnly:false);
83 if (!helpMessageShown) {
85 level.osdMessage("PRESS $PAY TO TALK.", -666);
87 } else if (talk == TalkState.Bargaining) {
88 string msg = va("CAN YOU LEND ME A LITTLE MONEY?\nI NEED ~$%d~ FOR A NEW SHORTCUT.\n|DONATE: %d|", level.stats.leftForNextTunnel(), donate);
89 level.osdMessageTalk(msg, replace:true, timeout:999999, inShopOnly:false);
90 if (helpMessageShown != 2) {
92 level.osdMessage("PRESS $PAY TO PAY.\nPRESS $UP OR $DOWN TO CHANGE DONATION.", -666);
94 } else if (talk == TalkState.Thanks) {
95 level.osdMessageTalk("THANKS! YOU WON'T REGRET IT!", replace:true, timeout:999999, inShopOnly:false);
96 } else if (talk == TalkState.Complaining) {
97 level.osdMessageTalk("I'LL NEVER GET THIS SHORTCUT BUILT!", replace:true, timeout:999999, inShopOnly:false);
98 } else if (talk == TalkState.ShortcutOpened) {
99 level.osdMessageTalk("ONE SHORTCUT, COMING UP!", replace:true, timeout:999999, inShopOnly:false);
104 override void thinkFrame () {
105 auto stats = level.stats;
109 if (talk == TalkState.Hello) {
110 talk = TalkState.Bargaining;
111 } else if (talk == TalkState.Bargaining) {
114 bool digged = stats.payForTunnel(donate);
115 talk = (digged ? TalkState.ShortcutOpened : TalkState.Thanks);
116 stats.takeMoney(donate);
117 //global.moneySpent += donate;
119 talk = TalkState.Complaining;
125 if (talk == TalkState.Bargaining) {
126 if (upPressed || downPressed) {
127 udHoldCounter = udHoldCounterFirst;
128 donate = min(donate+1000, stats.money);
129 } else if (udHoldCounter > 0) {
130 if (--udHoldCounter == 0) {
131 donate = min(donate+(upHold ? 1000 : downHold ? -1000 : 0), stats.money);
132 udHoldCounter = udHoldCounterMax;
140 override void drawWithOfs (int xpos, int ypos, int scale, float currFrameDelta) {
141 ::drawWithOfs(xpos, ypos, scale, currFrameDelta);
143 auto oclr = GLVideo.color;
144 GLVideo.color = 0xff_ff_00;
145 level.sprStore.loadFont('sFontSmall');
147 level.sprStore.renderText((ix-32)*scale-xpos, (iy-18)*scale-ypos, "MY HERO!", 3);
148 GLVideo.color = oclr;