WASD keys to move - UPDATE: Sound starts when player moves right
A fork of Game of Music by Joe DeNavas (DD89)
xxxxxxxxxx
//Store page to get youself a cool shirt! https://streamlabs.com/sl_id_72a9c899-5992-36f4-ba16-9cfb419365a6/merch
/*
Update: If you haven't already, please check out some of the new games I've made!
Wizarding World! https://openprocessing.org/sketch/2119935
Save the Mushrooms; Save the world! 1.5 https://openprocessing.org/sketch/2076032
Save the Mushrooms! Save Halloween! https://openprocessing.org/sketch/2038031
With Sparky & the Prism; Save Egypt! https://openprocessing.org/sketch/1999984
Don't Fall https://openprocessing.org/sketch/2017956
Hey sableraph and friends!
This is a short game I put together using the p5play library, that was orginally a fork of:
"Platformer | p5play" by Quinton Ashley
https://openprocessing.org/sketch/1869796
Still trying to figure out how to add enemies to move them left and right,
have them fire projectiles, add a layer over the game etc. Hopefully will have that figured out for next week's
sketch!
p5play website and very helpful reference page: https://p5play.org/learn/
Hope you all enjoy! Music is also good for streaming!
*/
//mushroom item image from https://opengameart.org/content/large-mushroom
//music from https://opengameart.org/content/beyond-the-clouds-orchestral-theme
//background image created using midjourney
let player, groundSensor, grass, water, coins;
let grassImg, waterImg, coinsImg, charactersImg;
let ImageAppear=false
let score = 0;
let moveRight=false
let coinTimer=false
let coinSoundCounter=0
let YouWon=false
let playTheMusic=true
function preload()
{
ending = loadImage('ending.png') //loads images and sounds
grassImg = loadImage('grass.png');
waterImg = loadImage('water.png');
coinsImg = loadImage('Mushroom.png');
fungibg = loadImage('fungibg2.png');
charactersImg = loadImage('characters.png');
soundFormats('mp3', "wav");
song = loadSound('beyondtheclouds.mp3');
}
function playmusic()
{
if(playTheMusic==true)
{
song.play() //play and loop sound
song.loop()
playTheMusic=false
}
}
function setup()
{
new Canvas(400, 160, 'pixelated');
world.gravity.y = 10;
allSprites.pixelPerfect = true;
grass = new Group(); //grass data
grass.layer = 0;
grass.collider = 'static';
grass.img = grassImg;
grass.tile = 'g';
water = new Group(); //water data
water.layer = 2;
water.collider = 'static';
water.img = waterImg;
water.h = 8;
water.tile = 'w';
coins = new Group(); //mushroom data
coins.layer = 2;
coins.collider = 'static';
coins.img = coinsImg;
coins.scale=.098
coins.y=100
coins.tile = 'm';
//map of level
new Tiles(
[
'mm',
'gg ',
' m m m m',
' gg g',
' m m g m',
' ggg m g ',
' g mmm', // pillars and rotating logs
' g mmm', // are placed seperatley by code below
' m m m m m m mmm',
'gggggggggggwwwwwggggg gggggggggggggggggggggggggggg '
],
8,
8,
16,
16
);
//brown logs in game that rotate
let flipper = new Sprite(860, 100,'k');
flipper.width = 100;
flipper.height = 10;
flipper.color = 'brown';
flipper.rotationSpeed = 1;
let flipper2 = new Sprite(890+50, 100,'k');
flipper2.width = 40;
flipper2.height = 10;
flipper2.color = 'brown';
let flipper3 = new Sprite(1020, 100,'k');
flipper3.width = 100;
flipper3.height = 10;
flipper3.color = 'brown';
flipper3.rotationSpeed = 1;
let flipper4 = new Sprite(1020, 100,'k');
flipper4.width = 100;
flipper4.height = 10;
flipper4.color = 'brown';
flipper4.velocity.y = -1;
let flipper5 = new Sprite(-50, 100,'k');
flipper5.width = 100;
flipper5.height = 10;
flipper5.color = 'brown';
flipper5.rotationSpeed = 1;
//3 pillars at end of level
pillar = new Sprite(1080, 362, 10, 500, 'static');
pillar.color = 'brown';
pillar2 = new Sprite(1150, 362, 10, 500, 'static');
pillar2.color = 'brown';
pillar3 = new Sprite(1220, 362, 10, 500, 'static');
pillar3.color = 'brown';
//player data
player = new Sprite(48, 100, 12, 12);
player.layer = 1;
player.anis.w = 16;
player.anis.h = 16;
player.anis.offset.y = 1;
player.anis.frameDelay = 8;
player.spriteSheet = charactersImg;
player.addAnis({
idle: { row: 0, frames: 4 },
knockback: { row: 0, frames: 1 },
run: { row: 1, frames: 3 },
jump: { row: 1, col: 3, frames: 2 }
});
player.ani = 'idle';
player.rotationLock = true;
// IMPORTANT! prevents the player from sticking to the sides of walls
player.friction = 0;
player.overlaps(coins, collectCoin);
//ground sensor data
groundSensor = new Sprite(48, 106, 6, 12);
groundSensor.visible = false;
groundSensor.mass = 0.01;
groundSensor.overlaps(allSprites);
new GlueJoint(player, groundSensor);
textAlign(CENTER);
}
function collectCoin(player, coin) //if you collect a mushroom
{
score++
coin.remove();
}
function draw()
{
background(0);
image(fungibg, 48-(player.x/5)-100, 0); //background image
fungibg.resize(width+220, height); //resize background image
//display score
fill(255);
if(score<25) text('Mushrooms Needed to Save The World: ' + eval(25-score), 130, 20);
else
{
text('Winner!', width/2,height/2);
//if you win, everything sctops on screen
YouWon=true
}
//if you dont win, game runs normal
if(YouWon==false)
{
//if player collides with 1 out of 3 pillers at end of level
if (player.collides(pillar))
{
player.vel.y = -5;
pillar.h -= 40;
}
if (player.collides(pillar2))
{
player.vel.y = -5;
pillar2.h -= 40;
}
if (player.collides(pillar3))
{
player.vel.y = -5;
pillar3.h -= 40;
}
//if you're in the water
if (groundSensor.overlapping(water))
{
player.drag = 20;
player.friction = 10;
} else //if you're not in the water
{
player.drag = 0;
player.friction = 0;
}
if (groundSensor.overlapping(grass) || groundSensor.overlapping(water))
{
if (kb.presses('up') || kb.presses('space'))
{
player.ani = 'jump';
player.vel.y = -4.5;
}
}
if (kb.pressing('left'))
{
player.ani = 'run';
player.vel.x = -1.5;
player.mirror.x = true;
} else if (kb.pressing('right'))
{
playmusic()
player.ani = 'run';
player.vel.x = 1.5;
player.mirror.x = false;
} else
{
player.ani = 'idle';
player.vel.x = 0;
}
if (player.y > 400) //if player dies
{
player.speed = 0;
player.x = 48;
player.y = 100;
}
if (kb.presses('up') || kb.presses('space')) //alows player to infinitly jump
{
player.ani = 'jump';
player.vel.y = -4.5;
}
camera.x = player.x + 52;
}
}