PDA

View Full Version : Connections and Player in Centre


the O rly? owl
June 22nd, 2005, 07:03 AM
In order to use the tutorial, you mUST change the screen size by adding two scripts

Add this script before all other scripts.
#================================================= =============================
# ■ Win32API
#------------------------------------------------------------------------------
# by Squall squall@loeher.znn.com
# Change the window size
# I must thank cybersam for his mouse and keyboard scripts. they were very
# useful finding some winapi function.
#
# !! this script MUST be on top of all other or the game will crash,
# if you use scripts to enlarge maps!
#================================================= =============================

class Win32API
#--------------------------------------------------------------------------
# ● define constant
#--------------------------------------------------------------------------
GAME_INI_FILE = ".\\Game.ini" # define "Game.ini" file
HWND_TOPMOST = 0 # window always active
HWND_TOP = -1 # window active when used only
SWP_NOMOVE = 0 # window pos and sizes can be changed
#--------------------------------------------------------------------------
# ● Win32API.GetPrivateProfileString // check your game title in Game.ini
#--------------------------------------------------------------------------
def Win32API.GetPrivateProfileString(section, key)
val = "\0"*256
gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l')
gps.call(section, key, "", val, 256, GAME_INI_FILE)
val.delete!("\0")
return val
end
#--------------------------------------------------------------------------
# ● Win32API.FindWindow // find the RGSS window
#--------------------------------------------------------------------------
def Win32API.FindWindow(class_name, title)
fw = Win32API.new('user32', 'FindWindow', %(p, p), 'i')
hWnd = fw.call(class_name, title)
return hWnd
end
#--------------------------------------------------------------------------
# ● Win32API.SetWindowPos // change window positions and sizes
#--------------------------------------------------------------------------
def Win32API.SetWindowPos(w, h)
title = Win32API.GetPrivateProfileString("Game", "Title")
hWnd = Win32API.FindWindow("RGSS Player", title)
swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i')
win = swp.call(hWnd, HWND_TOP, 0, 0, w + 6, h + 32, 0)

#the line below makes the window on top of all others
#win = swp.call(hWnd, HWND_TOPMOST, 0, 0, w + 6, h + 32, SWP_NOMOVE)
return win
end
#--------------------------------------------------------------------------
# ● Win32API.client_size // check the window width and height
#--------------------------------------------------------------------------
def Win32API.client_size
title = Win32API.GetPrivateProfileString("Game", "Title")
hWnd = Win32API.FindWindow("RGSS Player", title)
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(hWnd, rect)
width, height = rect.unpack('l4')[2..3]
return width, height
end
end

#================================================= =============================
# ■ proceed with creation of the window
#------------------------------------------------------------------------------
# the width and height variables set the screen size.
#================================================= =============================
$width = 480
$height = 320
win = Win32API.SetWindowPos($width, $height)
if(win == 0)
p "Size change has failed!"
end

Also, you have to add that script before the Main script in the list
#================================================= =============================
# ■ Game_Player
#------------------------------------------------------------------------------
#  remade to be compatible with change sreen size script
#================================================= =============================

class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● define constant
#--------------------------------------------------------------------------
CENTER_X = ($width/2 - 16) * 4 # X coordinate in the center of the screen
CENTER_Y = ($height/2 - 16) * 4 # Y coordinate in the center of the screen
end

#================================================= =============================
# ■ Spriteset_Map //squall@loeher.zzn.com
#------------------------------------------------------------------------------
# remade to be compatible with change sreen size script
#================================================= =============================

class Spriteset_Map
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def initialize
@viewport2 = Viewport.new(0, 0, $width, $height)
@viewport3 = Viewport.new(0, 0, $width, $height)
@viewport4 = Viewport.new(640, 0, $width-640, 480)
@viewport5 = Viewport.new(0, 480, 640, $height-480)
@viewport6 = Viewport.new(640, 480, $width-640, $height-480)
@viewport1 = Viewport.new(0, 0, $width, $height)

@viewport2.z = 200
@viewport3.z = 5000

@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities

@panorama = Plane.new(@viewport1)
@panorama.z = -1000

@fog = Plane.new(@viewport1)
@fog.z = 3000

@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Character.new(@view port1, $game_player))

@weather = RPG::Weather.new(@viewport1)

@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport 2, $game_screen.pictures[i]))
end

@timer_sprite = Sprite_Timer.new

@tilemap2 = Tilemap.new(@viewport4)
@tilemap2.tileset = RPG::Cache.tileset($game_map.tileset_name)
@tilemap3 = Tilemap.new(@viewport5)
@tilemap3.tileset = RPG::Cache.tileset($game_map.tileset_name)
@tilemap4 = Tilemap.new(@viewport6)
@tilemap4.tileset = RPG::Cache.tileset($game_map.tileset_name)

for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap2.autotiles[i] = RPG::Cache.autotile(autotile_name)
@tilemap3.autotiles[i] = RPG::Cache.autotile(autotile_name)
@tilemap4.autotiles[i] = RPG::Cache.autotile(autotile_name)
end

@tilemap2.map_data = $game_map.data
@tilemap3.map_data = $game_map.data
@tilemap4.map_data = $game_map.data

update
end
#--------------------------------------------------------------------------
# ● Dispose the sprite
#--------------------------------------------------------------------------
def dispose

@tilemap.tileset.dispose
@tilemap2.tileset.dispose
@tilemap3.tileset.dispose
@tilemap4.tileset.dispose

