-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
213 lines (188 loc) · 5.44 KB
/
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
<html>
<head>
<title> Panjiva Coding Lesson </title>
<link rel="stylesheet" href="ansi.css" type="text/css" media="all" />
<script src='jquery.js' type='text/javascript'></script>
<script src="jqconsole-2.7.min.js"></script>
<style>
html, body {
background-color: #333;
color: white;
font-family: monospace;
margin: 40px;
padding: 0;
}
.px640x300 {
margin: 0 auto;
width: 640px;
}
#console {
height: 400px;
width: 750px;
position:relative;
background-color: black;
border: 2px solid #CCC;
margin: 0 auto;
margin-top: 50px;
}
.jqconsole {
padding: 10px;
padding-bottom: 10px;
}
.jqconsole-cursor {
background-color: #999;
}
.jqconsole-blurred .jqconsole-cursor {
background-color: #666;
}
.jqconsole-prompt {
color: #0d0;
}
.jqconsole-old-prompt {
color: #0b0;
font-weight: normal;
}
.jqconsole-input {
color: #dd0;
}
.jqconsole-old-input {
color: #bb0;
font-weight: normal;
}
.brace {
color: #00FFFF;
}
.paran {
color: #FF00FF;
}
.bracket {
color: #FFFF00;
}
.jqconsole-composition {
background-color: red;
}
</style>
<script>
$(function() {
// Creating the console.
var header = 'Welcome to Panjiva Lisp!\n' +
'Try typing code here...\n'
window.jqconsole = $('#console').jqconsole(header, '> ');
// Abort prompt on Ctrl+Z.
jqconsole.RegisterShortcut('Z', function() {
jqconsole.AbortPrompt();
handler();
});
// Move to line start Ctrl+A.
jqconsole.RegisterShortcut('A', function() {
jqconsole.MoveToStart();
handler();
});
// Move to line end Ctrl+E.
jqconsole.RegisterShortcut('E', function() {
jqconsole.MoveToEnd();
handler();
});
// Bootstrap solution
jqconsole.RegisterShortcut('M', function() {
interpret("(defun north() (setq direction 0)");
interpret("(defun east() (setq direction 1)");
interpret("(defun south() (setq direction 2)");
interpret("(defun west() (setq direction 3)");
handler();
});
// Bind Control Keys: WASD
$(document).keydown(function(e){
if (e.keyCode == 37) {
interpret('(west)');
} else if(e.keyCode == 38) {
interpret('(north)');
} else if(e.keyCode == 39) {
interpret('(east)');
} else if(e.keyCode == 40) {
interpret('(south)');
}
});
jqconsole.RegisterMatching('{', '}', 'brace');
jqconsole.RegisterMatching('(', ')', 'paran');
jqconsole.RegisterMatching('[', ']', 'bracket');
// Handle a command.
var handler = function(command) {
if (command) {
try {
// if(command[0] = '(')
jqconsole.Write('==> ' + interpret(command) + '\n');
} catch (e) {
jqconsole.Write('ERROR: ' + e.message + '\n');
}
}
jqconsole.Prompt(true, handler);
};
// Initiate the first prompt.
handler();
});
</script>
<script src='lisp.js' type='text/javascript'></script>
<script src='processing-1.3.6.js' type='text/javascript'></script>
</head>
<body>
<div class='px640x300'>
<!-- game -->
<script type='application/processing'>
// @pjs preload must be used to preload the image so that it will be available when used in the sketch
/* @pjs preload="map.png"; */
PImage a;
speed = 0.5;
x = 100;
y = 100;
height = 300;
width = 640;
void setup() {
size(width, height);
smooth();
a = loadImage("map.png");
}
void draw() {
background(24);
image( a, 0, 0 );
// output = interpret($('#program').val());
// $('#output').val(output);
if(typeof(direction) == 'undefined') {
direction = 0;
}
console.log(direction);
if(direction == 0) {
target_x = x;
target_y = y - speed;
} else if(direction == 1) {
target_x = x + speed;
target_y = y;
} else if(direction == 2) {
target_x = x;
target_y = y + speed;
} else if(direction == 3) {
target_x = x - speed;
target_y = y;
}
//console.log([x, y, target_x, target_y, speed, direction]);
target_x = target_x % width;
if (target_x < 0)
target_x += width;
target_y = target_y % height;
if (target_y < 0)
target_y += height;
if(typeof(move) != 'undefined') {
interpret('(move)');
}
ellipse(target_x, target_y, 10, 10);
x = target_x;
y = target_y;
}
</script>
<canvas width="640" height="300"></canvas>
</div>
<div id="console"></div>
<div style='display:none'><img src="map.png" id="map.png"/></div>
</div>
</body>
</html>