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.

Day/Night and Onscreen Clock! Plus Clear Lights

Star

Sponsor

Idea1.png

This is me taking a screenshot of my game and putting it in a paint program and making my own lights using another layer

Idea2.png

This is me having lights appear at night in my game. As you can see the lights go over top of the dark layer and don't actually clear it up. I wanna able to open up the dark layer.

Any ideas on how I could go about working around this?
 
Ummmm, instead of adding white, subtract black.
Your base is a "daylight" map. The overlay is mostly black (semi-transparent). The areas with the lights are more transparent.

Lemme see if I can find an example...

cave.png
+
fog.png
=

cave_fog.png
 

Star

Sponsor

So you're saying I should create a overlaying picture for it that has all the light shades and stuff. Well, that would work if everything was the same thing, but I'm doing a DNS so 24 hour light duty. Can you imagine making lighted maps for all 12 of 24 hours on 100x100 maps O_O. People will scream at me for file size.

Let me explain this a little better.

I'm using a fog that's just a dark transparent overlay of the map, Pretty much would work the same as change screen color tone in the event page.

But I want a way to make an animation that cuts through either the tone or the fog making it appear to be a light source.

Is there a way to do that? Or am I screwed into making lots of picture files? :(
 
The problem with having a light system that dynamic is that the only way to do it properly is to do it in a 3D game. Any time you do it in a 2D game, you either have to have no dynamic light system, a few set times of day (a la Pokemon Gold, Silver, and Crystal) or a fuckton of images to represent every possible time of day, which just isn't an option.
 
I was merely suggesting a strategy. Adding white at any transparency will make it look 'foggy' / 'hazy'.
What if you placed your animations first, then filled in the rest of the fog overlay with a single 'fill' color?
As long as you know where the animations are, we could write a 'Fill' script to lay in a single color wherever the animations 'aren't'.
You'd just need to match the edges of your animations to the fill color.
 

Star

Sponsor

Thanks for your help guys. You've been a ton of help. I see that. I know your first strategy, brew, would be the wisest. If I had smaller maps itd be easy to work with and I can move shadows during the suns motions. But since that would require lots of effort and time and a ton of images I'll try your second suggestion for now. I had thought of that in my head and I did think of filling the places where animations didn't go. But I was gonna do it in lots of events which would be horrible for my size map. I'm willing to try scripting this out. I hadn't really thought of it. I'm still very low level at scripting. I made my own cms once and edited a lot of things and still try. If you can help me figure how to do this it would be great. I know the class would be scene_map but how would I make a fill "unless animation present"?
 
I was playing around with this a little bit. It's not as easy as you'd think!!! :)
I think the best solution would be to add functionality to the fog layer itself, and use 'subtraction' images to do the animation.
i.e. your light image would be black in the center, at the light source, then fade to white around the edges.
Then when subtracted from the fog, whatever color/tone, it would produce a nice realistic light effect.

The other problem would be moving lights. Flashlight, torch, etc.. I noticed you had a light on the player above.
Maybe this is just a matter of having another subtraction object on the fog layer, and synchronizing it with the player.

Did you look at any of the other Dynamic Light scripts that are already available?
Do that first, and see if anything will suit. Maybe we can make some tweaks from there.
 

Star

Sponsor

Code:
class Nightime < Sprite

  def initialize(x,y)

    super()

    width = 32

    height = 32

    @width = width

    @height = height

    self.x = x

    self.y = y

    self.bitmap = Bitmap.new(@width, @height)

    self.bitmap.clear

    fillnight

  end

  def refresh

   self.bitmap.clear

   fillnight

   end

  def fillnight

    @width = 32

    @height = 32

 if $game_variables[9] == 0 or $game_variables[9] == 2 or

        $game_variables[9] == 24 or $game_variables[9] == 23 or

        $game_variables[9] == 22 or $game_variables[9] == 1

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,210))

  end

      if $game_variables[9] == 3 or $game_variables[9] == 21

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,180))

  end

      if $game_variables[9] == 4 or $game_variables[9] == 20

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,150))

  end

      if $game_variables[9] == 5 or $game_variables[9] == 19

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,120))

  end

      if $game_variables[9] == 6 or $game_variables[9] == 18

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,90))

  end

      if $game_variables[9] == 7 or $game_variables[9] == 17

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,30))

  end

      if $game_variables[9] == 8 or $game_variables[9] == 9 or

        $game_variables[9] == 10 or $game_variables[9] == 11 or

        $game_variables[9] == 12 or $game_variables[9] == 13 or

        $game_variables[9] == 14 or $game_variables[9] == 15 or

        $game_variables[9] == 16

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,0))

  end

