RPG Maker Forums

Here's the first part of my line of sight implementation.

I say tutorial, but it's basically me writing it as I go.

First, I want to be able to visualize my line of sight. Tilemap natively supports tile flashing, so I make use of that.



This is the code I use to draw my highlights.

It is updated every frame.

class Scene_Map def update_highlight(tiles) @spriteset.reserve_highlights(tiles) if @spriteset endendclass Spriteset_Map alias :th_event_trigger_range_create_tilemap :create_tilemap def create_tilemap th_event_trigger_range_create_tilemap @reserved_tiles = [] clear_highlights end alias :th_trigger_range_highlight_update_tilemap :update_tilemap def update_tilemap th_trigger_range_highlight_update_tilemap update_highlights end def update_highlights clear_highlights @reserved_tiles.each do |pos| @tilemap.flash_data[pos[0], pos[1]] = 0x8f2 end @reserved_tiles.clear end def reserve_highlights(tiles) @reserved_tiles.concat(tiles) end def clear_highlights @tilemap.flash_data = Table.new($game_map.width, $game_map.height) endend
And here's some code that shows the player's line of sight

class Game_Player @@sight = 12 alias :th_los_update :update def update th_los_update update_line_of_sight end def update_line_of_sight arr = [] @@sight.times {|i| arr << [@x + normalize_dir_x * i, @y + normalize_dir_y * i] } SceneManager.scene.update_highlight(arr) end def normalize_dir_x case @direction when 4 return -1 when 6 return 1 else return 0 end end def normalize_dir_y case @direction when 2 return 1 when 8 return -1 else return 0 end endend
It currently does not implement obstacle checking, but that's the next step after being able to visualize it.

It also assumes 4-dir line of sight.

Feel free to point out anything that can be improved.

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top