Professional Documents
Culture Documents
Kod
Kod
DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body onload='zaidimas()'>
<style>
canvas{
background-color: green;
div {
text-align: center;
width: 300px;
}
button{
width: 60px;
background-color: thistle;
}
</style>
<div>
<button onmousedown="aukstyn()" onmouseup="judek()"> Aukstyn </button>
<button onmousedown="kairen()" onmouseup="judek()"> Kairen </button>
<button onmousedown="desinen()" onmouseup="judek()"> Desinen </button>
<button onmousedown="apacion()" onmouseup="judek()"> Apacion </button>
</div>
<script>
function zaidimas(){
ekranas.start()
figura = new veikejas(25,25,"aqua",50,25);
}
var ekranas = {
canvas: document.createElement('canvas'),
start: function(){
this.canvas.width = 350;
this.canvas.height = 250;
this.context = this.canvas.getContext('2d');
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
this.interval = setInterval(ekranoAtnaujinimas, 20)
},
clear:function(){
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}
function veikejas(width, height, color, x, y){
this.width = width;
this.height = height;
this.x = 0;
this.y = 0;
this.update = function(){
ctx = ekranas.context;
ctx.fillStyle = color;
ctx.fillRect(this.x,this.y,this.width,this.height)
}
this.pozicija = function(){
this.x += this.speedX
this.y += this.speedY
}
function ekranoAtnaujinimas(){
ekranas.clear();
figura.pozicija();
figura.update();
}
function judek(){
figura.speedX = 0;
figura.speedY = 0;
}
function aukstyn(){
figura.speedY += 1
}
function kairen(){
figura.speedX -= 1
}
function desinen(){
figura.speedX += 1
}
function apacion(){
figura.speedY -= 1
}
// document.write(komanda2 [4]);
// document.write(komanda3 [2])
// function dabartis(){
// var LKL2021 = 2021 - this.ikurimo_metai
// return LKL2021;
// }
// document.write(vilnius.komanda())
</script>
</body>
</html>