Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Dhoom
- module DIR8
- Filename = "%s_1"
- end
- end
- class Game_Character
- attr_accessor :diagonal
- alias dhoom_dir8_gmplayer_initialize initialize
- def initialize
- dhoom_dir8_gmplayer_initialize
- @diagonal = false
- end
- end
- class Game_Player < Game_Character
- def move_by_input
- return unless movable?
- return if $game_map.interpreter.running?
- case Input.dir8
- when 2; move_down
- when 4; move_left
- when 6; move_right
- when 8; move_up
- when 7; move_upper_left
- when 9; move_upper_right
- when 1; move_lower_left
- when 3; move_lower_right
- end
- end
- alias dhoom_dir8_gmplayer_set_direction set_direction
- def set_direction(dir)
- dhoom_dir8_gmplayer_set_direction(dir)
- @diagonal = [1,3,7,9].include?(dir)
- end
- def move_lower_left
- set_direction(1)
- if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
- (passable?(@x-1, @y) and passable?(@x-1, @y+1))
- @x -= 1
- @y += 1
- increase_steps
- @move_failed = false
- else
- @move_failed = true
- end
- end
- #--------------------------------------------------------------------------
- # * Move Lower Right
- #--------------------------------------------------------------------------
- def move_lower_right
- set_direction(3)
- if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or
- (passable?(@x+1, @y) and passable?(@x+1, @y+1))
- @x += 1
- @y += 1
- increase_steps
- @move_failed = false
- else
- @move_failed = true
- end
- end
- #--------------------------------------------------------------------------
- # * Move Upper Left
- #--------------------------------------------------------------------------
- def move_upper_left
- set_direction(7)
- if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or
- (passable?(@x-1, @y) and passable?(@x-1, @y-1))
- @x -= 1
- @y -= 1
- increase_steps
- @move_failed = false
- else
- @move_failed = true
- end
- end
- #--------------------------------------------------------------------------
- # * Move Upper Right
- #--------------------------------------------------------------------------
- def move_upper_right
- set_direction(9)
- if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or
- (passable?(@x+1, @y) and passable?(@x+1, @y-1))
- @x += 1
- @y -= 1
- increase_steps
- @move_failed = false
- else
- @move_failed = true
- end
- end
- end
- class Sprite_Character < Sprite_Base
- def update
- super
- update_bitmap
- self.visible = (not @character.transparent)
- update_src_rect
- self.x = @character.screen_x
- self.y = @character.screen_y
- self.z = @character.screen_z
- self.opacity = @character.opacity
- self.blend_type = @character.blend_type
- self.bush_depth = @character.bush_depth
- update_balloon
- if @character.animation_id != 0
- animation = $data_animations[@character.animation_id]
- start_animation(animation)
- @character.animation_id = 0
- end
- if @character.balloon_id != 0
- @balloon_id = @character.balloon_id
- start_balloon
- @character.balloon_id = 0
- end
- end
- #--------------------------------------------------------------------------
- # * Get tile set image that includes the designated tile
- # tile_id : Tile ID
- #--------------------------------------------------------------------------
- def tileset_bitmap(tile_id)
- set_number = tile_id / 256
- return Cache.system("TileB") if set_number == 0
- return Cache.system("TileC") if set_number == 1
- return Cache.system("TileD") if set_number == 2
- return Cache.system("TileE") if set_number == 3
- return nil
- end
- #--------------------------------------------------------------------------
- # * Update Transfer Origin Bitmap
- #--------------------------------------------------------------------------
- def update_bitmap
- if @tile_id != @character.tile_id or
- @character_name != @character.character_name or
- @character_index != @character.character_index or
- @character_diagonal != @character.diagonal
- @tile_id = @character.tile_id
- @character_name = @character.character_name
- @character_index = @character.character_index
- @character_diagonal = @character.diagonal
- if @tile_id > 0
- sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32;
- sy = @tile_id % 256 / 8 % 16 * 32;
- self.bitmap = tileset_bitmap(@tile_id)
- self.src_rect.set(sx, sy, 32, 32)
- self.ox = 16
- self.oy = 32
- else
- if @character_diagonal
- self.bitmap = Cache.character(sprintf(Dhoom::DIR8::Filename, @character_name))
- else
- self.bitmap = Cache.character(@character_name)
- end
- sign = @character_name[/^[\!\$]./]
- if sign != nil and sign.include?('$')
- @cw = bitmap.width / 3
- @ch = bitmap.height / 4
- else
- @cw = bitmap.width / 12
- @ch = bitmap.height / 8
- end
- self.ox = @cw / 2
- self.oy = @ch
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Transfer Origin Rectangle
- #--------------------------------------------------------------------------
- def update_src_rect
- if @tile_id == 0
- index = @character.character_index
- pattern = @character.pattern < 3 ? @character.pattern : 1
- sx = (index % 4 * 3 + pattern) * @cw
- if @character_diagonal
- d = @character.direction
- d -= 2 if @character.direction > 5
- sy = (index / 4 * 4 + (d - 1) / 2) * @ch
- else
- sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
- end
- self.src_rect.set(sx, sy, @cw, @ch)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement