-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fleshing sub grid actor movements
- Loading branch information
Showing
24 changed files
with
556 additions
and
245 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.77 KB
clients/player-client/public/game-assets/sprites/meeku-oni/idle-1x4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
2 changes: 1 addition & 1 deletion
2
clients/player-client/src/core/IsometricCanvas/draw/SpriteMap.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Duration } from 'luxon'; | ||
import { Actor } from '../Actor/Actor.dto'; | ||
import { SpriteMapActionId } from '../SpriteMap/SpriteMapType.type'; | ||
|
||
export abstract class Action { | ||
waitDuration: Duration; | ||
actDuration: Duration; | ||
recoveryDuration: Duration; | ||
|
||
public spriteMapId: SpriteMapActionId; | ||
public progress: number; | ||
public frames: number; | ||
|
||
constructor(params: { wait?: Duration; act: Duration; recovery?: Duration }) { | ||
this.waitDuration = params.wait ?? Duration.fromObject({ seconds: 0 }); | ||
this.actDuration = params.act ?? Duration.fromObject({ seconds: 0 }); | ||
this.recoveryDuration = | ||
params.recovery ?? Duration.fromObject({ seconds: 0 }); | ||
} | ||
|
||
isComplete(): boolean { | ||
return this.progress === 100; | ||
} | ||
|
||
frameDuration(): Duration { | ||
const duration = this.actDuration; | ||
const divisor = this.frames; | ||
const milliseconds = duration.as('milliseconds'); | ||
const dividedMilliseconds = milliseconds / divisor; | ||
return Duration.fromMillis(dividedMilliseconds); | ||
} | ||
|
||
abstract actionRun(actor: Actor, targets?: Actor[]): Promise<boolean>; | ||
} |
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,66 @@ | ||
import { Duration } from 'luxon'; | ||
import { ActorOrientation } from '../Actor/ActorOrientation.type'; | ||
import { Actor } from '../Actor/Actor.dto'; | ||
import { Action } from './Action'; | ||
import { pause } from './pause'; | ||
import { SpriteMapActionId } from '../SpriteMap/SpriteMapType.type'; | ||
|
||
export class WalkAction extends Action { | ||
direction: ActorOrientation; | ||
|
||
constructor(params: { | ||
wait: Duration; | ||
act: Duration; | ||
recovery: Duration; | ||
direction: ActorOrientation; | ||
frames: number; | ||
}) { | ||
super(params); | ||
this.direction = params.direction; | ||
this.frames = params.frames; | ||
|
||
this.progress = 0; | ||
this.spriteMapId = SpriteMapActionId.WALK; | ||
} | ||
|
||
async actionRun(actor: Actor): Promise<boolean> { | ||
const executeRun = async ( | ||
resolve: (value: boolean | PromiseLike<boolean>) => void, | ||
) => { | ||
this.progress = 0; | ||
let delta: { x?: number; y?: number } = {}; | ||
|
||
switch (this.direction) { | ||
case ActorOrientation.NORTHEAST: | ||
delta = { y: -0.1 }; | ||
break; | ||
case ActorOrientation.NORTHWEST: | ||
delta = { x: -0.1 }; | ||
break; | ||
case ActorOrientation.SOUTHEAST: | ||
delta = { x: 0.1 }; | ||
break; | ||
case ActorOrientation.SOUTHWEST: | ||
delta = { y: 0.1 }; | ||
break; | ||
} | ||
|
||
actor.spriteMapActionId = this.spriteMapId; | ||
actor.orientation = this.direction; | ||
|
||
for (let currentFrame = 0; currentFrame < this.frames; currentFrame++) { | ||
actor.position.move(delta); | ||
actor.spriteMapCurrentFrame = currentFrame; | ||
this.progress = ((currentFrame + 1) / this.frames) * 100; | ||
await pause(this.frameDuration()); | ||
} | ||
|
||
actor.spriteMapCurrentFrame = 0; | ||
actor.spriteMapActionId = SpriteMapActionId.IDLE; | ||
|
||
resolve(true); | ||
}; | ||
|
||
return new Promise(executeRun); | ||
} | ||
} |
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,7 @@ | ||
import { Duration } from 'luxon'; | ||
|
||
export function pause(duration: Duration): Promise<void> { | ||
return new Promise(resolve => | ||
setTimeout(resolve, duration.as('milliseconds')), | ||
); | ||
} |
Oops, something went wrong.