end

 

end

 

 

class Spriteset_Map

   def initialize

    # Make viewports

    @viewport1 = Viewport.new(0, 0, 640, 480)

    @viewport2 = Viewport.new(0, 0, 640, 480)

    @viewport3 = Viewport.new(0, 0, 640, 480)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @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

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @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(@viewport1, $game_player))

    # Make weather

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

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Frame update

    @nightime = Nightime.new(0,0)

    update

  end

  def update

    

    # If panorama is different from current one

    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 is different than current fog

    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

    # Update tilemap

    @tilemap.ox = $game_map.display_x / 4

    @tilemap.oy = $game_map.display_y / 4

    @tilemap.update

    # Update panorama plane

    @panorama.ox = $game_map.display_x / 8

    @panorama.oy = $game_map.display_y / 8

    # Update fog plane

    @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

    # Update character sprites

    for sprite in @character_sprites

      sprite.update

    end

    # Update weather graphic

    @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

    # Update picture sprites

    for sprite in @picture_sprites

      sprite.update

    end

    # Update timer sprite

    @timer_sprite.update

    # Set screen color tone and shake position

    @viewport1.tone = $game_screen.tone

    @viewport1.ox = $game_screen.shake

    # Set screen flash color

    @viewport3.color = $game_screen.flash_color

    # Update viewports

    @viewport1.update

    @viewport3.update

  end

end

 

class Game_Map

    def initialize

    @map_id = 0

    @display_x = 0

    @display_y = 0

    @hour_of_day = $game_variables[9]

  end

  def update

    if @hour_of_day == $game_variables[9]

      

    else

      @Nightime.refresh

      @hour_of_day = $game_variables[9]

      end

    # Refresh map if necessary

    if $game_map.need_refresh

      refresh

    end

    # If scrolling

    if @scroll_rest > 0

      # Change from scroll speed to distance in map coordinates

      distance = 2 ** @scroll_speed

      # Execute scrolling

      case @scroll_direction

      when 2  # Down

        scroll_down(distance)

      when 4  # Left

        scroll_left(distance)

      when 6  # Right

        scroll_right(distance)

      when 8  # Up

        scroll_up(distance)

      end

      # Subtract distance scrolled

      @scroll_rest -= distance

    end

    # Update map event

    for event in @events.values

      event.update

    end

    # Update common event

    for common_event in @common_events.values

      common_event.update

    end

    # Manage fog scrolling

    @fog_ox -= @fog_sx / 8.0

    @fog_oy -= @fog_sy / 8.0

    # Manage change in fog color tone

    if @fog_tone_duration >= 1

      d = @fog_tone_duration

      target = @fog_tone_target

      @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d

      @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d

      @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d

      @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d

      @fog_tone_duration -= 1

    end

    # Manage change in fog opacity level

    if @fog_opacity_duration >= 1

      d = @fog_opacity_duration

      @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d

      @fog_opacity_duration -= 1

    end

  end

end

 

 

Okay, I gave it a shot, but I have trouble refreshing the thing during the time change. It gives me an undef variable when I do $Nightime.refresh I'm not sure I'm doing it right, infact, i know I'm not. Plus, I haven't got it to span over the map yet.. Argh, this is hard.
 
Ok, this takes care of the nighttime sprite, and updating it.
I bumped it up to 640x480 just to test it.

Code:
class Nighttime < Sprite

  def initialize(x,y)

    super()

    @width = $game_map.width * 32

    @height = $game_map.height * 32

    self.x = x

    self.y = y

    self.bitmap = Bitmap.new(@width, @height)

    self.bitmap.clear

    fillnight

  end

  

  def refresh

    self.bitmap.clear

    fillnight

  end

 

  def fillnight

    case $game_variables[9]

    when 0,1,2,22,23,24

      alpha = 210

    when 3,21

      alpha = 180

    when 4,20

      alpha = 150

    when 5,19

      alpha = 120

    when 6,18

      alpha = 90

    when 7,17

      alpha = 30

    else

      alpha = 0

    end

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,alpha))

  end

end

 

 

