class Game_Map
# Returns true if the tile is considered to have a graphic displayed under
# the character's sprite.
def bottom_graphic_tile?(x, y)
if @map_id != 0
for i in [2, 1, 0]
tile_id = data[x, y, i]
if tile_id == nil
return false
elsif @terrain_tags[tile_id] == 7
return true
end
end
end
return false
end
def tile_id(x, y, h = nil)
if @map_id != 0
return tile_id[x,y,h] unless h.nil?
for i in [2, 1, 0]
tile_id = data[x, y, i]
next if tile_id == nil or tile_id == 0
return data[x,y,i]
end
end
return nil
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Character < RPG::Sprite
alias reinit_this_again_for_tiles initialize
def initialize(viewport, character = nil)
@over_special_tile = false
@grass_sprite = Sprite.new(viewport)
@grass_sprite.bitmap = Bitmap.new(32, 5)
reinit_this_again_for_tiles(viewport, character)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias update_grass_graphic_after update
def update
# Call alias update method
update_grass_graphic_after
# If tile that the character is over is a 'special' tile
cx, cy = character.real_x/128, character.real_y/128
# Check if moving over a layer tile
if $game_map.bottom_graphic_tile?(cx, cy) or
$game_map.bottom_graphic_tile?(cx+1, cy) or
$game_map.bottom_graphic_tile?(cx, cy+1)
# Initialize overlaying graphic
@grass_sprite.bitmap.clear
#@grass_sprite.bitmap.dispose unless @grass_sprite.bitmap.nil?
#@grass_sprite.bitmap = nil
# Set bitmap to width of 32 and height of 5
#@grass_sprite.bitmap = Bitmap.new(32, 5) #if @grass_sprite.bitmap.nil?
# Get tileset graphic
tileset_bitmap = RPG::Cache.tileset($game_map.tileset_name)
# Get tile IDs (current, to the right, to the south)
tile_id1 = $game_map.tile_id(cx, cy)
tile_id2 = $game_map.tile_id(cx+1, cy)
tile_id3 = $game_map.tile_id(cx, cy+1)
#p [tile_id1,tile_id2,tile_id3] if Input.trigger?(Input::SHIFT)
# Condition checking variables
current_grassy = (tile_id1 >= 384 and $game_map.bottom_graphic_tile?(cx, cy))
right_grassy = (tile_id2 >= 384 and $game_map.bottom_graphic_tile?(cx+1, cy))
bottom_grassy = (tile_id3 >= 384 and $game_map.bottom_graphic_tile?(cx, cy+1))
tile_id1 -= 384
tile_id2 -= 384
tile_id3 -= 384
#If current tile is grassy, and not moving
if current_grassy and !@character.moving?
sox, soy = (tile_id1 % 8) * 32, (tile_id1 / 8) * 32 + 26
rect = Rect.new(sox, soy, 32, 5)
@grass_sprite.bitmap.blt(0, 0, tileset_bitmap, rect)
elsif !current_grassy and !@character.moving?
#If on grass and moving down to grass: Draw all the rectangles from x,y to x,y+1.
elsif current_grassy and bottom_grassy and @character.real_y / 128 < @character.y
height_remaining = 5
y1 = (@character.real_y % 128) / 4
p y1 if Input.trigger?(Input::SHIFT)
unless y1 >= 5
sox, soy = (tile_id1 % 8) * 32, (tile_id1 / 8) * 32 + 26 + y1
h = 5-y1
rect = Rect.new(sox,soy,32,h)
@grass_sprite.bitmap.blt(0, 0, tileset_bitmap, rect)
height_remaining -= h
end
if height_remaining > 0
sox, soy = (tile_id3 % 8) * 32, (tile_id3 / 8) * 32 + [y1 - 5, 0].max
rect = Rect.new(sox,soy,32,height_remaining)
@grass_sprite.bitmap.blt(0, 5-height_remaining, tileset_bitmap, rect)
end
#If on grass and moving down off grass: Do not bother to draw rectangles at all
elsif current_grassy and !bottom_grassy and @character.real_y / 128 < @character.y
#If on grass and moving up to grass: Same as first condition
elsif bottom_grassy and current_grassy and @character.real_y / 128 >= @character.y
height_remaining = 5
y1 = (@character.real_y % 128) / 4
unless y1 == 0 #<- Is that even possible? I don't think so
sox, soy = (tile_id3 % 8) * 32, (tile_id3 / 8) * 32 + [y1 - 5, 0].max
h = [y1, 5].min
height_remaining -= h
rect = Rect.new(sox,soy,32,h)
@grass_sprite.bitmap.blt(0, [height_remaining, 0].max, tileset_bitmap, rect)
end
if height_remaining > 0
sox, soy = (tile_id1 % 8) * 32, (tile_id1 / 8) * 32 + (31 - y1)
rect = Rect.new(sox,soy,32,height_remaining)
@grass_sprite.bitmap.blt(0, 0, tileset_bitmap, rect)
end
#If on grass and moving up to nothing: Draw rectangles all the way to the last possible spot
elsif bottom_grassy and !current_grassy and @character.real_y / 128 >= @character.y
y1 = (@character.real_y % 128) / 4
p y1 if Input.trigger?(Input::SHIFT)
unless y1 == 0 #<- Is that even possible? I don't think so
sox, soy = (tile_id3 % 8) * 32, (tile_id3 / 8) * 32 + [y1 - 5, 0].max
h = [y1, 5].min
rect = Rect.new(sox,soy,32,h)
@grass_sprite.bitmap.blt(0, 0, tileset_bitmap, rect)
end
#If not on grass and moving down onto grass: Reverse process of above
elsif !current_grassy and bottom_grassy and @character.real_y / 128 < @character.y
y1 = (@character.real_y % 128) / 4
unless y1 == 0 #<- Is that even possible? I don't think so
sox, soy = (tile_id3 % 8) * 32, (tile_id3 / 8) * 32 + [y1 - 5, 0].max
h = [y1, 5].min
rect = Rect.new(sox,soy,32,h)
@grass_sprite.bitmap.blt(0, 0, tileset_bitmap, rect)
end
#If not on grass and moving up onto grass: Do not bother to draw rectangles
elsif !bottom_grassy and current_grassy
end
end
@grass_sprite.x = @character.screen_x - 16
@grass_sprite.y = @character.screen_y - 5
@grass_sprite.z = @character.screen_z + 32
end
end