Skip to content

Commit dba760b

Browse files
committed
Clarity changes & market scene
1 parent 14079c7 commit dba760b

7 files changed

Lines changed: 58 additions & 44 deletions

File tree

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010

1111
<body>
1212
<header>
13-
Mysterious Header
13+
Move the boat using the arrow keys
1414
</header>
1515
<main>
1616

1717
<nav id="navbar" class="navbar navbar-dark bg-dark">
18-
<a id="brand" class="navbar-brand" >C4C Game Title Here</a>
18+
<a id="brand" class="navbar-brand" >Fishing Game</a>
1919
<ul class="nav me-auto">
2020
<li class="nav-item">
2121
<button id="tackle-box" type="button" class="btn btn-primary" style = "margin-right:10px">Tackle Box</button>
22-
<button id="badges" type="button" class="btn btn-primary" style = "margin-right:10px">Badges</button>
22+
<button id="my-fish" type="button" class="btn btn-primary" style = "margin-right:10px">My Fish</button>
23+
<button id="market" type="button" class="btn btn-primary" style = "margin-right:10px">Market</button>
2324
</li>
2425
<li class="nav-item">
2526
<button id="run-code" type="button" class="btn btn-success">Run Code</button>

src/assets/background.jpg

-1.14 KB
Binary file not shown.

src/assets/character.png

-7.03 KB
Binary file not shown.

src/index.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import C4C from 'c4c-lib';
33
import Phaser from 'phaser';
44
import MainGame from './scenes/mainGame';
55
import TackleBox from './scenes/tacklebox';
6-
import Badges from './scenes/badges';
6+
import MyFish from './scenes/myfish';
7+
import Market from './scenes/market'
78

89
// Load style.css into our page
910
import './assets/style.css';
@@ -25,7 +26,7 @@ const theme = {
2526
// Create the C4C editor
2627
// The functions that you want the code editor to autocomplete
2728
// If you want to add more on the fly depending on the scene, you will have to create a new editor
28-
const autocompleteFunctions = ['moveRight', 'moveLeft', 'cast', 'addBait'];
29+
const autocompleteFunctions = ['cast', 'addBait'];
2930
C4C.Editor.create(document.getElementById('code-editor'), theme, false, autocompleteFunctions);
3031

3132
// Create the game
@@ -42,7 +43,7 @@ const config = {
4243
// Where the game is located (id of the DOM element)
4344
parent: 'game-container',
4445
// All the scenes in the game
45-
scene: [MainGame, TackleBox, Badges]
46+
scene: [MainGame, TackleBox, MyFish, Market]
4647
}
4748

4849
const game = new Phaser.Game(config);
@@ -63,37 +64,54 @@ document.getElementById('tackle-box').addEventListener('click', () => {
6364
// Stop running any code that's currently running
6465
codeRunner.reset();
6566
clearInterval(gameLoop);
66-
// If the current scene is mainGame.js, or badges.js, switch to tacklebox.js
67+
// If the current scene is mainGame.js, or myfish.js, switch to tacklebox.js
6768
if (game.scene.isActive('MainGame')) {
6869
game.scene.stop('MainGame');
6970
game.scene.start('TackleBox');
70-
} else if(game.scene.isActive('Badges')){
71-
game.scene.stop('Badges');
71+
} else if(game.scene.isActive('MyFish')){
72+
game.scene.stop('MyFish');
7273
game.scene.start('TackleBox');
7374
} else {
7475
game.scene.stop('TackleBox');
7576
game.scene.start('MainGame');
7677
}
7778
});
7879

79-
// Switch the scene whenever the "Badges" button is pressed
80-
document.getElementById('badges').addEventListener('click', () => {
80+
// Switch the scene whenever the "My Fish" button is pressed
81+
document.getElementById('my-fish').addEventListener('click', () => {
8182
// Stop running any code that's currently running
8283
codeRunner.reset();
8384
clearInterval(gameLoop);
84-
// If the current scene is mainGame.js, or tacklebox.js, switch to badges.js
85+
// If the current scene is mainGame.js, or tacklebox.js, switch to myfish.js
8586
if (game.scene.isActive('MainGame')) {
8687
game.scene.stop('MainGame');
87-
game.scene.start('Badges');
88+
game.scene.start('MyFish');
8889
} else if(game.scene.isActive('TackleBox')){
8990
game.scene.stop('TackleBox');
90-
game.scene.start('Badges');
91+
game.scene.start('MyFish');
9192
} else {
92-
game.scene.stop('Badges');
93+
game.scene.stop('MyFish');
9394
game.scene.start('MainGame');
9495
}
9596
});
9697

98+
// Switch the scene whenever the "Market" button is pressed
99+
document.getElementById('market').addEventListener('click', () => {
100+
// Stop running any code that's currently running
101+
codeRunner.reset();
102+
clearInterval(gameLoop);
103+
// If the current scene is mainGame.js, or myfish.js, switch to tacklebox.js
104+
if (game.scene.isActive('MainGame')) {
105+
game.scene.stop('MainGame');
106+
game.scene.start('Market');
107+
} else if(game.scene.isActive('MyFish')){
108+
game.scene.stop('MyFish');
109+
game.scene.start('Market');
110+
} else {
111+
game.scene.stop('TackleBox');
112+
game.scene.start('MainGame');
113+
}
114+
});
97115

98116
// Run the code whenever the "Run Code" button is pressed
99117
document.getElementById('run-code').addEventListener('click', () => {

src/scenes/mainGame.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class MainGame extends Phaser.Scene{
88
constructor(){
99
super('MainGame');
1010

11-
this.boatSpeed = 100;
11+
this.speed = 100;
1212

1313
}
1414

@@ -33,32 +33,6 @@ export default class MainGame extends Phaser.Scene{
3333
this.cursor = this.input.keyboard.createCursorKeys();
3434

3535
// Define functions used in the written code----------------------------
36-
C4C.Interpreter.define('moveRight', (speed) => {
37-
if (speed === undefined) {
38-
speed = 100;
39-
}
40-
this.boat.setVelocityX(speed);
41-
// Stop after 1 game loop
42-
setTimeout(() => {
43-
// This could fail if we switch scenes
44-
try {
45-
this.boat.setVelocityX(0);
46-
} catch (e){};
47-
}, gameLoopSpeed);
48-
})
49-
50-
C4C.Interpreter.define('moveLeft', (speed) => {
51-
if (speed === undefined) {
52-
speed = 100;
53-
}
54-
this.boat.setVelocityX(-speed);
55-
// Stop after 1 game loop
56-
setTimeout(() => {
57-
try {
58-
this.boat.setVelocityX(0);
59-
} catch (e){};
60-
}, gameLoopSpeed);
61-
})
6236

6337
C4C.Interpreter.define('cast', (speed) => {
6438
if (speed === undefined) {

src/scenes/market.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import C4C from 'c4c-lib';
2+
3+
export default class Market extends Phaser.Scene{
4+
constructor(){
5+
super('Market');
6+
}
7+
8+
preload(){
9+
10+
}
11+
12+
create(){
13+
C4C.Editor.setText(`// You can buy things here\n$__\n`);
14+
}
15+
16+
update(){
17+
// Game Logic
18+
}
19+
20+
// Functions
21+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import C4C from 'c4c-lib';
22

3-
export default class Badges extends Phaser.Scene{
3+
export default class MyFish extends Phaser.Scene{
44
constructor(){
5-
super('Badges');
5+
super('MyFish');
66
}
77

88
preload(){

0 commit comments

Comments
 (0)