Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
daisyzhang2024 committed Oct 23, 2023
2 parents d575b48 + f70e256 commit bae8976
Show file tree
Hide file tree
Showing 15 changed files with 611 additions and 28 deletions.
6 changes: 3 additions & 3 deletions _posts/2023-10-06-Background.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ courses: { compsci: {week: 7} }
y: -2000
}
var interval = setInterval(function() {
bg1.y +=5;
bg2.y +=5;
bg3.y +=5;
bg1.y +=3;
bg2.y +=3;
bg3.y +=3;
if (bg1.y == 2000) {
bg1.y = 0;
}
Expand Down
7 changes: 1 addition & 6 deletions _posts/2023-10-10-game_framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ comments: False
<label for="handstand">Handstand</label>
</div>
<canvas id="backgroundID">
<img id="backgroundImage" src="{{site.baseurl}}/images/medieval_background.jpeg" />
<img id="backgroundImage" src="{{}}/images/medieval_background.jpeg" />
</canvas>
</div>

Expand Down Expand Up @@ -205,13 +205,8 @@ backgroundImg.onload = function () {
const defaultFilter = getComputedStyle(document.documentElement).getPropertyValue('--default-canvas-filter');
toggleCanvasEffect.addEventListener("click", function () {
if (isFilterEnabled) {
<<<<<<< HEAD
canvas.style.filter = "none"; // remove filter
goblinCanvas.style.filter = "none";
=======
canvas.style.filter = "invert(100%)"; // remove filter
dogCanvas.style.filter = "invert(100%)";
>>>>>>> 1654a8b5be40f12a1f967be7cbdb7eb8c086cc78
} else {
canvas.style.filter = defaultFilter; // Apply the default filter value
goblinCanvas.style.filter = defaultFilter;
Expand Down
130 changes: 130 additions & 0 deletions _posts/2023-10-11-MainGameFile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
layout: post
title: Main Game!
description: Jump with Link!
author: Katelyn Gelle, Gabriel Gravin, Kaden Vo, Daisy Zhang
courses: {'compsci': {'week': 6}}
type: hacks
comments: True
---

**Directions**
Freeplay with Link! Use "D" to make him move right, use the "A" to make him move left, and use the space bar to jump.

<!DOCTYPE html>
<html>
<head>
<title>Flip or Freeze!</title>
</head>
<body>
<canvas id="gameCanvas" width="800" height="400"></canvas>
<script type="module">
import { Character } from '{{site.baseurl}}/assets/js/Character.js'
var Link = new Character('{{site.baseurl}}/images/linksprites.png', 96, 104, 100, 400 - 104, -10, .5, 2);
// Get the canvas and its 2D rendering context
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
// Load the background image
const backgroundImage = new Image();
backgroundImage.src = '{{site.baseurl}}/images/park.jpg';
// Function to update sprite animation
function updateSpriteAnimation() {
if (Link.frameX < Link.maxFrame) {
Link.frameX++;
} else {
Link.frameX = 0;
}
}
// Function to handle jumping when spacebar is pressed
function jump() {
if (!Link.isJumping) {
Link.spriteVelocityY = Link.jumpStrength;
Link.isJumping = true;
}
}
// Function to handle moving left when a is pressed
function moveLeft() {
Link.isMovingLeft = true;
Link.isIdle = false;
Link.frameY = 5;
Link.maxFrame = 9;
}
// Function to handle moving right when d is pressed
function moveRight() {
Link.isMovingRight = true;
Link.isIdle = false;
Link.frameY = 7;
Link.maxFrame = 9;
}
// Function to handle idle
function idle() {
Link.isIdle = true;
Link.frameY = 0;
Link.maxFrame = 2;
}
// Event listener for key downs
window.addEventListener('keydown', (event) => {
if (event.key === ' ') {
jump();
} else if (event.key === 'a') {
moveLeft();
} else if (event.key === 'd') {
moveRight();
}
});
// Event listener for key ups
window.addEventListener('keyup', (event) => {
if (event.key === 'a') {
idle();
Link.isMovingLeft = false;
} else if (event.key === 'd') {
idle();
Link.isMovingRight = false;
}
})
// Game loop
let framesPerSecond = 30;
function gameLoop() {
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw the background image
ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);
// Update sprite position based on key down left and right
if (Link.isMovingLeft) {
Link.spriteX -= 10;
}
if (Link.isMovingRight) {
Link.spriteX += 10;
}
// Update the sprite position based on gravity
Link.spriteVelocityY += Link.gravity;
Link.spriteY += Link.spriteVelocityY;
// Check if the sprite has landed
if (Link.spriteY >= canvas.height - Link.spriteHeight) {
Link.spriteY = canvas.height - Link.spriteHeight;
Link.spriteVelocityY = 0;
Link.isJumping = false;
}
// Draw the current sprite frame
ctx.drawImage(
Link.spriteImage,
Link.frameX * Link.spriteWidth, // Adjust the X-coordinate of the frame within the sprite sheet
Link.frameY * Link.spriteHeight, // The Y-coordinate within the sprite sheet (assuming Y is always 0 for frames)
Link.spriteWidth, // Width of the frame
Link.spriteHeight, // Height of the frame
Link.spriteX, // X-coordinate where the frame is drawn on the canvas
Link.spriteY, // Y-coordinate where the frame is drawn on the canvas
Link.spriteWidth, // Width of the frame when drawn on the canvas
Link.spriteHeight // Height of the frame when drawn on the canvas
);
// Update sprite animation
updateSpriteAnimation();
// Keeps loop running
setTimeout(function() {
requestAnimationFrame(gameLoop);
}, 1000 / framesPerSecond);
}
gameLoop();
</script>
</body>
</html>
7 changes: 4 additions & 3 deletions _posts/2023-10-11-minigame.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: post
title: Freeplay Minigame!
title: Freeplay Minigame !
description: Jump with Link!
author: Katelyn Gelle, Gabriel Gravin, Kaden Vo, Daisy Zhang
courses: {'compsci': {'week': 6}}
Expand Down Expand Up @@ -45,6 +45,7 @@ Freeplay with Link! Use "D" to make him move right, use the "A" to make him move
let maxFrame = 2;
let isMovingLeft = false;
let isMovingRight = false;
let isIdle = true;
// Function to update sprite animation
function updateSpriteAnimation() {
if (frameX < maxFrame) {
Expand All @@ -63,12 +64,14 @@ Freeplay with Link! Use "D" to make him move right, use the "A" to make him move
// Function to handle moving left when a is pressed
function moveLeft() {
isMovingLeft = true;
isIdle = false;
frameY = 5;
maxFrame = 9;
}
// Function to handle moving right when d is pressed
function moveRight() {
isMovingRight = true;
isIdle = false;
frameY = 7;
maxFrame = 9;
}
Expand All @@ -86,8 +89,6 @@ Freeplay with Link! Use "D" to make him move right, use the "A" to make him move
moveLeft();
} else if (event.key === 'd') {
moveRight();
} else {
idle();
}
});
// Event listener for key ups
Expand Down
4 changes: 4 additions & 0 deletions _posts/2023-10-12-gameframework_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ backgroundImg.onload = function () {
toggleCanvasEffect.addEventListener("click", function () {
if (isFilterEnabled) {
canvas.style.filter = "invert(100%)"; // remove filter
<<<<<<< HEAD
linkCanvas.style.filter = "invert(100%)";
=======
goblinCanvas.style.filter = "invert(100%)";
>>>>>>> f70e2562aa112f946c7cf37a843b8e41d50d92a2
} else {
canvas.style.filter = defaultFilter; // Apply the default filter value
linkCanvas.style.filter = defaultFilter;
Expand Down
103 changes: 87 additions & 16 deletions _posts/2023-10-12-teamwork.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,85 @@ courses: { compsci: {week: 7} }
// Create an array to hold platform information
var platforms = [];

// Function to generate random platforms
// Constants for jump behavior
const gravity = 0.5;
const jumpStrength = -10;

// Function to generate random platforms throughout the screen
function generateRandomPlatform() {
// Define the platform properties
var platform = {
width: 150, // Increased width
height: 20, // Increased height
x: Math.random() * (canvas.width - 150), // Adjusted width
y: -50 // Start platforms off-screen
width: 150,
height: 20,
x: Math.random() * (canvas.width - 150),
y: canvas.height - Math.random() * (canvas.height) // Platforms appear at various vertical positions
};
platforms.push(platform);

// Add a trampoline on some platforms randomly
if (Math.random() < 0.2) { // Adjust the probability as needed
var trampoline = {
x: platform.x + platform.width / 2 - 10, // Adjust for the trampoline's width
y: platform.y - 10, // Adjust for the trampoline's height
width: 20, // Adjust to match the trampoline's width
height: 5, // Adjust to match the trampoline's height
};
platforms.push(trampoline);
}
}

// Function to generate platforms at the top of the screen
function generateTopPlatform() {
var platform = {
width: 150,
height: 20,
x: Math.random() * (canvas.width - 150),
y: -20 // Platforms appear at the top of the screen
};
platforms.push(platform);

// Add a trampoline on some platforms randomly
if (Math.random() < 0.2) { // Adjust the probability as needed
var trampoline = {
x: platform.x + platform.width / 2 - 10, // Adjust for the trampoline's width
y: platform.y - 10, // Adjust for the trampoline's height
width: 20, // Adjust to match the trampoline's width
height: 5, // Adjust to match the trampoline's height
};
platforms.push(trampoline);
}
}

// function to generate platforms at bottom of screen
function generateBottomPlatform() {
var platform = {
width: 150,
height: 20,
x: Math.random() * (canvas.width - 150),
y: canvas.height + 20
};
platforms.push(platform);

// add trampoline on some platforms randomly
if (Math.random() < 0.2) { // Adjust probability as needed
var trampoline = {
x: platform.x + platform/width / 2 - 10, // Adjust for trampoline width
y: platform.y - 10, // Adjust for trampoline height
width: 20, // Adjust to match trampoline width
height: 5, // Adjust to match trampoline height
};
platforms.push(trampoline);
}
}

// Call the platform generation function at regular intervals
setInterval(generateRandomPlatform, 3000); // Adjust the interval as needed
// Call the platform generation function initially to ensure a platform is within jumping distance
generateRandomPlatform();

// Call the platform generation function more frequently to have more platforms
setInterval(generateRandomPlatform, 700); // Decreased interval for more platforms

// Call the top platform generation function at regular intervals
setInterval(generateTopPlatform, 3000); // Platforms at the top every 2 seconds

// Main game loop
var interval = setInterval(function () {
Expand All @@ -81,17 +146,23 @@ courses: { compsci: {week: 7} }
c.drawImage(bgImage, bg2.x, bg2.y);
c.drawImage(bgImage, bg3.x, bg3.y);

// Move and draw the platforms
// Move and draw the platforms, including trampolines
platforms.forEach(function (platform) {
platform.y += 5; // Adjust the platform's speed
c.fillStyle = "yellow"; // Changed platform color to yellow
c.fillRect(platform.x, platform.y, platform.width, platform.height);

// Remove platforms that are off-screen
if (platform.y > canvas.height) {
platforms.splice(platforms.indexOf(platform), 1);
if (platform.width === 20) {
// Draw a green line for the trampoline
c.strokeStyle = "cyan";
c.lineWidth = 5;
c.beginPath();
c.moveTo(platform.x, platform.y + 5);
c.lineTo(platform.x + platform.width, platform.y + 5);
c.stroke();
} else {
// Draw a yellow platform
c.fillStyle = "yellow";
c.fillRect(platform.x, platform.y, platform.width, platform.height);
}
platform.y += 5;
});
}, 50);
}, 90);
};
</script>
Loading

0 comments on commit bae8976

Please sign in to comment.