/*-------------------------------------------------------------------- * METHODS * --------------------------------------------------------------------*/ /*********************************************************** * * Method: * mario_type * * Description: * Constructor. * ***********************************************************/ public mario_type() { physics = new physics_type(); physics.hit_box.Width = 10; physics.hit_box.Height = 12; sprite_id = 0; status = mario_status_enum.STILL_R; ground_status = char_status_enum.GROUND; layer = (float)layer_enum.MARIO / (float)layer_enum.COUNT; } /* mario_type() */
/*********************************************************** * * Method: * animate_mario_pipe * * Description: * Updates mario during a pipe transition. * ***********************************************************/ private mario_status_enum animate_mario_pipe() { mario_status_enum status = model.level.mario.status; physics_type physics = model.level.mario.physics; model.level.mario.layer = (float)layer_enum.BEHIND_PIPE / (float)layer_enum.COUNT; switch (model.pipe_status) { case pipe_status_enum.ENTER: if (Animations.frame_count >= (init_frame + 48)) { init_frame = Animations.frame_count; model.pipe_status = pipe_status_enum.BLACK; pipe_entered.set_destination(model.level.mario); } if (pipe_entered.is_vertical) { physics.position.y += (1 << 12); if (model.level.mario.facing_right()) { status = mario_status_enum.STILL_R; } else { status = mario_status_enum.STILL_L; } } else { if (Animations.frame_count >= (init_frame + 16)) { model.level.mario.layer = (float)layer_enum.INVALID / (float)layer_enum.COUNT; } physics.position.x += MarioPhysics.vx_walk_no_ctrl_max; status = mario_status_enum.WALK_R; } break; case pipe_status_enum.BLACK: if (Animations.frame_count >= (init_frame + 24)) { if (pipe_entered.link_is_pipe()) { model.level.mario.physics.position.y += (32 << 12); init_frame = Animations.frame_count; model.pipe_status = pipe_status_enum.EXIT; } else { model.level.mario.ground_status = char_status_enum.AIR; model.level.mario.layer = (float)layer_enum.MARIO / (float)layer_enum.COUNT; model.game_status = game_status_enum.gameplay; } } break; case pipe_status_enum.EXIT: if (Animations.frame_count >= (init_frame + 92)) { model.game_status = game_status_enum.gameplay; model.level.mario.layer = (float)layer_enum.MARIO / (float)layer_enum.COUNT; } if (Animations.frame_count >= (init_frame + 60)) { model.level.mario.physics.position.y -= (1 << 12); } status = mario_status_enum.STILL_R; break; } return(status); }
} /* update_mario() */ /*********************************************************** * * Method: * update_mario_level_complete * * Description: * Updates mario after level is complete. * ***********************************************************/ private mario_status_enum update_mario_level_complete() { mario_status_enum status = model.level.mario.status; physics_type physics = model.level.mario.physics; //set status to falling when we hit the pole, then make a check if falling here switch (status) { case mario_status_enum.FALL_L: status = mario_status_enum.FALL_R; break; case mario_status_enum.JUMP_L: status = mario_status_enum.JUMP_R; break; case mario_status_enum.FALL_R: case mario_status_enum.JUMP_R: /*---------------------------------------------------------- * Let mario fall till the top of the pole, then start descent * ----------------------------------------------------------*/ if (((physics.position.y + physics.hit_box.Height - (8 << 12)) >> 16) >= ((model.level.map.flag_loc.Top) >> 4)) { status = mario_status_enum.POLE_R; } else { update_mario_falling(physics); physics.position.y += physics.velocity.y; physics.position.x = (model.level.map.flag_loc.X - physics.hit_box.Width + 6) << 12; } break; case mario_status_enum.POLE_R: case mario_status_enum.POLE_BOTTOM_R: Boolean mario_bottom = (physics.position.y >> 12) + physics.hit_box.Height >= model.level.map.flag_loc.Bottom; Boolean flag_bottom = (model.level.map.flag.y + model.level.map.flag.height + 4) >= model.level.map.flag_loc.Bottom; /*---------------------------------------------------------- * Slide down pole * ----------------------------------------------------------*/ physics.position.x = (model.level.map.flag_loc.X - physics.hit_box.Width + 6) << 12; if (!mario_bottom) { physics.position.y += MarioPhysics.vy_desc_vine; } else { status = mario_status_enum.POLE_BOTTOM_R; } if (!flag_bottom) { model.level.map.flag.y += (MarioPhysics.vy_desc_vine >> 12); } /*---------------------------------------------------------- * Switch pole sides once mario hits the bottom * ----------------------------------------------------------*/ if (mario_bottom && flag_bottom) { physics.position.y = (model.level.map.flag_loc.Bottom - physics.hit_box.Height) << 12; physics.position.x += ((2 + physics.hit_box.Width) << 12); status = mario_status_enum.POLE_L; init_frame_pole_l = Animations.frame_count; } break; case mario_status_enum.POLE_L: if (Animations.frame_count >= (init_frame_pole_l + 30)) { status = mario_status_enum.WALK_CTRL_L; init_frame_pole_l = Animations.frame_count; } break; case mario_status_enum.WALK_CTRL_L: if (Animations.frame_count >= (init_frame_pole_l + 8)) { status = mario_status_enum.WALK_CTRL_R; } else if (Animations.frame_count >= (init_frame_pole_l + 4)) { physics.position.x += (2 << 12); physics.position.y += ((Animations.frame_count - init_frame_pole_l - 4) << 12); } else { physics.position.x += (2 << 12); } break; case mario_status_enum.WALK_CTRL_R: physics.position.y = (model.level.map.flag_loc.Bottom - physics.hit_box.Height + 17) << 12; physics.position.x += MarioPhysics.vx_walk_no_ctrl_max; ViewDims.move_view_location(MarioPhysics.vx_walk_no_ctrl_max); if (physics.position.x >= model.level.map.exit_loc_x) { status = mario_status_enum.STILL_R; model.game_status = game_status_enum.level_score; } break; default: status = mario_status_enum.POLE_R; break; } return(status); }
} /* update() */ /*********************************************************** * * Method: * update_mario * * Description: * Updates mario during game play. * ***********************************************************/ private mario_status_enum update_mario() { physics_type physics = model.level.mario.physics; char_status_enum location = model.level.mario.ground_status; mario_status_enum status = model.level.mario.status; /*---------------------------------------------------------- * Update mario Y location on jump * ----------------------------------------------------------*/ if (location == char_status_enum.GROUND && KeyBinding.A_BTN_pressed) { if (model.level.mario.facing_right()) { status = mario_status_enum.JUMP_R; } else { status = mario_status_enum.JUMP_L; } physics.init_velocity.x = physics.velocity.x; physics.init_velocity.y = physics.velocity.y; if (KeyBinding.B_BTN_pressed) { physics.init_velocity.x++; } v_idx = 0; if (physics.velocity.x >= MarioPhysics.vy_j_thresh1) { v_idx++; } if (physics.velocity.x >= MarioPhysics.vy_j_thresh2) { v_idx++; } physics.acceleration.y = MarioPhysics.ay_j_a[v_idx]; physics.velocity.y = MarioPhysics.vy_j_init[v_idx]; } /*---------------------------------------------------------- * Update mario Y location on fall * ----------------------------------------------------------*/ else if (prev_location == char_status_enum.GROUND && location == char_status_enum.AIR && physics.velocity.y == 0) { if (model.level.mario.facing_right()) { status = mario_status_enum.FALL_R; } else { status = mario_status_enum.FALL_L; } physics.init_velocity.x = physics.velocity.x; physics.init_velocity.y = physics.velocity.y; if (KeyBinding.B_BTN_pressed) { physics.init_velocity.x++; } v_idx = 0; if (physics.velocity.x >= MarioPhysics.vy_j_thresh1) { v_idx++; } if (physics.velocity.x >= MarioPhysics.vy_j_thresh2) { v_idx++; } physics.acceleration.y = MarioPhysics.ay_j_f[v_idx]; physics.velocity.y += physics.acceleration.y; } /*---------------------------------------------------------- * Update mario Y location in air * ----------------------------------------------------------*/ else if (location == char_status_enum.AIR) { update_mario_falling(physics); } /*---------------------------------------------------------- * Update mario Y location on ground * ----------------------------------------------------------*/ else { physics.acceleration.y = 0; physics.velocity.y = 0; /*---------------------------------------------------------- * Skidding left * ----------------------------------------------------------*/ if ((KeyBinding.D_RIGHT_pressed) && (physics.velocity.x < -1 * MarioPhysics.vx_skid_thresh) && (location == char_status_enum.GROUND)) { physics.acceleration.x = MarioPhysics.ax_skid; physics.velocity.x += physics.acceleration.x; status = mario_status_enum.SKID_R; } /*---------------------------------------------------------- * Skidding right * ----------------------------------------------------------*/ else if ((KeyBinding.D_LEFT_pressed) && (physics.velocity.x > MarioPhysics.vx_skid_thresh) && (location == char_status_enum.GROUND)) { physics.acceleration.x = -1 * MarioPhysics.ax_skid; physics.velocity.x += physics.acceleration.x; status = mario_status_enum.SKID_L; } /*---------------------------------------------------------- * Running right * ----------------------------------------------------------*/ else if (KeyBinding.D_RIGHT_pressed && KeyBinding.B_BTN_pressed && (location == char_status_enum.GROUND)) { if (physics.velocity.x < 0) { physics.velocity.x = 0; } if (physics.velocity.x <= MarioPhysics.vx_walk_max) { status = mario_status_enum.WALK_R; } else { status = mario_status_enum.RUN_R; } physics.acceleration.x = MarioPhysics.ax_run; physics.velocity.x += physics.acceleration.x; if (physics.velocity.x > MarioPhysics.vx_run_max) { physics.velocity.x = MarioPhysics.vx_run_max; } if (physics.velocity.x < MarioPhysics.vx_walk_min) { physics.velocity.x = MarioPhysics.vx_walk_min; } } /*---------------------------------------------------------- * Running left * ----------------------------------------------------------*/ else if (KeyBinding.D_LEFT_pressed && KeyBinding.B_BTN_pressed && (location == char_status_enum.GROUND)) { if (physics.velocity.x > 0) { physics.velocity.x = 0; } if (physics.velocity.x >= -1 * MarioPhysics.vx_walk_max) { status = mario_status_enum.WALK_L; } else { status = mario_status_enum.RUN_L; } physics.acceleration.x = -1 * MarioPhysics.ax_run; physics.velocity.x += physics.acceleration.x; if (physics.velocity.x < -1 * MarioPhysics.vx_run_max) { physics.velocity.x = -1 * MarioPhysics.vx_run_max; } if (physics.velocity.x > -1 * MarioPhysics.vx_walk_min) { physics.velocity.x = -1 * MarioPhysics.vx_walk_min; } } /*---------------------------------------------------------- * Walking right * ----------------------------------------------------------*/ else if (KeyBinding.D_RIGHT_pressed && !KeyBinding.B_BTN_pressed && (location == char_status_enum.GROUND)) { status = mario_status_enum.WALK_R; physics.acceleration.x = MarioPhysics.ax_walk; physics.velocity.x += physics.acceleration.x; if (physics.velocity.x > MarioPhysics.vx_walk_max) { physics.velocity.x = MarioPhysics.vx_walk_max; } if (physics.velocity.x < MarioPhysics.vx_walk_min) { physics.velocity.x = MarioPhysics.vx_walk_min; } } /*---------------------------------------------------------- * Walking left * ----------------------------------------------------------*/ else if (KeyBinding.D_LEFT_pressed && !KeyBinding.B_BTN_pressed && (location == char_status_enum.GROUND)) { status = mario_status_enum.WALK_L; physics.acceleration.x = -1 * MarioPhysics.ax_walk; physics.velocity.x += physics.acceleration.x; if (physics.velocity.x < -1 * MarioPhysics.vx_walk_max) { physics.velocity.x = -1 * MarioPhysics.vx_walk_max; } if (physics.velocity.x > -1 * MarioPhysics.vx_walk_min) { physics.velocity.x = -1 * MarioPhysics.vx_walk_min; } } /*---------------------------------------------------------- * Sliding right * ----------------------------------------------------------*/ else if ((physics.velocity.x > MarioPhysics.vx_walk_min) && (location == char_status_enum.GROUND)) { physics.acceleration.x = -1 * MarioPhysics.ax_release; physics.velocity.x += physics.acceleration.x; if (model.level.mario.facing_right()) { status = mario_status_enum.STILL_R; } else { status = mario_status_enum.STILL_L; } } /*---------------------------------------------------------- * Sliding left * ----------------------------------------------------------*/ else if ((physics.velocity.x < -1 * MarioPhysics.vx_walk_min) && (location == char_status_enum.GROUND)) { physics.acceleration.x = MarioPhysics.ax_release; physics.velocity.x += physics.acceleration.x; if (model.level.mario.facing_right()) { status = mario_status_enum.STILL_R; } else { status = mario_status_enum.STILL_L; } } /*---------------------------------------------------------- * Standing still * ----------------------------------------------------------*/ else if (location == char_status_enum.GROUND) { physics.acceleration.x = 0; physics.velocity.x = 0; if (model.level.mario.facing_right()) { status = mario_status_enum.STILL_R; } else { status = mario_status_enum.STILL_L; } } } /*---------------------------------------------------------- * Handle all collisions * ----------------------------------------------------------*/ int x_pixel = ((physics.position.x + physics.velocity.x) >> 12) + physics.hit_box.Width; if (((model.level.map.flag_loc.X + 6) <= x_pixel) && ((x_pixel >> 4) < model.level.map.tier_widths[0])) { model.game_status = game_status_enum.level_complete; } if (physics.position.y + physics.velocity.y < 0) { physics.position += physics.velocity; } else { update_hit_box(model.level.mario); } /*---------------------------------------------------------- * Check for entering a vertical pipe * ----------------------------------------------------------*/ if ((KeyBinding.D_DOWN_pressed) && (model.level.mario.ground_status == char_status_enum.GROUND)) { pipe_type p = on_pipe(); if (null != p) { int x = model.level.mario.physics.position.x >> 16; int y = ((model.level.mario.physics.position.y >> 12) + model.level.mario.physics.hit_box.Height) >> 4; if (p.is_linked(model.level.mario.physics.position.x, y << 16)) { model.game_status = game_status_enum.pipe_transition; pipe_entered = p; init_frame = Animations.frame_count; model.pipe_status = pipe_status_enum.ENTER; } } } /*---------------------------------------------------------- * Never scroll screen left * ----------------------------------------------------------*/ if (physics.position.x < ViewDims.view.X) { physics.position.x = ViewDims.view.X; physics.acceleration.x = 0; physics.velocity.x = 0; } return(status); } /* update_mario() */