@@ -103,8 +103,8 @@ pub const PlayerAction = enum(u8) {
103103 },
104104 };
105105 }
106- fn withoutCarry (self : * PlayerAction ) PlayerAction {
107- return switch (self .* ) {
106+ fn withoutCarry (self : PlayerAction ) PlayerAction {
107+ return switch (self ) {
108108 .Rest_Carry = > .Rest ,
109109 .Walk_Carry = > .Walk ,
110110 .Jump_Carry = > .Jump ,
@@ -120,10 +120,31 @@ pub const PlayerAction = enum(u8) {
120120 .Hit_Carry = > .Hit ,
121121 .HitBurn_Carry = > .HitBurn ,
122122 else = > {
123- return self .* ;
123+ return self ;
124124 },
125125 };
126126 }
127+
128+ pub fn str (self : PlayerAction ) []const u8 {
129+ const no_carry = self .withoutCarry ();
130+ return switch (no_carry ) {
131+ .Rest = > "Rest" ,
132+ .Walk = > "Walk" ,
133+ .Jump = > "Jump" ,
134+ .Crawl = > "Crawl" ,
135+ .Slide = > "Slide" ,
136+ .KneeStand = > "KneeStand" ,
137+ .Climb = > "Climb" ,
138+ .Grab = > "Grab" ,
139+ .Drop = > "Drop" ,
140+ .SilentRest = > "SRest" ,
141+ .SilentWalk = > "SWalk" ,
142+ .Headache = > "Headache" ,
143+ .Hit = > "Hit" ,
144+ .HitBurn = > "HitBurn" ,
145+ else = > "Unknown"
146+ };
147+ }
127148};
128149
129150pub fn move_player (arg_context : * render.ScreenContext , arg_level : * lvl.Level ) c_int {
@@ -187,12 +208,12 @@ pub fn move_player(arg_context: *render.ScreenContext, arg_level: *lvl.Level) c_
187208 globals .GRANDBRULE_FLAG = false ;
188209 if (globals .LADDER_FLAG ) {
189210 action = .Climb ;
190- } else if (! globals .PRIER_FLAG and player .jump_pressed and player .y_axis <= 0 and globals .SAUT_FLAG == 0 ) {
211+ } else if (! globals .low_ceiling and player .jump_pressed and player .y_axis <= 0 and globals .jump_timer == 0 ) {
191212 action = .Jump ;
192213 if (globals .LAST_ORDER == .KneeStand ) { // Test if last order was kneestanding
193214 globals .FURTIF_FLAG = 100 ; // If jump after kneestanding, init silent walk timer
194215 }
195- } else if (globals .PRIER_FLAG or (globals .SAUT_FLAG != 6 and player .y_axis > 0 )) {
216+ } else if (globals .low_ceiling or (globals .jump_timer != 6 and player .crouch_pressed )) {
196217 if (player .x_axis != 0 ) { // Move left or right
197218 action = .Crawl ; // Action: crawling
198219 } else {
@@ -204,7 +225,7 @@ pub fn move_player(arg_context: *render.ScreenContext, arg_level: *lvl.Level) c_
204225 action = .Rest ; // Action: rest (no action)
205226 }
206227 // Is space button pressed?
207- if (player .action_pressed and ! globals .PRIER_FLAG ) {
228+ if (player .action_pressed and ! globals .low_ceiling ) {
208229 if (! globals .DROP_FLAG ) {
209230 if (action == .Crawl or action == .KneeStand ) { // Kneestand
210231 globals .DROPREADY_FLAG = false ;
@@ -480,7 +501,7 @@ fn TAKE_BLK_AND_YTEST(level: *lvl.Level, tileY_in: i16, tileX_in: i16) void {
480501 var tileX = tileX_in ;
481502 const player = & level .* .player ;
482503 globals .POCKET_FLAG = false ;
483- globals .PRIER_FLAG = false ;
504+ globals .low_ceiling = false ;
484505 globals .LADDER_FLAG = false ;
485506 var change : i8 = undefined ;
486507 // if player is too high (<= -1), skip test
@@ -552,12 +573,12 @@ fn BLOCK_YYPRGD(level: *lvl.Level, cflag: lvl.CeilingType, tileY_in: i16, tileX_
552573 // Stop movement
553574 player .sprite .speed_y = 0 ;
554575 player .sprite .y = @as (i16 , @bitCast (@as (u16 , @bitCast (player .sprite .y )) & 0xFFF0 )) + 16 ;
555- globals .SAUT_COUNT = 0xFF ;
576+ globals .jump_acceleration_counter = 0xFF ;
556577 } else if (player .sprite .number != 10 and // 10 = Free fall
557578 player .sprite .number != 21 and // 21 = Free fall (c)
558- globals .SAUT_FLAG != 6 )
579+ globals .jump_timer != 6 )
559580 {
560- globals .PRIER_FLAG = true ;
581+ globals .low_ceiling = true ;
561582 if (globals .CARRY_FLAG ) {
562583 const maybe_object = player_drop_carried (level );
563584 if (maybe_object ) | object | {
@@ -582,7 +603,7 @@ fn BLOCK_YYPRGD(level: *lvl.Level, cflag: lvl.CeilingType, tileY_in: i16, tileX_
582603 //if (player.sprite.speed_y < 0 and player.sprite.speed_x == 0) {
583604 //if (player.sprite.speed_y <= 0 and player.y_axis < 0 and player.x_axis == 0) {
584605 if (player .sprite .speed_y <= 0 and player .y_axis < 0 ) {
585- globals .SAUT_COUNT = 10 ;
606+ globals .jump_acceleration_counter = 10 ;
586607 globals .LADDER_FLAG = true ;
587608 }
588609 },
@@ -625,7 +646,7 @@ fn player_block_x(level: *lvl.Level) void {
625646 // Horizontal hit (wall), stop the player
626647 player .sprite .x -= player .sprite .speed_x >> 4 ;
627648 player .sprite .speed_x = 0 ;
628- if (globals .KICK_FLAG != 0 and globals .SAUT_FLAG != 6 ) {
649+ if (globals .KICK_FLAG != 0 and globals .jump_timer != 6 ) {
629650 globals .CHOC_FLAG = 20 ;
630651 globals .KICK_FLAG = 0 ;
631652 }
@@ -666,7 +687,7 @@ pub fn player_drop_carried(level: *lvl.Level) ?*lvl.Object {
666687fn player_fall (level : * lvl.Level ) void {
667688 // No wall under the player; fall down!
668689 const player = & level .player ;
669- globals .SAUT_FLAG = 6 ;
690+ globals .jump_timer = 6 ;
670691 if (globals .KICK_FLAG != 0 ) {
671692 return ;
672693 }
@@ -747,30 +768,36 @@ fn BLOCK_YYPRG(level: *lvl.Level, floor: lvl.FloorType, floor_above: lvl.FloorTy
747768 return ;
748769 }
749770 const order = globals .LAST_ORDER .withoutCarry ();
771+ const is_in_air = globals .YFALL != 0 or globals .jump_acceleration_counter != 0 ;
750772 // Skip if walking/crawling
751- if (order == .Walk or order == .Crawl or order == .Grab or order == .Drop ) {
752- player_block_yu (player ); // Stop fall
753- return ;
754- }
755- // Crawl
756- if (order == .KneeStand ) { // action baisse
757- player_fall_F (); // Free fall
758- sprites .updatesprite (level , & player .sprite , 14 , true ); // sprite: start climbing down
759- player .sprite .y += 8 ;
760- }
761- if (floor_above != .Ladder ) { // ladder
762- if (order == .Rest ) { // action repos
773+ if (order == .Walk or order == .Crawl or order == .Grab or order == .Drop or order == .KneeStand or order == .Rest ) {
774+ if (player .y_axis <= 0 and ! is_in_air ) {
763775 player_block_yu (player ); // Stop fall
764776 return ;
765777 }
778+ else
779+ {
780+ player_fall_F (); // Free fall
781+ const flip = player .sprite .flipped ;
782+ sprites .updatesprite (level , & player .sprite , 14 , true ); // sprite: start climbing down
783+ player .sprite .flipped = flip ;
784+ player .sprite .y += 8 ;
785+ }
786+ }
787+ // we stand on top of a ladder
788+ if (floor_above != .Ladder ) { // ladder
789+ // if (order == .Rest) { // action repos
790+ // player_block_yu(player); // Stop fall
791+ // return;
792+ // }
766793 if (player .y_axis < 0 and order == .Climb ) { // action UP + climb ladder
767794 player_block_yu (player ); // Stop fall
768795 return ;
769796 }
770797 }
771798
772- common .subto0 (& globals .SAUT_FLAG );
773- globals .SAUT_COUNT = 0 ;
799+ common .subto0 (& globals .jump_timer );
800+ globals .jump_acceleration_counter = 0 ;
774801 globals .YFALL = 2 ;
775802
776803 globals .LADDER_FLAG = true ;
@@ -811,8 +838,8 @@ fn player_block_yu(player: *lvl.Player) void {
811838 }
812839 player .sprite .y = @bitCast (@as (u16 , @bitCast (player .sprite .y )) & 0xFFF0 );
813840 player .sprite .speed_y = 0 ;
814- common .subto0 (& globals .SAUT_FLAG );
815- globals .SAUT_COUNT = 0 ;
841+ common .subto0 (& globals .jump_timer );
842+ globals .jump_acceleration_counter = 0 ;
816843 globals .YFALL = 2 ;
817844}
818845
@@ -916,13 +943,13 @@ fn ACTION_PRG(level: *lvl.Level, action: PlayerAction) void {
916943 },
917944 .Jump , .Jump_Carry = > {
918945 // Handle a jump
919- if (globals .SAUT_COUNT == 0 ) {
946+ if (globals .jump_acceleration_counter == 0 ) {
920947 events .triggerEvent (.Event_PlayerJump );
921948 }
922- if (globals .SAUT_COUNT >= 3 ) {
923- globals .SAUT_FLAG = 6 ; // Stop jump animation and acceleration
949+ if (globals .jump_acceleration_counter >= 3 ) {
950+ globals .jump_timer = 6 ; // Stop jump animation and acceleration
924951 } else {
925- globals .SAUT_COUNT +%= 1 ;
952+ globals .jump_acceleration_counter +%= 1 ;
926953 YACCELERATION_NEG (player , globals .MAX_Y * 16 / 4 );
927954 XACCELERATION (player , globals .MAX_X * 16 );
928955 NEW_FORM (player , action );
@@ -964,6 +991,13 @@ fn ACTION_PRG(level: *lvl.Level, action: PlayerAction) void {
964991 sprites .updatesprite (level , & player .sprite , 23 , true ); // First climb sprite (c)
965992 }
966993 }
994+ const is_in_air = globals .YFALL != 0 or globals .jump_acceleration_counter != 0 ;
995+ // attach to ladder in air
996+ if (is_in_air and globals .LAST_ORDER != .Climb ) {
997+ NEW_FORM (player , if (globals .CARRY_FLAG ) .Climb_Carry else .Climb );
998+ GET_IMAGE (level );
999+ player .sprite .speed_y = 0 ;
1000+ }
9671001 if (player .y_axis != 0 ) {
9681002 NEW_FORM (player , if (globals .CARRY_FLAG ) .Climb_Carry else .Climb );
9691003 GET_IMAGE (level );
@@ -1342,8 +1376,8 @@ fn player_collide_with_elevators(level: *lvl.Level) void {
13421376 player .sprite .y = elevator .sprite .y ;
13431377
13441378 player .sprite .speed_y = 0 ;
1345- common .subto0 (& globals .SAUT_FLAG );
1346- globals .SAUT_COUNT = 0 ;
1379+ common .subto0 (& globals .jump_timer );
1380+ globals .jump_acceleration_counter = 0 ;
13471381 globals .YFALL = 2 ;
13481382
13491383 player .sprite .x += elevator .sprite .speed_x ;
@@ -1438,8 +1472,8 @@ fn player_collide_with_objects(level: *lvl.Level) void {
14381472 } else {
14391473 player .sprite .speed_y = 0 ;
14401474 }
1441- common .subto0 (& globals .SAUT_FLAG );
1442- globals .SAUT_COUNT = 0 ;
1475+ common .subto0 (& globals .jump_timer );
1476+ globals .jump_acceleration_counter = 0 ;
14431477 globals .YFALL = 2 ;
14441478 }
14451479}
0 commit comments