@@ -46,6 +46,7 @@ import Logger from "../../log";
46
46
import { WormState , InnerWormState } from "./wormState" ;
47
47
import { filter , first } from "rxjs" ;
48
48
import { TweenEngine } from "../../motion/tween" ;
49
+ import { TiledSpriteAnimated } from "../../utils/tiledspriteanimated" ;
49
50
50
51
export enum EndTurnReason {
51
52
TimerElapsed = 0 ,
@@ -84,9 +85,6 @@ export interface WormRecordedState extends PlayableRecordedState {
84
85
weapon : IWeaponCode ;
85
86
}
86
87
87
- const ANIM_FRAME_RATE = 2 ;
88
- const TILES_PER_SHEET = 0 ;
89
-
90
88
/**
91
89
* Physical representation of a worm on the map. May be controlled.
92
90
*/
@@ -109,9 +107,6 @@ export class Worm extends PlayableEntity<WormRecordedState> {
109
107
private static idleAnim : Texture ;
110
108
private static impactDamageMultiplier = 0.75 ;
111
109
private static minImpactForDamage = 12 ;
112
- private tileCounter = 0 ;
113
- private timeSinceLastAnim = 0 ;
114
-
115
110
protected fireWeaponDuration = 0 ;
116
111
private currentWeapon : IWeaponDefinition = WeaponBazooka ;
117
112
protected state = new WormState ( InnerWormState . Inactive ) ;
@@ -191,28 +186,27 @@ export class Worm extends PlayableEntity<WormRecordedState> {
191
186
private readonly toaster ?: Toaster ,
192
187
private readonly recorder ?: StateRecorder ,
193
188
) {
194
- console . log (
195
- Worm . idleAnim
196
- )
197
- const sprite = new TilingSprite ( {
189
+ const sprite = new TiledSpriteAnimated ( {
198
190
texture : Worm . idleAnim ,
199
191
width : 96 ,
200
192
height : 144 ,
201
193
tileScale : { x : 1 , y : 1 } ,
202
- tilePosition : { x : 0 , y : 0 }
194
+ tilePosition : { x : 0 , y : 0 } ,
195
+ scale : { x : 0.33 , y : 0.33 } ,
196
+ anchor : { x : 0.5 , y : 0.5 } ,
197
+ columns : 10 ,
198
+ tileCount : 120 ,
199
+ fps : 60 ,
203
200
} ) ;
204
- sprite . scale . set ( 0.33 , 0.33 ) ;
205
- sprite . anchor . set ( 0.5 , 0.5 ) ;
206
201
const body = world . createRigidBodyCollider (
207
202
ColliderDesc . cuboid (
208
- ( sprite . width * 0.33 ) / ( PIXELS_PER_METER * 2 ) ,
209
- ( sprite . height * 0.33 ) / ( PIXELS_PER_METER * 2 ) ,
203
+ ( sprite . width * sprite . scale . x ) / ( PIXELS_PER_METER * 2 ) ,
204
+ ( sprite . height * sprite . scale . y ) / ( PIXELS_PER_METER * 2 ) ,
210
205
)
211
206
. setActiveEvents ( ActiveEvents . COLLISION_EVENTS )
212
207
. setCollisionGroups ( Worm . collisionBitmask )
213
208
. setSolverGroups ( Worm . collisionBitmask )
214
209
. setFriction ( 0.1 ) ,
215
- //.setMass(5),
216
210
RigidBodyDesc . dynamic ( )
217
211
. setTranslation ( position . worldX , position . worldY )
218
212
. lockRotations ( ) ,
@@ -439,7 +433,7 @@ export class Worm extends PlayableEntity<WormRecordedState> {
439
433
this . fireAngle = Math . PI * 2 - this . fireAngle ;
440
434
}
441
435
this . facingRight = ! this . facingRight ;
442
- this . sprite . scale . x = this . facingRight ? 0.33 : - 0.33 ;
436
+ this . sprite . scale . x = this . facingRight ? Math . abs ( this . sprite . scale . x ) : - Math . abs ( this . sprite . scale . x ) ;
443
437
}
444
438
445
439
this . state . transition (
@@ -651,22 +645,10 @@ export class Worm extends PlayableEntity<WormRecordedState> {
651
645
652
646
update ( dt : number , dMs : number ) : void {
653
647
super . update ( dt , dMs ) ;
654
- this . timeSinceLastAnim += dMs ;
655
- if ( this . timeSinceLastAnim > 30 ) {
656
- this . timeSinceLastAnim = 0 ;
657
- this . tileCounter += 1 ;
658
- const tile = ( this . sprite as TilingSprite ) ;
659
- if ( this . tileCounter % 10 === 0 ) {
660
- this . tileCounter = 0 ;
661
- tile . tilePosition . x += 0 ;
662
- tile . tilePosition . y += tile . height ;
663
- } else {
664
- tile . tilePosition . x += tile . width ;
665
- }
666
- }
667
648
if ( this . sprite . destroyed ) {
668
649
return ;
669
650
}
651
+ ( this . sprite as TiledSpriteAnimated ) . update ( dMs ) ;
670
652
this . wireframe . setDebugText (
671
653
`worm_state: ${ this . state . stateName } , velocity: ${ this . body . linvel ( ) . y } ${ this . impactVelocity } , aim: ${ this . fireAngle } ` ,
672
654
) ;
0 commit comments