Browse Source

sprite work

master
Stephanie Gredell 3 weeks ago
parent
commit
d370b2bc1b
  1. BIN
      Gemini_Generated_Image_60mila60mila60mi.png
  2. BIN
      Gemini_Generated_Image_bw4vqvbw4vqvbw4v.png
  3. BIN
      Gemini_Generated_Image_d2uiz4d2uiz4d2ui.png
  4. BIN
      Gemini_Generated_Image_kefpnykefpnykefp.png
  5. BIN
      customer_right.png
  6. BIN
      cuttingboard.png
  7. BIN
      grass_generated.png
  8. BIN
      ice_generated.png
  9. 2
      index.html
  10. 61
      index.js
  11. BIN
      knife.png
  12. BIN
      person_generated.png
  13. BIN
      pitcher_full.png
  14. BIN
      seesaw.png
  15. BIN
      signpost.png
  16. BIN
      slide.png
  17. BIN
      stand.jpg
  18. 27
      style.css
  19. BIN
      tree.png
  20. BIN
      tree_generated.png
  21. BIN
      white_stand.png
  22. BIN
      white_stand_1.png

BIN
Gemini_Generated_Image_60mila60mila60mi.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 860 KiB

BIN
Gemini_Generated_Image_bw4vqvbw4vqvbw4v.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 907 KiB

BIN
Gemini_Generated_Image_d2uiz4d2uiz4d2ui.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 656 KiB

BIN
Gemini_Generated_Image_kefpnykefpnykefp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1023 KiB

BIN
customer_right.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 652 KiB

BIN
cuttingboard.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

BIN
grass_generated.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

BIN
ice_generated.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 920 KiB

2
index.html

@ -25,6 +25,8 @@
<li>Ice: </li> <li>Ice: </li>
<li>Cups: </li> <li>Cups: </li>
</ul> </ul>
<button class="go-shopping-btn">Go shopping</button>
</section> </section>
<section class="game_section"> <section class="game_section">

61
index.js

@ -66,11 +66,23 @@ const sprites = {
ice: createSprite({ ice: createSprite({
source: 'ice.png' source: 'ice.png'
}), }),
pitcher: createSprite({
source: 'pitcher_full.png'
}),
lemons: createSprite({ lemons: createSprite({
source: 'lemons.png' source: 'lemons.png'
}), }),
grass: createSprite({ grass: createSprite({
source: 'grass.png' source: 'grass.png'
}),
tree: createSprite({
source: 'tree.png'
}),
slide: createSprite({
source: 'slide.png'
}),
seesaw: createSprite({
source: 'seesaw.png'
}) })
}; };
@ -112,10 +124,10 @@ function createCup(x, y, scale = 0.1) {
// Game objects // Game objects
const cups = [ const cups = [
createCup(455, 250), createCup(455, 325, 0.15),
createCup(485, 250), createCup(495, 325, 0.15),
createCup(515, 250), createCup(535, 325, 0.15),
createCup(545, 250), createCup(575, 325, 0.15),
] ]
@ -237,28 +249,54 @@ function drawInstance(instance) {
function drawGround() { function drawGround() {
if (!sprites.grass.ready) return; if (!sprites.grass.ready) return;
const pattern = ctx.createPattern(sprites.grass.image, 'repeat') const pattern = ctx.createPattern(sprites.grass.image, 'repeat');
ctx.fillStyle = pattern; ctx.fillStyle = pattern;
const groundHeight = 250; const groundHeight = 250;
ctx.fillRect(0, canvas.height - groundHeight, canvas.width, groundHeight) ctx.fillRect(0, canvas.height - groundHeight, canvas.width, groundHeight);
}
/**
* Draws an oval shadow.
*
* @param {number} x - Center x position
* @param {number} y - Center y position
* @param {number} radiusX - Horizontal radius
* @param {number} radiusY - Vertical radius
* @param {string} [color='rgba(0, 0, 0, 0.25)'] - Shadow color
*/
function drawShadow(x, y, radiusX, radiusY, color = 'rgba(0, 0, 0, 0.3)') {
ctx.beginPath();
ctx.ellipse(x, y, radiusX, radiusY, 0, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
} }
function render() { function render() {
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.clearRect(0, 0, canvas.width, canvas.height);
drawGround(); drawGround();
drawSprite(sprites.tree, 600, 50, 0.25);
drawSprite(sprites.tree, 200, 50, 0.2);
// Slide on the right
drawSprite(sprites.slide, 880, 80, 0.4);
// Seesaw
drawSprite(sprites.seesaw, 200, 280, 0.30);
drawSprite(sprites.maker, 430, 140, 0.4); // Shadow under the stand
drawSprite(sprites.stand, 350, 50, 0.5); drawShadow(500, 360, 180, 50);
drawSprite(sprites.ice, 550, 190, 0.125);
drawSprite(sprites.maker, 430, 160, 0.6);
drawSprite(sprites.stand, 350, 50, 0.7);
drawSprite(sprites.pitcher, 620, 290, 0.3);
// Draw all cup instances // Draw all cup instances
cups.forEach(cup => drawInstance(cup)); cups.forEach(cup => drawInstance(cup));
drawSprite(sprites.lemons, 360, 220, 0.1);
} }
render(); render();
@ -268,5 +306,4 @@ setTimeout(() => {
cups[0].fill(); cups[0].fill();
sprites.maker.frameIndex = 1; sprites.maker.frameIndex = 1;
render(); render();
}, 1000); }, 1000);

BIN
knife.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

BIN
person_generated.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 945 KiB

BIN
pitcher_full.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
seesaw.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

BIN
signpost.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

BIN
slide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

BIN
stand.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

27
style.css

@ -64,3 +64,30 @@ canvas {
display: block; display: block;
pointer-events: none; pointer-events: none;
} }
.go-shopping-btn {
font-family: 'Fredoka', sans-serif;
font-size: 16px;
font-weight: 600;
background: linear-gradient(180deg, #FDB813 0%, #f5a800 100%);
color: #5C4632;
border: 3px solid #3f7a33;
border-radius: 12px;
padding: 10px 20px;
cursor: pointer;
box-shadow: 0 4px 0 #3f7a33;
transition: all 0.1s ease;
margin: 12px auto 0;
display: block;
}
.go-shopping-btn:hover {
background: linear-gradient(180deg, #ffe066 0%, #FDB813 100%);
transform: translateY(-2px);
box-shadow: 0 6px 0 #3f7a33;
}
.go-shopping-btn:active {
transform: translateY(2px);
box-shadow: 0 2px 0 #3f7a33;
}

BIN
tree.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 KiB

BIN
tree_generated.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 842 KiB

BIN
white_stand.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 KiB

BIN
white_stand_1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 KiB

Loading…
Cancel
Save