У меня есть эта программа, которую я создал, и она отлично работает, но когда я добавляю вражеский класс в свой код.Класс игрока принимает все цветовые свойства класса врага, а класс врага принимает все свойства класса игрока.Я не знаю, как это исправить.На самом деле главное, что неправильно, это то, что класс круга и класс врага меняют цвета, когда я запускаю его.Как я изменю цвет в классе круга, и класс врага изменится на указанный цвет.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Arrow Keys</title>
<script src="../p5/p5.js" type="text/javascript"></script>
<script src="../p5/addons/p5.dom.js" type="text/javascript"></script>
<script src="../p5/addons/p5.sound.js" type="text/javascript"></script>
<style>
#score {
display: block;
color: #333333;
padding-bottom: 1%;
font-family: arial;
}
div{
margin: 0;
display: flex;
/* This centers our sketch horizontally. */
justify-content: center;
/* This centers our sketch vertically. */
align-items: center;
}
</style>
</head>
<body>
<div id="score"></div>
<script>
function setup() {
createCanvas(windowWidth-100, windowHeight-100);
frameRate(-1);
enemy = new Enemy();
circle = new Circle();
enemys = [];
}
function draw() {
background(51);
enemy.show();
circle.show();
}
function Circle() {
this.x = width/2;
this.y = height/2;
this.xspeed = 0;
this.yspeed = 0;
this.size = [30,30]
this.radius = this.size[0]/2;
this.score = 0;
this.show = function(fillColor = "#FFFFFF") {
this.playerEllipse = ellipse(this.x, this.y, this.size[0], this.size[1]);
this.playerEllipse.fill("#FFFFDD")
this.playerEllipse.stroke("#FFFFDD");
}
}
function Enemy() {
this.x = random(1,200);
this.y = random(1,200);
this.xspeed = 0;
this.yspeed = 0;
this.size = [30,30];
this.radius = this.size[0]/2;
this.show = function() {
this.enemyEliipse = ellipse(this.x, this.y, this.size[0], this.size[1]);
this.enemyEliipse.fill("#FF0000");
this.enemyEliipse.stroke("#FF0000");
}
}
</script>
</body>
</html>