Still not a roguelike, by anyone's standards.
catseye
12 years ago
0 | 0 | // requires playfield.js |
1 | 1 | NonRoguelike = function() { |
2 | var p; | |
2 | var map; | |
3 | var actors; | |
3 | 4 | var canvas; |
4 | 5 | var ctx; |
5 | 6 | var intervalId; |
9 | 10 | var w = 40; |
10 | 11 | var h = 40; |
11 | 12 | var counter = 0; |
13 | var state = undefined; | |
12 | 14 | |
13 | 15 | var WALL = { |
14 | 16 | 'draw': function(ctx, x, y) { |
15 | ctx.beginPath(); | |
16 | 17 | ctx.fillStyle = "black"; |
17 | 18 | ctx.fillRect(x * w, y * h, w, h); |
18 | 19 | }, |
19 | 'pass': function() { return false; } | |
20 | 'pass': function(x, y) { | |
21 | return false; | |
22 | } | |
20 | 23 | }; |
21 | 24 | |
22 | var HERO = { | |
25 | var DOOR = { | |
23 | 26 | 'draw': function(ctx, x, y) { |
24 | ctx.beginPath(); | |
25 | ctx.fillStyle = "blue"; | |
26 | ctx.arc(x * w + (w / 2), y * h + (h / 2), w/2, 0, 2 * Math.PI, false); | |
27 | ctx.fill(); | |
27 | ctx.fillStyle = "brown"; | |
28 | ctx.fillRect(x * w, y * h, w, h); | |
29 | }, | |
30 | 'pass': function(x, y) { | |
31 | return true; | |
28 | 32 | } |
29 | 33 | }; |
30 | 34 | |
38 | 42 | ctx.closePath(); |
39 | 43 | ctx.fill(); |
40 | 44 | }, |
41 | 'pass': function() { gold += 10; return true; } | |
45 | 'pass': function(x, y) { | |
46 | map.put(x, y, undefined); | |
47 | gold += 10; | |
48 | return true; | |
49 | } | |
50 | }; | |
51 | ||
52 | var HERO = { | |
53 | 'draw': function(ctx, x, y) { | |
54 | ctx.beginPath(); | |
55 | ctx.fillStyle = "blue"; | |
56 | ctx.arc(x * w + (w / 2), y * h + (h / 2), w/2, 0, 2 * Math.PI, false); | |
57 | ctx.fill(); | |
58 | } | |
59 | }; | |
60 | ||
61 | var MONSTER = { | |
62 | 'draw': function(ctx, x, y) { | |
63 | ctx.beginPath(); | |
64 | ctx.fillStyle = "green"; | |
65 | ctx.arc(x * w + (w / 2), y * h + (h / 2), w/2, 0, 2 * Math.PI, false); | |
66 | ctx.fill(); | |
67 | } | |
42 | 68 | }; |
43 | 69 | |
44 | 70 | this.draw = function() { |
71 | /* | |
45 | 72 | w = 35 + Math.sin(counter) * 5; |
46 | 73 | h = 35 + Math.sin(Math.PI + counter) * 5; |
47 | 74 | counter += 0.05; |
75 | */ | |
48 | 76 | ctx.clearRect(0, 0, canvas.width, canvas.height); |
49 | 77 | |
50 | p.foreach(function (x, y, thing) { | |
51 | thing['draw'](ctx, x, y); | |
78 | map.foreach(function (x, y, thing) { | |
79 | thing.draw(ctx, x, y); | |
80 | }); | |
81 | actors.foreach(function (x, y, actor) { | |
82 | actor.draw(ctx, x, y); | |
52 | 83 | }); |
53 | 84 | } |
54 | 85 | |
55 | 86 | this.moveHero = function(dx, dy) { |
56 | 87 | var newHeroX = heroX + dx; |
57 | 88 | var newHeroY = heroY + dy; |
58 | var thing = p.get(newHeroX, newHeroY); | |
59 | var pass = (thing === undefined) ? true : thing['pass'](); | |
89 | var thing = map.get(newHeroX, newHeroY); | |
90 | var pass = true; | |
91 | if (thing !== undefined) { | |
92 | pass = thing.pass(newHeroX, newHeroY); | |
93 | } | |
94 | var creature = actors.get(newHeroX, newHeroY); | |
95 | if (creature !== undefined) { | |
96 | document.getElementById('status').innerHTML = "FighT!"; | |
97 | pass = false; | |
98 | } | |
60 | 99 | if (pass) { |
61 | p.put(heroX, heroY, undefined); | |
100 | actors.put(heroX, heroY, undefined); | |
62 | 101 | heroX = newHeroX; |
63 | 102 | heroY = newHeroY; |
64 | p.put(heroX, heroY, HERO); | |
103 | actors.put(heroX, heroY, HERO); | |
65 | 104 | document.getElementById('status').innerHTML = "Gold: " + gold; |
66 | 105 | } |
67 | 106 | }; |
68 | 107 | |
69 | 108 | this.start = function(c) { |
70 | p = new Playfield(); | |
71 | var map = { | |
109 | map = new Playfield(); | |
110 | var legend = { | |
72 | 111 | ' ': undefined, |
73 | 112 | '*': WALL, |
74 | '$': GOLD | |
113 | '$': GOLD, | |
114 | '+': DOOR | |
75 | 115 | }; |
76 | p.load(0, 0, map, | |
116 | map.load(0, 0, legend, | |
77 | 117 | "***************\n" + |
78 | 118 | "* * *\n" + |
79 | 119 | "* * *\n" + |
80 | 120 | "* * $ *\n" + |
81 | 121 | "*** ** *\n" + |
82 | "*** ******** **\n" + | |
122 | "*** ********+**\n" + | |
83 | 123 | "*** ** *\n" + |
84 | "*** *\n" + | |
124 | "*** + *\n" + | |
85 | 125 | "****** *\n" + |
86 | 126 | "***************\n" |
87 | 127 | ); |
88 | 128 | |
89 | p.put(heroX, heroY, HERO); | |
129 | actors = new Playfield(); | |
130 | actors.put(heroX, heroY, HERO); | |
131 | actors.put(10, 2, MONSTER); | |
90 | 132 | |
91 | 133 | canvas = c; |
92 | 134 | ctx = canvas.getContext('2d'); |