• API
• FAQ
• Tools
• Archive
A Pastebin account makes a great Christmas gift
SHARE
TWEET

# Untitled

a guest Nov 21st, 2018 84 Never
ENDING IN00days00hours00mins00secs

1. /*************
2.  * lasers.js *
3.  *************
4.  *
5.  * Time to unleash the killer lasers! Each laser will kill you
6.  * unless you have the appropriate color. Too bad you can't
7.  * see which color corresponds to which laser!
8.  */
9.
10. function getRandomInt(min, max) {
11.     return Math.floor(Math.random() * (max - min + 1)) + min;
12. }
13.
14. function startLevel(map) {
15.     map.placePlayer(0, 0);
16.     map.placeObject(map.getWidth()-1, map.getHeight()-1, 'exit');
17.     var player = map.getPlayer();
18.
19.     for (var i = 0; i < 25; i++) {
20.         var colors = ['red', 'yellow', 'teal'];
21.
22.         var startX = getRandomInt(0, 600);
23.         var startY = getRandomInt(0, 500);
24.         var angle = getRandomInt(0, 360);
25.         var length = getRandomInt(200, 300);
26.         var color = colors[i % 3];
27.         createLaser(startX, startY, angle, length, color);
28.     }
29.
30.     function createLaser(centerX, centerY, angleInDegrees, length, color) {
31.         var angleInRadians = angleInDegrees * Math.PI / 180;
32.
33.         var x1 = centerX - Math.cos(angleInRadians) * length / 2;
34.         var y1 = centerY + Math.sin(angleInRadians) * length / 2;
35.         var x2 = centerX + Math.cos(angleInRadians) * length / 2;
36.         var y2 = centerY - Math.sin(angleInRadians) * length / 2;
37.
38.         // map.createLine() creates a line with an effect when
39.         // the player moves over it, but doesn't display it
40.         map.createLine([x1, y1], [x2, y2], function (player) {
41.             if (player.getColor() != color) {
42.                 player.killedBy('a ' + color + ' laser');
43.             }
44.         });
45.
46.         // using canvas to draw the line
47.         var colors = ['red', 'yellow', 'teal'];
48.         map.turnNum++
49.         if(map.turnNum.toString() == "NaN"){
50.             map.turnNum = 0;
51.         }
52.         ctx = map.getCanvasContext();
53.         ctx.beginPath();
54.         ctx.strokeStyle = colors[map.turnNum % 3];
55.         ctx.lineWidth = 5;
56.         ctx.moveTo(x1, y1);
57.         ctx.lineTo(x2, y2);
58.         ctx.stroke();
59.
60.     }
61.
62.
63. player.setPhoneCallback(function(){
64. var colors = ['red', 'yellow', 'teal'];
65.     player.setColor(colors[Math.floor(Math.random()*3)])
66. })
67.
68.
69.
70.
71.
72.
73.
74. }
75.
76. function validateLevel(map) {
77.     map.validateExactlyXManyObjects(1, 'exit');
78.     map.validateAtLeastXLines(25);
79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top