class Spriteset_Map

   def initialize

    # Make viewports

    @viewport1 = Viewport.new(0, 0, 640, 480)

    @viewport2 = Viewport.new(0, 0, 640, 480)

    @viewport3 = Viewport.new(0, 0, 640, 480)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @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

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @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(@viewport1, $game_player))

    # Make weather

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

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Make nighttime sprite

    @nighttime = Nighttime.new(0,0)

    @hour = 0

    # Frame update

    update

  end

  def update

    # If panorama is different from current one

    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 is different than current fog

    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

    # Update tilemap

    @tilemap.ox = $game_map.display_x / 4

    @tilemap.oy = $game_map.display_y / 4

    @tilemap.update

    # Update panorama plane

    @panorama.ox = $game_map.display_x / 8

    @panorama.oy = $game_map.display_y / 8

    # Update fog plane

    @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

    # Update character sprites

    for sprite in @character_sprites

      sprite.update

    end

    # Update weather graphic

    @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

    # Update picture sprites

    for sprite in @picture_sprites

      sprite.update

    end

    # Update timer sprite

    @timer_sprite.update

    # Update nighttime sprite

    if @hour != $game_variables[9]

      @nighttime.refresh

    end

    # Set screen color tone and shake position

    @viewport1.tone = $game_screen.tone

    @viewport1.ox = $game_screen.shake

    # Set screen flash color

    @viewport3.color = $game_screen.flash_color

    # Update viewports

    @viewport1.update

    @viewport3.update

  end

end

