about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/broughlike-tutorial/stage5.html
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
committerelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
commit562a9a52d599d9a05f871404050968a5fd282640 (patch)
tree7d3305c1252c043bfe246ccc7deff0056aa6b5ab /js/games/nluqo.github.io/broughlike-tutorial/stage5.html
parent5d012c6c011a9dedf7d0a098e456206244eb5a0f (diff)
downloadtour-562a9a52d599d9a05f871404050968a5fd282640.tar.gz
*
Diffstat (limited to 'js/games/nluqo.github.io/broughlike-tutorial/stage5.html')
-rw-r--r--js/games/nluqo.github.io/broughlike-tutorial/stage5.html704
1 files changed, 704 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/broughlike-tutorial/stage5.html b/js/games/nluqo.github.io/broughlike-tutorial/stage5.html
new file mode 100644
index 0000000..3e6e08e
--- /dev/null
+++ b/js/games/nluqo.github.io/broughlike-tutorial/stage5.html
@@ -0,0 +1,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>
\ No newline at end of file