Skip to content

Commit

Permalink
Create fruitClass and add falling watermelon
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyawho committed Sep 15, 2024
1 parent 0e0615d commit 92d883d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions anthony_cindy_fruitCatcher/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h1>Catch with some Math!</h1>
<script src="./js/GraphicsCommon.js"></script>
<script src="./js/ImageLoading.js"></script>
<script src="./js/Player.js"></script>
<script src="./js/Fruit.js"></script>
<script src="./js/World.js"></script>
<script src="./js/Input.js"></script>
<script src="./js/Main.js"></script>
Expand Down
33 changes: 33 additions & 0 deletions anthony_cindy_fruitCatcher/js/Fruit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const FALL_SPEED = 3;

function fruitClass() { //create a class to easily create new fruits
this.x = 75;
this.y = 75;
this.fruitPic; //which picture to use
this.name = "Unknown Fruit"; //default name

this.reset = function(whichImage, fruitName) {
this.name = fruitName;
this.fruitPic = whichImage;
for(var eachRow = 0; eachRow < WORLD_ROWS; eachRow++){
for(var eachCol = 0; eachCol < WORLD_COLS; eachCol++){
var arrayIndex = rowColtoArrayIndex(eachCol, eachRow);
if(worldGrid[arrayIndex] == WORLD_PLAYERSTART) {
worldGrid[arrayIndex] = WORLD_ROAD;
this.x = eachCol * WORLD_W + WORLD_W/2;
this.y = eachRow * WORLD_H + WORLD_H/2;
return;
} // end of PlayerStart if - is this world here
} //end of col for
} // end of row for
console.log("NO FRUIT FOUND!");
} // end of playerReset func

this.move = function(){
this.y += FALL_SPEED;
}

this.draw = function() {
drawBitmapCenteredWithRotation(this.fruitPic, this.x, this.y, 0);
}
}
2 changes: 2 additions & 0 deletions anthony_cindy_fruitCatcher/js/ImageLoading.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var playerPic = document.createElement("img");
var fruitPic = document.createElement("img");
var worldPics = [];

var picsToLoad = 0; // set automatically based on imageList in loadImages();
Expand All @@ -23,6 +24,7 @@ function loadImageForWorldCode(worldCode, fileName){
function loadImages() {
var imageList = [
{varName: playerPic, theFile: "playerBasketDraft-Med.png"},
{varName: fruitPic, theFile: "watermelon.png"},

{worldType: WORLD_ROAD, theFile: "world_road.png"},
{worldType: WORLD_WALL, theFile: "world_wall.png"},
Expand Down
8 changes: 6 additions & 2 deletions anthony_cindy_fruitCatcher/js/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var canvas, canvasContext;
var framesPerSecond = 30;

var playerOne = new playerClass(); //create a blue player using class definition
var fruitOne = new fruitClass(); //create a fruit using class definition temporarily - array for fruit to make it dynamic?

// ~~~~~~~~~~~~~~~~ Main Game Code ~~~~~~~~~~~~~~~~
window.onload = function() {
Expand Down Expand Up @@ -33,7 +34,8 @@ function nextLevel() {

function loadLevel(whichLevel) {
worldGrid = whichLevel.slice(); // copy level array to worldGrid
playerOne.reset(playerPic, "Blue Storm");
playerOne.reset(playerPic, "Addition Character");
fruitOne.reset(fruitPic, "Apple Fruit");
}

function updateAll() {
Expand All @@ -42,7 +44,8 @@ function updateAll() {
}

function moveAll() {
playerOne.move();
playerOne.move();
fruitOne.move();
}

function clearScreen() {
Expand All @@ -52,5 +55,6 @@ function clearScreen() {
function drawAll() {
drawWorlds();
playerOne.draw();
fruitOne.draw();
drawUserStats(playerOne);
}
3 changes: 0 additions & 3 deletions anthony_cindy_fruitCatcher/js/Player.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const WALK_SPEED = 4;
const REVERSE_POWER = 0.2;
const TURN_RATE = 0.05;
const MIN_SPEED_TO_TURN = 0.5;

function playerClass() { //create a class to easily create new players
this.x = 75;
Expand Down
4 changes: 1 addition & 3 deletions anthony_cindy_fruitCatcher/js/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ function playerWorldHandling(whichPlayer) {
nextLevel();
// alert(whichPlayer.name + " WINS!!"); // player keeps going after alert as if up key was still pressed
}
else if(tileHere == WORLD_APPLE) {
else if(tileHere == WORLD_APPLE || tileHere == WORLD_WATERMELON) {
whichPlayer.fruitsHeld++;
// console.log(whichPlayer.fruitsHeld);
// console.log(playerWorldCol, ":", playerWorldRow, ":", worldGrid[playerWorldCol + WORLD_COLS*playerWorldRow]);
// console.log(rowColtoArrayIndex(playerWorldCol, playerWorldRow));
worldGrid[rowColtoArrayIndex(playerWorldCol, playerWorldRow)] = WORLD_ROAD;
}
else if(!tileTypeMove(tileHere) ||
Expand Down

0 comments on commit 92d883d

Please sign in to comment.