git @ Cat's Eye Technologies The-Dipple / e29787b
Still not a roguelike, by anyone's standards. catseye 12 years ago
1 changed file(s) with 64 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
00 // requires playfield.js
11 NonRoguelike = function() {
2 var p;
2 var map;
3 var actors;
34 var canvas;
45 var ctx;
56 var intervalId;
910 var w = 40;
1011 var h = 40;
1112 var counter = 0;
13 var state = undefined;
1214
1315 var WALL = {
1416 'draw': function(ctx, x, y) {
15 ctx.beginPath();
1617 ctx.fillStyle = "black";
1718 ctx.fillRect(x * w, y * h, w, h);
1819 },
19 'pass': function() { return false; }
20 'pass': function(x, y) {
21 return false;
22 }
2023 };
2124
22 var HERO = {
25 var DOOR = {
2326 '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;
2832 }
2933 };
3034
3842 ctx.closePath();
3943 ctx.fill();
4044 },
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 }
4268 };
4369
4470 this.draw = function() {
71 /*
4572 w = 35 + Math.sin(counter) * 5;
4673 h = 35 + Math.sin(Math.PI + counter) * 5;
4774 counter += 0.05;
75 */
4876 ctx.clearRect(0, 0, canvas.width, canvas.height);
4977
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);
5283 });
5384 }
5485
5586 this.moveHero = function(dx, dy) {
5687 var newHeroX = heroX + dx;
5788 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 }
6099 if (pass) {
61 p.put(heroX, heroY, undefined);
100 actors.put(heroX, heroY, undefined);
62101 heroX = newHeroX;
63102 heroY = newHeroY;
64 p.put(heroX, heroY, HERO);
103 actors.put(heroX, heroY, HERO);
65104 document.getElementById('status').innerHTML = "Gold: " + gold;
66105 }
67106 };
68107
69108 this.start = function(c) {
70 p = new Playfield();
71 var map = {
109 map = new Playfield();
110 var legend = {
72111 ' ': undefined,
73112 '*': WALL,
74 '$': GOLD
113 '$': GOLD,
114 '+': DOOR
75115 };
76 p.load(0, 0, map,
116 map.load(0, 0, legend,
77117 "***************\n" +
78118 "* * *\n" +
79119 "* * *\n" +
80120 "* * $ *\n" +
81121 "*** ** *\n" +
82 "*** ******** **\n" +
122 "*** ********+**\n" +
83123 "*** ** *\n" +
84 "*** *\n" +
124 "*** + *\n" +
85125 "****** *\n" +
86126 "***************\n"
87127 );
88128
89 p.put(heroX, heroY, HERO);
129 actors = new Playfield();
130 actors.put(heroX, heroY, HERO);
131 actors.put(10, 2, MONSTER);
90132
91133 canvas = c;
92134 ctx = canvas.getContext('2d');