repl.it
@Ov3R10rd/

Dungeon Thief

HTML, CSS, JS

This is my entry for the game Jam. I hope you like it!

fork
loading
Files
  • index.html
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
<!DOCTYPE html>
<html>
  <head>
    <style>
      canvas{
        border:solid grey;
        background-color:grey;
      }
      body{
        margin:0px;
        text-align:center;
      }
      html{
        border:solid black;
        background-color:lightblue;
      }
      #point_base{
        text-align:left;
        background-color:red;
        border:solid black;
      }
      #controls{
        background-color:green;
        border:solid black;
      }
      #modSec{
        background-color:blue;
        border:solid black;
        width:200px;
        height:320px;
      }
    </style>
  </head>
  <body>
    <div id='title'>
      <h1>THE DUNGEON THIEF</h1><br><h1>By Ov3r10rd</h1>
    </div>
    <div>
      <canvas id='myCanvas' width=500 height=500>Uh oh! Something went wrong! Try to reload the page. Sorry!</canvas>


      
      <div style:'align:' id='modSec'>
      <h2 style='text-decoration:underline'>Mod Section</h2>
      <br>
      <button onclick='mod1()'>Increase your <br> player's  speed!</button>
      <br>
      <br>
      <button onclick='mod2()'>Decrease your <br> speed!</button>
      <br>
      <br>
      <button onclick='mod3()'>Toggle blindness!</button>
      <br>
      <br>
      <button onclick='mod4()'; >Endless Mode!</button>
      <br>
      <br>
      <button onclick='mod5()'>Add Level</button>
    </div>
    </div>
    <script>
      //-----------------VARIABLES------------------
      var canvas=document.getElementById('myCanvas');
      var c=canvas.getContext('2d');
      var score=0;
      var goal=5;
      var deaths=0;
      var width=500;
      var height=500;
      var playerX=225;
      var playerY=225;
      var appleX=Math.floor(Math.random()*475);
      var appleY=Math.floor(Math.random()*475);
      var enemyX=400;
      var enemyY=0;
      var ev=1.5;
      var pv=5;
      var level=1;
      var points=0;
      var blindness=true;
      var endless=false;
      //-----------------DECORATIONS----------------
      function decorations(){
        c.fillStyle='darkgrey';
        c.fillRect(100,200,30,75)
        c.fillRect(450,300,40,40)
        c.fillRect(30,20,60,50);
        c.fillRect(225,50,100,70);
        c.fillRect(275,275,100,75);
        c.fillRect(75,350,100,60);
        c.fillRect(215,200,50,20);
      };
      decorations();
      //-----------------SPRITES--------------------
      function enemyAI(x,y){
        c.beginPath();
        c.fillStyle='white';
        c.fillRect(x,y,100,100);
        c.fillStyle='red';
        c.fillRect(x+20,y+20,20,20);
        c.fillRect(x+60,y+20,20,20);
        c.fillStyle='black';
        c.fillRect(x+28,y+27,5,5);
        c.fillRect(x+68,y+27,5,5);
        c.fillStyle='red';
        c.fillRect(x+25,y+65,20,20);
        c.fillRect(x+55,y+65,20,20);
        c.fillRect(x+45,y+70,10,25);
        c.fillRect(x+20,y+60,5,15);
        c.fillRect(x+15,y+50,5,15);
        c.fillRect(x+75,y+60,5,15);
        c.fillRect(x+80,y+50,5,15);
      };

      function player(x,y){
        c.fillStyle='tan';
        c.fillRect(x,y,50,50);
        c.fillStyle='green';
        c.fillRect(x,y+30,50,20);
        c.moveTo(x+20,y+30);
        c.lineTo(x+20,y+50);
        c.fillStyle='white';
        c.fillRect(x+10,y+5,10,10);
        c.fillRect(x+30,y+5,10,10);
        c.fillStyle='blue';
        c.fillRect(x+12.5,y+8,5,5);
        c.fillRect(x+32.5,y+8,5,5);
        c.stroke();
        c.beginPath();
        c.fillStyle='black';
        c.arc(x+25,y+35,2.5,0,Math.PI*2,false);
        c.arc(x+25,y+45,2.5,0,Math.PI*2,false);
        c.fill();
        c.beginPath();
        c.arc(x+25,y+20,5,0,Math.PI,false);
        //Player outlines
        c.strokeStyle='black';
        c.rect(x,y,50,50);
        c.rect(x,y+30,50,20);
        c.stroke();
        if(blindness==true){
          c.fillStyle='black';
          c.fillRect(x-1000,y+100,2000,2000);
          c.fillRect(x-1000,y-2050,2000,2000);
          c.fillRect(x+100,y-100,1000,225);
          c.fillRect(x-1100,y-100,1050,225);
        }else{}
      };
      apple(appleX,appleY);
      player(playerX,playerY);
      function apple(x,y){
        c.beginPath();
        c.fillStyle='gold';
        c.fillRect(x,y,25,25);
        c.fillStyle='white';
        c.fillRect(x+5,y+5,5,15);
        c.fillRect(x+10,y+5,10,5);
        c.fillRect(x+10,y+15,10,5);
        c.strokeStyle='black';
        c.rect(x,y,25,25);
        c.moveTo(x+5,y+5);
        c.lineTo(x+20,y+5);
        c.lineTo(x+20,y+10);
        c.lineTo(x+10,y+10);
        c.lineTo(x+10,y+15);
        c.lineTo(x+20,y+15);
        c.lineTo(x+20,y+20);
        c.lineTo(x+5,y+20);
        c.lineTo(x+5,y+5);
        c.stroke();
      };
      function drawScore(i,g){
        c.fillStyle='red';
        c.font='30px Comic Sans MS';
        c.fillText('Coins Gathered: '+i+'/'+g,0,30);
      };
      drawScore(score,goal);

      function drawPoints(points){
        c.fillStyle='red';
        c.font='25px Comic Sans MS'
        c.fillText('Points: '+points,0,60);
      };
      drawPoints(points);

      function drawLevel(level){
        c.fillStyle='red';
        c.font='25px Arial'
        c.fillText('Night: '+level,0,495);
      };
      drawLevel(level); 
      //--------------GAME FUNCTIONS----------------
      function eatApple(x,y,ax,ay){
        if(x<ax+25&&x+50>ax&&y<ay+25&&y+50>ay){
          score+=1;
          points+=10;
          appleX=Math.floor(Math.random()*475);
          appleY=Math.floor(Math.random()*475);
          apple(appleX,appleY);
          player(playerX,playerY);
        }
      };
      eatApple(playerX,playerY,appleX,appleY);

      function nextLevel(score){
        if(score==goal){
          level+=1;
          if(level>=4){
            goal+=5;
            ev+=0.05;
            spawn();
            scoreFix();
            points+=200;
          }else if(level==3){
            goal=goal+5;
            ev+=0.1;
            spawn();
            scoreFix();
            points+=100;
          }else{
            goal=goal+5;
            ev+=0.5;
            spawn();
            scoreFix(); 
            points+=100;
          }
        }
      };
      nextLevel(score);

      function spawn(){
        playerX=225;
        playerY=225;
        enemyX=400;
        enemyY=0;
      };

      function scoreFix(){
        for(var i=0;i<5;i++){
          score=0;
        }
      };

      function easterEgg(){
        alert('How did you know that this game took 2 weeks to develop?! Easter egg found!');
      };

      function gameEnd(level){
        if(endless==true){
        }else{
          if(level==4){
            if(blindness!=true||pv!=5){
              alert('You may have completed the game, but because you cheated, it does not count.');
              document.location.reload();
              }else{
                if(deaths<=5){
                alert('Oh my gosh! You finished the game with less than 5 deaths!')
                document.location.reload();
              }else if(deaths==0){
                alert('By breaking this challenge, you have finished night 3 with no deaths! That takes serious skill.');
                document.location.reload();
              }else{
                alert('You completed the game with '+deaths+' deaths!');
              }
            }
          }
        }
      };
      gameEnd(level);

      function lose(x,y,ex,ey){
        if(x<ex+100&&x+50>ex&&y<ey+100&&y+50>ey){
          spawn();
          scoreFix();
          points-=20;
          alert('YOU DIED');
        }
      };
      lose(playerX,playerY,enemyX,enemyY);

      function mod1(){
        if(pv>=50){
          alert('Sorry, your too fast!');
        }else{
          pv+=5;
        }
      };
      function mod2(){
        if(pv<=0){
          alert('Sorry, but your speed is too low!');
        }else{
          pv-=5;
        }
      };
      function mod3(){
        if(blindness==true){
          blindness=false;
        }else if(blindness==false){
          blindness=true;
        }
        player(playerX,playerY);
      };
      function mod4(){
        endless=true;
      };
      function mod5(){
        if(endless==false){
          alert('Toggle endless first!');
        }else{
          level+=1;
          goal+=5;
          ev+=0.05;
          spawn();
          scoreFix();
        }
      };
      function enemyMove(px,py,ex,ey){
        if(px>ex&&py>ey){
          enemyX+=ev;
          enemyY+=ev;
        }else if(px>ex&&py<ey){
          enemyX+=ev;
          enemyY-=ev;
        }else if(px<ex&&py>ey){
          enemyX-=ev;
          enemyY+=ev;
        }else if(px<ex&&py<ey){
          enemyX-=ev;
          enemyY-=ev;
        }
        enemyAI(enemyX,enemyY);
      };
      //--------------MOVE FUNCTION-----------------
      function move(e){
        if(e.keyCode==68&&playerX<width-50){
          playerX+=pv;
        }else if(e.keyCode==65&&playerX>0){
          playerX-=pv;
        }else if(e.keyCode==83&&playerY<height-50){
          playerY+=pv;
        }else if(e.keyCode==87&&playerY>0){
          playerY-=pv;
        }else if(e.keyCode==78){
          alert('Starting new game...');
          document.location.reload();
        }else if(e.keyCode==50){
          easterEgg();
        }
        canvas.width=canvas.width;
        enemyMove(playerX,playerY,enemyX,enemyY);

        decorations();
        apple(appleX,appleY);
        enemyAI(enemyX,enemyY);
        player(playerX,playerY);
        drawScore(score,goal);
        drawPoints(points);
        drawLevel(level);

        eatApple(playerX,playerY,appleX,appleY);
        nextLevel(score);
        lose(playerX,playerY,enemyX,enemyY);
        gameEnd(level);
      };
      document.onkeydown=move;
    </script>
    <h2 style='color:red'>WARNING:</h2><h2>The ghost will protect its coins at all costs!!</h2>
    <div id='controls'>
      <h3>W A S D to move!</h3> 
      <h3>N to start a new game!</h3>
      <h3>Finish 3 nights to win!</h3>
    </div>
    <div id="point_base">
      <h3>You may have noticed that there are some different ways to get points. Here are a bunch of them:<h3>
      <ul>
        <li>Coins: +10 points</li>
        <li>Level up: +100 points(+200 if you are on endless)</li>
        <li>Death: -20 points</li>
      </ul>
      <p>These are all of the ways you can earn and lose points. Good luck! ;)</p>
    </div>
  </body>
</html>
result
console