Hi, the structure of my entire board game code below summarized. I don’t know how to move sections of it to function update(){}
var game = new Phaser.Game(config);
//Game variables, buttons, texs, arrays etc
activePlayer = player1;
function Assets1{
//code
};
function Assets2{
//code
};
function preload() {
//Load spritesheets, images
}
function create() {
//Code to add spritesheets, images
function switchTurns1() {
//Code
};
function switchTurns2() {
//code
};
//example code below for player 1 (summarized)
let popup1 = this.add.image(680, 300, 'popup'); //popup to buy asset for player 1
let yesButton1 = this.add.image(popup1.x - 50, popup1.y + 60, 'yes-up');//yes to buy asset player1
let noButton1 = this.add.image(popup1.x + 50, popup1.y + 60, 'no-up');// no to buy asset player 1
yesButton1.setInteractive();
popup1.visible = false;
noButton1.visible = false;
yesButton1.visible = false;
//Roll dice for player 1
diceButton1.on('pointerup', function () {
if (activePlayer !== player1) return;
diceButton1.visible = false; // Hide dice 1
movePlayer1.visible = true; //Show move player1
//Add cash for passing start
//Change player position on board
//Move player1 to pixel position on board
movePlayer1.on('pointerup', function () {
this.tweens.add({
targets: woman,
x: playerPixelPosition[player1.position][0],
y: playerPixelPosition[player1.position][1],
duration: 1000
});
// Landing on special cases
switch (ASSETS[player1.position][0]) {
case "START":
//code here
break;
case "Bett-on Bets":
//Randomly select betting option from betting array
//Variables defining popup for betting are declared here
yesButton.on('pointerdown', function() {
//Code to ay based of outcome of dice roll
if (dice1===dice2){
//code
}
else{
//code
};
//code
switchTurns1();
});
noButton.on('pointerdown', function() {
//code
switchTurns1();
});
break;
default:
// Code for Player 1 purchase asset
//Code for opponent already own the asset? Process payment
//Code for player already owns the asset
//Code for player does not have enough money to buy the asset
break;
}
}
}, this);
}, this);
//Code to compute networth1 value for player 1
//Roll dice for player 2
//Repeat example code for player 1
}
function update() {
}