Coordinates infront of Player

Hello, I have some trouble figuring out an algorithm to calculate the coordinates in front of the player.

                                             # x, y

Lets say you have an array: [3, 3]

The players coordinates are for example: 5, 5

Now I want to get the Coordinates infront of the player in a 3x3 Field( 0 = The Coordinates I want based on the facing of the player):

Player facing up:X X X X X X X X X XX X X 0 0 0 X X X XX X X 0 0 0 X X X XX X X 0 0 0 X X X XX X X X ^ X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XPlayer facing left:X X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX 0 0 0 X X X X X XX 0 0 0 < X X X X XX 0 0 0 X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XIf the Array would be [1, 5] for example it should give me following coordinates:

Player facing right:X X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X > 0 0 0 0 0X X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XX X X X X X X X X XHelp is really appreciated.
I ever wrote a simple snippet to get coordinate right in front of player

class Game_Player < Game_Character def front_x $game_map.round_x_with_direction(@x,@direction) end def front_y $game_map.round_y_with_direction(@y,@direction) end endIt's used within Game_Event to determine if the event is right in front of player or not

class Game_Event def in_front_of_player? self.x == $game_player.front_x && self.y == $game_player.front_y endendI hope it will do a hint 🙂
Thanks for your response.

Here is the snipped I made, but Its so complicated and I hope that there are some easier ways for this:

class Game_Character def x_offset(direction) case direction when 2, 8 return 1 else return 0 end end def y_offset(direction) case direction when 4, 6 return 1 else return 0 end end def get_front_coordinates(px, py, d, columns, rows) temp_x = [] temp_y = [] temp_coordinates = [] start_x = columns / 2 start_y = rows / 2 columns.times do |i| if x_offset(d).zero? temp_x.push(d == 4 ? i * (-1) : i) else temp_x.push(start_x * x_offset(d)) start_x -= 1 end end rows.times do |i| if y_offset(d).zero? temp_y.push(d == 8 ? i * (-1) : i) else temp_y.push(start_y * y_offset(d)) start_y -= 1 end end temp_x.each do |x| temp_y.each do |y| t_x = $game_map.round_x_with_direction(px, d) + x t_y = $game_map.round_y_with_direction(py, d) + y temp_coordinates.push([t_x, t_y]) end end return temp_coordinates endendIt works how I want it to work, but I hope that someone have a better way for doing this.

And this snipped works only correct with uneven numbers for rows, but this isnt a problem, cause I will never use even numbers for rows.

Ok the snipped above had got some errors, this version should be error free, but im still wondering if anyone have something better:

Spoiler
Code:
def get_front_coordinates(px, py, d, columns, rows)    temp_x = []    temp_y = []    temp_coordinates = []    start_x = columns / 2    start_y = rows / 2        columns.times do |i|      temp_x.push(start_x)      start_x -= 1    end        rows.times do |i|      temp_y.push(i)    end        if d == 4 || d == 6      temp_x, temp_y = temp_y, temp_x      temp_y.map!{|e| e * -1}    end        if d == 4 || d == 8      temp_y.map!{|e| e * -1}       temp_x.map!{|e| e * -1}    end        temp_x.each do |x|      temp_y.each do |y|        t_x = $game_map.round_x_with_direction(px, d) + x         t_y = $game_map.round_y_with_direction(py, d) + y        temp_coordinates.push([t_x, t_y])      end    end    return temp_coordinates  end

Original thread: https://forums.rpgmakerweb.com/threads/coordinates-infront-of-player.27400/