generated from nighthawkcoders/platformer3x
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Flag class and integrate into Greece level; update player finish …
…line logic
- Loading branch information
1 parent
eb730b4
commit ae78552
Showing
5 changed files
with
72 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import GameEnv from './GameEnv.js'; | ||
import Coin from './Coin.js'; | ||
|
||
export class Flag extends Coin { | ||
constructor(canvas, image, data, xPercentage, yPercentage) { | ||
super(canvas, image, data, xPercentage, yPercentage); | ||
this.x = xPercentage * GameEnv.innerWidth; | ||
this.y = yPercentage * GameEnv.bottom; | ||
this.size(); | ||
this.id = this.initiateId() | ||
this.scaleSize = data?.scaleSize || 80; | ||
} | ||
draw() { | ||
this.ctx.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height); | ||
} | ||
size() { | ||
if (this.id) { | ||
if (GameEnv.hasFlag.includes(this.id)) { | ||
this.hide() | ||
} | ||
} | ||
const scaledHeight = GameEnv.innerHeight * (this.scaleSize / 832); | ||
const scaledWidth = scaledHeight * this.aspect_ratio; | ||
const coinX = this.coinX; | ||
const coinY = (GameEnv.bottom - scaledHeight) * this.coinY; | ||
|
||
// Set variables used in Display and Collision algorithms | ||
this.bottom = coinY; | ||
this.collisionHeight = scaledHeight; | ||
this.collisionWidth = scaledWidth; | ||
|
||
this.canvas.width = scaledWidth; | ||
this.canvas.height = scaledHeight; | ||
this.canvas.style.width = `${scaledWidth}px`; | ||
this.canvas.style.height = `${scaledHeight}px`; | ||
this.canvas.style.position = 'absolute'; | ||
this.canvas.style.left = `${coinX}px`; | ||
this.canvas.style.top = `${coinY}px`; | ||
} | ||
collisionAction() { | ||
// check player collision | ||
if (this.collisionData.touchPoints.other.id === "player") { | ||
if (this.id) { | ||
GameEnv.hasFlag.push(this.id) | ||
} | ||
this.destroy(); | ||
|
||
GameEnv.playSound("coin"); | ||
|
||
|
||
} | ||
} | ||
} | ||
export default Flag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.