Skip to content

Commit dacff48

Browse files
committed
Starting to implement addBait()
1 parent dffd87f commit dacff48

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

src/scenes/mainGame.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import fish from '../assets/testFish.png';
88
import line from '../assets/line.png'
99
// Fish images:
1010
import Minnow from '../assets/Minnow.png';
11+
// Bait images:
12+
1113

1214

1315
export default class MainGame extends Phaser.Scene{
@@ -16,6 +18,7 @@ export default class MainGame extends Phaser.Scene{
1618

1719
this.speed = 100;
1820
this.length = 100;
21+
this.baitType = '';
1922

2023
}
2124

@@ -99,11 +102,36 @@ export default class MainGame extends Phaser.Scene{
99102

100103
// Define functions used in the C4C written coding area---------------------
101104

102-
// addBait(bait type)
105+
// addBait(baitType)
106+
C4C.Interpreter.define('addBait', (baitType) => {
107+
if (this.canCast) {
108+
valid = false;
109+
110+
if (baitType === undefined) {
111+
baitType = '';
112+
}
113+
else if (baitType != ''){
114+
// TODO
115+
// Check if baitType entered is valid & unlocked (using global variables)--> change boolean 'valid' accordingly
116+
// Retrieve the corresponding image path string
117+
baitImgVar = baitType.toLowercase();
118+
}
103119

120+
// Create bait sprite iff baitType is valid & unlocked
121+
if (baitType != '' && valid) {
122+
if (this.rightFacing) {
123+
this.bait = this.physics.add.sprite(this.player.x + 90, this.player.y - 60, baitImgVar).setDisplaySize(15, 30);
124+
} else {
125+
this.bait = this.physics.add.sprite(this.player.x - 90, this.player.y - 60, baitImgVar).setDisplaySize(15, 30);
126+
}
127+
}
128+
// TODO
129+
// Find a way to make the bait follow/tween with the hook (add this.bait in cast method?)
130+
}
131+
});
104132

105-
// cast(length)
106-
C4C.Interpreter.define('cast', (length) => {
133+
// cast(length)
134+
C4C.Interpreter.define('cast', (length) => {
107135
if (this.canCast) {
108136
if (length === undefined) length = 100;
109137
else if (length > 500) length = 500;

0 commit comments

Comments
 (0)