Of course, we'll need a way to control the size. Probably just extract it from the map size.
(If we weren't adding lights, we could just use a Plane object instead of a Sprite.)

Then we can take a look at how to implement the lights.

[edit] got the map size..
 

Star

Sponsor

Hmm.. Now that I think about it. If I can get this to work from the map and paste a 32 x 32 Square on every tile according to the map size. I can tell it not to paste a tile if a tile has a terrain tag of a certain number so i can place lights. Since there will be no moving lights. I can only seem to get it to paste a 32x32 on the screen itself that scrolls with it instead of staying put.

I do like how you edited and made it much more simpler, I learn something everyday, and I like how the update thing was soo easy yet I couldn't figure it out. "Case" seems much more helpful than pasting a crap load of "IF MY SWORD IS YELLOW TWO"

I know if I can get this to work as a fourth layer of the map I can use an array (is that what it's called?) the "for i in blah blah blah. Which I'll use for i in ...$game_map.width and for j in ...$game_map.height then x = i * 32 y = j * 32
 
Ah, I didn't check to see if it moved when the screen scrolled...
We just need to adjust the sprites position when the map moves. (just like the @tilemap.ox/oy & @fog.ox/oy)
Now you can use a full map width/height sprite instead of a bunch of 32x32 images.

Code:
 

    # Update nighttime sprite

    @nighttime.ox = $game_map.display_x / 4

    @nighttime.oy = $game_map.display_y / 4

    if @hour != $game_variables[9]

      @nighttime.refresh

    end

 

If you won't have any moving lights that makes it easier. My thought was just to SUBTRACT the pattern for a light from the nighttime bitmap, leaving a hole of transparency that let the 'daytime' underlying map show through. I'll see if I can make this work.

[EDIT]

Check this out...

http://www.hbgames.org/user_files/Star_ ... g_Test.exe

hit the mailbox to change the hour. You can still lay animations under the 'light hole'

If this works out, we just need to figure out how to place the lights per each map, and how to control the size of each light.
And how to turn the whole thing off on maps where it's not needed.

What you think?
 
The scene gets disposed, but I didn't dispose the 'nighttime' sprite. Easy to add.

I'm not getting any lag, and I'm also unfolding a big piece of sheet-metal on my laptop (big CAE calculation that's been running for the last 15 minutes...)

refresh only gets called when the game_variable changes (once per game hour), so although the subtraction algorithm is a bit of a hog, it only operates on a relatively small area at a time, so it shouldn't have much impact.

This is a RAD-JAD WIP, so it's nowhere near 'done'. :scruff:


Star, add this to Spriteset_Map

Code:
  alias dns_dispose dispose

  def dispose

    dns_dispose

    @nighttime.dispose

  end

 
 

Star

Sponsor

Beautiful.. This is beautiful. *tears in eyes* Amazingly fine work. Incredible.

Oh add this too

if @hour != $game_variables[9]
@nighttime.refresh
@hour = $game_variables[9]
end

Else it refreshes forever until your computer implodes. Which is what Radethdart was talking about.

Now to figure out how to comment lights as events on the map. That way you can have several maps with light locations. It seems we're moving along nicely and I feel like I haven't done crap, but I sure am learning a crap load.

"Moving lights?"
Nah, Too much for me. Would be sweet to have a guard or two walking around with a torch like in obilivion but lets take this one easy step at a time.

I know I've seen Scripts and script makers use event "Comment" as a way to do things so I'm going to see what they did and see if I can't replicate it.
 
I can't believe I left that out. I also can't believe I didn't notice the lag from it. This quad-core i7 & 8gb of Ram hammered right through it.

I like the idea of using events. One thing to keep in mind is I used an event for the fire light, and we'll want the light effect centered on the same event. My first thought was to use event.name since it's easier to access than a comment buried on a page.
But, the information we'll need to input would be the location if different than the center of the tile, and the diameter of the light effect (or which light effect picture to use)
I think pictures is better, that way if you, or anyone else wants to use it in a corner or to more accurately show the effect on a wall (bend line at the floor), they can make the subtraction picture any way they want.

This is a learning experience for me too. And it's something that's going to be pretty useful, so it's fun.
I'll let you see what you can come up with on the comment.

Radeth, it's all good! another set of eyes never hurts.

Be Well
 

Star

Sponsor

Code:
module SDK

  def self.event_comment_input(*args)

    parameters = []

    list = *args[0].list

    elements = *args[1]

    trigger = *args[2]

    return nil if list == nil

    return nil unless list.is_a?(Array)

    for item in list

      next unless item.code == 108 || item.code == 408

      if item.parameters[0] == trigger

        start = list.index(item) + 1

        finish = start + elements

        for id in start...finish

        end

          next if !list[id]

          parameters.push(list[id].parameters[0])

        return parameters

      end

    end

    return nil

  end

end

 

class Nighttime < Sprite

  def initialize(x,y)

    super()

    @width = $game_map.width * 32

    @height = $game_map.height * 32

    self.x = x

    self.y = y

    self.bitmap = Bitmap.new(@width, @height)

    self.bitmap.clear

    fillnight

  end

 

  def refresh

    self.bitmap.clear

    fillnight

  end

 

  def fillnight

    case $game_variables[9]

    when 0,1,2,22,23,24

      alpha = 210

    when 3,21

      alpha = 180

    when 4,20

      alpha = 150

    when 5,19

      alpha = 120

    when 6,18

      alpha = 90

    when 7,17

      alpha = 30

    else

      alpha = 0

    end

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,alpha))

    # Now subtract out the lights

    # Testing with a single light at tile 7,11

    light = RPG::Cache.picture("light_sub_160")

    for i in $game_map.events.keys.sort

      shiny = SDK.event_comment_input($game_map.events[i], 1, "Light")

      x = $game_map.events[shiny].x * 32

      y = $game_map.events[shiny].y * 32

    self.bitmap.sub(x,y,light)

    end

  end

end

 

 

class Spriteset_Map

   def initialize

    # Make viewports

    @viewport1 = Viewport.new(0, 0, 640, 480)

    @viewport2 = Viewport.new(0, 0, 640, 480)

    @viewport3 = Viewport.new(0, 0, 640, 480)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @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

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    # Make character sprites

    @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(@viewport1, $game_player))

    # Make weather

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

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2,

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Make nighttime sprite

    @nighttime = Nighttime.new(0,0)

    @nighttime.z = 2000

    @hour = 0

    # Frame update

    update

  end

    alias dns_dispose dispose

   def dispose

     dns_dispose

     @nighttime.dispose

   end

  def update

    # If panorama is different from current one

    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 is different than current fog

    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

    # Update tilemap

    @tilemap.ox = $game_map.display_x / 4

    @tilemap.oy = $game_map.display_y / 4

    @tilemap.update

    # Update panorama plane

    @panorama.ox = $game_map.display_x / 8

    @panorama.oy = $game_map.display_y / 8

    # Update fog plane

    @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

    # Update character sprites

    for sprite in @character_sprites

      sprite.update

    end

    # Update weather graphic

    @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

    # Update picture sprites

    for sprite in @picture_sprites

      sprite.update

    end

    # Update timer sprite

    @timer_sprite.update

    # Update nighttime sprite

    @nighttime.ox = $game_map.display_x / 4

    @nighttime.oy = $game_map.display_y / 4

    if @hour != $game_variables[9]

      @nighttime.refresh

      @hour = $game_variables[9]

    end

    # Set screen color tone and shake position

    @viewport1.tone = $game_screen.tone

    @viewport1.ox = $game_screen.shake

    # Set screen flash color

    @viewport3.color = $game_screen.flash_color

    # Update viewports

    @viewport1.update

    @viewport3.update

  end

end

Okay, I tried taking something from SDK. I'm not claiming it, they'll get credit of course. But it's not working. Throws head on spear.

