提示コードのコメント部内部のコードですがなぜグローバル変数をp5ライブラリの関数color()
で初期化しようとすると下記のエラーが出てconstructor
で初期化するとエラーが出ないのでしょうか?そもそも出来ないのでしょうか?
参考サイトを参考にサンプルコードを入れて色々実験しましたが上手くいきません。
参考サイト
Console
Uncaught ReferenceError: color is not defined
at Game.js:17:19
(anonymous) @ Game.js:17
Main.js:9 Uncaught (in promise) ReferenceError: Game is not defined
at setup (Main.js:9:7)
at p5._setup (p5.js:62985:27)
at p5._start (p5.js:62908:25)
at new p5 (p5.js:63261:22)
at _globalInit (p5.js:62189:17)
Game.js
const STAGE_WIDTH = 10;
const STAGE_HEIGHT = 23;
const STAGE_OFFSET_WIDTH = 200;
const STAGE_OFFSET_HEIGHT = 150;
const CELL = 30;
const DONW_SPEED = 5;
const START_POSITION_X = 3;
const START_POSITION_Y = 3;
let t;
/////////////////////////////////////////////////////////////////
const ColorCode = [
// [0,0,0], //背景
color(0,0,0),
[255,255,255], //壁
[0,255,255], //水色
[255,255,0], //黄色
[0,128,0], //緑
[255,0,0], //赤
[0,0,166], //ネイビー
[255,166,0], //オレンジ
[128,0,128], //紫
];
///////////////////////////////////////////////////////////////
//ブロック
const Block =
[
[
[1,1,1,1],
[0,0,0,0],
[0,0,0,0],
[0,0,0,0],
],
[
[1,1,0,0],
[1,1,0,0],
[0,0,0,0],
[0,0,0,0],
],
[
[0,1,1,0],
[1,1,0,0],
[0,0,0,0],
[0,0,0,0],
],
[
[1,1,0,0],
[0,1,1,0],
[0,0,0,0],
[0,0,0,0],
],
[
[1,0,0,0],
[1,1,1,1],
[0,0,0,0],
[0,0,0,0],
],
[
[0,0,0,1],
[1,1,1,1],
[0,0,0,0],
[0,0,0,0],
],
[
[0,1,0,0],
[1,1,1,0],
[0,0,0,0],
[0,0,0,0],
],
];
// ################################################################
// # stage クラス
// ################################################################
class Stage
{
constructor()
{
/////////////////////////////////////////////////////////////
t = color(0,0,0);
//////////////////////////////////////////////////////////////
//ステージ
this.stage =
[
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1]
]
}
// ################################ ラインを削除 ################################
// ################################ Update ################################
Update()
{
}
// ################################ Renderer ################################
Renderer()
{
}
}
Main.js
/////////////////
new p5();
/////////////////
let game = new Game();; //基底ループ
//初期化
function setup()
{
createCanvas(1000,800); //キャンバスサイズ
frameRate(60);
}
//描画
function draw()
{
background(127); //背景色
game.Update();
game.Renderer();
frameRate(60);
}
index.html
<!DOCTYPE html>
<html lang=ja>
<head>
<meta charset="utf-8">
<title>Tetris</title>
<body>
<link rel="stylesheet" href="style.css">
<script src=../p5/p5.js></script>
<!-- ユーティリティ -->
<script src=../Utility/Math.js></script>
<script src=../Utility/Vector.js></script>
<script src=../Utility/Collision.js></script>
<script src="Script/Game.js" ></script>
<script src="Script/Main.js" ></script>
</body>
</head>
</html>