Page 1 of 1

[SOLVED] Help with rotation

Posted: Sun Oct 18, 2015 1:41 pm
by zikesha93
Hi I was working on a simple dungeon crawler maze, I am basically drawing walls on the screen with love.draw.polygon().
I placed everything into neat tables so i don't have to retype the co-ordinates. The units go by width 100, height 100.

You can use the arrow keys to move around (navigate the table when key is released). I am sort of stuck with the rotation part. I am using the , and . keys to rotate (, is rotate counter clockwise . is rotate clockwise).

The problem is when I rotate the co-ords go off, Is there an easy way to do this?

I want to rotate into a new table and keep the orientation right with x and y.

Also Im really wasting a lot of space with empty polygons just to keep things square. This means the collision does not work and you can go straight through walls.

My aim is to make a simple FPS Dungeon Crawler like some of the first DOS games.
screenshot 2
screenshot 2
Screen Shot 2015-10-18 at 4.33.45 PM.png (26.53 KiB) Viewed 2929 times
screenshot 1
screenshot 1
Screen Shot 2015-10-18 at 4.28.51 PM.png (22.16 KiB) Viewed 2929 times
FPS_POLY.love
File Download
(2.03 KiB) Downloaded 194 times
x = x array in table (left and right)
y = y array in table (forward and backwards)
t = table chunk with a bunch of walls for each step.
v[t][x][y][j] would get you a point. v[t][x][y] would get you a bunch of points in a tables (one polygon).

Re: Help with rotation

Posted: Sun Oct 18, 2015 8:55 pm
by zikesha93
I figured it out. you just have to map each co-ordinate yourself manually each time the map table changes to keep the orientation in place.

So you would need to get the area of your x and y and just string in lots and lots of if statements for each possible co-ord.

Code: Select all

    
        if x == 1 and y == 1 then x = new_x;y = new_y end
	if x == 2 and y == 1 then x = new_x;y = new_y end
	if x == 3 and y == 1 then x = new_x;y = new_y end
	if x == 4 and y == 1 then x = new_x;y = new_y end
	if x == 5 and y == 1 then x = new_x;y = new_y end
	if x == 1 and y == 2 then x = new_x;y = new_y end
	if x == 2 and y == 2 then x = new_x;y = new_y end
	if x == 3 and y == 2 then x = new_x;y = new_y end
	if x == 4 and y == 2 then x = new_x;y = new_y end
	if x == 5 and y == 2 then x = new_x;y = new_y end
	if x == 1 and y == 3 then x = new_x;y = new_y end
	if x == 2 and y == 3 then x = new_x;y = new_y end
	if x == 3 and y == 3 then x = new_x;y = new_y end
	if x == 4 and y == 3 then x = new_x;y = new_y end
	if x == 5 and y == 3 then x = new_x;y = new_y end
	if x == 1 and y == 4 then x = new_x;y = new_y end
	if x == 2 and y == 4 then x = new_x;y = new_y end
	if x == 3 and y == 4 then x = new_x;y = new_y end
	if x == 4 and y == 4 then x = new_x;y = new_y end
	if x == 5 and y == 4 then x = new_x;y = new_y end
	if x == 1 and y == 5 then x = new_x;y = new_y end
	if x == 2 and y == 5 then x = new_x;y = new_y end
	if x == 3 and y == 5 then x = new_x;y = new_y end
	if x == 4 and y == 5 then x = new_x;y = new_y end
	if x == 5 and y == 5 then x = new_x;y = new_y end
WOW COMPUTERS ARE SOOO STUPID!!!

Re: Help with rotation

Posted: Sun Oct 18, 2015 11:37 pm
by zorg
zikesha93 wrote:

Code: Select all

    
       -- why
or...

Code: Select all

for i= 0,all_possible_x_values do
  for j= 0,all_possible_y_values do
    x = new_x; y = new_y
  end
end
or at least, that's how your snippet can be optimized... without other info about it, this may be wrong though.

[SOLVED] Help with rotation

Posted: Mon Oct 19, 2015 10:17 am
by zikesha93
zorg wrote:
zikesha93 wrote:

Code: Select all

    
       -- why
or...

Code: Select all

for i= 0,all_possible_x_values do
  for j= 0,all_possible_y_values do
    x = new_x; y = new_y
  end
end
or at least, that's how your snippet can be optimized... without other info about it, this may be wrong though.
Good idea

--rotate right

Code: Select all

-- rotating right
for i= 0,all_possible_x_values do
for j= 0,all_possible_y_values do
    x = i + change_in_x; y = j + change_in_y
end
end
--rotate left

Code: Select all

-- rotating left
for i= 0,all_possible_x_values do
for j= 0,all_possible_y_values do
    x = i - change_in_x; y = j - change_in_y
end
end