mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
More renaming and rearranging, fixed typo from earlier commit, tweaked splash and title screen code
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,443 +0,0 @@
|
||||
def bltMinimapAutotile(dstBitmap,x,y,srcBitmap,id)
|
||||
return if id>=48 || !srcBitmap || srcBitmap.disposed?
|
||||
anim=0
|
||||
cxTile=3
|
||||
cyTile=3
|
||||
tiles = TileDrawingHelper::Autotiles[id>>3][id&7]
|
||||
src=Rect.new(0,0,0,0)
|
||||
for i in 0...4
|
||||
tile_position = tiles[i] - 1
|
||||
src.set(
|
||||
tile_position % 6 * cxTile + anim,
|
||||
tile_position / 6 * cyTile, cxTile, cyTile)
|
||||
dstBitmap.blt(i%2*cxTile+x,i/2*cyTile+y, srcBitmap, src)
|
||||
end
|
||||
end
|
||||
|
||||
def passable?(passages,tile_id)
|
||||
return false if tile_id == nil
|
||||
passage = passages[tile_id]
|
||||
return (passage && passage<15)
|
||||
end
|
||||
|
||||
def getPassabilityMinimap(mapid)
|
||||
map = load_data(sprintf("Data/Map%03d.rxdata",mapid))
|
||||
tileset = $data_tilesets[map.tileset_id]
|
||||
minimap = AnimatedBitmap.new("Graphics/Pictures/minimap_tiles")
|
||||
ret = Bitmap.new(map.width*6,map.height*6)
|
||||
passtable = Table.new(map.width,map.height)
|
||||
passages = tileset.passages
|
||||
for i in 0...map.width
|
||||
for j in 0...map.height
|
||||
pass=true
|
||||
for z in [2,1,0]
|
||||
if !passable?(passages,map.data[i,j,z])
|
||||
pass=false
|
||||
break
|
||||
end
|
||||
end
|
||||
passtable[i,j]=pass ? 1 : 0
|
||||
end
|
||||
end
|
||||
neighbors=TileDrawingHelper::NeighborsToTiles
|
||||
for i in 0...map.width
|
||||
for j in 0...map.height
|
||||
if passtable[i,j]==0
|
||||
nb=TileDrawingHelper.tableNeighbors(passtable,i,j)
|
||||
tile=neighbors[nb]
|
||||
bltMinimapAutotile(ret,i*6,j*6,minimap.bitmap,tile)
|
||||
end
|
||||
end
|
||||
end
|
||||
minimap.disposes
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
|
||||
module ScreenPosHelper
|
||||
def self.pbScreenZoomX(ch)
|
||||
zoom=1.0
|
||||
if $PokemonSystem.tilemap==2
|
||||
zoom=((ch.screen_y - 16) - (Graphics.height / 2)) *
|
||||
(Draw_Tilemap::Pitch*1.0 / (Graphics.height * 25)) + 1
|
||||
end
|
||||
return zoom*Game_Map::TILE_WIDTH/32.0
|
||||
end
|
||||
|
||||
def self.pbScreenZoomY(ch)
|
||||
zoom=1.0
|
||||
if $PokemonSystem.tilemap==2
|
||||
zoom=((ch.screen_y - 16) - (Graphics.height / 2)) *
|
||||
(Draw_Tilemap::Pitch*1.0 / (Graphics.height * 25)) + 1
|
||||
end
|
||||
return zoom*Game_Map::TILE_HEIGHT/32.0
|
||||
end
|
||||
|
||||
def self.pbScreenX(ch)
|
||||
ret=ch.screen_x
|
||||
if $PokemonSystem.tilemap==2
|
||||
widthdiv2=(Graphics.width / 2)
|
||||
ret=widthdiv2+(ret-widthdiv2)*pbScreenZoomX(ch)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def self.pbScreenY(ch)
|
||||
ret=ch.screen_y
|
||||
if $PokemonSystem.tilemap==2 && Draw_Tilemap::Curve && Draw_Tilemap::Pitch != 0
|
||||
zoomy=pbScreenZoomY(ch)
|
||||
oneMinusZoomY=1-zoomy
|
||||
ret += (8 * oneMinusZoomY * (oneMinusZoomY /
|
||||
(2 * ((Draw_Tilemap::Pitch*1.0 / 100) / (Graphics.height*1.0 / 16.0))) + 0.5))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
@heightcache={}
|
||||
|
||||
def self.bmHeight(bm)
|
||||
h=@heightcache[bm]
|
||||
if !h
|
||||
bmap=AnimatedBitmap.new("Graphics/Characters/"+bm,0)
|
||||
h=bmap.height
|
||||
@heightcache[bm]=h
|
||||
bmap.dispose
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
def self.pbScreenZ(ch,height=nil)
|
||||
if height==nil
|
||||
height=0
|
||||
if ch.tile_id > 0
|
||||
height=32
|
||||
elsif ch.character_name!=""
|
||||
height=bmHeight(ch.character_name)/4
|
||||
end
|
||||
end
|
||||
ret=ch.screen_z(height)
|
||||
if $PokemonSystem.tilemap==2
|
||||
ret-=(pbScreenZoomY(ch) < 0.5 ? 1000 : 0)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
###############################################
|
||||
|
||||
|
||||
|
||||
class Draw_Tilemap # This class controls a set of sprites, with
|
||||
attr_reader :tileset # different Z values, arranged into horizontal bars
|
||||
attr_reader :map_data
|
||||
attr_reader :flash_data
|
||||
attr_reader :priorities
|
||||
attr_reader :terrain_tags
|
||||
attr_reader :autotiles
|
||||
attr_accessor :bitmaps
|
||||
attr_accessor :pitch
|
||||
attr_accessor :ox
|
||||
attr_accessor :oy
|
||||
attr_accessor :visible
|
||||
attr_reader :viewport
|
||||
attr_accessor :color
|
||||
attr_accessor :tone
|
||||
StripSize = 16
|
||||
Curve = true
|
||||
Pitch = 3
|
||||
FlashOpacity = [100,90,80,70,80,90]
|
||||
|
||||
def initialize(viewport=nil)
|
||||
@tileset=nil
|
||||
@map_data=nil
|
||||
@priorities=nil
|
||||
@terrain_tags=nil
|
||||
@autotiles=[nil,nil,nil,nil,nil,nil,nil]
|
||||
@viewport=viewport
|
||||
@visible=true
|
||||
@helper=TileDrawingHelper.new(nil,@autotiles)
|
||||
@drawnstrips=[]
|
||||
@contentstrips=[]
|
||||
@disposed=false
|
||||
@bitmaps=[]
|
||||
@sprites=[]
|
||||
@ox=0
|
||||
@oy=0
|
||||
@tone=Tone.new(0,0,0,0)
|
||||
@color=Color.new(0,0,0,0)
|
||||
@flash_data=nil
|
||||
@numsprites=0
|
||||
end
|
||||
|
||||
def tileset=(value)
|
||||
@tileset=value
|
||||
@helper.tileset=value
|
||||
@doredraw=true
|
||||
end
|
||||
|
||||
def map_data=(value)
|
||||
@map_data=value
|
||||
@doredraw=true
|
||||
end
|
||||
|
||||
def flash_data=(value)
|
||||
@flash_data=value
|
||||
@doredraw=true
|
||||
end
|
||||
|
||||
def priorities=(value)
|
||||
@priorities=value
|
||||
@doredraw=true
|
||||
end
|
||||
|
||||
def terrain_tags=(value)
|
||||
@terrain_tags=value
|
||||
@doredraw=true
|
||||
end
|
||||
|
||||
def redrawmap
|
||||
# Provide blank data in proper object form
|
||||
self.clear
|
||||
xsize=@map_data.xsize
|
||||
ysize=@map_data.ysize
|
||||
# Bitmaps used for each priority's drawing. Priorities 2-5 are combined.
|
||||
@bitmaps = [Bitmap.new(xsize*32, ysize*32+StripSize),
|
||||
Bitmap.new(xsize*32, ysize*32+StripSize),
|
||||
Bitmap.new(xsize*32, ysize*32+StripSize)]
|
||||
for i in @bitmaps
|
||||
i.clear
|
||||
end
|
||||
if @flash_data
|
||||
@bitmaps.push(Bitmap.new(xsize*32, ysize*32+StripSize))
|
||||
end
|
||||
@drawnstrips.clear
|
||||
@contentstrips.clear
|
||||
# Generate blank sprites
|
||||
@sprites.clear
|
||||
@numsprites=ysize * (32 / StripSize)
|
||||
@map_data.zsize.times do # For each layer
|
||||
@sprites.push([])
|
||||
@contentstrips.push([])
|
||||
end
|
||||
if @flash_data
|
||||
@sprites.push([])
|
||||
@contentstrips.push([])
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if !@flash_data.nil? && @sprites.length>0
|
||||
flashindex=@sprites.length-1
|
||||
for j in 0...@numsprites
|
||||
sprite=@sprites[flashindex][j]
|
||||
next if !sprite.is_a?(Sprite)
|
||||
sprite.opacity=FlashOpacity[(Graphics.frame_count/2) % 6]
|
||||
end
|
||||
end
|
||||
for s in @sprites
|
||||
for sprite in s
|
||||
next if !sprite.is_a?(Sprite)
|
||||
# sprite.tone=@tone
|
||||
# sprite.color=@color
|
||||
end
|
||||
end
|
||||
if @doredraw
|
||||
@drawnstrips=[]
|
||||
redrawmap
|
||||
@doredraw=false
|
||||
elsif @oldOx==@ox && @oldOy==@oy
|
||||
return
|
||||
end
|
||||
@oldOx=@ox
|
||||
@oldOy=@oy
|
||||
@pitch = Pitch
|
||||
minvalue=[0, ((Graphics.height / 2) -
|
||||
((Graphics.height * 60) / @pitch) + @oy) / StripSize].max.to_i
|
||||
maxvalue=[@numsprites - 1,(@oy + Graphics.height) / StripSize].min.to_i
|
||||
return if minvalue>maxvalue
|
||||
for j in 0...@numsprites
|
||||
if j<minvalue || j>maxvalue
|
||||
for i in 0...@sprites.length
|
||||
sprite=@sprites[i][j]
|
||||
if sprite
|
||||
sprite.dispose if sprite.is_a?(Sprite)
|
||||
@sprites[i][j]=nil
|
||||
end
|
||||
end
|
||||
else
|
||||
drawStrip(j)
|
||||
end
|
||||
end
|
||||
vpy=@viewport.rect.y
|
||||
vpr=@viewport.rect.x+@viewport.rect.width
|
||||
numsprites=0
|
||||
for i in @sprites
|
||||
numsprites+=i.compact.length
|
||||
end
|
||||
for j in minvalue..maxvalue
|
||||
# For each strip within the visible screen, update OX/Y
|
||||
x=Graphics.width/2
|
||||
sox=@ox+x
|
||||
y = (j * StripSize - @oy)
|
||||
zoom_x=1.0
|
||||
zoom_y=1.0
|
||||
unless @pitch == 0 # Apply X Zoom
|
||||
zoom_x = (y - Graphics.height*1.0 / 2) * (@pitch*1.0 / (Graphics.height * 25)) + 1
|
||||
if Curve # Zoom Y values same as X, and compensate
|
||||
zoom_y = zoom_x
|
||||
yadd = StripSize*1.0 * (1 - zoom_y) * ((1 - zoom_y) /
|
||||
(2 * ((@pitch*1.0 / 100) / (Graphics.height*1.0 / (StripSize * 2)))) + 0.5)
|
||||
y+=yadd
|
||||
end
|
||||
end
|
||||
xstart=(x-sox*zoom_x)
|
||||
yend=(y+(StripSize*2)*zoom_y)
|
||||
if xstart>vpr || yend<=vpy
|
||||
for i in 0...@sprites.length
|
||||
sprite=@sprites[i][j]
|
||||
if sprite.is_a?(Sprite)
|
||||
sprite.dispose
|
||||
@sprites[i][j]=nil
|
||||
end
|
||||
end
|
||||
else
|
||||
for i in 0...@sprites.length
|
||||
sprite=@sprites[i][j]
|
||||
next if !sprite
|
||||
if sprite==true
|
||||
sprite=newSprite(i,j)
|
||||
@sprites[i][j]=sprite
|
||||
end
|
||||
sprite.visible=@visible
|
||||
sprite.x = x
|
||||
sprite.ox = sox
|
||||
sprite.y = y
|
||||
sprite.zoom_x = zoom_x
|
||||
sprite.zoom_y = zoom_y
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def clear
|
||||
for i in @bitmaps
|
||||
i.dispose
|
||||
end
|
||||
@bitmaps.clear
|
||||
for i in 0...@sprites.length
|
||||
for j in 0...@sprites[i].length
|
||||
@sprites[i][j].dispose if @sprites[i][j].is_a?(Sprite)
|
||||
end
|
||||
@sprites[i].clear
|
||||
end
|
||||
@sprites.clear
|
||||
end
|
||||
|
||||
def dispose
|
||||
return if @disposed
|
||||
self.clear
|
||||
for i in 0...7
|
||||
self.autotiles[i]=nil
|
||||
end
|
||||
@helper=nil
|
||||
@sprites=nil
|
||||
@bitmaps=nil
|
||||
@disposed = true
|
||||
end
|
||||
|
||||
def disposed?
|
||||
return @disposed
|
||||
end
|
||||
|
||||
def newSprite(i,j)
|
||||
sprite=Sprite.new(@viewport)
|
||||
sprite.bitmap=@bitmaps[i]
|
||||
sprite.src_rect.set(0, j * StripSize, @map_data.xsize * 32, StripSize * 2)
|
||||
sprite.x = Graphics.width / 2
|
||||
sprite.y = -64
|
||||
sprite.z = (i * 32)
|
||||
sprite.tone=@tone
|
||||
sprite.color=@color
|
||||
if i==@bitmaps.length-1 && !@flash_data.nil?
|
||||
sprite.blend_type=1
|
||||
sprite.z=1
|
||||
sprite.opacity=FlashOpacity[(Graphics.frame_count/2) % 6]
|
||||
end
|
||||
return sprite
|
||||
end
|
||||
|
||||
def drawStrip(j)
|
||||
minY=(j*StripSize)/32
|
||||
maxY=(j*StripSize+StripSize*2)/32
|
||||
minY=0 if minY<0
|
||||
minY=@map_data.ysize-1 if minY>@map_data.ysize-1
|
||||
maxY=0 if maxY<0
|
||||
maxY=@map_data.ysize-1 if maxY>@map_data.ysize-1
|
||||
for y in minY..maxY
|
||||
if !@drawnstrips[y]
|
||||
for x in 0...@map_data.xsize
|
||||
draw_position(x, y)
|
||||
end
|
||||
@drawnstrips[y]=true
|
||||
end
|
||||
end
|
||||
for i in 0...@sprites.length # For each priority
|
||||
sprite=@sprites[i][j]
|
||||
if !sprite || (sprite!=true && sprite.disposed?)
|
||||
havecontent=false
|
||||
for y in minY..maxY
|
||||
havecontent=havecontent||@contentstrips[i][y]
|
||||
end
|
||||
sprite=(havecontent) ? true : nil
|
||||
@sprites[i][j]=sprite
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def draw_position(x, y)
|
||||
for layer in 0...@map_data.zsize
|
||||
pos = @map_data[x, y, layer]
|
||||
priopos=@priorities[pos]
|
||||
priopos=0 if !priopos
|
||||
prio=(2<priopos) ? 2 : priopos
|
||||
@contentstrips[prio][y]=true if pos>0
|
||||
@helper.bltTile(@bitmaps[prio],x*32,y*32,pos,0)
|
||||
end
|
||||
if !@flash_data.nil?
|
||||
lastlayer=@bitmaps.length-1
|
||||
id=@flash_data[x,y,0]
|
||||
r=(id>>8)&15
|
||||
g=(id>>4)&15
|
||||
b=(id)&15
|
||||
@contentstrips[lastlayer][y]=true
|
||||
color=Color.new(r*16,g*16,b*16)
|
||||
@bitmaps[lastlayer].fill_rect(x*32,y*32,32,32,color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class Sprite_Character
|
||||
alias perspectivetilemap_initialize initialize
|
||||
attr_accessor :character
|
||||
|
||||
def initialize(viewport, character = nil)
|
||||
@character = character
|
||||
perspectivetilemap_initialize(viewport,character)
|
||||
end
|
||||
|
||||
alias update_or :update
|
||||
|
||||
def update
|
||||
update_or
|
||||
if $PokemonSystem.tilemap==2
|
||||
self.zoom_y=ScreenPosHelper.pbScreenZoomY(@character)
|
||||
self.zoom_x=ScreenPosHelper.pbScreenZoomX(@character)
|
||||
self.x=ScreenPosHelper.pbScreenX(@character)
|
||||
self.y=ScreenPosHelper.pbScreenY(@character)
|
||||
self.z=ScreenPosHelper.pbScreenZ(@character,@ch)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,117 +0,0 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class SynchronizedTilemapAutotilesInternal
|
||||
def initialize(oldat)
|
||||
@atdisposables = [[],[],[],[],[],[],[]]
|
||||
@atframes = [[],[],[],[],[],[],[]]
|
||||
@atframe = [-1,-1,-1,-1,-1,-1,-1]
|
||||
@autotiles = []
|
||||
@oldat = oldat
|
||||
end
|
||||
|
||||
def dispose
|
||||
for i in 0...7
|
||||
for bitmap in @atdisposables[i]
|
||||
bitmap.dispose
|
||||
end
|
||||
@atdisposables[i].clear
|
||||
@atframes[i].clear
|
||||
end
|
||||
end
|
||||
|
||||
def [](i)
|
||||
return @autotiles[i]
|
||||
end
|
||||
|
||||
def []=(i,value)
|
||||
for frame in @atdisposables[i]
|
||||
frame.dispose
|
||||
end
|
||||
@atframe[i] = -1
|
||||
@atframes[i].clear
|
||||
@atdisposables[i].clear
|
||||
if value && !value.disposed?
|
||||
if value.height==32
|
||||
frames = value.width/32
|
||||
for j in 0...frames
|
||||
@atdisposables[i][j] = Bitmap.new(32,32)
|
||||
@atdisposables[i][j].blt(0,0,value,Rect.new(j*32,0,32,32))
|
||||
@atframes[i][j] = @atdisposables[i][j]
|
||||
end
|
||||
elsif value.height==128
|
||||
frames = value.width/96
|
||||
for j in 0...frames
|
||||
@atdisposables[i][j] = Bitmap.new(96,128)
|
||||
@atdisposables[i][j].blt(0,0,value,Rect.new(j*96,0,96,128))
|
||||
@atframes[i][j] = @atdisposables[i][j]
|
||||
end
|
||||
else
|
||||
@atframes[i][0] = value
|
||||
end
|
||||
else
|
||||
@atframes[i][0] = value
|
||||
end
|
||||
@autotiles[i] = value
|
||||
sync
|
||||
end
|
||||
|
||||
def sync
|
||||
for i in 0...7
|
||||
frames = [1,@atframes[i].length].max
|
||||
frame = (Graphics.frame_count/15)%frames
|
||||
if frames>1 && @atframe[i]!=frame
|
||||
@oldat[i] = @atframes[i][frame]
|
||||
@atframe[i] = frame
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class SynchronizedTilemapAutotiles
|
||||
def initialize(autotiles)
|
||||
@autotiles = autotiles
|
||||
end
|
||||
|
||||
def [](i)
|
||||
return @autotiles[i]
|
||||
end
|
||||
|
||||
def []=(i,value)
|
||||
@autotiles[i] = value
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class SynchronizedTilemap < Tilemap
|
||||
# This class derives from Tilemap just to synchronize
|
||||
# the tilemap animation.
|
||||
attr_accessor :numupdates
|
||||
|
||||
def initialize(viewport=nil)
|
||||
super(viewport)
|
||||
@updating = true
|
||||
@autotiles = SynchronizedTilemapAutotilesInternal.new(self.autotiles)
|
||||
@autos = SynchronizedTilemapAutotiles.new(@autotiles)
|
||||
@updating = false
|
||||
end
|
||||
|
||||
def dispose
|
||||
@autotiles.dispose
|
||||
super
|
||||
end
|
||||
|
||||
def autotiles
|
||||
return @autos if !@updating
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
return if disposed?
|
||||
@autotiles.sync
|
||||
super
|
||||
end
|
||||
end
|
||||
@@ -1,70 +0,0 @@
|
||||
class TilemapLoader
|
||||
def initialize(viewport)
|
||||
@viewport = viewport
|
||||
@tilemap = nil
|
||||
@color = Color.new(0,0,0,0)
|
||||
@tone = Tone.new(0,0,0,0)
|
||||
updateClass
|
||||
end
|
||||
|
||||
def updateClass
|
||||
case $PokemonSystem.tilemap
|
||||
when 1 # Custom (recommended)
|
||||
setClass(CustomTilemap)
|
||||
when 2 # Perspective
|
||||
setClass(Draw_Tilemap)
|
||||
else # Original (SynchronizedTilemap) or custom (CustomTilemap)
|
||||
if Tilemap.method_defined?(:passages)
|
||||
setClass(CustomTilemap)
|
||||
else
|
||||
setClass(SynchronizedTilemap)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setClass(cls)
|
||||
newtilemap = cls.new(@viewport)
|
||||
if @tilemap
|
||||
newtilemap.tileset = @tilemap.tileset
|
||||
newtilemap.map_data = @tilemap.map_data
|
||||
newtilemap.flash_data = @tilemap.flash_data
|
||||
newtilemap.priorities = @tilemap.priorities
|
||||
newtilemap.terrain_tags = @tilemap.terrain_tags
|
||||
newtilemap.visible = @tilemap.visible
|
||||
newtilemap.ox = @tilemap.ox
|
||||
newtilemap.oy = @tilemap.oy
|
||||
for i in 0...7
|
||||
newtilemap.autotiles[i] = @tilemap.autotiles[i]
|
||||
end
|
||||
@tilemap.dispose
|
||||
@tilemap = newtilemap
|
||||
newtilemap.update if cls!=SynchronizedTilemap
|
||||
else
|
||||
@tilemap = newtilemap
|
||||
end
|
||||
end
|
||||
|
||||
def dispose; @tilemap.dispose; end
|
||||
def disposed?; @tilemap && @tilemap.disposed?; end
|
||||
def update; @tilemap.update; end
|
||||
def viewport; @tilemap.viewport; end
|
||||
def autotiles; @tilemap.autotiles; end
|
||||
def tileset; @tilemap.tileset; end
|
||||
def tileset=(v); @tilemap.tileset = v; end
|
||||
def map_data; @tilemap.map_data; end
|
||||
def map_data=(v); @tilemap.map_data = v; end
|
||||
def flash_data; @tilemap.flash_data; end
|
||||
def flash_data=(v); @tilemap.flash_data = v; end
|
||||
def priorities; @tilemap.priorities; end
|
||||
def priorities=(v); @tilemap.priorities = v; end
|
||||
def terrain_tags; (@tilemap.terrain_tags rescue nil); end
|
||||
def terrain_tags=(v); (@tilemap.terrain_tags = v rescue nil); end
|
||||
def visible; @tilemap.visible; end
|
||||
def visible=(v); @tilemap.visible = v; end
|
||||
def tone; (@tilemap.tone rescue @tone); end
|
||||
def tone=(value); (@tilemap.tone = value rescue nil); end
|
||||
def ox; @tilemap.ox; end
|
||||
def ox=(v); @tilemap.ox = v; end
|
||||
def oy; @tilemap.oy; end
|
||||
def oy=(v); @tilemap.oy = v; end
|
||||
end
|
||||
@@ -1,202 +0,0 @@
|
||||
class TileDrawingHelper
|
||||
attr_accessor :tileset
|
||||
attr_accessor :autotiles
|
||||
|
||||
Autotiles = [
|
||||
[ [27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
|
||||
[27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12] ],
|
||||
[ [27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
|
||||
[27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12] ],
|
||||
[ [25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
|
||||
[15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
|
||||
[ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
|
||||
[39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46] ],
|
||||
[ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
|
||||
[17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
|
||||
[ [37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
|
||||
[37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8] ]
|
||||
]
|
||||
|
||||
# converts neighbors returned from tableNeighbors to tile indexes
|
||||
NeighborsToTiles = [
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
45, 39, 45, 39, 33, 31, 33, 29, 45, 39, 45, 39, 33, 31, 33, 29,
|
||||
37, 27, 37, 27, 23, 15, 23, 13, 37, 27, 37, 27, 22, 11, 22, 9,
|
||||
45, 39, 45, 39, 33, 31, 33, 29, 45, 39, 45, 39, 33, 31, 33, 29,
|
||||
36, 26, 36, 26, 21, 7, 21, 5, 36, 26, 36, 26, 20, 3, 20, 1,
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
45, 38, 45, 38, 33, 30, 33, 28, 45, 38, 45, 38, 33, 30, 33, 28,
|
||||
37, 25, 37, 25, 23, 14, 23, 12, 37, 25, 37, 25, 22, 10, 22, 8,
|
||||
45, 38, 45, 38, 33, 30, 33, 28, 45, 38, 45, 38, 33, 30, 33, 28,
|
||||
36, 24, 36, 24, 21, 6, 21, 4, 36, 24, 36, 24, 20, 2, 20, 0
|
||||
]
|
||||
|
||||
def self.tableNeighbors(data,x,y)
|
||||
return 0 if x < 0 || x >= data.xsize
|
||||
return 0 if y < 0 || y >= data.ysize
|
||||
t = data[x,y]
|
||||
xp1 = [x + 1, data.xsize - 1].min
|
||||
yp1 = [y + 1, data.ysize - 1].min
|
||||
xm1 = [x - 1, 0].max
|
||||
ym1 = [y - 1, 0].max
|
||||
i = 0
|
||||
i |= 0x01 if data[ x, ym1] == t # N
|
||||
i |= 0x02 if data[xp1, ym1] == t # NE
|
||||
i |= 0x04 if data[xp1, y] == t # E
|
||||
i |= 0x08 if data[xp1, yp1] == t # SE
|
||||
i |= 0x10 if data[ x, yp1] == t # S
|
||||
i |= 0x20 if data[xm1, yp1] == t # SW
|
||||
i |= 0x40 if data[xm1, y] == t # W
|
||||
i |= 0x80 if data[xm1, ym1] == t # NW
|
||||
return i
|
||||
end
|
||||
|
||||
def self.fromTileset(tileset)
|
||||
bmtileset=pbGetTileset(tileset.tileset_name)
|
||||
bmautotiles=[]
|
||||
for i in 0...7
|
||||
bmautotiles.push(pbGetAutotile(tileset.autotile_names[i]))
|
||||
end
|
||||
return self.new(bmtileset,bmautotiles)
|
||||
end
|
||||
|
||||
def initialize(tileset, autotiles)
|
||||
if tileset.mega?
|
||||
@tileset = TileWrap::wrapTileset(tileset)
|
||||
tileset.dispose
|
||||
@shouldWrap = true
|
||||
else
|
||||
@tileset = tileset
|
||||
@shouldWrap = false
|
||||
end
|
||||
@autotiles = autotiles
|
||||
end
|
||||
|
||||
def dispose
|
||||
@tileset.dispose if @tileset
|
||||
@tileset = nil
|
||||
for i in 0...@autotiles.length
|
||||
@autotiles[i].dispose
|
||||
@autotiles[i] = nil
|
||||
end
|
||||
end
|
||||
|
||||
def bltSmallAutotile(bitmap,x,y,cxTile,cyTile,id,frame)
|
||||
return if id >= 384 || frame < 0 || !@autotiles
|
||||
autotile = @autotiles[id / 48 - 1]
|
||||
return if !autotile || autotile.disposed?
|
||||
cxTile = [cxTile / 2, 1].max
|
||||
cyTile = [cyTile / 2, 1].max
|
||||
if autotile.height == 32
|
||||
anim = frame * 32
|
||||
src_rect = Rect.new(anim, 0, 32, 32)
|
||||
bitmap.stretch_blt(Rect.new(x, y, cxTile * 2, cyTile * 2), autotile, src_rect)
|
||||
else
|
||||
anim = frame * 96
|
||||
id %= 48
|
||||
tiles = TileDrawingHelper::Autotiles[id >> 3][id & 7]
|
||||
src = Rect.new(0, 0, 0, 0)
|
||||
for i in 0...4
|
||||
tile_position = tiles[i] - 1
|
||||
src.set(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)
|
||||
bitmap.stretch_blt(Rect.new(i % 2 * cxTile + x, i / 2 * cyTile + y, cxTile, cyTile),
|
||||
autotile, src)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def bltSmallRegularTile(bitmap,x,y,cxTile,cyTile,id)
|
||||
return if id < 384 || !@tileset || @tileset.disposed?
|
||||
rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
|
||||
rect = TileWrap::getWrappedRect(rect) if @shouldWrap
|
||||
bitmap.stretch_blt(Rect.new(x, y, cxTile, cyTile), @tileset, rect)
|
||||
end
|
||||
|
||||
def bltSmallTile(bitmap,x,y,cxTile,cyTile,id,frame=0)
|
||||
if id >= 384
|
||||
bltSmallRegularTile(bitmap, x, y, cxTile, cyTile, id)
|
||||
elsif id > 0
|
||||
bltSmallAutotile(bitmap, x, y, cxTile, cyTile, id, frame)
|
||||
end
|
||||
end
|
||||
|
||||
def bltAutotile(bitmap,x,y,id,frame)
|
||||
bltSmallAutotile(bitmap, x, y, 32, 32, id, frame)
|
||||
end
|
||||
|
||||
def bltRegularTile(bitmap,x,y,id)
|
||||
bltSmallRegularTile(bitmap, x, y, 32, 32, id)
|
||||
end
|
||||
|
||||
def bltTile(bitmap,x,y,id,frame=0)
|
||||
if id >= 384
|
||||
bltRegularTile(bitmap, x, y, id)
|
||||
elsif id > 0
|
||||
bltAutotile(bitmap, x, y, id, frame)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
# Unused
|
||||
def createMinimap2(mapid)
|
||||
map=load_data(sprintf("Data/Map%03d.rxdata",mapid)) rescue nil
|
||||
return BitmapWrapper.new(32,32) if !map
|
||||
bitmap=BitmapWrapper.new(map.width*4,map.height*4)
|
||||
black=Color.new(0,0,0)
|
||||
bigmap=(map.width>40 && map.height>40)
|
||||
tilesets=$data_tilesets
|
||||
tileset=tilesets[map.tileset_id]
|
||||
return bitmap if !tileset
|
||||
helper=TileDrawingHelper.fromTileset(tileset)
|
||||
for y in 0...map.height
|
||||
for x in 0...map.width
|
||||
if bigmap
|
||||
next if (x>8 && x<=map.width-8 && y>8 && y<=map.height-8)
|
||||
end
|
||||
for z in 0..2
|
||||
id=map.data[x,y,z]
|
||||
next if id==0 || !id
|
||||
helper.bltSmallTile(bitmap,x*4,y*4,4,4,id)
|
||||
end
|
||||
end
|
||||
end
|
||||
bitmap.fill_rect(0,0,bitmap.width,1,black)
|
||||
bitmap.fill_rect(0,bitmap.height-1,bitmap.width,1,black)
|
||||
bitmap.fill_rect(0,0,1,bitmap.height,black)
|
||||
bitmap.fill_rect(bitmap.width-1,0,1,bitmap.height,black)
|
||||
return bitmap
|
||||
end
|
||||
|
||||
def createMinimap(mapid)
|
||||
map=load_data(sprintf("Data/Map%03d.rxdata",mapid)) rescue nil
|
||||
return BitmapWrapper.new(32,32) if !map
|
||||
bitmap=BitmapWrapper.new(map.width*4,map.height*4)
|
||||
black=Color.new(0,0,0)
|
||||
tilesets=$data_tilesets
|
||||
tileset=tilesets[map.tileset_id]
|
||||
return bitmap if !tileset
|
||||
helper=TileDrawingHelper.fromTileset(tileset)
|
||||
for y in 0...map.height
|
||||
for x in 0...map.width
|
||||
for z in 0..2
|
||||
id=map.data[x,y,z]
|
||||
id=0 if !id
|
||||
helper.bltSmallTile(bitmap,x*4,y*4,4,4,id)
|
||||
end
|
||||
end
|
||||
end
|
||||
bitmap.fill_rect(0,0,bitmap.width,1,black)
|
||||
bitmap.fill_rect(0,bitmap.height-1,bitmap.width,1,black)
|
||||
bitmap.fill_rect(0,0,1,bitmap.height,black)
|
||||
bitmap.fill_rect(bitmap.width-1,0,1,bitmap.height,black)
|
||||
return bitmap
|
||||
end
|
||||
Reference in New Issue
Block a user