venom12314

MustafaUtilities

Jan 2nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.01 KB | None | 0 0
  1. SCREEN_HEIGHT=486
  2.  
  3. class Game_Map
  4. alias in_range_old in_range?
  5. def in_range?(object)
  6. return true if $PokemonSystem.tilemap==2
  7. screne_x = display_x - 4*32*4
  8. screne_y = display_y - 4*32*4
  9. screne_width = display_x + Graphics.width*4 + 4*32*4
  10. screne_height = display_y + SCREEN_HEIGHT*4 + 4*32*4
  11. return false if object.real_x <= screne_x
  12. return false if object.real_x >= screne_width
  13. return false if object.real_y <= screne_y
  14. return false if object.real_y >= screne_height
  15. return true
  16. end
  17.  
  18. alias display_y_old display_y
  19. def display_y=(value)
  20. @display_y=value
  21. if pbGetMetadata(self.map_id,MetadataSnapEdges)
  22. max_y = (self.height - SCREEN_HEIGHT*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY
  23. @display_y = [0, [@display_y, max_y].min].max
  24. end
  25. $MapFactory.setMapsInRange if $MapFactory
  26. end
  27.  
  28. alias scroll_downright_old scroll_downright
  29. def scroll_downright(distance)
  30. @display_x = [@display_x + distance,
  31. (self.width - Graphics.width*1.0/Game_Map::TILEWIDTH) * Game_Map.realResX].min
  32. @display_y = [@display_y + distance,
  33. (self.height - SCREEN_HEIGHT*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY].min
  34. end
  35.  
  36. alias scroll_downleft_old scroll_downleft
  37. def scroll_downleft(distance)
  38. @display_x = [@display_x - distance, 0].max
  39. @display_y = [@display_y + distance,
  40. (self.height - SCREEN_HEIGHT*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY].min
  41. end
  42. end
  43.  
  44. class Interpreter
  45. alias autoscroll_old autoscroll
  46. def autoscroll(x,y,speed=SCROLL_SPEED_DEFAULT)
  47. if $game_map.scrolling?
  48. return false
  49. elsif not $game_map.valid?(x,y)
  50. print 'Map Autoscroll: given x,y is invalid'
  51. return command_skip
  52. elsif not (1..6).include?(speed)
  53. print 'Map Autoscroll: invalid speed (1-6 only)'
  54. return command_skip
  55. end
  56. center_x = (Graphics.width/2 - Game_Map::TILEWIDTH/2) * 4 # X coordinate in the center of the screen
  57. center_y = (SCREEN_HEIGHT/2 - Game_Map::TILEHEIGHT/2) * 4 # Y coordinate in the center of the screen
  58. max_x = ($game_map.width - Graphics.width*1.0/Game_Map::TILEWIDTH) * 4 * Game_Map::TILEWIDTH
  59. max_y = ($game_map.height - SCREEN_HEIGHT*1.0/Game_Map::TILEHEIGHT) * 4 * Game_Map::TILEHEIGHT
  60. count_x = ($game_map.display_x - [0,[x*Game_Map.realResX-center_x,max_x].min].max)/Game_Map.realResX
  61. count_y = ($game_map.display_y - [0,[y*Game_Map.realResY-center_y,max_y].min].max)/Game_Map.realResY
  62. if not @diag
  63. @diag = true
  64. dir = nil
  65. if count_x > 0
  66. if count_y > 0
  67. dir = 7
  68. elsif count_y < 0
  69. dir = 1
  70. end
  71. elsif count_x < 0
  72. if count_y > 0
  73. dir = 9
  74. elsif count_y < 0
  75. dir = 3
  76. end
  77. end
  78. count = [count_x.abs,count_y.abs].min
  79. else
  80. @diag = false
  81. dir = nil
  82. if count_x != 0 and count_y != 0
  83. return false
  84. elsif count_x > 0
  85. dir = 4
  86. elsif count_x < 0
  87. dir = 6
  88. elsif count_y > 0
  89. dir = 8
  90. elsif count_y < 0
  91. dir = 2
  92. end
  93. count = count_x != 0 ? count_x.abs : count_y.abs
  94. end
  95. $game_map.start_scroll(dir, count, speed) if dir != nil
  96. if @diag
  97. return false
  98. else
  99. return true
  100. end
  101. end
  102. end
  103.  
  104. class Game_Player < Game_Character
  105. alias center_old center
  106. def center(x, y)
  107. # X coordinate in the center of the screen
  108. center_x = (Graphics.width/2 - Game_Map::TILEWIDTH/2) * Game_Map::XSUBPIXEL
  109. # Y coordinate in the center of the screen
  110. center_y = (SCREEN_HEIGHT/2 - Game_Map::TILEHEIGHT/2) * Game_Map::YSUBPIXEL
  111. max_x = (self.map.width - Graphics.width*1.0/Game_Map::TILEWIDTH) * Game_Map.realResX
  112. max_y = (self.map.height - SCREEN_HEIGHT*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY
  113. dispx=x * Game_Map.realResX - center_x
  114. dispy=y * Game_Map.realResY - center_y
  115. self.map.display_x = dispx
  116. self.map.display_y = dispy
  117. end
  118. alias update_old update
  119. def update
  120. # Remember whether or not moving in local variables
  121. last_moving = moving?
  122. # If moving, event running, move route forcing, and message window
  123. # display are all not occurring
  124. dir=Input.dir4
  125. unless moving? or $game_system.map_interpreter.running? or
  126. @move_route_forcing or $game_temp.message_window_showing or
  127. $PokemonTemp.miniupdate
  128. # Move player in the direction the directional button is being pressed
  129. if dir==@lastdir && Graphics.frame_count-@lastdirframe>2
  130. case dir
  131. when 2
  132. move_down
  133. when 4
  134. move_left
  135. when 6
  136. move_right
  137. when 8
  138. move_up
  139. end
  140. elsif dir!=@lastdir
  141. case dir
  142. when 2
  143. turn_down
  144. when 4
  145. turn_left
  146. when 6
  147. turn_right
  148. when 8
  149. turn_up
  150. end
  151. end
  152. end
  153. $PokemonTemp.dependentEvents.updateDependentEvents
  154. if dir!=@lastdir
  155. @lastdirframe=Graphics.frame_count
  156. end
  157. @lastdir=dir
  158. # Remember coordinates in local variables
  159. last_real_x = @real_x
  160. last_real_y = @real_y
  161. super
  162. center_x = (Graphics.width/2 - Game_Map::TILEWIDTH/2) *
  163. Game_Map::XSUBPIXEL # Center screen x-coordinate * 4
  164. center_y = (SCREEN_HEIGHT/2 - Game_Map::TILEHEIGHT/2) *
  165. Game_Map::YSUBPIXEL # Center screen y-coordinate * 4
  166. # If character moves down and is positioned lower than the center
  167. # of the screen
  168. if @real_y > last_real_y and @real_y - $game_map.display_y > center_y
  169. # Scroll map down
  170. $game_map.scroll_down(@real_y - last_real_y)
  171. end
  172. # If character moves left and is positioned more left on-screen than
  173. # center
  174. if @real_x < last_real_x and @real_x - $game_map.display_x < center_x
  175. # Scroll map left
  176. $game_map.scroll_left(last_real_x - @real_x)
  177. end
  178. # If character moves right and is positioned more right on-screen than
  179. # center
  180. if @real_x > last_real_x and @real_x - $game_map.display_x > center_x
  181. # Scroll map right
  182. $game_map.scroll_right(@real_x - last_real_x)
  183. end
  184. # If character moves up and is positioned higher than the center
  185. # of the screen
  186. if @real_y < last_real_y and @real_y - $game_map.display_y < center_y
  187. # Scroll map up
  188. $game_map.scroll_up(last_real_y - @real_y)
  189. end
  190. # Count down the time between allowed bump sounds
  191. @bump_se-=1 if @bump_se && @bump_se>0
  192. # If not moving
  193. unless moving?
  194. # If player was moving last time
  195. if last_moving
  196. $PokemonTemp.dependentEvents.pbTurnDependentEvents
  197. result = pbCheckEventTriggerFromDistance([2])
  198. # Event determinant is via touch of same position event
  199. result |= check_event_trigger_here([1,2])
  200. # If event which started does not exist
  201. Kernel.pbOnStepTaken(result) # *Added function call
  202. end
  203. # If C button was pressed
  204. if Input.trigger?(Input::C) && !$PokemonTemp.miniupdate
  205. # Same position and front event determinant
  206. check_event_trigger_here([0])
  207. check_event_trigger_there([0,2]) # *Modified to prevent unnecessary triggers
  208. end
  209. end
  210. end
  211. end
  212.  
  213. class Spriteset_Map
  214. alias initialize_old initialize
  215. def initialize(map=nil)
  216. @map=map ? map : $game_map
  217. @viewport1 = Viewport.new(0, 0, Graphics.width,SCREEN_HEIGHT) # Panorama, map, events, player, fog
  218. @viewport1a = Viewport.new(0, 0, Graphics.width,SCREEN_HEIGHT) # Weather
  219. @viewport2 = Viewport.new(0, 0, Graphics.width,SCREEN_HEIGHT) # "Show Picture" event command pictures
  220. @viewport3 = Viewport.new(0, 0, Graphics.width,SCREEN_HEIGHT) # Flashing
  221. @viewport1a.z = 100
  222. @viewport2.z = 200
  223. @viewport3.z = 500
  224. # @viewport1.resizedZoomX=0.8
  225. @tilemap = TilemapLoader.new(@viewport1)
  226. @tilemap.tileset = pbGetTileset(@map.tileset_name)
  227. for i in 0...7
  228. autotile_name = @map.autotile_names[i]
  229. @tilemap.autotiles[i] = pbGetAutotile(autotile_name)
  230. end
  231. @tilemap.map_data = @map.data
  232. @tilemap.priorities = @map.priorities
  233. @panorama = AnimatedPlane.new(@viewport1)
  234. @panorama.z = -1000
  235. @fog = AnimatedPlane.new(@viewport1)
  236. @fog.z = 3000
  237. @reflectedSprites=[]
  238. @character_sprites = []
  239. for i in @map.events.keys.sort
  240. sprite = Sprite_Character.new(@viewport1, @map.events[i])
  241. @character_sprites.push(sprite)
  242. if [email protected][i].name[/noreflect/]
  243. @reflectedSprites.push(ReflectedSprite.new(sprite,@map.events[i],@viewport1))
  244. end
  245. end
  246. playersprite=Sprite_Character.new(@viewport1, $game_player)
  247. @playersprite=playersprite
  248. @reflectedSprites.push(ReflectedSprite.new(playersprite,$game_player,@viewport1))
  249. @character_sprites.push(playersprite)
  250. @weather = RPG::Weather.new(@viewport1a)
  251. @picture_sprites = []
  252. for i in 1..50
  253. @picture_sprites.push(Sprite_Picture.new(@viewport2,$game_screen.pictures[i]))
  254. end
  255. @timer_sprite = Sprite_Timer.new
  256. Kernel.pbOnSpritesetCreate(self,@viewport1)
  257. update
  258. end
  259. alias in_range_old in_range?
  260. def in_range?(object)
  261. return true if $PokemonSystem.tilemap==2
  262. screne_x = @map.display_x - 4*32*4
  263. screne_y = @map.display_y - 4*32*4
  264. screne_width = @map.display_x + Graphics.width*4 + 4*32*4
  265. screne_height = @map.display_y + SCREEN_HEIGHT*4 + 4*32*4
  266. return false if object.real_x <= screne_x
  267. return false if object.real_x >= screne_width
  268. return false if object.real_y <= screne_y
  269. return false if object.real_y >= screne_height
  270. return true
  271. end
  272. alias update_old update
  273. def update
  274. if @panorama_name != @map.panorama_name or
  275. @panorama_hue != @map.panorama_hue
  276. @panorama_name = @map.panorama_name
  277. @panorama_hue = @map.panorama_hue
  278. if @panorama.bitmap != nil
  279. @panorama.setPanorama(nil)
  280. end
  281. if @panorama_name != ""
  282. @panorama.setPanorama(@panorama_name, @panorama_hue)
  283. end
  284. Graphics.frame_reset
  285. end
  286. if @fog_name != @map.fog_name or @fog_hue != @map.fog_hue
  287. @fog_name = @map.fog_name
  288. @fog_hue = @map.fog_hue
  289. if @fog.bitmap != nil
  290. @fog.setFog(nil)
  291. end
  292. if @fog_name != ""
  293. @fog.setFog(@fog_name, @fog_hue)
  294. end
  295. Graphics.frame_reset
  296. end
  297. tmox = @map.display_x.to_i / 4
  298. tmoy = @map.display_y.to_i / 4
  299. @tilemap.ox=tmox
  300. @tilemap.oy=tmoy
  301. if $PokemonSystem.tilemap==0
  302. # Original Map View only, to prevent wrapping
  303. @viewport1.rect.x=[-tmox,0].max
  304. @viewport1.rect.y=[-tmoy,0].max
  305. @viewport1.rect.width=
  306. [@tilemap.map_data.xsize*Game_Map::TILEWIDTH-tmox,Graphics.width].min
  307. @viewport1.rect.height=
  308. [@tilemap.map_data.ysize*Game_Map::TILEHEIGHT-tmoy,SCREEN_HEIGHT].min
  309. @viewport1.ox=[-tmox,0].max
  310. @viewport1.oy=[-tmoy,0].max
  311. else
  312. @viewport1.rect.set(0,0,Graphics.width,SCREEN_HEIGHT)
  313. @viewport1.ox=0
  314. @viewport1.oy=0
  315. end
  316. @viewport1.ox += $game_screen.shake
  317. @tilemap.update
  318. @panorama.ox = @map.display_x / 8
  319. @panorama.oy = @map.display_y / 8
  320. @fog.zoom_x = @map.fog_zoom / 100.0
  321. @fog.zoom_y = @map.fog_zoom / 100.0
  322. @fog.opacity = @map.fog_opacity
  323. @fog.blend_type = @map.fog_blend_type
  324. @fog.ox = @map.display_x / 4 + @map.fog_ox
  325. @fog.oy = @map.display_y / 4 + @map.fog_oy
  326. @fog.tone = @map.fog_tone
  327. @panorama.update
  328. @fog.update
  329. for sprite in @character_sprites
  330. if sprite.character.is_a?(Game_Event)
  331. if sprite.character.trigger == 3 || sprite.character.trigger == 4 ||
  332. in_range?(sprite.character)
  333. sprite.update
  334. end
  335. else
  336. sprite.update
  337. end
  338. end
  339. for sprite in @reflectedSprites
  340. sprite.visible=true
  341. sprite.visible=(@map==$game_map) if sprite.event==$game_player
  342. sprite.update
  343. end
  344. # Avoids overlap effect of player sprites if player is near edge of
  345. # a connected map
  346. self.map==$game_map || $game_player.x<=0 || $game_player.y<=0 ||
  347. ($game_map && ($game_player.x>=$game_map.width ||
  348. $game_player.y>=$game_map.height)))
  349.  
  350. if self.map!=$game_map
  351. @weather.max-=2 if @weather.max>0
  352. @weather.max=0 if @weather.max<0
  353. @weather.type = 0 if @weather.max==0
  354. @weather.ox = 0 if @weather.max==0
  355. @weather.oy = 0 if @weather.max==0
  356. else
  357. @weather.type = $game_screen.weather_type
  358. @weather.max = $game_screen.weather_max
  359. @weather.ox = @map.display_x / 4
  360. @weather.oy = @map.display_y / 4
  361. end
  362. @weather.update
  363. for sprite in @picture_sprites
  364. sprite.update
  365. end
  366. @timer_sprite.update
  367. @viewport1.tone = $game_screen.tone
  368. @viewport1a.ox += $game_screen.shake
  369. @viewport3.color = $game_screen.flash_color
  370. @viewport1.update
  371. @viewport1a.update
  372. @viewport3.update
  373. end
  374. end
Advertisement
Add Comment
Please, Sign In to add comment