Skip to content

Commit

Permalink
Improved score display
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 14, 2024
1 parent cd140e9 commit 68aa923
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 45 deletions.
20 changes: 15 additions & 5 deletions images.g.jres
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
"mimeType": "image/x-mkcd-f4",
"displayName": "Pirate"
},
"image5": {
"data": "hwQMAAwAAAAAUAAAAAAAAABVBVAABQAAUFRVVVUEAABQVVVFVQUAAABVd1VVAAAAADXn7lUAAABQVVdVVQAAAFBFVVVVBQAAAFBVVEUFAAAAUFRVVQUAAAAAVQVQAAAAAAAAAAAAAAA=",
"mimeType": "image/x-mkcd-f4",
"displayName": "island"
},
"image6": {
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAABEVUUEAAAAAFREVAQAAAAAVERVBAAAAABERVUEAAAAAERERAQAAAAARFRFBAAAAABERVQEAAAAAERFVAQAAEBERFRFREQAAEREREREBAAAQEREREQAAAAAREREBAAAAAAARAQAAAAAAABAAAAAAA==",
"mimeType": "image/x-mkcd-f4",
Expand Down Expand Up @@ -49,6 +44,21 @@
"mimeType": "image/x-mkcd-f4",
"displayName": "Splash Screen"
},
"image5": {
"data": "hwQIAAgAAAAAUAAAAFUFAFBUVQVVVVUDVVV3U1A1515QVVdVAFBVAA==",
"mimeType": "image/x-mkcd-f4",
"displayName": "Island Icon"
},
"image3": {
"data": "hwQIAAgAAAAAAA4AAADuAAAA7g7g7u4O8A/uDvAP7g4AAO4OAADuDg==",
"mimeType": "image/x-mkcd-f4",
"displayName": "Boat Icon"
},
"image11": {
"data": "hwQIAAgAAAAAAAAA4ADu7u7d7e7u3e3u7t3u7uDd7u7gAO4OAAAAAA==",
"mimeType": "image/x-mkcd-f4",
"displayName": "Pocket Icon"
},
"anim14": {
"namespace": "myAnimations",
"id": "anim14",
Expand Down
48 changes: 33 additions & 15 deletions images.g.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ d d d e e e e d d d . . . . . .
d d a a a c c d d . . . . . . .
. a a a . . c c . . . . . . . .
. f f f f . f f f . . . . . . .
`;
case "image5":
case "island":return img`
. . . . . . . . . . . .
. . 5 5 . . 5 5 . . . .
. 5 4 5 5 5 5 5 . . . .
5 5 5 5 5 3 5 4 5 5 . .
. 5 5 5 7 7 7 5 5 4 5 .
. . 5 5 7 e 5 5 5 5 5 .
. . 5 5 5 e 5 5 4 5 5 .
. 5 5 4 5 e 5 5 5 5 . .
. . 5 5 5 5 5 5 5 5 . .
. . 5 5 5 5 5 5 4 5 5 .
. 5 4 5 . . . 5 5 5 . .
. . . . . . . . . . . .
`;
case "image6":
case "Arrow":return img`
Expand Down Expand Up @@ -319,6 +304,39 @@ f d d a a a a a a c e e f . . .
6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
`;
case "image5":
case "Island Icon":return img`
. . . 5 5 . . .
. . 5 5 5 5 5 .
. 5 4 5 5 5 5 .
5 5 5 5 5 3 5 5
. 5 5 5 7 7 7 5
. . 5 5 7 e 5 5
. . 5 3 3 e 5 .
. . . . 5 5 5 .
`;
case "image3":
case "Boat Icon":return img`
. . . . . . . .
. . . e f f . .
. . . e f f . .
. . . e . . . .
e e e e e e e e
. e e e e e e e
. . e e e e e e
. . . . . . . .
`;
case "image11":
case "Pocket Icon":return img`
. . e e e . . .
. e e e e e e .
. . d d d d . .
. . d d d d . .
. e d d e e e .
. e e e e e e .
. e e e e e e .
. e e e e e . .
`;
}
return null;
Expand Down
2 changes: 2 additions & 0 deletions island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace Island {

// manually check each enemy to see if they overlap, also check for parry
currentEnemies.forEach((enemy) => {
// Do nothing on dead enemies
if (enemy.health <= 0) return
if (direction === 'right'
&& enemy.sprite.x >= hitXZone[0] && enemy.sprite.x <= hitXZone[1]
// Bottom of pirate is overlapping the top of the enemy (and opposite)
Expand Down
11 changes: 11 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const playerState = {
currentIsland: ''
}

const debugMode: boolean = false

let currentState: States
let currentIsland: Map.Island
let treasureSprite: Sprite
Expand Down Expand Up @@ -71,6 +73,15 @@ game.onUpdate(() => {
}
})

if (debugMode) {
game.onUpdateInterval(5000, () => {
console.log('Delta ' + control.eventContext().deltaTimeMillis)
// GC Stats only works on hardware
// console.log('Mem: ' + control.gcStats())
control.heapSnapshot()
})
}

function switchState(state: States) {
currentState = state
switch (currentState) {
Expand Down
12 changes: 6 additions & 6 deletions map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Map {
image: Image,
sprite?: Sprite,
// The number of screens in the level
// Time limits = random scenes :)
// Development time limits = random scenes :)
segments: number
}

Expand All @@ -22,7 +22,7 @@ namespace Map {
let _onSelectIsland: (island: Island) => void
let _islands: Array<Island>
// Prevents smashing and accidentally going to the same island
let _selectIslandDelay: number = 1500
let _selectIslandDelay: number = 600
let _leftIslandTick: number = 0

function selectIsland() {
Expand Down Expand Up @@ -91,10 +91,10 @@ namespace Map {

// Rendering the islands
islands.forEach(island => {
const sprite = sprites.create(island.image)
sprite.x = island.x
sprite.y = island.y
island.sprite = sprite
// const sprite = sprites.create(island.image)
// sprite.x = island.x
// sprite.y = island.y
// island.sprite = sprite
})

// Keyboard inputs
Expand Down
12 changes: 9 additions & 3 deletions militia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ class Militia {
this.attack()
}
// Check your distance from the target randomly (TODO)
// if ((control.millis() - this._lastDirectionTick) > Militia.directionChangeInterval) {
// this._lastDirectionTick = control.millis()
// }
if ((control.millis() - this._lastDirectionTick) > Militia.directionChangeInterval) {
this._lastDirectionTick = control.millis()
if (Math.abs(Utils.getDistance(
{ x: this.sprite.x, y: this.sprite.y },
{ x: this.currentTarget.sprite.x, y: this.currentTarget.sprite.y }
)) < 30) {
console.log('SSTop walking!')
}
}

// Face your target
if (this.currentTarget.sprite.x < this.sprite.x && this.facing === 'right' && !this._isAttacking) {
Expand Down
6 changes: 1 addition & 5 deletions pirate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ class Pirate {
characterAnimations.setCharacterState(this.sprite, 1024)

if (this.health > 0) {
// characterAnimations.clearCharacterState(this.sprite)

animation.runImageAnimation(
this.sprite,
this.facing === 'right' ? this.hurtRightAnimation : this.hurtLeftAnimation,
Expand All @@ -153,7 +151,6 @@ class Pirate {
}, this.hurtLeftAnimation.length * 200)
} else {
// You dead!
// We simply say he's always getting hurt when he's dead
animation.runImageAnimation(
this.sprite,
this.facing === 'right' ? this.deathRightAnimation : this.deathLeftAnimation,
Expand All @@ -164,9 +161,8 @@ class Pirate {
this.die()

setTimeout(() => {
// Not really needed since you are dead but just to be tidy
this.isGettingHurt = false
// Re-enable the character animations
characterAnimations.clearCharacterState(this.sprite)
}, this.deathLeftAnimation.length * 100)
}

Expand Down
53 changes: 42 additions & 11 deletions treasureStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ namespace TreasureStats {
pulledFromIsland?: Map.Island['id']
}

let treasureSprite: Sprite
const boatIcon: Image = assets.image`Boat Icon`
const islandIcon: Image = assets.image`Island Icon`
const pocketIcon: Image = assets.image`Pocket Icon`

let treasureSprites: Sprite[] = []
let iconSprites: Sprite[] = []
let currentDisplayCombo: Array<'island' | 'boat' | 'pocket'> = ['island']

const currentTreasure: TreasureStat = {
Expand Down Expand Up @@ -40,19 +45,45 @@ namespace TreasureStats {
export function show(combination?: Array<'island' | 'boat' | 'pocket'>) {
currentDisplayCombo = combination ? combination : currentDisplayCombo

if (treasureSprite) {
treasureSprite.destroy()
}
let currentY = 8

treasureSprite = textsprite.create(currentTreasure.onBoat + '', 1, 15)
treasureSprite.x = 80
treasureSprite.y = 8
treasureSprite.z = 100
treasureSprites.forEach(t => t.destroy())
iconSprites.forEach(icon => icon.destroy())

currentDisplayCombo.forEach((statType) => {
let text: number
let iconSprite: Sprite
switch(statType) {
case 'boat':
text = currentTreasure.onBoat
iconSprite = sprites.create(boatIcon)
break;
case 'island':
text = currentTreasure.onIsland
iconSprite = sprites.create(islandIcon)
break;
default:
text = currentTreasure.inPocket
iconSprite = sprites.create(pocketIcon)
break;
}

const scoreSprite = textsprite.create(text + '', 1, 15)
scoreSprite.x = 80
scoreSprite.y = currentY
scoreSprite.z = 100
treasureSprites.push(scoreSprite)

iconSprite.x = 80 - (scoreSprite.width / 2 + 3)
iconSprite.x = 70
iconSprite.y = currentY
iconSprites.push(iconSprite)
currentY += 9
})
}

export function hide() {
if (treasureSprite) {
treasureSprite.destroy()
}
treasureSprites.forEach(t => t.destroy())
iconSprites.forEach(i => i.destroy())
}
}
7 changes: 7 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ namespace Utils {
})
}

export function getDistance(pointA: { x: number, y: number }, pointB: { x: number, y: number }) {
const dx = pointB.x - pointA.x;
const dy = pointB.y - pointA.y;

return Math.sqrt(dx * dx + dy * dy);
}

export function swapAnimationColors(anim: Image[], fromColor: number, toColor: number) {
anim.map(frame => frame.replace(fromColor, toColor))
return anim
Expand Down

0 comments on commit 68aa923

Please sign in to comment.