for i in 0..6
@tilemap.autotiles[i].dispose
@tilemap2.autotiles[i].dispose
@tilemap3.autotiles[i].dispose
@tilemap4.autotiles[i].dispose
end

@tilemap.dispose
@tilemap2.dispose
@tilemap3.dispose
@tilemap4.dispose

@panorama.dispose
@fog.dispose

for sprite in @character_sprites
sprite.dispose
end

@weather.dispose

for sprite in @picture_sprites
sprite.dispose
end

@timer_sprite.dispose
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose

@viewport4.dispose
@viewport5.dispose
@viewport6.dispose
end
#--------------------------------------------------------------------------
# ● Update the sprite
#--------------------------------------------------------------------------
def update

if @panorama_name != $game_map.panorama_name or
@panorama_hue != $game_map.panorama_hue
@panorama_name = $game_map.panorama_name
@panorama_hue = $game_map.panorama_hue
if @panorama.bitmap != nil
@panorama.bitmap.dispose
@panorama.bitmap = nil
end
if @panorama_name != ""
@panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
end
Graphics.frame_reset
end

if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
@fog_name = $game_map.fog_name
@fog_hue = $game_map.fog_hue
if @fog.bitmap != nil
@fog.bitmap.dispose
@fog.bitmap = nil
end
if @fog_name != ""
@fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
end
Graphics.frame_reset
end

@tilemap.ox = $game_map.display_x / 4
@tilemap.oy = $game_map.display_y / 4
@tilemap.update

#if @tilemap.ox > $game_map.width * 32 - $width
#@tilemap.ox = $game_map.width * 32 - $width
#end
#if @tilemap.oy > $game_map.width * 32 - $height
#@tilemap.oy = $game_map.height * 32 - $height
#end

@tilemap2.ox = @tilemap.ox + 640
@tilemap2.oy = @tilemap.oy
@tilemap2.update

@tilemap3.ox = @tilemap.ox
@tilemap3.oy = @tilemap.oy + 480
@tilemap3.update

@tilemap4.ox = @tilemap.ox + 640
@tilemap4.oy = @tilemap.oy + 480
@tilemap4.update

@panorama.ox = $game_map.display_x / 8
@panorama.oy = $game_map.display_y / 8

@fog.zoom_x = $game_map.fog_zoom / 100.0
@fog.zoom_y = $game_map.fog_zoom / 100.0
@fog.opacity = $game_map.fog_opacity
@fog.blend_type = $game_map.fog_blend_type
@fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
@fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
@fog.tone = $game_map.fog_tone

for sprite in @character_sprites
sprite.update
end

@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.ox = $game_map.display_x / 4
@weather.oy = $game_map.display_y / 4
@weather.update

for sprite in @picture_sprites
sprite.update
end

@timer_sprite.update

@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
@viewport3.color = $game_screen.flash_color
@viewport1.update
@viewport3.update
end
end
class Game_Map
#--------------------------------------------------------------------------
# ● Scroll the map down
# distance : Distance to scroll in real units (4 = 1 pixel).
#--------------------------------------------------------------------------
def scroll_down(distance)
@display_y = [@display_y + distance, (self.height - ($height / 32.0)) * 128].min
end
#--------------------------------------------------------------------------
# ● Scroll the map left
# distance : Distance to scroll in real units (4 = 1 pixel).
#--------------------------------------------------------------------------
def scroll_left(distance)
@display_x = [@display_x - distance, 0].max
end
#--------------------------------------------------------------------------
# ● Scroll the map right
# distance : Distance to scroll in real units (4 = 1 pixel).
#--------------------------------------------------------------------------
def scroll_right(distance)
@display_x = [@display_x + distance, (self.width - ($width / 32.0)) * 128].min
end
#--------------------------------------------------------------------------
# ● Scroll the map up
# distance : Distance to scroll in real units (4 = 1 pixel).
#--------------------------------------------------------------------------
def scroll_up(distance)
@display_y = [@display_y - distance, 0].max
end
end

Now your screen size is 480*320, just like a double sized GBA.

~~~~~~~~~~

To make the player in the middle like the gba - do this below.

You need to know the formula to make the player stays in the very centre as well as making the connections accurately with Teleport event commands.

I am not responsible for any mess up of teleports, or loss of any maps. You have to make sure one teleport link is in same spot like if you place the event on the exit of Newbark town, you have to put it in the same spot at the border's edge of Route 29. Got it? :) Also you must have something to block something on the teleport so people wont get trapped on the border edges.


Height:
^
8
V
Your
map
size
^
12
V



Width:
<8> Your map size <12>


Ta-da! I have corrected the up-down conenctions so its finalized for your use.


Rewritten with addition of screen changing size script

Cursed
June 22nd, 2005, 06:18 PM
is this for rm2k3? If not, which program

the O rly? owl
June 22nd, 2005, 06:20 PM
This doc is for any RM-related programs, not just RMXP...

the O rly? owl
June 23rd, 2005, 07:25 PM
OKAY, I have changed it with addition of screen size script :)

Blizzy
June 24th, 2005, 04:00 AM
This doc is for any RM-related programs, not just RMXP...
this is only for rmxp, it's a script.
rm2k3 doesn't support rgss scripting :\

Datriot
June 24th, 2005, 01:44 PM
Yeah, it's an intresting tutorial, good work Jade.:)