Skip to content

Commit 68bdb7d

Browse files
committed
Beginning market implementation
1 parent 0aca954 commit 68bdb7d

File tree

7 files changed

+61
-8
lines changed

7 files changed

+61
-8
lines changed

index.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
</head>
1010

1111
<body>
12-
<header>
13-
Move the boat using the arrow keys
14-
</header>
12+
1513
<main>
1614

1715
<nav id="navbar" class="navbar navbar-dark bg-dark">
18-
<a id="brand" class="navbar-brand" >Fishing Game</a>
16+
<a id="brand" class="navbar-brand" >Rico's Fishing Adventure</a>
1917
<ul class="nav me-auto">
2018
<li class="nav-item">
2119
<button id="MainGame" type="button" class="btn btn-primary" style = "margin-right:10px">🎣</button>

src/assets/Bluegill.png

4.71 KB
Loading

src/assets/Catfish.png

277 KB
Loading

src/assets/Market1-worms.PNG

23.2 KB
Loading

src/assets/Marketbkg.PNG

250 KB
Loading

src/scenes/mainGame.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Minnow from '../assets/Minnow.png';
1111
import Carp from '../assets/Carp.png';
1212
import Bluegill from '../assets/Bluegill.png';
1313
import Trout from '../assets/Trout.png';
14+
import Catfish from '../assets/Catfish.png';
1415
// Bait images:
1516

1617

@@ -36,6 +37,7 @@ export default class MainGame extends Phaser.Scene{
3637
this.load.image('Carp', Carp);
3738
this.load.image('Bluegill', Bluegill);
3839
this.load.image('Trout', Trout);
40+
this.load.image('Catfish', Catfish);
3941
}
4042

4143
create(){
@@ -58,7 +60,7 @@ export default class MainGame extends Phaser.Scene{
5860
{type: 'Carp', speedRange: [-100, 100], depth: depthZone[0], imgName: 'Carp', displayX: 100, displayY: 50},
5961
{type: 'Bluegill', speedRange: [-100, 100], depth: depthZone[0], imgName: 'Bluegill', displayX: 70, displayY: 40},
6062
{type: 'Bass', speedRange: [-120, 120], depth: depthZone[1], imgName: 'fish', displayX: 100, displayY: 50},
61-
{type: 'Catfish', speedRange: [-120, 120], depth: depthZone[1], imgName: 'fish', displayX: 100, displayY: 50},
63+
{type: 'Catfish', speedRange: [-120, 120], depth: depthZone[1], imgName: 'Catfish', displayX: 110, displayY: 50},
6264
{type: 'Trout', speedRange: [-120, 120], depth: depthZone[1], imgName: 'Trout', displayX: 100, displayY: 30},
6365
{type: 'Salmon', speedRange: [-140, 140], depth: depthZone[2], imgName: 'fish', displayX: 100, displayY: 50},
6466
{type: 'Tuna', speedRange: [-140, 140], depth: depthZone[2], imgName: 'fish', displayX: 100, displayY: 50},
@@ -275,7 +277,7 @@ export default class MainGame extends Phaser.Scene{
275277
{type: 'Carp', speedRange: [-100, 100], depth: depthZone[0], imgName: 'Carp', displayX: 100, displayY: 50},
276278
{type: 'Bluegill', speedRange: [-100, 100], depth: depthZone[0], imgName: 'Bluegill', displayX: 70, displayY: 40},
277279
{type: 'Bass', speedRange: [-120, 120], depth: depthZone[1], imgName: 'fish', displayX: 100, displayY: 50},
278-
{type: 'Catfish', speedRange: [-120, 120], depth: depthZone[1], imgName: 'fish', displayX: 100, displayY: 50},
280+
{type: 'Catfish', speedRange: [-120, 120], depth: depthZone[1], imgName: 'Catfish', displayX: 110, displayY: 50},
279281
{type: 'Trout', speedRange: [-120, 120], depth: depthZone[1], imgName: 'Trout', displayX: 100, displayY: 30},
280282
{type: 'Salmon', speedRange: [-140, 140], depth: depthZone[2], imgName: 'fish', displayX: 100, displayY: 50},
281283
{type: 'Tuna', speedRange: [-140, 140], depth: depthZone[2], imgName: 'fish', displayX: 100, displayY: 50},

src/scenes/market.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,69 @@
11
import C4C from 'c4c-lib';
2+
import marketBkg from '../assets/Marketbkg.PNG';
3+
import item1 from '../assets/Market1-worms.PNG';
24

35
export default class Market extends Phaser.Scene{
46
constructor(){
57
super('Market');
68
}
79

810
preload(){
9-
11+
this.load.image('marketBkg', marketBkg);
12+
this.load.image('item1', item1);
1013
}
1114

1215
create(){
13-
C4C.Editor.setText(`// You can buy things here\n$__\n`);
16+
// Add images
17+
this.add.image(400, 300, 'marketBkg').setDisplaySize(800, 600);
18+
// Items for sale: Create & store
19+
this.itemImages = {
20+
1: this.add.image(400, 300, 'item1').setDisplaySize(800, 600)
21+
};
22+
23+
const items = [
24+
{item: 'item1', name: 'Worms', price: 5, type: 'Bait', itemID: 1},
25+
]
26+
27+
// Default text:
28+
C4C.Editor.setText(`// $__\n// To see item info, enter item number and run:\n details()\n`);
29+
30+
31+
// Define functions used in the C4C written coding area---------------------
32+
C4C.Interpreter.define('details', (ID) => {
33+
ID = Number(ID);
34+
35+
const i = items.find(item => item.itemID === ID);
36+
37+
if (!i) {
38+
C4C.Editor.setText(`// Please enter a valid number!`);
39+
return;
40+
}
41+
42+
// Item Details in text editor:
43+
C4C.Editor.setText(
44+
`// Item ID: ${i.itemID}\n` +
45+
`// Name: ${i.name}\n` +
46+
`// Type: ${i.type}\n` +
47+
`// Price: $${i.price}`
48+
);
49+
50+
highlightItem(ID);
51+
});
52+
// Additional Functions ----------------------------------------------------------------
53+
54+
// Grays out all other items
55+
const highlightItem = (itemID) => {
56+
Object.entries(this.itemImages).forEach(([id, img]) => {
57+
if (Number(id) === itemID) {
58+
img.clearTint();
59+
img.setAlpha(1);
60+
} else {
61+
img.setTint(0x888888); // grey tint
62+
img.setAlpha(0.5); // faded
63+
}
64+
});
65+
};
66+
1467
}
1568

1669
update(){

0 commit comments

Comments
 (0)