I tried making it to where it sorts through all events that have Light as Comment and see if it can give me that event number and I'll be able to use that to find the x and y of them. Blast. Maybe you have an idea? I might have to keep trying at it later.
 
So brew, I was thinking about this. I really like the idea. I was thinking it would be a good idea to do something more of a block transfer for the image. You of course would have a list of other lights in the area, and would be able to determine their spread.. so you do a block transfer for what you can, then do your method to determine the difference of the remaining overlay if lights are too close. I will try to put together some mock code here in a bit.. but I am gonna eat some dinner first. Just thought I would mention it incase you are out there looking at this now.
 
Gubid, thanks for taking a look

I thought about blt, but I'm not sure if you can do a subtract other than the way I did it.
I kind of expected that under the hood, a blt replaced bits anyways (but in core, not interpreted, so faster).
I'd like to see what you come up with. I think I have a few other Bitmap extensions that would be cool to bundle up into a package.

Star, the first argument needs to be a list of commands from a page, try...

SDK.event_comment_input($game_map.events.pages[0].list, 1, "Light")

The 1 might need to be a 0, I'll plug this in & give it a try tomorrow. (Couch time with mumma :scruff: )

Since this has become a scripting project, I'm sliding it over to Script Support...

Be Well
 
Well, I didnt have time to get into the blt section of things but I did make some improvements to the code. I will get the blt transfer stuff when I get up in the morning. if my wife was calling every 20 secs to get to bed.. then I would do it now.. Here is the latest code.

Code:
 

HOUR_VARIABLE = 9

class Nighttime < Sprite

  def initialize(x,y)

    super()

    @width = $game_map.width * 32

    @height = $game_map.height * 32

    @lights = {}

    self.x = x

    self.y = y

    self.bitmap = Bitmap.new(@width, @height)

    self.bitmap.clear

    fillnight

  end

  def refresh

    self.bitmap.clear

    create_lights

    fillnight

  end

  def create_lights

    for event in $game_map.events.values

      for i in 0...event.list.size

        if event.list[i].code == 108 #comment

          if event.erased and event.list[i].parameters[0].include?("light")

            @lights.delete(event)

            next

          elsif event.list[i].parameters[0].include?("light")

            @lights[event] = Light.new(event) unless @lights.keys.include?(event)

            event.is_light = true

            next

          end

        end

      end

      #in the event page is changed and it is no longer a light.. remove it. 

      if @lights[event] != nil and event.is_light == false

        @lights.delete(event)

      end

    end

  end

  def fillnight

    case $game_variables[HOUR_VARIABLE]

    when 0,1,2,22,23,24

      alpha = 210

    when 3,21

      alpha = 180

    when 4,20

      alpha = 150

    when 5,19

      alpha = 120

    when 6,18

      alpha = 90

    when 7,17

      alpha = 30

    else

      alpha = 0

    end

    self.bitmap.fill_rect(0, 0, @width, @height, Color.new(0,0,0,alpha))

    # Now subtract out the lights

    # Testing with a single light at tile 7,11

    apply_lights

  end

  def apply_lights

    light_image = RPG::Cache.picture("light_sub_160")

    for light in @lights.values

      self.bitmap.sub(light.x,light.y,light_image)

    end

  end

end

 

class Light

  def initialize(event)

    @event = event

  end

  def x

    return @event.real_x/4 + 16

  end

  def y

    return @event.real_y/4 + 16

  end

end

    

class Spriteset_Map

  alias init_spr_map_lights initialize 

  def initialize

    # Make nighttime sprite

    @nighttime = Nighttime.new(0,0)

    @nighttime.z = 2000

    @hour = -1 #this way a refresh is called right when the map is drawn

    init_spr_map_lights

  end

  alias upd_spr_map_lights update

  def update

    upd_spr_map_lights 

    # Update nighttime sprite

    @nighttime.ox = $game_map.display_x / 4

    @nighttime.oy = $game_map.display_y / 4

    if @hour != $game_variables[HOUR_VARIABLE]

      @hour = $game_variables[HOUR_VARIABLE]

      @nighttime.refresh

    end

  end

end

class Game_Event < Game_Character

  attr_reader :erased

  attr_accessor :is_light

  alias init_gm_evnt_lights initialize

  def initialize(*args)

    init_gm_evnt_lights(*args)

    @is_light = false

  end

  alias refresh_gm_evnt_lights refresh

  def refresh

    tmp_page = @page

    refresh_gm_evnt_lights 

    if tmp_page != @page

      @is_light = false

    end

  end

end

 
 

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