Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Cave Circle of Light Effect...

Kraft

Sponsor

Hey, while back Sephiroth gave me a script that places circles of light around the player and events when all the lights go out. I know how to do this with a pic placed ofer the screen, but I also want it around key events (such as torches, fires, lanterns, etc)

I have the script, but it is very laggy if there is more than 2 or 3 circles in the map, or if the circles are too big.

I love the script, I use it a lot, but I would like to know if there is anything that anyone (mainly seph) could do to improve the framerate, and possibly instead of a hard edge for the circle (ie, it does not fade to black, it is a hard edge) make it fade out around the edges a little.

You (seph) said that you would try it a while ago, and possibly use an pic instead of making the circle in the script.

Is there an update on this? If not then I will request one please.
If you need the script, here it is...

#==============================================================================
# ** Bitmap
#==============================================================================

class Bitmap
#--------------------------------------------------------------------------
# * Draw Circle
#--------------------------------------------------------------------------
def draw_circle(x, y, radius, color = Color.new(255, 255, 255, 255))
# Starts From Left
for i in (x - radius)..(x + radius)
# Finds Distance From Center
sa = (x - i).abs
# Finds X Position
x_ = i < x ? x - sa : i == x ? x : x + sa
# Finds Top Vertical Portion
y_ = Integer((radius ** 2 - sa ** 2) ** 0.5)
# Draws Vertical Bar
self.fill_rect(x_, y - y_, 1, y_ * 2, color)
end
end
end

#==============================================================================
# ** Game_System
#==============================================================================

class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :circle_of_light_on
attr_accessor :circle_of_light_opacity
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_gamesys_init initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_gamesys_init
# Turns On Defaults
@circle_of_light_on = false
@circle_of_light_opacity = 225
end
end

#==============================================================================
# ** Game_Player
#==============================================================================

class Game_Player
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :circle_of_light_on
attr_accessor :circle_of_light_radius
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_gameplyr_init initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_gameplyr_init
# Turns On Defaults
@circle_of_light_on = true
@circle_of_light_radius = 60
end
end

#==============================================================================
# ** Spriteset_Map
#==============================================================================

class Spriteset_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_ssmap_init initialize
alias seph_col_ssmap_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_ssmap_init
# Creates Circle Of Light Sprite
@circle_of_light_sprite = Sprite.new
@circle_of_light_sprite.bitmap = Bitmap.new(640, 480)
@circle_of_light_locations = {}
# Update
update
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# Original Initialization
seph_col_ssmap_update
# Stop If no Circle Of Light Sprite
unless @circle_of_light_sprite.nil?
# Update Visibilty
@circle_of_light_sprite.visible = $game_system.circle_of_light_on
# If Sprite Visible
if @circle_of_light_sprite.visible
# Update Circle Of Light
seph_col_updatecircleoflight
end
end
end
#--------------------------------------------------------------------------
# * Redraw Player Test
#--------------------------------------------------------------------------
def seph_col_redrawplayertest
# Test For Player Redraw
if $game_player.circle_of_light_on
# If Light Locations Don't Include Player
unless @circle_of_light_locations.has_key?(0)
# Returns Redraw
return true
# If Light Locations Include Player
else
# If Player Location Same
if @circle_of_light_locations[0][0] != $game_player.screen_x ||
@circle_of_light_locations[0][1] != $game_player.screen_y
# Returns Redraw
return true
end
end
end
# Returns Dont Redraw
return seph_col_redraweventstest
end
#--------------------------------------------------------------------------
# * Redraw Events Test
#--------------------------------------------------------------------------
def seph_col_redraweventstest
# Check All Events
$game_map.events.keys.each do |event_id|
# Returns Redraw If Need to Redraw Event
return true if seph_col_redraweventtest(event_id)
end
# Returns Dont Redraw
return false
end
#--------------------------------------------------------------------------
# * Redraw Event Test
#--------------------------------------------------------------------------
def seph_col_redraweventtest(event_id)
# Get Event Data
event = $game_map.events[event_id]
# Return if no List
return if event.list.nil?
# Checks All Event Commands
for i in 0...event.list.size
# Check For Comment Command
if event.list.code == 108
# Check For Circle of Light Comment
if event.list.parameters[0].include?('Circle Of Light')
# If Light Locations Dosen't Include Event
unless @circle_of_light_locations.has_key?(event_id)
# Returns Redraw
return true
# If Light Locations Include Event
else
# If Event Location Different
if @circle_of_light_locations[event_id][0] != event.screen_x ||
@circle_of_light_locations[event_id][1] != event.screen_y
# Returns Redraw
return true
end
end
end
end
end
# Returns Don't Redraw
return false
end
#--------------------------------------------------------------------------
# * Frame Update : Circle Of Light
#--------------------------------------------------------------------------
def seph_col_updatecircleoflight
# Stop If Not Redrawing Player or Event Circles
return unless seph_col_redrawplayertest
# Redraw Sprite Cover
color = Color.new(0, 0, 0, $game_system.circle_of_light_opacity)
@circle_of_light_sprite.bitmap.fill_rect(0, 0, 640, 480, color)
# Circle Color
circle_color = Color.new(0, 0, 0, 0)
# Redraw Player Circles
if seph_col_redrawplayertest
# Player Circle Center & Radius
x = $game_player.screen_x
y = $game_player.screen_y
r = $game_player.circle_of_light_radius
# Store X & Y Coordinates
@circle_of_light_locations[0] = [x, y]
@circle_of_light_sprite.bitmap.draw_circle(x, y - 32, r, circle_color)
# Redraw Event Circles
# Checks All Events
$game_map.events.each do |event_id, event|
# Next if nil list
next if event.list.nil?
# Checks All Event Commands
for i in 0...event.list.size
# Check For Comment Command
if event.list.code == 108
# Check For Circle of Light Comment
if event.list.parameters[0].include?('Circle Of Light')
event.list.parameters[0].dup.gsub(/(\d+)/, '')
# Collects Circle Center & Redius
x = event.screen_x
y = event.screen_y
r = $1.to_i
# Store Event Circle X & Y
@circle_of_light_locations[event_id] = [x, y]
# Draw Circle
@circle_of_light_sprite.bitmap.draw_circle(x, y - 16, r, circle_color)
end
end
end
end
end
end
end


