Advertisement
Arnethegreat

YoshTimer Alpha

Sep 2nd, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.09 KB | None | 0 0
  1. gui.opacity(0.8)
  2. --
  3. ---
  4. function Set(list)
  5.   local set = {}
  6.   for _, l in ipairs(list) do set[l] = true end
  7.   return set
  8. end
  9.  
  10. function addToSet(set, key)
  11.     set[key] = true
  12. end
  13.  
  14. function removeFromSet(set, key)
  15.     set[key] = nil
  16. end
  17.  
  18. function setContains(set, key)
  19.     return set[key]
  20. end
  21. ---
  22. ---
  23. -- function lag_frame_display()
  24.     -- lag_minutes = math.floor(current_level_lag_time/3600)
  25.     -- lag_seconds = math.floor((current_level_lag_time - lag_minutes*3600)/60)
  26.     -- lag_frames = math.floor(current_level_lag_time - lag_seconds*60 - lag_minutes*3600)
  27.     -- lag_tenths_seconds = math.floor(lag_frames/0.6)
  28.     -- gui.register(gui.text(10,17, lag_minutes .. ":" .. lag_seconds .. "." .. lag_tenths_seconds .. " (" .. lag_frames .. ")"))
  29. -- end
  30. --
  31. --
  32.  
  33. first_stage_in_world_list = Set({0, 12, 24, 36, 48, 60})
  34. last_stage_in_world_list = Set({7, 19, 31, 43, 55, 67})
  35. final_level_time = 0
  36. instage = 0
  37. current_level_time = 0
  38. current_world_time = 0
  39. stage_string = "S: "
  40. world_string = "W: "
  41. current_level_lag_time = 0
  42.  
  43.  
  44. --
  45. --
  46. function read_memory()
  47.     game_mode = memory.readbyte(0x7E0118)
  48.     bowser_completed = memory.readbyte(0x7E026D)
  49.     entering_stage = memory.readbyte(0x7E111D)
  50.     titlescreen = memory.readbyte(0x7E011C)
  51.     starting_file = memory.readbyte(0x7E112E)
  52.     stage_value = memory.readbyte(0x7E021A)
  53.     boss_explosion = memory.readbyte(0x7E096C)
  54. end
  55.  
  56. in_world = false
  57. function check_world_start()
  58.     if titlescreen == 12 and entering_stage == 1 and in_world == false and first_stage_in_world_list[stage_value] == true then
  59.         start_world_frame = emu.framecount()
  60.         in_world = true
  61.         print("I started it all")
  62.     end
  63. end
  64.  
  65. function check_world_end()
  66.     if in_world == true and (boss_explosion == 55 or boss_explosion == 52) and last_stage_in_world_list[stage_value] == true then
  67.         stop_world_timer = true
  68.         in_world = false
  69.         print("I stopped time")
  70.     end
  71. end
  72.  
  73. -- function check_file_start()
  74.     -- if starting_file == 1 and titlescreen == 6 then
  75.         -- start_game_frame = emu.framecount()
  76.     -- end
  77. -- end
  78.  
  79. -- function check_game_completion()
  80.     -- if bowser_completed == 1 then
  81.         -- end_frame = emu.framecount()
  82.         -- final_run_time = end_frame - start_game_frame
  83.     -- end
  84. -- end
  85.  
  86. function convert_and_display_level_time(timertime, timertype, yoffset)
  87.     local minutes = math.floor(timertime/3600)
  88.     local seconds = math.floor((timertime - minutes*3600)/60)
  89.     local frames = math.floor(timertime - seconds*60 - minutes*3600)
  90.     local tenths_seconds = math.floor(frames/0.6)
  91.     return gui.text(5, yoffset, timertype .. minutes .. ":" .. seconds .. "." .. tenths_seconds .. " (" .. frames .. ")")
  92. end
  93.  
  94. function check_level_start()
  95.     if game_mode == 15 and instage == 0 and (boss_explosion ~= 55 and boss_explosion ~= 52) then
  96.         level_start_frame = emu.framecount()
  97.         level_start_lag_frame = emu.lagcount()
  98.         instage = 1
  99.         print("check_level_start()")
  100.     end
  101. end
  102.  
  103. function in_level_time_display()
  104.     if instage == 1 then
  105.         current_level_time = emu.framecount() - level_start_frame
  106.         if game_mode == 15 then
  107.             current_level_lag_time = emu.lagcount() - level_start_lag_frame
  108.         end
  109.     end
  110. end
  111.  
  112. function in_world_time_display()
  113.     if in_world == true then
  114.         current_world_time = emu.framecount() - start_world_frame
  115.     end
  116. end
  117.  
  118. function check_level_end()
  119.     if instage == 1 then
  120.         if game_mode == 16 or boss_explosion == 55 or boss_explosion == 52 then
  121.             level_end_frame = emu.framecount()
  122.             level_end_lag_frame = emu.lagcount()
  123.     --      final_level_time = level_start_frame - level_end_frame
  124.     --      store_stage_time(currentstage,final_level_time)
  125.     --      check_best_times_and_replace(currentstage, final_level_time)
  126.             instage = 0
  127.             print("check_level_end()")
  128.         elseif game_mode == 34 or game_mode == 61 or game_mode == 53 then
  129.             instage = 0
  130.         end
  131.     end
  132. end
  133.  
  134.  
  135. while true do
  136.     read_memory()
  137.     check_level_start()
  138.     check_world_start()
  139.     check_world_end()
  140.     check_level_end()
  141.     in_level_time_display()
  142.     in_world_time_display()
  143.     gui.register(convert_and_display_level_time(current_level_time, "S: ", 10))
  144.     gui.register(convert_and_display_level_time(current_world_time, "W: ", 18))
  145.     emu.frameadvance()
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement