summary refs log tree commit diff stats
path: root/lib/std/private/ospaths2.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/private/ospaths2.nim')
0 files changed, 0 insertions, 0 deletions
n67'>67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
<!DOCTYPE html>
<html>
<head>
	<title>Broughlike tutorial - Stage 5</title>
	<meta charset="utf-8">
</head>
<body>
	<div id="outer">
        <div class="header">
            <a href="index.html">JavaScript Broughlike Tutorial</a>
            <a href="stage4.html">Previously: Monsters - Part 2</a>
        </div>
		<h1>Stage 5: Game Lifecycle: drawing text, title screen, failure condition, and moving between levels</h1>
        Currently, when monsters are killed they are immediately deleted from the game. That's great, but there is no code to handle <em>player</em> death. Let's tackle that now.
        <h2>Game state</h2>
        We'll add the concept of a 
        <div class="code-container-inline inline"><pre><code class="javascript">gameState</code></pre></div>
        so we can model the game as a <a href="https://en.wikipedia.org/wiki/Finite-state_machine">finite state machine</a> with four states.
        <br><br>
        Our four states:
        <ul>
            <li><strong>loading</strong>: waiting for the assets to load</li> 
            <li><strong>title</strong>: on the title screen</li> 
            <li><strong>running</strong>: playing the game actively</li> 
            <li><strong>dead</strong>: the moment after the player has died, but before returning to the title screen</li> 
        </ul>
        "Finite state machine" sounds super complicated. It's not.
        <img src="screens/state-machine.png">
        Just think about a title screen. That's a state. Then when the <em>actual game</em> is running, that's a state. Clearly different things are displayed on the title screen versus the game proper. And pressing a specific button in-game and pressing it on the title screen do different things. So that's all we're trying to accomplish.
        <br><br>
        To make this work, we need to only do two things.
        <ol>
            <li>When needed, switch states simply by setting <div class="code-container-inline inline"><pre><code class="javascript">gameState</code></pre></div> to a different state name</li>
            <li>Use conditionals checking the value of <div class="code-container-inline inline"><pre><code class="javascript">gameState</code></pre></div> to wrap behavior that should only occur in specific states</li>
            
        </ol>
        <div class="filename">index.html</div>
        <div class="code-container">
            <pre><code id="contentLOADING1" class="javascript"></code></pre>
            <pre><code id="contentLOADING2" class="javascript add"></code></pre>
            <pre><code id="contentLOADING3" class="javascript"></code></pre>
            <pre><code id="contentLOADING4" class="javascript add"></code></pre>
            <pre><code id="contentLOADING5" class="javascript"></code></pre>
            <pre><code id="contentLOADING6" class="javascript add"></code></pre>
            <pre><code id="contentLOADING7" class="javascript"></code></pre>
            <pre><code id="contentLOADING8" class="javascript remove"></code></pre>
            <pre><code id="contentLOADING9" class="javascript add"></code></pre>
            <pre><code id="contentLOADING10" class="javascript"></code></pre>
        </div>

        When our spritesheet image loads, we want to switch to showing the title screen which is accomplished by assigning a function to
        <div class="code-container-inline inline"><pre><code class="javascript">spritesheet.onload</code></pre></div>
        (we'll write that 
        <div class="code-container-inline inline"><pre><code class="javascript">showTitle</code></pre></div>
        function below next). But what's our first state? Unsurprisingly, we're initializing 
        <div class="code-container-inline inline"><pre><code class="javascript">gameState</code></pre></div>
        to "loading" because that's the first thing that happens. 
        <br><br>
        While we're here, we're adding some variables related to the game lifecycle: 
        <div class="code-container-inline inline"><pre><code class="javascript">startingHp</code></pre></div>
        and
        <div class="code-container-inline inline"><pre><code class="javascript">numLevels</code></pre></div>.
        <br><br>
        Within the  
        <div class="code-container-inline inline"><pre><code class="javascript">onkeypress</code></pre></div>
        handler, you can see where we're starting to add transitions between game states when buttons are pressed and also restricting when gameplay actions can take place (only when "running").
        <br><br>
        Lastly, we're moving out some code related to setting the
        <div class="code-container-inline inline"><pre><code class="javascript">player</code></pre></div>
        location and generating a level. If we're going to have multiple levels, it no longer makes sense to do these things only once.
        <br><br>

        There are several small changes to add to game.js:

        <div class="filename">game.js</div>
        <div class="code-container">
            <pre><code id="contentDRAW1" class="javascript"></code></pre>
            <pre><code id="contentDRAW2" class="javascript add"></code></pre>
            <pre><code id="contentDRAW3" class="javascript"></code></pre>
            <pre><code id="contentDRAW4" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACE" class="javascript"></code></pre>
            <pre><code id="contentNEWLINE" class="javascript"></code></pre>
            <pre><code id="contentTICK1" class="javascript"></code></pre>
            <pre><code id="contentTICK2" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACE" class="javascript"></code></pre>
            <pre><code id="contentNEWLINE" class="javascript"></code></pre>
            <pre><code id="contentSHOWTITLE" class="javascript add"></code></pre>
        </div>
        In 
        <div class="code-container-inline inline"><pre><code class="javascript">draw</code></pre></div>,
        we restrict our draw operations to when the game is running OR when the player just died.
        <br><br>
        In 
        <div class="code-container-inline inline"><pre><code class="javascript">tick</code></pre></div>,
        we change to the "dead" state when we detect that the player has died.
        <br><br>
        In 
        <div class="code-container-inline inline"><pre><code class="javascript">showTitle</code></pre></div>,
        we draw a semi-transparent black background, which will function as our title screen for now. Then we change to the "title" state.
        <br><br>
        In 
        <div class="code-container-inline inline"><pre><code class="javascript">startGame</code></pre></div>,
        we jump to the first floor, call <div class="code-container-inline inline"><pre><code class="javascript">startLevel</code></pre></div>, and we change to the "running" state.
        <br><br>
        In 
        <div class="code-container-inline inline"><pre><code class="javascript">startLevel</code></pre></div>,
        we move over the code that we took out of index.html. Also <div class="code-container-inline inline"><pre><code class="javascript">player</code></pre></div> gets initalized with 
        <div class="code-container-inline inline"><pre><code class="javascript">hp</code></pre></div>
         equal to the value passed in 
        <div class="code-container-inline inline"><pre><code class="javascript">playerHp</code></pre></div>. This value starts as 3, but in a little bit we'll use this function to persist player HP across levels.
        <br><br>
        Now load up the game. You'll see the "title screen", a black box for now. When you hit a key, the game will start running. And if you were to die, everything would freeze until you pressed another key... leading back to the title screen, this time overlaid semitransparently over the game. That's the whole state machine right there working!
        <h2>Spawning more monsters</h2>
        It's not easy to die in this game. No monsters spawn after the first two. Let's make it harder.

        <div class="filename">game.js</div>
        <div class="code-container">
            <pre><code id="contentTICK1" class="javascript"></code></pre>
            <pre><code id="contentTICK2" class="javascript"></code></pre>
            <pre><code id="contentNEWLINE" class="javascript"></code></pre>
            <pre><code id="contentSPAWN1" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACE" class="javascript"></code></pre>
            <pre><code class="break">...</code></pre>
            <pre><code id="contentSPAWN2" class="javascript"></code></pre>
            <pre><code id="contentSPAWN3" class="javascript add"></code></pre>
            <pre><code id="contentSPAWN4" class="javascript"></code></pre>
        </div>

        We're using two new global variables.

        <ul>
            <li>
                <div class="code-container-inline inline"><pre><code class="javascript">spawnCounter</code></pre></div>
                counts down until each spawn and then resets
            </li>
            <li>
                <div class="code-container-inline inline"><pre><code class="javascript">spawnRate</code></pre></div>
                is how often monsters will get spawned and provides the initial value for <div class="code-container-inline inline"><pre><code class="javascript">spawnCounter</code></pre></div> every time it is reset
            </li>
        </ul>
        After every spawn,
        <div class="code-container-inline inline"><pre><code class="javascript">spawnRate</code></pre></div>
        is decremented so that monsters come out even faster.
        <ul>
            <ol>After the first 15 turns, a new monster gets spawned</ol>
            <ol>14 turns after that, another monster spawns</ol>
            <ol>13 turns after that, another monster spawns</ol>
            <ol>...</ol>
            <ol>And so on until monsters spawn every turn</ol>
        </ul>
        Tweaking the initial value of
        <div class="code-container-inline inline"><pre><code class="javascript">spawnRate</code></pre></div>
        will have a massive impact on the game's design (try a value of 1 for some real fun).
        <br><br>
        Try that out and see how you like the spawn behavior.
        <h2>Teleport counter</h2>
        One more rough edge to smooth out. Monsters can spawn right next to us and immediately start attacking. It's also very weird to see monsters spawning in the middle of the map with no explanation.
        <br><br>
        One convenient explanation is that these monsters are being "teleported" into the map. While each monster is teleporting, which will take one extra turn, they will be unable to do anything. Think of this as equivalent to Magic's "summoning sickness".
        <br><br>
        To visually demonstrate this, we need a teleporting sprite. Let's draw that before getting to the code.
        <h2>Drawing the teleport sprite</h2>  
        <div class="drawing-section">
            There's not much to this one. We draw a spiral, add swirly limbs, and outline it.
            <img src="art/teleport.png">
         </div>

         To integrate this teleporting thing, we'll use a counter just like we did with 
         <div class="code-container-inline inline"><pre><code class="javascript">spawnCounter</code></pre></div>. 
         This should look familiar. You can do a <em>hell of a lot of work</em> with only boolean flags for statuses and integer counters for longer lasting effects.

        <div class="filename">monster.js</div>
        <div class="code-container">

            <pre><code id="contentTELEPORT1" class="javascript"></code></pre>
            <pre><code id="contentTELEPORT2" class="javascript add"></code></pre>
            <pre><code id="contentTELEPORT3" class="javascript"></code></pre>
            <pre><code id="contentTELEPORT4" class="javascript add"></code></pre>
            <pre><code id="contentTELEPORT5" class="javascript remove"></code></pre>
            <pre><code id="contentTELEPORT6" class="javascript add"></code></pre>
            <pre><code id="contentTELEPORT7" class="javascript"></code></pre>

            <pre><code class="break">...</code></pre>

            <pre><code id="contentTELEPORT8" class="javascript"></code></pre>
            <pre><code id="contentTELEPORT9" class="javascript add"></code></pre>
            <pre><code id="contentTELEPORT10" class="javascript"></code></pre>
            <pre><code id="contentTELEPORT11" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACEINDENT1" class="javascript"></code></pre>

            <pre><code class="break">...</code></pre>

            <pre><code id="contentTELEPORT12" class="javascript"></code></pre>
            <pre><code id="contentTELEPORT13" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACE" class="javascript"></code></pre>
        </div>
        The monsters are teleporting in and spawning nicely... eventually leading to an unwillable scenario. Let's give the player an <em>exit</em> from this situation.
        <h2>Drawing the exit sprite</h2>  
        <div class="drawing-section">
            I tried drawing something resembling a portal.
            <img src="art/exit.png">
         </div>

        Our 
        <div class="code-container-inline inline"><pre><code class="javascript">Exit</code></pre></div>
        tile is a pretty basic object, but it does need to do something (i.e. go to the next level) whenever the player moves onto it. It's within the monster code that we determine when we're stepping on something, but after that point it's best to delegate to the tiles themselves. Each tile will know exactly what to do when stepped on.

        <div class="filename">tile.js</div>
        <div class="code-container">

            <pre><code id="contentSTEPON1" class="javascript"></code></pre>
            <pre><code id="contentSTEPON2" class="javascript add"></code></pre>
            <pre><code id="contentSTEPON3" class="javascript"></code></pre>
            <pre><code id="contentEXIT" class="javascript add"></code></pre>
        </div>

        Notice that we need an empty 
        <div class="code-container-inline inline"><pre><code class="javascript">stepOn</code></pre></div>
        method for 
        <div class="code-container-inline inline"><pre><code class="javascript">Floor</code></pre></div> too because monsters will be stepping on them as well. It won't do anything for now but it's nice to leave a little reminder comment to finish up the behavior later. We'll never need this method for a 
        <div class="code-container-inline inline"><pre><code class="javascript">Wall</code></pre></div>
        because monsters don't step on those. And unlike in other languages we don't need this method on the base object in order to call it on the subclasses.
        <br><br>
        Now what happens when the player steps on the
        <div class="code-container-inline inline"><pre><code class="javascript">Exit</code></pre></div>? If we were already on the last level, we jump to the title screen. Otherwise, we start a new level with 1 extra HP.
        <br><br>
        Two more pieces to tie it all together: triggering
        <div class="code-container-inline inline"><pre><code class="javascript">stepOn</code></pre></div>
        and creating the
        <div class="code-container-inline inline"><pre><code class="javascript">Exit</code></pre></div>
        tile.


        <div class="filename">monster.js</div>
        <div class="code-container">
            <pre><code id="contentMONSTERSTEPON1" class="javascript"></code></pre>
            <pre><code id="contentMONSTERSTEPON2" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACEINDENT1" class="javascript"></code></pre>
        </div>
        <div class="filename">game.js</div>
        <div class="code-container">
            <pre><code id="contentREPLACEEXIT1" class="javascript"></code></pre>
            <pre><code id="contentREPLACEEXIT2" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACE" class="javascript"></code></pre>
        </div>

        With these small additions, the game has some real structure to it.
        <h2>Title time</h2>
        The title screen is seriously lacking though. I don't want to do anything too crazy for the title screen, but at the very least it needs some text.
        <br><br>
        If you're trying to draw UI elements for a browser game, I would typically recommend trying it with HTML. You've got a lot of functionality out of the box with HTML & CSS, built up over decades. But for a few simple lines of text, the canvas will do just fine.
        <br><br>
        Drawing text on the canvas is not much different from drawing images. The important bit here is at the end: 
        <div class="code-container-inline inline"><pre><code class="javascript">ctx.fillText</code></pre></div>.
        All we need to pass is what text to draw and where.

        <div class="filename">game.js</div>
        <div class="code-container">
            <pre><code id="contentDRAWTEXT" class="javascript add"></code></pre>
        </div>

        The first two lines of our function set the font color and size. The string
        <div class="code-container-inline inline"><pre><code class="javascript">"px monospace"</code></pre></div>
        might look a little cryptic. We're actually writing a bit of CSS : we specify a font size in "px" units (pixels) and specify the type of font we want, which is "monospace".
        <br><br>
        We're going to leave the Y position up to the caller, but to make things easier this function will handle X. We're going to draw text in two places basically: justified centered on the title screen and on the far right (where the UI is) during play. The 
        <div class="code-container-inline inline"><pre><code class="javascript">centered</code></pre></div>
         variable lets us toggle between these two.
        <br><br>
        So what does this line mean exactly? 
        <br><br>
        <div class="code-container-inline inline"><pre><code class="javascript">textX = (canvas.width-ctx.measureText(text).width)/2;</code></pre></div>
        <br><br>
        When you want to center <em>any</em> element, whether on the canvas or in HTML, the calculation is the same. For X: half the container width minus half the content width. For Y: half the container height minus half the content height. The reason is obvious when you see it:
        <br><br>

        <img src="screens/centering.png">
        <br><br>
        This is a good example of where HTML & CSS would be a lot easier to use! For one there are many easy ways to center things in CSS (there weren't for about 20 years but now there certainly are). And for two getting the width or height of an HTML element is very easy. None of this
        <div class="code-container-inline inline"><pre><code class="javascript">measureText</code></pre></div>
        nonsense. Did you know there isn't even a way to measure the height? Ugh!
        <br><br>
        Anyway, enough ranting... let's draw some text.

        <div class="filename">game.js</div>
        <div class="code-container">
            <pre><code id="contentDRAWSOMETEXT1" class="javascript"></code></pre>
            <pre><code id="contentDRAWSOMETEXT2" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACEINDENT1" class="javascript"></code></pre>
            <pre><code id="contentCLOSINGBRACE" class="javascript"></code></pre>

            <pre><code class="break">...</code></pre>

            <pre><code id="contentDRAWSOMETEXT3" class="javascript"></code></pre>
            <pre><code id="contentDRAWSOMETEXT4" class="javascript add"></code></pre>
            <pre><code id="contentCLOSINGBRACE" class="javascript"></code></pre>
        </div>


        To review the arguments to our 
        <div class="code-container-inline inline"><pre><code class="javascript">drawText</code></pre></div>
         function
        <ul>
            <li>some text</li>
            <li>a font size</li>
            <li>whether the text is centered</li>
            <li>the Y position</li>
            <li>the color</li>
        </ul>
         Whew! That's a mouthful, but trust me when I say it's preventing us from duplicating a lot of code.
        <br><br>
        We're drawing the level number on the UI during play and drawing the name of the game on the title screen. I chose a silly name. I'm sure you can do better.
        <br><br>
        Try it out. I think it's looking good. At this point, the game can be considered a fully playable and complete game. It's just not very interesting yet. We'll get there.
        <img src="screens/title-screen.png">
        In the <a href="stage6.html">next section</a>, we'll be adding treasure and score mechanics.
	</div>

	<script>
		let content = {
			LOADING1:
            `
<script> 
    tileSize = 64;
    numTiles = 11;
    uiWidth = 4;
    level = 1;
    maxHp = 6;

    spritesheet = new Image();
    spritesheet.src = 'spritesheet.png';
            `,
            LOADING2:
            `
    spritesheet.onload = showTitle;
                             
    gameState = "loading";  

    startingHp = 3; 
    numLevels = 6;          
            `,
            LOADING3:
            `

    document.querySelector("html").onkeypress = function(e){
            `,
            LOADING4:
            `
        if(gameState == "title"){                              
            startGame();                
        }else if(gameState == "dead"){                             
            showTitle();                                        
        }else if(gameState == "running"){                                               
            `,
            LOADING5:
            `
            if(e.key=="w") player.tryMove(0,-1);
            if(e.key=="s") player.tryMove(0,1);
            if(e.key=="a") player.tryMove(-1, 0);
            if(e.key=="d") player.tryMove(1, 0);
            `,
            LOADING6:
            `
        }
            `,
            LOADING7:
            `
    };

    setInterval(draw, 20);

    setupCanvas();

            `,
            LOADING8:
            `
    generateLevel();                

    let player = new Player(randomPassableTile());               
            `,
            LOADING9:
            `
            `,
            LOADING10:
            `  
<\/script>
            `,
            DRAW1:
            `
function draw(){
            `,
            DRAW2:
            `
    if(gameState == "running" || gameState == "dead"){  
            `,
            DRAW3:
            `
        ctx.clearRect(0,0,canvas.width,canvas.height);

        for(let i=0;i<numTiles;i++){
            for(let j=0;j<numTiles;j++){
                getTile(i,j).draw();
            }
        }


        for(let i=0;i<monsters.length;i++){
            monsters[i].draw();
        }

        player.draw();
            `,
            DRAW4:
            `
    }
            `,
            CLOSINGBRACE:
            `
}
            `,
            CLOSINGBRACEINDENT1:
            `
    }
            `,
            NEWLINE:
            `

            `,
            TICK1:
            `
function tick(){
    for(let k=monsters.length-1;k>=0;k--){
        if(!monsters[k].dead){
            monsters[k].update();
        }else{
            monsters.splice(k,1);
        }
    }

            `,
            TICK2:
            `
    if(player.dead){    
        gameState = "dead";
    }
            `,
            SHOWTITLE:
            `
function showTitle(){                                          
    ctx.fillStyle = 'rgba(0,0,0,.75)';
    ctx.fillRect(0,0,canvas.width, canvas.height);

    gameState = "title";
}

function startGame(){                                           
    level = 1;
    startLevel(startingHp);

    gameState = "running";
}

function startLevel(playerHp){                          
    generateLevel();

    player = new Player(randomPassableTile());
    player.hp = playerHp;
}
            `,
            SPAWN1:
            `
    spawnCounter--;
    if(spawnCounter <= 0){  
        spawnMonster();
        spawnCounter = spawnRate;
        spawnRate--;
    }
            `,
            SPAWN2:
            `
function startLevel(playerHp){ 
            `,
            SPAWN3:
            `
    spawnRate = 15;              
    spawnCounter = spawnRate;                      
            `,
            SPAWN4:
            `

    generateLevel();

    player = new Player(randomPassableTile());
    player.hp = playerHp;
}
            `,
            TELEPORT1:
            `
class Monster{
    constructor(tile, sprite, hp){
        this.move(tile);
        this.sprite = sprite;
        this.hp = hp;
            `,
            TELEPORT2:
            `
        this.teleportCounter = 2;
            `,
            TELEPORT3:
            `
    }                                                                           

    heal(damage){
        this.hp = Math.min(maxHp, this.hp+damage);
    }

    update(){
            `,
            TELEPORT4:
            `
        this.teleportCounter--;
            `,
            TELEPORT5:
            `
        if(this.stunned){   
            `,
            TELEPORT6:
            `
        if(this.stunned || this.teleportCounter > 0){                       
                `,
                TELEPORT7:
                `
            this.stunned = false;                                               
            return;
        }
        this.doStuff();
    }

            `,
            TELEPORT8:
            `
    draw(){
            `,
            TELEPORT9:
            `
        if(this.teleportCounter > 0){                                        
            drawSprite(10, this.tile.x, this.tile.y);                     
        }else{        
            `,
            TELEPORT10:
            `
            drawSprite(this.sprite, this.tile.x, this.tile.y);               
            this.drawHp();
            `,
            TELEPORT11:
            `
        }
            `,
            TELEPORT12:
            `
class Player extends Monster{                                               
    constructor(tile){
        super(tile, 0, 3);
        this.isPlayer = true;
            `,
            TELEPORT13:
            `
        this.teleportCounter = 0;
            `,
            STEPON1:
            `
class Floor extends Tile{
    constructor(x,y){
        super(x,y, 2, true);
    };

            `,
            STEPON2:
            `
    stepOn(monster){                                                           
        //TODO: complete
    }
            `,
            STEPON3:
            `
}

class Wall extends Tile{
   constructor(x, y){
       super(x, y, 3, false);
   }
}

            `,
            EXIT:
            `
class Exit extends Tile{
    constructor(x, y){
        super(x, y, 11, true);
    }

    stepOn(monster){
        if(monster.isPlayer){
            if(level == numLevels){
                showTitle();
            }else{
                level++;
                startLevel(Math.min(maxHp, player.hp+1));
            }
        }
    }
}
            `,
            MONSTERSTEPON1:
            `
    move(tile){
        if(this.tile){
        this.tile.monster = null;
        }
        this.tile = tile;
        tile.monster = this;                                              
            `,
            MONSTERSTEPON2:
            `
        tile.stepOn(this);       
            `,
            REPLACEEXIT1:
            `
function startLevel(playerHp){     
    spawnRate = 15;              
    spawnCounter = spawnRate;      

    generateLevel();

    player = new Player(randomPassableTile());
    player.hp = playerHp;

            `,
            REPLACEEXIT2:
            `
    randomPassableTile().replace(Exit);  
            `,
            DRAWTEXT:
            `
function drawText(text, size, centered, textY, color){
    ctx.fillStyle = color;
    ctx.font = size + "px monospace";
    let textX;
    if(centered){
        textX = (canvas.width-ctx.measureText(text).width)/2;
    }else{
        textX = canvas.width-uiWidth*tileSize+25;
    }

    ctx.fillText(text, textX, textY);
}
            `,
            DRAWSOMETEXT1:
            `
function draw(){
    if(gameState == "running" || gameState == "dead"){
        ctx.clearRect(0,0,canvas.width,canvas.height);

        for(let i=0;i<numTiles;i++){
            for(let j=0;j<numTiles;j++){
                getTile(i,j).draw();
            }
        }


        for(let i=0;i<monsters.length;i++){
            monsters[i].draw();
        }

        player.draw();

            `,
            DRAWSOMETEXT2:
            `
        drawText("Level: "+level, 30, false, 40, "violet");
            `,
            DRAWSOMETEXT3:
            `
function showTitle(){                                          
    ctx.fillStyle = 'rgba(0,0,0,.75)';
    ctx.fillRect(0,0,canvas.width, canvas.height);

    gameState = "title";

            `,
            DRAWSOMETEXT4:
            `
    drawText("SUPER", 40, true, canvas.height/2 - 110, "white");
    drawText("BROUGH BROS.", 70, true, canvas.height/2 - 50, "white"); 
            `
		};
	</script>

	<link rel="stylesheet" href="highlight.min.css">
	<link rel="stylesheet" href="style.css">
	<script src="highlight.min.js"></script>
	<script src="diff.js"></script>
</body>
</html>