Advertisement
Guest User

Fukuyama's Caterpillar Walking

a guest
Dec 20th, 2010
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.67 KB | None | 0 0
  1. # Config.rb
  2. #==============================================================================
  3. # ■ Train_Actor::Config
  4. #------------------------------------------------------------------------------
  5. # Caterpillar movement of actor is carried out on map
  6. #==============================================================================
  7.  
  8. module Train_Actor
  9.  
  10. # ●Switch setup for transparent status
  11. # When true, switch control is used
  12. # TRANSPARENT_SWITCH = true
  13. TRANSPARENT_SWITCH = false
  14.  
  15. # ●Switch number for transparent status
  16. # When TRANSPARENT_SWITCH is true, transparency will be activated when the switch of this number is on
  17. TRANSPARENT_SWITCHES_INDEX = 20
  18.  
  19. # ●Maximum number of actors
  20. # There will be support for a large number of people in a party in the future...
  21. TRAIN_ACTOR_SIZE_MAX = 4
  22.  
  23. # Constants
  24. DOWN_LEFT = 1
  25. DOWN_RIGHT = 3
  26. UP_LEFT = 7
  27. UP_RIGHT = 9
  28. JUMP = 5
  29.  
  30. end
  31.  
  32. # rgss
  33.  
  34. # Spriteset_Map_Module.rb
  35. #==============================================================================
  36. # ■ Spriteset_Map_Module
  37. #------------------------------------------------------------------------------
  38. # Caterpillar movement of actor is carried out on map
  39. #==============================================================================
  40.  
  41. module Train_Actor
  42.  
  43. module Spriteset_Map_Module
  44. def setup_actor_character_sprites?
  45. return @setup_actor_character_sprites_flag != nil
  46. end
  47. def setup_actor_character_sprites(characters)
  48. if !setup_actor_character_sprites?
  49. for character in characters.reverse
  50. @character_sprites.unshift(
  51. Sprite_Character.new(@viewport1, character)
  52. )
  53. end
  54. @setup_actor_character_sprites_flag = true
  55. end
  56. end
  57. end
  58.  
  59. end
  60.  
  61. class Spriteset_Map
  62. include Train_Actor::Spriteset_Map_Module
  63. end
  64.  
  65. # Scene_Map_Module.rb
  66. #==============================================================================
  67. # ■ Scene_Map_Module
  68. #------------------------------------------------------------------------------
  69. # Caterpillar movement of actor is carried out on map
  70. #==============================================================================
  71.  
  72. module Train_Actor
  73.  
  74. module Scene_Map_Module
  75. def setup_actor_character_sprites(characters)
  76. @spriteset.setup_actor_character_sprites(characters)
  77. end
  78. end
  79.  
  80. end
  81.  
  82. class Scene_Map
  83. include Train_Actor::Scene_Map_Module
  84. end
  85.  
  86. # Game_Party_Module.rb
  87. #==============================================================================
  88. # ■ Game_Party_Module
  89. #------------------------------------------------------------------------------
  90. # Caterpillar movement of actor is carried out on map
  91. #==============================================================================
  92.  
  93. module Train_Actor
  94.  
  95. module Game_Party_Module
  96. attr_reader :characters
  97. def actors_dead?
  98. for actor in actors
  99. if actor.dead?
  100. return true
  101. end
  102. end
  103. return false
  104. end
  105. def update_party_order
  106. if not actors_dead?
  107. return actors
  108. end
  109. alive_actors = []
  110. dead_actors = []
  111. for actor in actors
  112. if actor.dead?
  113. dead_actors.push actor
  114. else
  115. alive_actors.push actor
  116. end
  117. end
  118. return alive_actors + dead_actors
  119. end
  120. def setup_actor_character_sprites
  121. if @characters.nil?
  122. @characters = []
  123. for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  124. @characters.push(Game_Party_Actor.new)
  125. end
  126. end
  127. setup_actors = update_party_order
  128. for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  129. @characters[i - 1].setup(setup_actors[i])
  130. end
  131. if $scene.class.method_defined?('setup_actor_character_sprites')
  132. $scene.setup_actor_character_sprites(@characters)
  133. end
  134. end
  135. def update_party_actors
  136. update_party_order
  137. setup_actor_character_sprites
  138. transparent = $game_player.transparent
  139. if transparent == false
  140. if TRANSPARENT_SWITCH
  141. transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX]
  142. end
  143. end
  144. for character in @characters
  145. character.transparent = transparent
  146. character.move_speed = $game_player.move_speed
  147. character.step_anime = $game_player.step_anime
  148. character.update
  149. end
  150. end
  151. def moveto_party_actors( x, y )
  152. setup_actor_character_sprites
  153. for character in @characters
  154. character.moveto( x, y )
  155. end
  156. if @move_list == nil
  157. @move_list = []
  158. end
  159. move_list_setup
  160. end
  161. def move_party_actors
  162. if @move_list == nil
  163. @move_list = []
  164. move_list_setup
  165. end
  166. @move_list.each_index do |i|
  167. if @characters[i] != nil
  168. case @move_list[i].type
  169. when Input::DOWN
  170. @characters[i].move_down(@move_list[i].args[0])
  171. when Input::LEFT
  172. @characters[i].move_left(@move_list[i].args[0])
  173. when Input::RIGHT
  174. @characters[i].move_right(@move_list[i].args[0])
  175. when Input::UP
  176. @characters[i].move_up(@move_list[i].args[0])
  177. when DOWN_LEFT
  178. @characters[i].move_lower_left
  179. when DOWN_RIGHT
  180. @characters[i].move_lower_right
  181. when UP_LEFT
  182. @characters[i].move_upper_left
  183. when UP_RIGHT
  184. @characters[i].move_upper_right
  185. when JUMP
  186. @characters[i].jump(@move_list[i].args[0],@move_list[i].args[1])
  187. end
  188. end
  189. end
  190. end
  191. class Move_List_Element
  192. def initialize(type,args)
  193. @type = type
  194. @args = args
  195. end
  196. def type() return @type end
  197. def args() return @args end
  198. end
  199. def move_list_setup
  200. for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  201. @move_list[i] = nil
  202. end
  203. end
  204. def add_move_list(type,*args)
  205. @move_list.unshift(Move_List_Element.new(type,args)).pop
  206. end
  207. def move_down_party_actors(turn_enabled = true)
  208. move_party_actors
  209. add_move_list(Input::DOWN,turn_enabled)
  210. end
  211. def move_left_party_actors(turn_enabled = true)
  212. move_party_actors
  213. add_move_list(Input::LEFT,turn_enabled)
  214. end
  215. def move_right_party_actors(turn_enabled = true)
  216. move_party_actors
  217. add_move_list(Input::RIGHT,turn_enabled)
  218. end
  219. def move_up_party_actors(turn_enabled = true)
  220. move_party_actors
  221. add_move_list(Input::UP,turn_enabled)
  222. end
  223. def move_lower_left_party_actors
  224. move_party_actors
  225. add_move_list(DOWN_LEFT)
  226. end
  227. def move_lower_right_party_actors
  228. move_party_actors
  229. add_move_list(DOWN_RIGHT)
  230. end
  231. def move_upper_left_party_actors
  232. move_party_actors
  233. add_move_list(UP_LEFT)
  234. end
  235. def move_upper_right_party_actors
  236. move_party_actors
  237. add_move_list(UP_RIGHT)
  238. end
  239. def jump_party_actors(x_plus, y_plus)
  240. move_party_actors
  241. add_move_list(JUMP,x_plus, y_plus)
  242. end
  243. end
  244.  
  245. end
  246.  
  247. class Game_Party
  248. include Train_Actor::Game_Party_Module
  249. end
  250.  
  251. # Game_Player_Module.rb
  252. #==============================================================================
  253. # ■ Game_Player_Module
  254. #------------------------------------------------------------------------------
  255. # Caterpillar movement of actor is carried out on map
  256. #==============================================================================
  257.  
  258. module Train_Actor
  259.  
  260. module Game_Player_Module
  261. attr_reader :move_speed
  262. attr_reader :step_anime
  263.  
  264. def update_party_actors
  265. $game_party.update_party_actors
  266. $game_party.actors.each do |actor|
  267. if actor.dead?
  268. next
  269. end
  270. @character_name = actor.character_name
  271. @character_hue = actor.character_hue
  272. break
  273. end
  274. end
  275. def update
  276. update_party_actors
  277. super
  278. end
  279. def moveto( x, y )
  280. $game_party.moveto_party_actors( x, y )
  281. super( x, y )
  282. end
  283. def move_down(turn_enabled = true)
  284. if passable?(@x, @y, Input::DOWN)
  285. $game_party.move_down_party_actors(turn_enabled)
  286. end
  287. super(turn_enabled)
  288. end
  289. def move_left(turn_enabled = true)
  290. if passable?(@x, @y, Input::LEFT)
  291. $game_party.move_left_party_actors(turn_enabled)
  292. end
  293. super(turn_enabled)
  294. end
  295. def move_right(turn_enabled = true)
  296. if passable?(@x, @y, Input::RIGHT)
  297. $game_party.move_right_party_actors(turn_enabled)
  298. end
  299. super(turn_enabled)
  300. end
  301. def move_up(turn_enabled = true)
  302. if passable?(@x, @y, Input::UP)
  303. $game_party.move_up_party_actors(turn_enabled)
  304. end
  305. super(turn_enabled)
  306. end
  307. def move_lower_left
  308. # When possible to move from down→left or from left→down
  309. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  310. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  311. $game_party.move_lower_left_party_actors
  312. end
  313. super
  314. end
  315. def move_lower_right
  316. # When possible to move from down→right or from right→down
  317. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  318. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  319. $game_party.move_lower_right_party_actors
  320. end
  321. super
  322. end
  323. def move_upper_left
  324. # When possible to move from up→left or from left→up
  325. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  326. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  327. $game_party.move_upper_left_party_actors
  328. end
  329. super
  330. end
  331. def move_upper_right
  332. # When possible to move from up→right or from right→up
  333. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  334. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  335. $game_party.move_upper_right_party_actors
  336. end
  337. super
  338. end
  339. def jump(x_plus, y_plus)
  340. # New coordinates are calculated
  341. new_x = @x + x_plus
  342. new_y = @y + y_plus
  343. # When addition values are (0,0), it is possible to jump to the destination
  344. if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  345. $game_party.jump_party_actors(x_plus, y_plus)
  346. end
  347. super(x_plus, y_plus)
  348. end
  349. end
  350.  
  351. end
  352.  
  353. class Game_Player
  354. include Train_Actor::Game_Player_Module
  355. end
  356.  
  357. # Game_Event_Module.rb
  358. #==============================================================================
  359. # ■ Game_Event_Module
  360. #------------------------------------------------------------------------------
  361. # Caterpillar movement of actor is carried out on map
  362. #==============================================================================
  363.  
  364. module Train_Actor
  365.  
  366. module Game_Event_Module
  367. #--------------------------------------------------------------------------
  368. # ● Judgement determined
  369. # x : X coordinates
  370. # y : Y coordinates
  371. # d : Direction (0,2,4,6,8) ※ 0 = Checks if all directions are not able to be passed (for a jump)
  372. # return : Passing is impossible (false), possible (true)
  373. #--------------------------------------------------------------------------
  374. def passable?(x, y, d)
  375. result = super(x, y, d)
  376. if result
  377. # New coordinates are searched for
  378. new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  379. new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  380. # Loops for actor in train
  381. for actor in $game_party.characters
  382. # When displayed
  383. if not actor.character_name.empty?
  384. # When actor's coordinates correspond to the destination
  385. if actor.x == new_x and actor.y == new_y
  386. # When event
  387. if self != $game_player
  388. # Passing is impossible
  389. return false
  390. end
  391. end
  392. end
  393. end
  394. end
  395. return result
  396. end
  397. end
  398.  
  399. end
  400.  
  401. class Game_Event
  402. include Train_Actor::Game_Event_Module
  403. end
  404.  
  405. # Game_Party_Actor.rb
  406. #==============================================================================
  407. # ■ Game_Party_Actor
  408. #------------------------------------------------------------------------------
  409. # Caterpillar movement of actor is carried out on map
  410. #==============================================================================
  411.  
  412. module Train_Actor
  413.  
  414. class Game_Party_Actor < Game_Character
  415. attr_writer :move_speed
  416. attr_writer :step_anime
  417.  
  418. def initialize
  419. super()
  420. @through = true
  421. end
  422. def setup(actor)
  423. # The file name and hue of the character are set
  424. if actor != nil and (not actor.dead?) # When dead, it is erased for the time being...
  425. @character_name = actor.character_name
  426. @character_hue = actor.character_hue
  427. else
  428. @character_name = ""
  429. @character_hue = 0
  430. end
  431. # Opacity and blending method are initialized
  432. @opacity = 255
  433. @blend_type = 0
  434. end
  435. def screen_z(height = 0)
  436. if $game_player.x == @x and $game_player.y == @y
  437. return $game_player.screen_z(height) - 1
  438. end
  439. super(height)
  440. end
  441. #--------------------------------------------------------------------------
  442. # ● Move down
  443. # turn_enabled : Flag that permits direction change on the spot
  444. #--------------------------------------------------------------------------
  445. def move_down(turn_enabled = true)
  446. # Face down
  447. if turn_enabled
  448. turn_down
  449. end
  450. # When possible to pass
  451. if passable?(@x, @y, Input::DOWN)
  452. # Face down
  453. turn_down
  454. # Update coordinates
  455. @y += 1
  456. end
  457. end
  458. #--------------------------------------------------------------------------
  459. # ● Move left
  460. # turn_enabled : Flag that permits direction change on the spot
  461. #--------------------------------------------------------------------------
  462. def move_left(turn_enabled = true)
  463. # Face left
  464. if turn_enabled
  465. turn_left
  466. end
  467. # When possible to pass
  468. if passable?(@x, @y, Input::LEFT)
  469. # Face left
  470. turn_left
  471. # Update coordinates
  472. @x -= 1
  473. end
  474. end
  475. #--------------------------------------------------------------------------
  476. # ● Move right
  477. # turn_enabled : Flag that permits direction change on the spot
  478. #--------------------------------------------------------------------------
  479. def move_right(turn_enabled = true)
  480. # Face right
  481. if turn_enabled
  482. turn_right
  483. end
  484. # When possible to pass
  485. if passable?(@x, @y, Input::RIGHT)
  486. # Face right
  487. turn_right
  488. # Update coordinates
  489. @x += 1
  490. end
  491. end
  492. #--------------------------------------------------------------------------
  493. # ● Move up
  494. # turn_enabled : Flag that permits direction change on the spot
  495. #--------------------------------------------------------------------------
  496. def move_up(turn_enabled = true)
  497. # Face up
  498. if turn_enabled
  499. turn_up
  500. end
  501. # When possible to pass
  502. if passable?(@x, @y, Input::UP)
  503. # Face up
  504. turn_up
  505. # Update coordinates
  506. @y -= 1
  507. end
  508. end
  509. #--------------------------------------------------------------------------
  510. # ● Move lower left
  511. #--------------------------------------------------------------------------
  512. def move_lower_left
  513. # When no direction fixation
  514. unless @direction_fix
  515. # Turn left when facing right, turn down when facing up
  516. @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::UP ? Input::DOWN : @direction)
  517. end
  518. # When possible to move from down→left or from left→down
  519. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  520. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  521. # Update coordinates
  522. @x -= 1
  523. @y += 1
  524. end
  525. end
  526. #--------------------------------------------------------------------------
  527. # ● Move lower right
  528. #--------------------------------------------------------------------------
  529. def move_lower_right
  530. # When no direction fixation
  531. unless @direction_fix
  532. # Turn right when facing left, turn down when facing up
  533. @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::UP ? Input::DOWN : @direction)
  534. end
  535. # When possible to move from down→right or from right→down
  536. if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  537. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  538. # Update coordinates
  539. @x += 1
  540. @y += 1
  541. end
  542. end
  543. #--------------------------------------------------------------------------
  544. # ● move upper left
  545. #--------------------------------------------------------------------------
  546. def move_upper_left
  547. # When no direction fixation
  548. unless @direction_fix
  549. # Turn left when facing right, turn up when facing down
  550. @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::DOWN ? Input::UP : @direction)
  551. end
  552. # When possible to move from up→left or from left→up
  553. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  554. (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  555. # Update coordinates
  556. @x -= 1
  557. @y -= 1
  558. end
  559. end
  560. #--------------------------------------------------------------------------
  561. # ● move upper right
  562. #--------------------------------------------------------------------------
  563. def move_upper_right
  564. # When no direction fixation
  565. unless @direction_fix
  566. # Turn right when facing left, turn up when facing down
  567. @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::DOWN ? Input::UP : @direction)
  568. end
  569. # When possible to move from up→right or from right→up
  570. if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  571. (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  572. # Update coordinates
  573. @x += 1
  574. @y -= 1
  575. end
  576. end
  577. end
  578.  
  579. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement