Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from log-lot/main
Browse files Browse the repository at this point in the history
added optimization
  • Loading branch information
loglot authored Aug 21, 2024
2 parents f375aee + 8882f4e commit 73f94b0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
3 changes: 2 additions & 1 deletion imports/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Held } from "../system/map-player/player/heldItems/holdManager.js"
import { Bazooka } from "../system/map-player/player/heldItems/Bazooka.js"
import { Shotgun } from "../system/map-player/player/heldItems/Shotgun.js"
import { Dash } from "../system/map-player/player/heldItems/dash.js"
import { UiUtills } from "../system/variousParts/UIUtills.js"

export class Game{
// System
Expand All @@ -28,7 +29,7 @@ export class Game{
enemy;

// fields

uitills = new UiUtills(this)
shotgun = new Shotgun(this)
dash = new Dash(this)
keyManager = new KeyManager(this);
Expand Down
29 changes: 20 additions & 9 deletions system/map-player/player/heldItems/Shotgun.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class Shotgun{
particles = []
steps = 50
length = 0
frame = 0
colideTime = 1
constructor(game){
this.game = game
}
Expand All @@ -31,6 +33,7 @@ export class Shotgun{
this.particles[this.length].velX = (this.trajectory.x*30 + (Math.random() - .5) * 5)
this.particles[this.length].velY = (this.trajectory.y*30 + (Math.random() - .5) * 5)
this.particles[this.length].alpha = 2
this.particles[this.length].frame = 2
this.length++
if(this.length > 50){
this.length = 0
Expand Down Expand Up @@ -74,16 +77,24 @@ export class Shotgun{
this.reloading = false
}
}
for(let i = 0; i < this.particles.length; i++){
for(let h = 0; h < this.steps; h++){
this.particles[i].x -= (this.particles[i].velX * this.velMultiplyer) / this.steps
this.particles[i].y -= (this.particles[i].velY * this.velMultiplyer) / this.steps
if(this.particles[i].alpha > 0){
this.colideAll(this.game.map.ground, i)
}
this.particles[i].alpha -= 0.0001


for(let i = 0; i < this.particles.length; i++){
this.particles[i].frame++
//for(let h = 0; h < this.steps; h++){
this.particles[i].x -= (this.particles[i].velX * this.velMultiplyer) // this.steps
this.particles[i].y -= (this.particles[i].velY * this.velMultiplyer) // this.steps
//if(this.particles[i].alpha > 0 && this.particles[i].frame > 15){
this.colideAll(this.game.map.ground, i)
this.particles[i].frame = 0
//}
this.particles[i].alpha -= 0.0001


//}
}
}


if(this.velMultiplyer > 0){
this.velMultiplyer /= 1 + (this.velMultiplyer/15)
}
Expand Down
3 changes: 3 additions & 0 deletions system/variousParts/GameDisplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class GameDisplayer {
this.resizeCanvasForWindowSize(ballEffect, bctx);
this.resizeCanvasForWindowSize(postEffect, ppctx);


this.bgFade(this.targetR, this.targetG, this.targetB)
this.r += this.rC
this.g += this.gC
Expand All @@ -92,6 +93,8 @@ export class GameDisplayer {
ctx.drawImage(this.grid, 0, 0, this.originalWidth,625 * (this.originalWidth / 1000))
}

//this.game.uitills.draw()

for(let i = 0; i < this.game.shotgun.particles.length; i++) {
ctx.globalAlpha = Math.max(0, Math.min(1,this.game.shotgun.particles[i].alpha))
console.log(this.game.shotgun.particles[i].alpha)
Expand Down
19 changes: 19 additions & 0 deletions system/variousParts/UIUtills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const canvas = document.getElementById("UI")
const ctx = canvas.getContext("2d")

import { DrawUtils } from "../../utils/DrawUtils.js"

export class UiUtills {
tText = ""
tTime = 0
tY = 500
draw = new DrawUtils()

draw(){
//this.draw.Rect(500, 500, 500, 100, "#000000")
}

toast(text, time){

}
}

0 comments on commit 73f94b0

Please sign in to comment.