Skip to content

Commit

Permalink
Walking and attacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 13, 2024
1 parent 9546b75 commit 07891da
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 39 deletions.
2 changes: 1 addition & 1 deletion images.g.jres
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"namespace": "mySongs."
},
"song2": {
"data": "0078000408050400001c00010a006400f40164000004000000000000000000000000000500000494000000040002192504000c000219250c001000021b2710002000031d20292000240002192524002c000219252c003000021b2730004000021d294000440002192544004c000219254c005000021b2750006000021d296000640002192564006c000219256c007000021b2770008000021d298000880002192588008c000218248c009400021b27940098000219259800a00002192503001c0001dc00690000045e01000400000000000000000000056400010400031c0018002000021d2938004000021d2958006000021d2978008000021d2906001c00010a006400f401640000040000000000000000000000000000000002ea0000000400011d04000800012408000c00011d0c001000012410001400011d14001800012418001c00011d1c002000012420002400012024002800012728002c0001202c003000012730003400012034003800012738003c0001203c004000012740004400011d44004800012448004c00011d4c005000012450005400011d54005800012458005c00011d5c006000012460006400012064006800012768006c0001206c007000012770007400012074007800012778007c0001207c008000012780008400011d84008800012488008c00011d8c009000012490009400011d94009800012498009c00011d09010e02026400000403780000040a000301000000640001c80000040100000000640001640000040100000000fa0004af00000401c80000040a00019600000414000501006400140005010000002c0104dc00000401fa0000040a0001c8000004140005d0076400140005d0070000c800029001f40105c201f4010a0005900114001400039001000005c201f4010500058403050032000584030000fa00049001000005c201f4010500058403c80032000584030500640005840300009001049001000005c201f4010500058403c80064000584030500c8000584030000f40105ac0d000404a00f00000a0004ac0d2003010004a00f0000280004ac0d9001010004a00f0000280002d00700040408070f0064000408070000c80003c800c8000e7d00c80019000e64000f0032000e78000000fa00032c01c8000ee100c80019000ec8000f0032000edc000000fa0003f401c8000ea901c80019000e90010f0032000ea4010000fa0001c8000004014b000000c800012c01000401c8000000c8000190010004012c010000c80002c800000404c8000f0064000496000000c80002c2010004045e010f006400042c010000640002c409000404c4096400960004f6090000f40102b80b000404b80b64002c0104f40b0000f401022003000004200300040a000420030000ea01029001000004900100040a000490010000900102d007000410d0076400960010d0070000c8007800000001000104080009000106100011000104180019000106200021000104280029000106300031000104380039000106400041000104480049000106500051000104580059000106600061000104680069000106700071000104780079000106800081000104880089000106900091000104980099000106",
"data": "0078000408050400001c00010a006400f40164000004000000000000000000000000000500000494000000040002192504000c000219250c001000021b2710002000031d20292000240002192524002c000219252c003000021b2730004000021d294000440002192544004c000219254c005000021b2750006000021d296000640002192564006c000219256c007000021b2770008000021d298000880002192588008c000218248c009400021b27940098000219259800a00002192503001c0001dc00690000045e01000400000000000000000000050000010000031c0018002000021d2938004000021d2958006000021d2978008000021d2906001c00010a006400f401640000040000000000000000000000000000000002ea0000000400011d04000800012408000c00011d0c001000012410001400011d14001800012418001c00011d1c002000012420002400012024002800012728002c0001202c003000012730003400012034003800012738003c0001203c004000012740004400011d44004800012448004c00011d4c005000012450005400011d54005800012458005c00011d5c006000012460006400012064006800012768006c0001206c007000012770007400012074007800012778007c0001207c008000012780008400011d84008800012488008c00011d8c009000012490009400011d94009800012498009c00011d09010e02026400000403780000040a000301000000640001c80000040100000000640001640000040100000000fa0004af00000401c80000040a00019600000414000501006400140005010000002c0104dc00000401fa0000040a0001c8000004140005d0076400140005d0070000c800029001f40105c201f4010a0005900114001400039001000005c201f4010500058403050032000584030000fa00049001000005c201f4010500058403c80032000584030500640005840300009001049001000005c201f4010500058403c80064000584030500c8000584030000f40105ac0d000404a00f00000a0004ac0d2003010004a00f0000280004ac0d9001010004a00f0000280002d00700040408070f0064000408070000c80003c800c8000e7d00c80019000e64000f0032000e78000000fa00032c01c8000ee100c80019000ec8000f0032000edc000000fa0003f401c8000ea901c80019000e90010f0032000ea4010000fa0001c8000004014b000000c800012c01000401c8000000c8000190010004012c010000c80002c800000404c8000f0064000496000000c80002c2010004045e010f006400042c010000640002c409000404c4096400960004f6090000f40102b80b000404b80b64002c0104f40b0000f401022003000004200300040a000420030000ea01029001000004900100040a000490010000900102d007000410d0076400960010d0070000c8007800000001000104080009000106100011000104180019000106200021000104280029000106300031000104380039000106400041000104480049000106500051000104580059000106600061000104680069000106700071000104780079000106800081000104880089000106900091000104980099000106",
"mimeType": "application/mkcd-song",
"displayName": "We Boat",
"namespace": "mySongs."
Expand Down
2 changes: 1 addition & 1 deletion images.g.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ d d b f f f e e d . . . . . . .
case "song1":
case "mySong":return hex`0078000408050206001c00010a006400f401640000040000000000000000000000000000000002d20000000400012a04000800012908000c00012a0c001000012c10001400012a14001800012918001c00012a1c002000012c20002800012a28002c0001272c003000012930003400012a34003800012738003c0001293c004000012540004400012a44004800012c48004c00012a4c005000012950005400012a54005800012c58005c00012a5c006000012960006400012a64006800012c68007000012a70007400012c74007800012a78007c0001277c008000012c80008400012a84008800012c88008c00012a8c00900001299000a000012707001c00020a006400f401640000040000000000000000000000000000000003f00000000400012204000800012208000c0001220c001000011b10001400011d14001800012218001c0001221c002000012220002400011b24002800011d28002c0001222c003000012230003400012234003800011b38003c00011d3c004000012240004400012244004800012248004c00011b4c005000011d50005400011954005800011958005c0001195c006000011d60006400011e64006800011968006c0001196c007000011970007400011d74007800011e78007c0001197c008000011980008400011984008800011d88008c00011e8c009000012490009400012494009800012498009c0001259c00a0000127`;
case "song2":
case "We Boat":return hex`0078000408050400001c00010a006400f40164000004000000000000000000000000000500000494000000040002192504000c000219250c001000021b2710002000031d20292000240002192524002c000219252c003000021b2730004000021d294000440002192544004c000219254c005000021b2750006000021d296000640002192564006c000219256c007000021b2770008000021d298000880002192588008c000218248c009400021b27940098000219259800a00002192503001c0001dc00690000045e01000400000000000000000000056400010400031c0018002000021d2938004000021d2958006000021d2978008000021d2906001c00010a006400f401640000040000000000000000000000000000000002ea0000000400011d04000800012408000c00011d0c001000012410001400011d14001800012418001c00011d1c002000012420002400012024002800012728002c0001202c003000012730003400012034003800012738003c0001203c004000012740004400011d44004800012448004c00011d4c005000012450005400011d54005800012458005c00011d5c006000012460006400012064006800012768006c0001206c007000012770007400012074007800012778007c0001207c008000012780008400011d84008800012488008c00011d8c009000012490009400011d94009800012498009c00011d09010e02026400000403780000040a000301000000640001c80000040100000000640001640000040100000000fa0004af00000401c80000040a00019600000414000501006400140005010000002c0104dc00000401fa0000040a0001c8000004140005d0076400140005d0070000c800029001f40105c201f4010a0005900114001400039001000005c201f4010500058403050032000584030000fa00049001000005c201f4010500058403c80032000584030500640005840300009001049001000005c201f4010500058403c80064000584030500c8000584030000f40105ac0d000404a00f00000a0004ac0d2003010004a00f0000280004ac0d9001010004a00f0000280002d00700040408070f0064000408070000c80003c800c8000e7d00c80019000e64000f0032000e78000000fa00032c01c8000ee100c80019000ec8000f0032000edc000000fa0003f401c8000ea901c80019000e90010f0032000ea4010000fa0001c8000004014b000000c800012c01000401c8000000c8000190010004012c010000c80002c800000404c8000f0064000496000000c80002c2010004045e010f006400042c010000640002c409000404c4096400960004f6090000f40102b80b000404b80b64002c0104f40b0000f401022003000004200300040a000420030000ea01029001000004900100040a000490010000900102d007000410d0076400960010d0070000c8007800000001000104080009000106100011000104180019000106200021000104280029000106300031000104380039000106400041000104480049000106500051000104580059000106600061000104680069000106700071000104780079000106800081000104880089000106900091000104980099000106`;
case "We Boat":return hex`0078000408050400001c00010a006400f40164000004000000000000000000000000000500000494000000040002192504000c000219250c001000021b2710002000031d20292000240002192524002c000219252c003000021b2730004000021d294000440002192544004c000219254c005000021b2750006000021d296000640002192564006c000219256c007000021b2770008000021d298000880002192588008c000218248c009400021b27940098000219259800a00002192503001c0001dc00690000045e01000400000000000000000000050000010000031c0018002000021d2938004000021d2958006000021d2978008000021d2906001c00010a006400f401640000040000000000000000000000000000000002ea0000000400011d04000800012408000c00011d0c001000012410001400011d14001800012418001c00011d1c002000012420002400012024002800012728002c0001202c003000012730003400012034003800012738003c0001203c004000012740004400011d44004800012448004c00011d4c005000012450005400011d54005800012458005c00011d5c006000012460006400012064006800012768006c0001206c007000012770007400012074007800012778007c0001207c008000012780008400011d84008800012488008c00011d8c009000012490009400011d94009800012498009c00011d09010e02026400000403780000040a000301000000640001c80000040100000000640001640000040100000000fa0004af00000401c80000040a00019600000414000501006400140005010000002c0104dc00000401fa0000040a0001c8000004140005d0076400140005d0070000c800029001f40105c201f4010a0005900114001400039001000005c201f4010500058403050032000584030000fa00049001000005c201f4010500058403c80032000584030500640005840300009001049001000005c201f4010500058403c80064000584030500c8000584030000f40105ac0d000404a00f00000a0004ac0d2003010004a00f0000280004ac0d9001010004a00f0000280002d00700040408070f0064000408070000c80003c800c8000e7d00c80019000e64000f0032000e78000000fa00032c01c8000ee100c80019000ec8000f0032000edc000000fa0003f401c8000ea901c80019000e90010f0032000ea4010000fa0001c8000004014b000000c800012c01000401c8000000c8000190010004012c010000c80002c800000404c8000f0064000496000000c80002c2010004045e010f006400042c010000640002c409000404c4096400960004f6090000f40102b80b000404b80b64002c0104f40b0000f401022003000004200300040a000420030000ea01029001000004900100040a000490010000900102d007000410d0076400960010d0070000c8007800000001000104080009000106100011000104180019000106200021000104280029000106300031000104380039000106400041000104480049000106500051000104580059000106600061000104680069000106700071000104780079000106800081000104880089000106900091000104980099000106`;
}
return null;
})
Expand Down
4 changes: 2 additions & 2 deletions island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Island {
function onPirateAttack({ pirate, direction }: { pirate: Pirate, direction: 'left' | 'right' }) {
const dirPix = direction === 'left' ? -1 : 1
// The hit zone is the pirate "sword" box: [center, right|left] and [top, bottom]
const hitXZone = [pirate.currentSprite.x, pirate.currentSprite.x + (13 * dirPix)]
const hitXZone = [pirate.sprite.x, pirate.sprite.x + (13 * dirPix)]
// The sword is only near the top of the sprite, we don't kill with feet
const hitYZone = [pirate.currentSprite.y - 4, pirate.currentSprite.y + 2]
const hitYZone = [pirate.sprite.y - 4, pirate.sprite.y + 2]

// manually check each enemy to see if they overlap, also check for parry
currentEnemies.forEach((enemy) => {
Expand Down
91 changes: 78 additions & 13 deletions militia.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
class Militia {
static walkRightAnimation: Image[] = Utils.swapAnimationColors(assets.animation`Militia Walk`, 14, 6)
static walkLeftAnimation: Image[] = Utils.flipAnimation(Utils.swapAnimationColors(assets.animation`Militia Walk`, 14, 6))
static walkRightAnimation: Image[] = assets.animation`Militia Walk`
static walkLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Militia Walk`)
static attackRightAnimation: Image[] = assets.animation`Militia Shoot`
static attackLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Militia Shoot`)
static speed: number = 10
static directionChangeInterval: number = 1000
static attackDelayMin: number = 2000
static attackDelayMax: number = 2500
static attackDelayMin: number = 4000
static attackDelayMax: number = 6000

sprite: Sprite
currentTarget?: Pirate
facing: 'left' | 'right' = 'right'
_nextAttackTime: number = 400
_lastAttackTick: number = 0
_lastDirectionTick: number = 0
Expand All @@ -18,14 +21,9 @@ class Militia {
this.sprite = sprites.create(assets.animation`Militia Walk`[0])
this.place(x, y)

animation.runImageAnimation(
this.sprite,
Militia.walkRightAnimation,
300,
true
)

this.currentTarget = target

this.walk()
}

public place(x: number, y: number) {
Expand All @@ -48,17 +46,84 @@ class Militia {
}

public render() {
// Should we attack randomly?
// Attack randomly
if ((control.millis() - this._lastAttackTick) > this._nextAttackTime) {
console.log("FIRE!")
this._lastAttackTick = control.millis()
this._nextAttackTime = Math.randomRange(Militia.attackDelayMin, Militia.attackDelayMax)
this.attack()
}
// Check your distance from the target randomly
if ((control.millis() - this._lastDirectionTick) > Militia.directionChangeInterval) {
this._lastDirectionTick = control.millis()
console.log('Checking target')
}

// Face your target
if (this.currentTarget.sprite.x < this.sprite.x && this.facing === 'right') {
// Turn around
this.walk('left')
} else if (this.currentTarget.sprite.x > this.sprite.x && this.facing === 'left') {
// Turn around
this.walk('right')
}
this.sprite.z = this.sprite.y
// const timeDiff = this._lastAttackTick - control.millis()
// const tick = control.millis()
}

walk(direction?: 'left' | 'right') {
this.facing = direction ? direction : this.facing

if (this.facing === 'left') {
animation.runImageAnimation(
this.sprite,
Militia.walkLeftAnimation,
500,
true
)
} else {
animation.runImageAnimation(
this.sprite,
Militia.walkRightAnimation,
500,
true
)
}
}

attack() {
// Stop moving
this.sprite.follow(this.currentTarget.sprite, 0)
// Play the fire animation
if (this.facing === 'right') {
animation.runImageAnimation(
this.sprite,
Militia.attackRightAnimation,
100,
false
)
} else {
animation.runImageAnimation(
this.sprite,
Militia.attackLeftAnimation,
100,
false
)
}

// Slightly after the animation we check to see if we hit
setTimeout(() => {
// Check to see that our target is in range and fire the hit
if (Math.abs(this.sprite.y - this.currentTarget.sprite.y) < 30) {
this.currentTarget.hit(this, 1)
}
}, Militia.attackRightAnimation.length / 2 * 100)

// Resume walking
setTimeout(() => {
this.walk()
this.sprite.follow(this.currentTarget.sprite, Militia.speed)
}, Militia.attackRightAnimation.length * 100)

}
}
Loading

0 comments on commit 07891da

Please sign in to comment.