<!DOCTYPE html>
<html>
<head>
Создатель : 𝕷𝖊𝖍𝖆 <br>
<br>
<title></title>
</head>
<body>
♥️░▀█▀░░░▀█▀░▀█▀░▀█▀░░▀█▀▀▀▀█░♥️<br>
♥️░░█░░░░░█░░░█░▄▀░░░░░█░░░░░░♥️<br>
♥️░░█░░░░░█░░░█▀▄░░░░░░█▄▄▄░░░♥️<br>
♥️░░█░░░░░█░░░█░░▀▄░░░░█░░░░░░♥️<br>
♥️░▄█▄▄█░▄█▄░▄█▄░░▄█▄░▄█▄▄▄▄█░♥️<br>
<br>
<canvas id="canvas" width="1900" height="800"></canvas>
<script src="
https://code.jquery.com/jquery-2.1.0.js"></script>
<script>
var canvas = document.getElementById('canvas')
var ctx = canvas.getContext('2d')
var width = canvas.width
var height = canvas.height
var colors = ['Red','Orange','Yellow','Green','Blue','Purple']
var keyNames = {
32: 'space'
}
var Platform = function(){
this.speed = 10
this.y = 100;
this.x = 1800
this.ySpeed = 10
}
Platform.prototype.move = function(){
this.y += this.ySpeed
}
Platform.prototype.draw = function(){
ctx.fillStyle = 'Red'
ctx.fillRect(this.x,this.y,30,90)
}
Platform.prototype.checkCollision = function(){
if(this.y > height || this.y < 0){
this.ySpeed = -this.ySpeed
}
}
Platform.prototype.control = function(direction){
if (direction === 'space') {
this.ySpeed = -this.ySpeed
}
}
$('body').keydown(function(event){
var direction = (keyNames[event.keyCode])
platform.control(direction)
})
//------------------------------------------------------------------Платформа
var randomXYSpeed = [-5,-4,-3,-2,-1,1,2,3,4,5]
var Ball = function(){
this.color = colors[Math.floor(Math.random()* colors.length)]
this.radius = 10
this.speed = 1
this.x = 20;
this.y = height / 2;
this.xSpeed = Math.floor(Math.random() * randomXYSpeed.length)
this.ySpeed = Math.floor(Math.random() * randomXYSpeed.length)
};
var circle = function(x,y,radius,fillCircle){
ctx.beginPath()
ctx.arc(x,y,radius,0,Math.PI * 2 , false)
if(fillCircle){
ctx.fill()
}
else{
ctx.stroke()
}
};
Ball.prototype.move = function(){
this.x += this.xSpeed;
this.y += this.ySpeed;
}
Ball.prototype.draw = function(){
ctx.fillStyle = this.color
circle(this.x,this.y,this.radius,true)
}
Ball.prototype.checkCollision = function(){
if (this.x<0){
this.xSpeed = -this.xSpeed
}
if (this.y<0 || this.y > height ){
this.ySpeed = -this.ySpeed
}
}
Ball.prototype.gameOverCheck = function(){
if(this.x > width){
var gameOver = function () {
//clearInterval(intervalId);
var colors = ['Red','Orange','Yellow','Green','Blue','Purple']
ctx.font = "170px Courier";
ctx.fillStyle = colors[Math.floor(Math.random()* colors.length)]
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("Game Over", width / 2, height / 2);
};
gameOver()
}
}
var platform = new Platform()
var balls = []
for(var i = 0; i<=2;i++){
balls[i] = new Ball()
}
setInterval(function(){
ctx.clearRect(0,0,width,height)
platform.move()
platform.draw()
platform.checkCollision()
platform.control()