Thanks

Kraft
 
I have an updated version that uses pics, the problem being that if your pictures overlap, you end up drawing over one circle, so it doesn't work perfectly.

I still recommend it, since you can use the pics for events that don't move, and just use the bitmap draw_circ method for the player and moving objects.

I will try to dig it up and do a little work on it tomorrow at work.
 

Kraft

Sponsor

Cool, thanks!

Also, I have one thought...
could you make it so that if I were place a comment (such as "Guard") and a script switch into an event (the event I am thinking of would be a guard) and the player enters that circle of light around the event, it switches on the switch in the event?

This would be used in a dark room, where guards are patrolling, and if the players feet (the unit/square that he is standing on, not the circle of light around you) enters the guards, it flips the switch defined in the event.

Or possibly a Self-switch, if possible, so I dont have tons of switches.

This would also be useful in a lighted room, just dim the lights a tiny bit, so that you can see the circle of light around the guard, and avoid it.

That way I could make the guards patroll.

Thanks,

Kraft
 
Ok. Here's a demo I did. Took a bit longer than I thought, but yeah.

Demo

Let me know if you don't understand anything. It's time for a break for me. I will be back in probably 30 minutes - hour to answer any questions you may have.
 

Kraft

Sponsor

one question...

Is it possible with this script to change the size of the circle around the events?

and in the script, where it says effected maps, Yes I understand that I need to put the map ID #'s there, but if I were to add more than one, would I just use a comma?

Thanks!

Kraft

Edit,

Also, Is it possible to change the players circle of light radius in the game?
with a script call or something?
 
Hehe. Instructions coming now.

Defaults:
~ Affected Maps : Affected_Maps = [map_id, ...]
~ Default Cover Color : Cover_Color = Color.new(r, g, b, a)
~ Player Radius : Player COL Radius = n or 'filename'

Circle of Light Customizables
~ Turning On or Off Via Script
$game_map.cavelighteffects.on = true or false
~ Turning Player On or Off Via Script
$game_map.cavelighteffects.player_on = true or false
~ Changing Player Radius
$game_map.cavelighteffects.player_radius = n or 'filename'

Event Setup
~ Setting Radius (Using Draw Circle Method)
Comment : CIRCLE OF LIGHT (n) *
~ Setting Radius (Using File BLT)
Comment : CIRCLE OF LIGHT (filename)


Setting Circle of Light Manually for events
$game_map.events[event_id].col_radius = n or 'filename'



n = Number
'filename' = Picture Filename in Pictures Folder


It draws the highest number event first and the player last. Example : 8, 6, 5, 4, 2, 1, Player, so I suggest making stationary objects your high events and using draw circle methods for moving events / player with low event ids.

You can use files to transfer for the player or the draw circle. If you define a number, it uses the draw circle command. If you specify a string ('filename'), it uses a picture from the picture folder.


I didn't do the Event trigger, but that can be done with Near's Event Triggers with his View Range Module.
 

sixdd

Sponsor

I tried this system and like the way it works, but I have run into a bug with the pictures.

When setting a picture to the player rather than the "circle" I get this error.

Code:
Undefined method 'player_rad' for #<Game_CaveLightEffects:0x67603c8>

This only happens when the character is set to use an image, events work fine.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top