This is the first episode of Algo Code! First, before we start programming anything, we have to startup Algo Code.
First, create some files like this:
Algo Code {
Program Test {
}
Project 1 {
app.html
fcnt.js
MAIN.js
vbl.js
}
}
Easy, right?
Next, copy this code.
_________________________________________________________________________________
<canvas id="ctx" width="360" height="360" style="border: 1px solid #000000"></canvas>
<script src="fnct.js"></script>
<script src="vbl.js"></script>
<script src="MAIN.js"></script>
<script>
var ctx=document.getElementById("ctx").getContext("2d");
ctx.font='30px Comic Sans MS';
</script>
_________________________________________________________________________________
Save it in app.html.
After that, this code.
_________________________________________________________________________________
//color
cngCol=function(c_c) {
ctx.fillStyle=c_c;
}
//fill
text=function(wor_dr,x_y,y_x) {
ctx.fillText(wor_dr,x_y,y_x);
}
rect=function(x_x,y_y,w_j,h_j) {
ctx.fillRect(x_x,y_y,w_j,h_j);
}
//clear
cnvscls=function() {
ctx.clearRect(0,0,WIDTH,HEIGHT);
}
//time
wait=function(w_w) {
var v_v=w_w*25;
a_exist=true;
if(t_t<v_v && a_exist==true) {
b_exist=true;
}
if(t_t==v_v) {
a_exist=false;
b_exist=false;
n_n+=1;
t_t=0;
}
}
//console
conssay=function(w_v) {
console.log(w_v);
}
conscls=function() {
console.clear();
}
/*
document.onmousedown=function(mouse) {
if(mouseX>0 && mouseX<WIDTH && mouseY<0 && mouseY<HEIGHT) {
mouseisPressed=true;
}
}
*/
//rpt
vard=function() {
/*
var mouseX=mouse.clientX-0;
var mouseY=mouse.clientY-8;
*/
//time
if(b_exist==true) {
t_t+=1;
}
}
setInterval(vard,15);
//keyboard
document.onkeydown=function(event) {
//www.cambriaresearch.com/articles/15/javascript-char-codes-key-codes
if(event.keyCode === 39)
pressingRight = true;
else if(event.keyCode === 37)
pressingLeft = true;
else if(event.keyCode === 38)
pressingUp = true;
else if(event.keyCode === 40)
pressingDown = true;
else if(event.keyCode === 65)
pressingA = true;
else if(event.keyCode === 66)
pressingB = true;
else if(event.keyCode === 67)
pressingC = true;
}
document.onkeyup=function(event) {
//www.cambriaresearch.com/articles/15/javascript-char-codes-key-codes
if(event.keyCode === 39)
pressingRight = false;
else if(event.keyCode === 37)
pressingLeft = false;
else if(event.keyCode === 38)
pressingUp = false;
else if(event.keyCode === 40)
pressingDown = false;
else if(event.keyCode === 65)
pressingA = false;
else if(event.keyCode === 66)
pressingB = false;
else if(event.keyCode === 67)
pressingC = false;
}
_________________________________________________________________________________
Save this in fcnt.js .
Lastly, this in vbl.js .
_________________________________________________________________________________
//canvas
var WIDTH=360;
var HEIGHT=360;
//mouse
/*
var mouseX=mouse.clientX-0;
var mouseY=mouse.clientY-8;
var mouseisPressed=false;
*/
//keyboard
var pressingUp=false;
var pressingDown=false;
var pressingLeft=false;
var pressingRight=false;
var pressingA=false;
var pressingB=false;
var pressingC=false;
//time
var a_exist=false;
var b_exist=false;
var n_n=0;
var t_t=0;
_________________________________________________________________________________
These are the files that we need in Project 1.
Continue in Ep 2
22-03-2017
22-03-2017
No comments:
Post a Comment