Hi @filip, @ivan hope all is well,
Iâm struggling a little on this course on a couple of things and it doesnât seem that thereâs many people doing this particular course to be able to assist. Would you mind helping out? The first error message iâm getting doesnât prevent the game form playing but I canât locate this particular issue:
Phaser v3.15.1 (WebGL | Web Audio) https://phaser.io
(index):55 game is loading assets
(index):88 game is setting up the assets etc.
96phaser.min.js:1 Uncaught TypeError: Cannot read property 'texture' of undefined
at initialize.setCurrentFrame (phaser.min.js:1)
at initialize.updateFrame (phaser.min.js:1)
at initialize.updateAndGetNextTick (phaser.min.js:1)
at initialize.nextFrame (phaser.min.js:1)
at initialize.setFrame (phaser.min.js:1)
at initialize.update (phaser.min.js:1)
at initialize.preUpdate (phaser.min.js:1)
at initialize.update (phaser.min.js:1)
at initialize.h.emit (phaser.min.js:1)
at initialize.step (phaser.min.js:1)
The html code is as follows:
<!DOCTYPE html>
<html>
<head>
<title>Our Awesome Game</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
<script src ="https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js"></script>
<script src="eth.js"></script>
</head>
<body>
<h1>Collect Coins & Win Money</h1>
<h2>Collect 100 Bitcoin in 60 Seconds</h2>
<script>
var cursors;
var knight;
var crates;
var coinTimer;
var score = 0;
var scoreText;
var secondsLeft = 60;
var timeLeftText;
var timeLeftTimer;
var gameOver = false;
// Configure the game, (height, wodth, render-type, game loop functions)
var config = {
width:800,
height:450,
type:Phaser.AUTO,
scene:{
preload: gamePreload,
create: gameCreate,
update: gameUpdate
},
physics:{
default:"arcade",
arcade:{
gravity:{y:300},
debug:false
}
}
}
function gamePreload(){
// Loading Assets
console.log("game is loading assets");
this.load.image("knight", "assets/knight.png");
this.load.image("crate", "assets/crate.png");
this.load.image("background", "assets/background.png");
this.load.image("bitcoin", "assets/bitcoin.png");
// load the run animation frames
this.load.image("run_frame_1", "assets/knight/run/Run (1).png");
this.load.image("run_frame_2", "assets/knight/run/Run (2).png");
this.load.image("run_frame_3", "assets/knight/run/Run (3).png");
this.load.image("run_frame_4", "assets/knight/run/Run (4).png");
this.load.image("run_frame_5", "assets/knight/run/Run (5).png");
this.load.image("run_frame_6", "assets/knight/run/Run (6).png");
this.load.image("run_frame_7", "assets/knight/run/Run (7).png");
this.load.image("run_frame_8", "assets/knight/run/Run (8).png");
this.load.image("run_frame_9", "assets/knight/run/Run (9).png");
this.load.image("run_frame_10", "assets/knight/run/Run (10).png");
// load the idle animation frames
this.load.image("idle_frame_1", "assets/knight/idle/Idle (1).png");
this.load.image("idle_frame_2", "assets/knight/idle/Idle (2).png");
this.load.image("idle_frame_3", "assets/knight/idle/Idle (3).png");
this.load.image("idle_frame_4", "assets/knight/idle/Idle (4).png");
this.load.image("idle_frame_5", "assets/knight/idle/Idle (5).png");
this.load.image("idle_frame_6", "assets/knight/idle/Idle (6).png");
this.load.image("idle_frame_7", "assets/knight/idle/Idle (7).png");
this.load.image("idle_frame_8", "assets/knight/idle/Idle (8).png");
this.load.image("idle_frame_9", "assets/knight/idle/Idle (9).png");
this.load.image("idle_frame_10", "assets/knight/idle/Idle (10).png");
}
function gameCreate(){
// Monitoring inputs and telling game how to update
console.log("game is setting up the assets etc.");
// Create background
this.add.image(300,150,"background");
// Create the knight
knight = this.physics.add.sprite(100,100,"knight");
knight.body.setSize(400,600,200,10);
knight.scaleX = 0.1;
knight.scaleY = knight.scaleX;
// Create the crates
crates = this.physics.add.staticGroup();
// Floor
crates.create(40,450, "crate");
crates.create(120,450, "crate");
crates.create(200,450, "crate");
crates.create(280,450, "crate");
crates.create(360,450, "crate");
crates.create(520,450, "crate");
crates.create(600,450, "crate");
crates.create(680,450, "crate");
crates.create(760,450, "crate");
// Crates in the air
crates.create(40,250, "crate");
crates.create(120,250, "crate");
crates.create(200,250, "crate");
crates.create(280,250, "crate");
crates.create(760,350, "crate");
crates.create(600,150, "crate");
crates.create(680,300, "crate");
// Create Animations
this.anims.create({
key:"knight_run",
frames:[
{key: "run_frame_1"},
{key: "run_frame_2"},
{key: "run_frame_3"},
{key: "run_frame_4"},
{key: "run_frame_5"},
{key: "run_frame_6"},
{key: "run_frame_7"},
{key: "run_frame_8"},
{key: "run_frame_9"},
{key: "run_frame_10"},
],
frameRate: 10,
repeat: 1
});
this.anims.create({
key:"knight_idle",
frames:[
{key: "idle_frame_1"},
{key: "idle_frame_2"},
{key: "idle_frame_3"},
{key: "idle_frame_4"},
{key: "idle_frame_5"},
{key: "idle_frame_6"},
{key: "idle_frame_7"},
{key: "idle_frame_8"},
{key: "idleframe_9"},
{key: "idle_frame_10"},
],
frameRate: 10,
repeat: 1
});
this.physics.add.collider(crates, knight);
scoreText = this.add.text(16,16, "Bitcoin Bag: 0",
{fontSize: "32px",
fill: "#000"});
timeLeftText = this.add.text(16,66, secondsLeft + "seconds left",
{fontSize: "32px",
fill: "#f00"});
cursors = this.input.keyboard.createCursorKeys();
coinTimer = this.time.addEvent({
delay: Phaser.Math.Between(0,3000),
callback: generateCoins,
callbackScope: this,
repeat: -1
});
timLeftTimer = this.time.addEvent({
delay: 1000,
callback: updateTimeLeft,
callbackScope: this,
repeat: -1
});
}
function updateTimeLeft(){
if(gameOver) return;
secondsLeft -=1;
timeLeftText.setText(secondsLeft + "seconds left");
if(secondsLeft<=0){
this.physics.pause();
gameOver = true;
}
}
function generateCoins(){
var coins = this.physics.add.group({
key: "bitcoin",
repeat: 1,
setXY:{
x: Phaser.Math.Between(0,800),
y:-100,
stepX: Phaser.Math.Between(30,100)
}
});
coins.children.iterate (function(child){
child.setBounceY(Phaser.Math.FloatBetween(0.4,1.5))
});
this.physics.add.collider(coins, crates);
this.physics.add.overlap(knight, coins, collectCoin, null, this)
}
function collectCoin(knight, coin){
coin.disableBody(true, true);
score +=1;
scoreText.setText("Bitcoin Bag:" + score);
}
function gameUpdate(){
// Initial set up logic on the assets and other setup
if(cursors.left.isDown){
knight.setVelocityX(-200);
knight.play("knight_run", true);
knight.flipX = true;
}
else if(cursors.right.isDown){
knight.setVelocityX(200);
knight.play("knight_run", true);
knight.flipX = false;
}
else{
knight.setVelocityX(0);
knight.play("knight_idle", true);
}
if(cursors.up.isDown && knight.body.touching.down){
knight.setVelocityY(-300);
}
}
var game = new Phaser.Game(config);
</script>
</body>
</html>
The other issue I have is with the eth.js file and the following appears on the console:
eth.js:1 Uncaught ReferenceError: Web3 is not defined
at eth.js:1
My eth.js file is as follows:
web3 = new Web3 (new Web3.providers.HttpProvider("http:/localhost:9545"));
var abi = [
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "string",
"name": "_symbol",
"type": "string"
},
{
"internalType": "uint8",
"name": "_decimals",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "subtractedValue",
"type": "uint256"
}
],
"name": "decreaseAllowance",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "addedValue",
"type": "uint256"
}
],
"name": "increaseAllowance",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "uint256",
"name": "_value",
"type": "uint256"
}
],
"name": "mint",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
var contract = new web3.eth.Contract(abi, "0xEb8ccCd2D57FB6C61Ec22be8C1eF85C1F0226b3a");
console.log(contract);
function mintAfterGame (address, nrOfTokens){
contract.methods.mint(address, nrOfTokens).send({from: address})
.on('receipt', receipt => {
alert ("Transaction Complete");
})
}
Any guidance would be hugely appreciated