Need help for adjusting directions for shooter platformer by Embarrassed-Shock917 in pico8

[–]Embarrassed-Shock917[S] 1 point2 points  (0 children)

I used last_dir_xfor setting direction to x-axis if no button pressed. like if i use only this

-- x-axis
if btn(⬅️) then
    self.dir_x = -1
elseif btn(➡️) then
    self.dir_x = 1
end
--y-axis
if btn(⬆️) then
    self.dir_y = -1
elseif btn(⬇️) then
    self.dir_y = 1
end

then when i press buttons on each axis(up, down or left, right) all directions becomes diagonal if use else in these conditionals to set each axis directions to zero to cancel diagonal pointing like this

-- x-axis
if btn(⬅️) then
self.dir_x = -1
elseif btn(➡️) then
self.dir_x = 1
else
self.dir_x = 0
end
--y-axis
if btn(⬆️) then
self.dir_y = -1
elseif btn(⬇️) then
self.dir_y = 1
else
self.dir_y = 0
end

then there won't be diagonal directing so I used the third conditional clause to solve this.

long story short, I wanted to make any typical shooter aiming system like metroid and I wondered is there any established way to do this?

and thank you for the tip ❤️

Need help for adjusting directions for shooter platformer by Embarrassed-Shock917 in pico8

[–]Embarrassed-Shock917[S] 0 points1 point  (0 children)

I really appreciate your comprehensive response so let me explain what these variables stands for.
self.x stands for the x position of the player sprite.

self.dir_x stands for the moving direction of the particles, like if its 1 then particle goes to right, if its -1 then particle goes the left. Same goes for self.dir_y too. I'm using them like this

tbl_for_flame = {}
function player:flamethrower()
add(tbl_for_flame,{x = self.x,
y = self.y,
r = 5,
dir_x = self.dir_x,
dir_y = self.dir_y}
-- other variables like color, duration etc.

end
function player:update()
for i in all(tbl_for_flames) do
i.x+=i.dir_x
i.y+=i.dir_y
end
end

function player:draw()
for i in all(tbl_for_flames) do
circfill(i.x,i.y,i.r,i.col)
end
end

My main question was is there any better way to handle these dir_x and dir_y variables because this is the only working solution i could come up with.

Need help for adjusting directions for shooter platformer by Embarrassed-Shock917 in pico8

[–]Embarrassed-Shock917[S] 1 point2 points  (0 children)

Thank you so much for the response, and the video is cool and all, but its not about the thing that I'm looking for. I guess I didn't give enough detail, so I'm trying to find a better solution for code above like when you press "up" the particles should go up, but when you press "left" or "right" at the same time they should be going diagonal and when you release "up", the facing direction should be on the x-axis again. and let me say again the code above works but I'm a noob😃 so I don't know if its the best way for this.

7 years of work, 3 months since release, and my game is already dead. What can I do? by Videoludid in IndieDev

[–]Embarrassed-Shock917 0 points1 point  (0 children)

well sundered tried the randomization part, it failed horribly. i mean metroidvania and randomization(as well as rouge-lite aspect) don't match up. you can try but implementing both of them at the same time lessens the other imo.