However, I've hit a snag and am tearing my hair out trying to figure out how to get access to two attributes:
The name of the current map, that can be set in the game editor
The name of an event, that can be set in the game editor
This info will be referred to in the initialize function for SelFeenaPhoto
Here's my code so far...
CODE
=begin
##############################
## Basic Photo System V 1.0 ##
##############################
Author : Sel Feena
Date : -.06.11
A simple system that lets your party keep a collection of
screenshots, which are stored along with descriptive data.
The data stored is:
* The snapshot itself (obviously), which is a Bitmap object.
* The ID of the map the photo was taken on.
* The player's XY coords and what direction they were facing.
* The top left XY coords of the photo.
* Information about any events that are captured in the photo:
-The event's ID
-The event's XY coords
-The values for the event's Self-Switches
Compatibility
-------------
Adds new functions to the Game_Party class, and changes its
initialize function. Should be fine.
Possible Bugs
-------------
It doesn't seem possible in the editor, but using maps in your game that are
smaller than 17 X 13 in size could mess things up.
################
## How To Use ##
################
Create Photo
------------
To create a photo, use the following script call:
myPhoto = SelFeenaPhoto.new
Add Photo to Collection
-----------------------
To add the photo to your collection, you'd then type:
$game_party.addPhoto(myPhoto)
The new photo will be added to your party's collection. HOWEVER, if your
collection is full then the photo in slot 0 will be erased to make room.
Set the maximum number of photos allowed in the module below.
Get Photo from Collection
-------------------------
To get a photo, call:
myPhoto = $game_party.getPhoto( x )
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Remove Photo from Collection
----------------------------
To destroy a photo, call:
$game_party.delPhoto( x )
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Get Number of Photos in Collection
----------------------------------
Use this script:
collection_size = $game_party.getPhotoCount
Make good use of this function call to avoid out-of-bounds errors!
Get Photo Image
---------------
myPhoto = $game_party.getPhoto( x )
picture = myPhoto.getImage
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns a Bitmap object.
Get Location of Photo
---------------------
myPhoto = $game_party.getPhoto( x )
location = myPhoto.getLocationID
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Variable 'location' will then have the Map ID of where the photo was taken.
Get Player's Position when Taking Photo
---------------------------------------
myPhoto = $game_party.getPhoto( x )
player_loc_data = myPhoto.getPlayerPosition
player_x = player_loc_data[0]
player_y = player_loc_data[1]
player_dir = player_loc_data[2]
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns an array of three integers:
- The player's X position.
- The player's Y position.
- The direction the player was facing:
- 2 -> Down
- 4 -> Left
- 6 -> Right
- 8 -> Up
Get Photo's Position
--------------------
myPhoto = $game_party.getPhoto( x )
photo_loc_data = myPhoto.getPhotoPosition
photo_x = photo_loc_data[0]
photo_y = photo_loc_data[1]
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns an array of two integers:
- The photo's top-left X position.
- The photo's top-left Y position.
Get Number of Events in Photo
-----------------------------
myPhoto = $game_party.getPhoto( x )
events_in_photo = myPhoto.getEventCount
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Is a Certain Event in Photo?
---------------------------
myPhoto = $game_party.getPhoto( x )
has_event = myPhoto.hasEventWithID( i )
Where x is the index of the photo in the collection, and i is the ID
number you're looking for.
Returns true or false.
=end
=begin
This module contains settings that allow you to customise
the photo system.
=end
module SelFeenaPhotoModule
MaxPhotos = 8 # Number of photos allowed in collection.
end
###############################
###############################
## ##
## DON'T GO PAST HERE! ##
## ##
###############################
###############################
=begin
Update Game_Party to include access to photo data.
=end
class Game_Party < Game_Unit
alias selfeena_init initialize
def initialize
@photos = []
selfeena_init
end
def getPhotoCount
return @photos.length
end
def getPhoto(i)
return @photos[i]
end
def delPhoto(i)
@photos.delete_at(i)
end
def addPhoto(p)
if(@photos.length == SelFeenaPhotoModule::MaxPhotos)
@photos.delete_at(0)
end
@photos.push(p)
end
end
=begin
Class encapsulating photo data.
=end
class SelFeenaPhoto
def initialize
# Save image data...
@image_data = Graphics.snap_to_bitmap
# Save Map ID...
@map_id = $game_map.map_id
# Save player position and direction...
@player_x = $game_player.x
@player_y = $game_player.y
@player_dir = $game_player.direction
# Save xy position of photo (top-left corner) as map coordinates
@photo_pos_x = $game_map.display_x / 256
@photo_pos_y = $game_map.display_y / 256
# What events have we captured in the photo?
arr = []
for x in @photo_pos_x..(@photo_pos_x + 16)
if(x >= $game_map.width) # Horizontal loop fix
x -= $game_map.width
end
for y in @photo_pos_y..(@photo_pos_y + 12)
if(y >= $game_map.height) # Vertical loop fix
y -= $game_map.height
end
arr = arr + $game_map.events_xy(x, y)
end
end
# For each event within photo, store data...
@event_data = []
for i in arr
i_swa = $game_self_switches[[$game_map.map_id, i.id, "A"]]
i_swb = $game_self_switches[[$game_map.map_id, i.id, "B"]]
i_swc = $game_self_switches[[$game_map.map_id, i.id, "C"]]
i_swd = $game_self_switches[[$game_map.map_id, i.id, "D"]]
@event_data.push([i.id,[i.x,i.y],[i_swa,i_swb,i_swc,i_swd]])
end
end
def dispose
@image_data.dispose
end
def getImage
return @image_data
end
def getLocationID
return @map_id
end
def getPlayerPosition
return [@player_x, @player_y, @player_dir]
end
def getPhotoPosition
return [@photo_pos_x, @photo_pos_y]
end
def getEventCount
return @event_data.length
end
def hasEventWithID(target_id)
result = false
for i in @event_data
if i[0] == target_id
result = true
end
end
return result
end
end
##############################
## Basic Photo System V 1.0 ##
##############################
Author : Sel Feena
Date : -.06.11
A simple system that lets your party keep a collection of
screenshots, which are stored along with descriptive data.
The data stored is:
* The snapshot itself (obviously), which is a Bitmap object.
* The ID of the map the photo was taken on.
* The player's XY coords and what direction they were facing.
* The top left XY coords of the photo.
* Information about any events that are captured in the photo:
-The event's ID
-The event's XY coords
-The values for the event's Self-Switches
Compatibility
-------------
Adds new functions to the Game_Party class, and changes its
initialize function. Should be fine.
Possible Bugs
-------------
It doesn't seem possible in the editor, but using maps in your game that are
smaller than 17 X 13 in size could mess things up.
################
## How To Use ##
################
Create Photo
------------
To create a photo, use the following script call:
myPhoto = SelFeenaPhoto.new
Add Photo to Collection
-----------------------
To add the photo to your collection, you'd then type:
$game_party.addPhoto(myPhoto)
The new photo will be added to your party's collection. HOWEVER, if your
collection is full then the photo in slot 0 will be erased to make room.
Set the maximum number of photos allowed in the module below.
Get Photo from Collection
-------------------------
To get a photo, call:
myPhoto = $game_party.getPhoto( x )
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Remove Photo from Collection
----------------------------
To destroy a photo, call:
$game_party.delPhoto( x )
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Get Number of Photos in Collection
----------------------------------
Use this script:
collection_size = $game_party.getPhotoCount
Make good use of this function call to avoid out-of-bounds errors!
Get Photo Image
---------------
myPhoto = $game_party.getPhoto( x )
picture = myPhoto.getImage
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns a Bitmap object.
Get Location of Photo
---------------------
myPhoto = $game_party.getPhoto( x )
location = myPhoto.getLocationID
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Variable 'location' will then have the Map ID of where the photo was taken.
Get Player's Position when Taking Photo
---------------------------------------
myPhoto = $game_party.getPhoto( x )
player_loc_data = myPhoto.getPlayerPosition
player_x = player_loc_data[0]
player_y = player_loc_data[1]
player_dir = player_loc_data[2]
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns an array of three integers:
- The player's X position.
- The player's Y position.
- The direction the player was facing:
- 2 -> Down
- 4 -> Left
- 6 -> Right
- 8 -> Up
Get Photo's Position
--------------------
myPhoto = $game_party.getPhoto( x )
photo_loc_data = myPhoto.getPhotoPosition
photo_x = photo_loc_data[0]
photo_y = photo_loc_data[1]
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
This function returns an array of two integers:
- The photo's top-left X position.
- The photo's top-left Y position.
Get Number of Events in Photo
-----------------------------
myPhoto = $game_party.getPhoto( x )
events_in_photo = myPhoto.getEventCount
Where x is the index of the photo in the collection. Just like
arrays, this starts from 0
Is a Certain Event in Photo?
---------------------------
myPhoto = $game_party.getPhoto( x )
has_event = myPhoto.hasEventWithID( i )
Where x is the index of the photo in the collection, and i is the ID
number you're looking for.
Returns true or false.
=end
=begin
This module contains settings that allow you to customise
the photo system.
=end
module SelFeenaPhotoModule
MaxPhotos = 8 # Number of photos allowed in collection.
end
###############################
###############################
## ##
## DON'T GO PAST HERE! ##
## ##
###############################
###############################
=begin
Update Game_Party to include access to photo data.
=end
class Game_Party < Game_Unit
alias selfeena_init initialize
def initialize
@photos = []
selfeena_init
end
def getPhotoCount
return @photos.length
end
def getPhoto(i)
return @photos[i]
end
def delPhoto(i)
@photos.delete_at(i)
end
def addPhoto(p)
if(@photos.length == SelFeenaPhotoModule::MaxPhotos)
@photos.delete_at(0)
end
@photos.push(p)
end
end
=begin
Class encapsulating photo data.
=end
class SelFeenaPhoto
def initialize
# Save image data...
@image_data = Graphics.snap_to_bitmap
# Save Map ID...
@map_id = $game_map.map_id
# Save player position and direction...
@player_x = $game_player.x
@player_y = $game_player.y
@player_dir = $game_player.direction
# Save xy position of photo (top-left corner) as map coordinates
@photo_pos_x = $game_map.display_x / 256
@photo_pos_y = $game_map.display_y / 256
# What events have we captured in the photo?
arr = []
for x in @photo_pos_x..(@photo_pos_x + 16)
if(x >= $game_map.width) # Horizontal loop fix
x -= $game_map.width
end
for y in @photo_pos_y..(@photo_pos_y + 12)
if(y >= $game_map.height) # Vertical loop fix
y -= $game_map.height
end
arr = arr + $game_map.events_xy(x, y)
end
end
# For each event within photo, store data...
@event_data = []
for i in arr
i_swa = $game_self_switches[[$game_map.map_id, i.id, "A"]]
i_swb = $game_self_switches[[$game_map.map_id, i.id, "B"]]
i_swc = $game_self_switches[[$game_map.map_id, i.id, "C"]]
i_swd = $game_self_switches[[$game_map.map_id, i.id, "D"]]
@event_data.push([i.id,[i.x,i.y],[i_swa,i_swb,i_swc,i_swd]])
end
end
def dispose
@image_data.dispose
end
def getImage
return @image_data
end
def getLocationID
return @map_id
end
def getPlayerPosition
return [@player_x, @player_y, @player_dir]
end
def getPhotoPosition
return [@photo_pos_x, @photo_pos_y]
end
def getEventCount
return @event_data.length
end
def hasEventWithID(target_id)
result = false
for i in @event_data
if i[0] == target_id
result = true
end
end
return result
end
end
Thanks for your time!
