// // ****************** // Video Game Calls // ****************** // global_x = 0; initialize(); if (!player_is_dead) { inertia_tracker(); player_jumpcheck(); gravitycheck(); player_interaction(); enemy_interaction(); clear_registers(); } else if (player_is_dead == 2) { global_x = 0; player_is_dead = 0; initialize_game = 0; clear_screen(); initialize(); } // // ********************** // Begin Game Functions // ********************** // // Calls all functions to set up new game function initialize() { if (!initialize_game) { initialize_game = 1; initialize_level(1, 1); initialize_player(); initialize_enemys(); initialize_movie(); } } // Sets up movie parameters (Size, Scale, Quality, Keyboard Buffer) function initialize_movie() { last_keypress = 0; this._width = 512; this._height = 384; fscommand("allowscale", "false"); // fscommand("showmenu", "false"); _quality = "LOW"; } // Loads level, Sets up Map, Places First Tile, Initializes Variables function initialize_level(level, section) { friction = 20; ground = 159; speedup_threshold = 10; gravity = 6; scroll_background = 0; global_x = 0; this.attachMovie("level_"+level+"_"+section, "level_tile_1", 80); this.attachMovie("level_"+level+"_"+section+"_background", "background_tile", 70); current_level = level; current_section = section; level_tile_1.gotoAndStop(1); level_tile_1._x = 0; level_tile_1._y = 0; background_tile._x = 0; background_tile._y = 0; current_tile = 1; map_edgeflip = 1; } // Sets up Player, Sprite Checkers, and Variables function initialize_player() { player_animation_counter = 0; touching_right_side = 0; touching_left_side = 0; horizontal_flip = 0; speed_marker = 0; player_base_speed = 1; player_speed_multiplyer = 1; player_speed_counter = 0; player_animation_edgeflip_01 = 4; player_animation_edgeflip_02 = 7; falling_counter = 0; player_jumping = 0; jump_force = 0; jumping_counter = 0; this.attachMovie("player", "player", 100); player._x = 100; player._y = 149; player.gotoAndStop(1); this.attachMovie("clear_pixel", "foot", 101); foot._x = player._x+3; foot._y = 170; foot._width = 10; foot._y = foot._y-amount; foot._alpha = 0; this.attachMovie("clear_pixel", "head", 102); head._x = player._x+3; head._y = 151; head._width = 10; head._alpha = 0; this.attachMovie("clear_pixel", "left_side", 103); left_side._x = player._x; left_side._y = 155; left_side._height = 13; left_side._alpha = 0; this.attachMovie("clear_pixel", "right_side", 104); right_side._x = player._x+player._width; right_side._y = 155; right_side._height = 13; right_side._alpha = 0; } // Initialize Enemy Objects function initialize_enemys() { enemy_stack = new Array(); } // Tracks how much speed the player has accumulated function inertia_tracker() { if (player_speed_counter>friction) { player_speed_counter = player_speed_counter-1; } if (player_speed_counter>speedup_threshold) { player_speed_multiplyer = 2; } else { player_speed_multiplyer = 1; } } // Check to see if player is jumping and if so execute jump routine function player_jumpcheck() { if (player_jumping) { if (touching_head) { player_jumping = 0; } jumping_counter++; if (horizontal_flip) { player.gotoAndStop(13); } else { player.gotoAndStop(4); } if (jumping_counter>8) { moveplayer(3, 4); } else { moveplayer(gravity, 4); } if (jumping_counter>(7+jump_force)) { jumping_counter = 0; player_jumping = 0; } } } // Check to see if player is touching ground and if not make player fall function gravitycheck() { if (!touching_floor && !player_jumping) { if (player._y>200) { player_is_dead = 1; this.attachMovie("player_die", "player_die", 500); player_die._x = player._x; player_die._y = player._y; player.removeMovieClip(); } falling_counter++; if (horizontal_flip) { player.gotoAndStop(14); } else { player.gotoAndStop(5); } if (falling_counter<5) { moveplayer(3, 3); } else { moveplayer(gravity, 3); } } else { if (ground && !player_jumping) { moveplayer_y_exact(ground); } falling_counter = 0; } } // Keyboard routines and player interaction with world function player_interaction() { if (Key.isDown(Key.RIGHT) && !touching_right_side) { last_keypress = 2; player_animation_counter++; if (horizontal_flip) { horizontal_flip = 0; player_speed_counter = 0; } else if (last_keypress == 2) { player_speed_counter++; } if (player_animation_counterplayer_animation_edgeflip_02) { player_animation_counter = 0; } else if (touching_floor) { player.gotoAndStop(1); } moveplayer((player_base_speed*player_speed_multiplyer), 2); } else if (Key.isDown(Key.LEFT) && !touching_left_side) { last_keypress = 1; player_animation_counter++; if (!horizontal_flip) { horizontal_flip = 1; player_speed_counter = 0; } else if (last_keypress == 1) { player_speed_counter++; } if (player_animation_counterplayer_animation_edgeflip_02) { player_animation_counter = 0; } else if (touching_floor) { player.gotoAndStop(10); } moveplayer((player_base_speed*player_speed_multiplyer), 1); } else if (Key.isDown(Key.DOWN) && horizontal_flip) { player.gotoAndStop(12); if (player_speed_multiplyer>1) { player_speed_counter = player_speed_counter-1; if (player_speed_counter>13) { moveplayer((player_base_speed*player_speed_multiplyer), 1); } else { moveplayer(player_base_speed, 1); } if (player_speed_counter<1) { player_speed_multiplyer = 0; } } } else if (Key.isDown(Key.DOWN) && !horizontal_flip) { player.gotoAndStop(3); if (player_speed_multiplyer>1) { player_speed_counter = player_speed_counter-1; if (player_speed_counter>13) { moveplayer((player_base_speed*player_speed_multiplyer), 2); } else { moveplayer(player_base_speed, 2); } if (player_speed_counter<1) { player_speed_multiplyer = 0; } } } else if (horizontal_flip && player_speed_multiplyer<2 && touching_floor) { player.gotoAndStop(10); } else if (!horizontal_flip && player_speed_multiplyer<2 && touching_floor) { player.gotoAndStop(1); } else if (horizontal_flip && player_speed_multiplyer>1) { last_keypress = 0; player_speed_counter = player_speed_counter-1; if (player_speed_counter>13) { moveplayer((player_base_speed*player_speed_multiplyer), 1); } else { moveplayer(player_base_speed, 1); } if (player_speed_counter<1) { player_speed_multiplyer = 0; } } else if (!horizontal_flip && player_speed_multiplyer>1) { player_speed_counter = player_speed_counter-1; if (player_speed_counter>13) { moveplayer((player_base_speed*player_speed_multiplyer), 2); } else { moveplayer(player_base_speed, 2); } if (player_speed_counter<1) { player_speed_multiplyer = 0; } } if (Key.isDown(67) && !player_jumping && touching_floor) { player_jumping = 1; jump_force = 1; } else if (Key.isDown(67) && player_jumping) { jump_force++; if (jump_force>(gravity+3)) { jump_force = (gravity+3); } } } // set the players y position to exact (for setting foot into the ground) function moveplayer_y_exact(ground) { player._y = ground-player._height; foot._y = ground; head._y = player._y; left_side._y = (player._y+6); right_side._y = (player._y+6); } // move the player according to passed variables function moveplayer(amount, direction) { if (direction == 1 && !touching_left_side && player._x>10) { player._x = player._x-amount; foot._x = foot._x-amount; head._x = head._x-amount; left_side._x = left_side._x-amount; right_side._x = right_side._x-amount; } else if (direction == 2 && !touching_right_side) { if (player._x<120 || current_tile == total_tiles+1) { player._x = player._x+amount; foot._x = foot._x+amount; head._x = head._x+amount; left_side._x = left_side._x+amount; right_side._x = right_side._x+amount; } else { if (level_tile_1._x<2 && map_edgeflip == 1) { map_edgeflip = 2; current_tile++; this.attachMovie("level_"+current_level+"_"+current_section, "level_tile_2", 90); level_tile_2.gotoAndStop(current_tile); level_tile_2._x = level_tile_1._x+level_tile_1._width; level_tile_2._y = level_tile_1._y; } if (level_tile_2._x<2 && map_edgeflip == 2) { map_edgeflip = 1; current_tile++; this.attachMovie("level_"+current_level+"_"+current_section, "level_tile_1", 80); level_tile_1.gotoAndStop(current_tile); level_tile_1._x = level_tile_2._x+level_tile_2._width; level_tile_1._y = level_tile_2._y; } if (background_tile._x<2 && scroll_background) { this.attachMovie("level_"+current_level+"_"+current_section+"_background", "background_tile_b", 75); background_tile_b._x = background_tile._x+background_tile._width; background_tile_b._y = background_tile._y; } if (background_tile_b._x<2 && scroll_background) { background_tile._x = background_tile_b._x+background_tile_b._width; background_tile._y = background_tile_b._y; } global_x = amount; level_tile_1._x = level_tile_1._x-amount; level_tile_2._x = level_tile_2._x-amount; if (scroll_background) { background_tile._x = background_tile._x-.5; background_tile_b._x = background_tile_b._x-.5; } } } else if (direction == 3) { player._y = player._y+amount; foot._y = foot._y+amount; head._y = head._y+amount; left_side._y = left_side._y+amount; right_side._y = right_side._y+amount; } else if (direction == 4) { player._y = player._y-amount; foot._y = foot._y-amount; head._y = head._y-amount; left_side._y = left_side._y-amount; right_side._y = right_side._y-amount; } } // Move enemys and make them interact with world function enemy_interaction() { if (enemy_stack.length) { for (i=0; i200) { eval("this.enemy_"+(i+1)).gotoAndPlay(24); eval("this.enemy_"+(i+1)).dead = 1; eval("this.enemy_"+(i+1))._y = eval("this.enemy_"+(i+1))._y+3; enemy_stack[i] = 0; } if (!eval("this.enemy_"+(i+1)).touching_floor) { eval("this.enemy_"+(i+1))._y = eval("this.enemy_"+(i+1))._y+4; eval("this.enemy_"+(i+1)+"_left")._y = eval("this.enemy_"+(i+1)+"_left")._y+4; eval("this.enemy_"+(i+1)+"_right")._y = eval("this.enemy_"+(i+1)+"_right")._y+4; } eval("this.enemy_"+(i+1)).touching_floor = 0; for (z=0; z