Skip to content

Commit

Permalink
Cooper, Bullets and Explosions
Browse files Browse the repository at this point in the history
Bullets now have a proper hitbox
Explosions also have a proper hitbox
Changed the lifespan of objects to reflect DeltaTime (Turret Bullet, Turrets)
Added Cooper's grenade attack
  • Loading branch information
BoomBoomMushroom committed Dec 14, 2023
1 parent 52e2357 commit 121bec5
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 50 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
<h3 style="position: fixed; top: 0px; right: 0px;">
FPS: <span id="fpsCounter">0</span>
</h3>

<h3 style="position: fixed; bottom: 0px; right: 0px;" id="consoleEmpty"></h3>
</body>


Expand Down
33 changes: 25 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let characterBuilds = {
},
"Dillion": {
"Neutral_B": (color,user)=>{},
"Side_B": (color,user)=>{dillionSideB_GrappleDirection(color,user)},
"Side_B": (color,user)=>{return dillionSideB_GrappleDirection(color,user)},
"Up_B": (color,user)=>{return dillionUpB_RecoverUp(color, user)},
"Down_B": (summonerColor, user)=>{return spawnTurret(summonerColor, user)},

Expand All @@ -127,7 +127,7 @@ let characterBuilds = {
"Ultimate": (color, user)=>{return spawnBlackhole(color, user)},
},
"Cooper": {
"Neutral_B": (color,user)=>{},
"Neutral_B": (color,user)=>{return dillionSideB_GrappleDirection(color,user)},
"Side_B": (color,user)=>{return CooperSideB_LongPunch(color, user)},
"Up_B": (color,user)=>{},
"Down_B": (summonerColor, user)=>{},
Expand All @@ -136,7 +136,7 @@ let characterBuilds = {
"Side_A": (color,user)=>{},
"LeftSide_A_air": (color,user)=>{},
"RightSide_A_air": (color,user)=>{},
"Down_A": (color,user)=>{},
"Down_A": (color,user)=>{return CooperDownA_Grenade(color, user)},
"Up_A": (color,user)=>{},

"Ultimate": (color, user)=>{},
Expand Down Expand Up @@ -364,6 +364,7 @@ function animate() {

performanceNow = performance.now()
deltaTimeMS = performanceNow-lastFrameNow
dtMultiplier = deltaTimeMS / 1000
lastFrameNow = performanceNow + 0
FPS = 1000 / deltaTimeMS
fpsCounter.innerText = Math.round(FPS)
Expand All @@ -376,8 +377,8 @@ function animate() {
for(var i=0;i<turrets.length;i++){
let turret = turrets[i]
if(turret.cooldown == null){ turret.cooldown = 0 }
else{ turret.cooldown -= 1 }
turret.life -= 1
else{ turret.cooldown -= 1 * dtMultiplier }
turret.life -= 1 * dtMultiplier
if(turret.life <= 0){ turrets.splice(i, 1) }

if(turret.entity.position.y+(turret.entity.height/3)+7 < floor){
Expand Down Expand Up @@ -426,7 +427,7 @@ function animate() {
tEntity.image.src = turret.sprites[kIndex]
tEntity.draw()

if(turret.cooldown == 0){
if(turret.cooldown < 0){
let newProj = new Sprite({
position: {
x: tEntity.position.x + tEntity.width/4,
Expand All @@ -436,6 +437,9 @@ function animate() {
scale: canvasScale * 10,
framesMax: 1,
})
newProj.width = 16
newProj.height = 8

damageSprites.push({
entity: newProj,
color: turret.color,
Expand All @@ -444,7 +448,7 @@ function animate() {
uses: -1,
})

turret.cooldown = 100
turret.cooldown = 1
}
}

Expand All @@ -461,7 +465,8 @@ function animate() {

for(var j=0;j<damageSprites.length;j++){
let atkBox = {attackBox: damageSprites[j].entity}
let collide = rectangularCollision({rectangle1:atkBox, rectangle2:entity})
//let collide = rectangularCollision({rectangle1:atkBox, rectangle2:entity})
let collide = entity.hitBoxCollision(damageSprites[j].entity, entity)
if(collide && entity.color != damageSprites[j].color){
damageSprites[j].uses -= 1
entity.takeHit(damageSprites[j].dmg, damageSprites[j].entity.position)
Expand Down Expand Up @@ -490,6 +495,18 @@ function animate() {
}
}
entity.entity.update()

/*
// draw hit box
c.beginPath();
c.moveTo(entity.entity.position.x, entity.entity.position.y);
c.lineTo(entity.entity.position.x + entity.entity.width, entity.entity.position.y);
c.lineTo(entity.entity.position.x + entity.entity.width, entity.entity.position.y+entity.entity.height);
c.lineTo(entity.entity.position.x, entity.entity.position.y+entity.entity.height);
c.lineTo(entity.entity.position.x, entity.entity.position.y);
c.stroke();
*/

if(entity.vel != null){
entity.entity.position.x += entity.vel.x
entity.entity.position.y += entity.vel.y
Expand Down
46 changes: 39 additions & 7 deletions js/customAttacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,35 @@ function binaryRain(count, dmg, summonerColor){
}

// Cooper Attacks
function CooperDownA_Grenade(color, user){
let grenadeSprite = new Sprite({
position: user.position,
imageSrc: './sprites/cooper_stock_photos/grenade_pull_6frames.png',
scale: canvasScale * 1,
framesMax: 6,
offset: {
"x": 0,
"y": 0
}
})
sprites.push(grenadeSprite)

let clearingId = setInterval(()=>{
if(grenadeSprite.framesCurrent != grenadeSprite.framesMax-1) return
sprites.splice( sprites.indexOf(grenadeSprite), 1)
explosionCreate(color, {
"x": user.position.x,
"y": user.position.y - user.height/2,
})
clearInterval(clearingId)
}, 1)

return 6000
}

function CooperSideB_LongPunch(summonerColor, user){
let spriteName = user.facingRight ? "right" : "left"

let e = new Sprite({
position: {
"x": user.position.x,
Expand All @@ -53,21 +79,22 @@ function CooperSideB_LongPunch(summonerColor, user){

//pullUser: true,
life: 9000,
})
})

return 2000
return 2000
}



// Dillion Attacks
function spawnTurret(summonerColor, user){
let usetTurretCount = 0
let maxTurrets = 1
let usetTurretCount = 0
for(var i=0;i<turrets.length;i++){
let turret = turrets[i]
if(turret.summoner == user){ usetTurretCount += 1 }
}
if(usetTurretCount >= 3){ return 0 }
if(usetTurretCount >= maxTurrets){ return 0 }

let e = new Sprite({
position: {
Expand Down Expand Up @@ -146,6 +173,7 @@ function dillionUpA_DestroyTurrets(color, user){
x: user.position.x - (user.width/2),
y: user.position.y - (user.height/2)
})
user.takeHit(randomInt(1, 10), user.position)

for(var i=0;i<turrets.length;i++){
if(turrets[i] == null){ continue }
Expand Down Expand Up @@ -181,7 +209,7 @@ function spawnBlackhole(summonerColor, user){
dmg: 3,
scaleTo: 5,
scaleFrom: 0,
life: 250, // 5 seconds?
life: 5000, // 5 seconds?
uses: Infinity,
})
}
Expand All @@ -199,11 +227,15 @@ function explosionCreate(summonerColor, position){
scale: canvasScale * 7,
framesMax: 7,
})

e.width = 135
e.height = 135

damageSprites.push({
entity: e,
dmg: randomInt(20, 45),
color: summonerColor,
uses: 1,
life: 30,
life: 500,
})
}
38 changes: 22 additions & 16 deletions js/customClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class Fighter extends Sprite {
this.onGround = false
this.stunFrames = 0

this.critChance = 0.01 // <-- 1% chance
this.attackDamage = 1

this.facingRight = facingRight
this.damage = 0
this.immunityFrames = 0
Expand Down Expand Up @@ -282,12 +285,11 @@ class Fighter extends Sprite {
this.immunityFrames -= 1
this.stunFrames -= 1

this.attackRunTime -= deltaTimeMS
this.attackRunTime -= deltaTimeMS / 1000
this.isAttacking = this.attackRunTime > 0

let attkCooldownKeys = Object.keys(this.cooldowns)
for(let i=0;i<attkCooldownKeys.length;i++){
//this.cooldowns[attkCooldownKeys[i]] -= 1
this.cooldowns[attkCooldownKeys[i]] -= deltaTimeMS
if(isNaN(this.cooldowns[attkCooldownKeys[i]])) this.cooldowns[attkCooldownKeys[i]] = 0
}
Expand All @@ -305,7 +307,7 @@ class Fighter extends Sprite {

if(this.position.y < 0){ this.velocity.y *= -1 }
if(this.position.x < 0){
this.velocity.x = Math.abs(this.velocity.x)
this.velocity.x = 5
if(this.velocity.x <= 0) this.velocity.x = 10
}

Expand Down Expand Up @@ -415,12 +417,19 @@ class Fighter extends Sprite {
}
}

c.fillStyle = this.color;
c.font = "16px PressStart2P";
//c.fillStyle = this.color;
//c.font = "16px PressStart2P";

let percent = this.damage/300
let move = (percent * 14) + 7
c.fillText(this.damage+"%",this.position.x+(this.width/4)-move,this.position.y-15);
//c.fillText(this.damage+"%",this.position.x+(this.width/4)-move,this.position.y-15);
this.drawText(this.color, "16px PressStart2P", this.damage+"%", {"x": this.position.x+(this.width/4)-move, "y":this.position.y-15})
}

drawText(color, font, text, position){
c.fillStyle = color
c.font = font
c.fillText(text, position.x, position.y)
}

drawHitbox(hitboxData, color) {
Expand Down Expand Up @@ -526,18 +535,15 @@ class Fighter extends Sprite {
let collision = this.hitBoxCollision(attackingHitbox, entityHitbox)
if(collision == false) continue

entities[i].takeHit(1, this.position)
this.ultimateCharge += this.attackDamage
document.getElementById("consoleEmpty").innerText = this.ultimateCharge
entities[i].takeHit(this.attackDamage, this.position)
console.log(collision, "Collision!")
}
this.isAttacking = false

//console.log(attackDirection)
}

attack() {
if(this.isAttacking){return}

this.isAttacking = true
}

jump(){
if(this.onGround == false) return
Expand Down Expand Up @@ -584,8 +590,6 @@ class Fighter extends Sprite {

clearInterval(clearingId)
}, 1)

console.log("I am dead")
}

killPlayer(reason){
Expand All @@ -596,6 +600,8 @@ class Fighter extends Sprite {

takeHit(dmg, src) {
if(this.immunityFrames > 0) return
if(Math.random() <= this.critChance) dmg += randomInt(1, 10)

this.damage += dmg
this.immunityFrames = 5

Expand Down Expand Up @@ -711,7 +717,7 @@ class Fighter extends Sprite {

if(didAttack == false) return
this.isAttacking = true
this.attackRunTime = 100
this.attackRunTime = 0.05
}

determineAndUpdateSprite(){
Expand Down
49 changes: 30 additions & 19 deletions notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ Dillion Attacks and Notes
> Spawn Black Hole on current position


Cooper Attacks and Notes
* A Attacks
- Neutral ~ Everyone becomes Miles Morales suprised for X seconds
- Side ~ Stick hand grapple to enemy or wall
- Side Air ~ Same as grapple - ground side
- Down ~ Pull grenade pin and explode everyone
- Up ~ Turn into plane, and blow up one player
* B Attacks
- Neutral ~ Pull someone towards you (facing direction) (Side B in Dillion)
- Side ~ Long punch in direction (comically long hand)
- Up ~ Stock Photo hand Punch Up Quickly
- Down ~ Stock Photo hand Punch Down Quickly
* Ultimate
~ Giga Chad for X seconds w/ buff attack and speed


Ryan Attacks and Notes
* A Attacks
- Neutral ~ Spout factual nonsence firing a projectile that deals decent damage
- Side ~ Pulls out big ol' book that smack enemies in front of him
- Side Air ~ Dashes forward trying yo stab someone with a chess queen (can spike)
- Down ~ Does the funny little tap dance, minor damage and temp. stuns nearby enemies
- Up ~ Smacks the words "no" and "life" together above himself good damge and blasts enemy away
* B Attacks
- Neutral ~ Prays to god, recieves 1 of 5 buffs (damahe, defense, speed, jump, or 1% chance to one-tap enemy)
- Side ~ Sings incredibly loudly and fires a music note towards enemies (damage based on charge)
- Up ~ Pulls out winged shoes and given a moment to target (sepherof up b in smash bros ult.)
- Down ~ Smmons a skeleton that can have a gun, a sword, or a shield that attacks enemies
* Ultimate
~ God and Goku appear in the background and combine the power to fire a ray of light where targeted (HUGE DAMAGE)



Expand Down Expand Up @@ -67,25 +97,6 @@ Ult gigachad head massive buff to speed and attack



Cooper Attacks and Notes
* A Attacks
- Neutral ~ Everyone becomes Miles Morales suprised for X seconds
- Side ~ Stick hand grapple to enemy or wall
- Side Air ~ Same as grapple - ground side
- Down ~ Pull grenade pin and explode everyone
- Up ~ Turn into plane, and blow up one player
* B Attacks
- Neutral ~ Pull someone towards you (facing direction) (Side B in Dillion)
- Side ~ Long punch in direction (comically long hand)
- Up ~ Stock Photo hand Punch Up Quickly
- Down ~ Stock Photo hand Punch Down Quickly
* Ultimate
~ Giga Chad for X seconds w/ buff attack and speed





EmptyPlayer Attacks and Notes
* A Attacks
- Neutral ~
Expand Down

0 comments on commit 121bec5

Please sign in to comment.