Forum

> > CS2D > Scripts > Return true if line from pos to pos is clear
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Return true if line from pos to pos is clear

14 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Re: Return true if line from pos to pos is clear

Bowlinghead
User Off Offline

Zitieren
I think user Infinite Rain means lua...
(Its in "Scripts" section!)

You can use

1
if tile(x,y,"walkable") then
or
1
if tile(x,y,"obstacle")~=true then

And this can help (Never worked with):
1
imagepos(id,x,y,rot)		Changes position and rotation (0°-360°) of an image
2× editiert, zuletzt 18.10.11 16:16:50

alt Re: Return true if line from pos to pos is clear

DannyDeth
User Off Offline

Zitieren
the coordinates are in tiles:
1
2
3
4
5
6
7
8
9
10
11
12
function checkClearPath(start_x,start_y,destination_x,destination_y)
	rot = math.atan2(destination_y - start_y,desitnation_x - start_x ) -- finds rotation
	local tmpx = start_x; local tmpy = start_y -- these are used to store currect pos
	while(tmpx < destination_x and tmpy < destination_y) do --fixed it :)
		tmpx = tmpx + math.cos(rot)
		tmpy = tmpy + math.sin(rot)
		if not tile(tmpx,tmpy,"walkable") then
			return false
		end
	end
	return true
end
1× editiert, zuletzt 18.10.11 17:05:00

alt Re: Return true if line from pos to pos is clear

HeroBurak
BANNED Off Offline

Zitieren
user DannyDeth hat geschrieben
the coordinates are in tiles:
1
2
3
4
5
6
7
8
9
10
11
12
function checkClearPath(start_x,start_y,destination_x,destination_y)
	rot = math.atan2(destination_y - start_y,desitnation_x - start_x ) -- finds rotation
	local tmpx = start_x; local tmpy = start_y -- these are used to store currect pos
	while(tmpx < destination_x and tmpy < destination_y) do --fixed it :)
		tmpx = tmpx + math.cos(rot)
		tmpy = tmpy + math.sin(rot)
		if not tile(tmpx,tmpy,"walkable") then
			return false
		end
	end
	return true
end



Slight improvement:

1
2
3
4
5
6
7
8
9
10
11
12
13
function checkClearPath(start_x,start_y,destination_x,destination_y)
	rot = math.atan2(destination_y - start_y,destination_x - start_x ) -- finds rotation
	local tmpx = start_x; local tmpy = start_y -- these are used to store currect pos
	local xincrement = math.cos(rot); local yincrement = math.sin(rot)
	while(tmpx < destination_x and tmpy < destination_y) do --fixed it :)
		tmpx = tmpx + xincrement
		tmpy = tmpy + yincrement
		if not tile(tmpx,tmpy,"walkable") then
			return false
		end
	end
	return true
end

alt Re: Return true if line from pos to pos is clear

MikuAuahDark
User Off Offline

Zitieren
it uses tile:
code:
Spoiler >

bdw it's uses rectangular area. sorry if im wrong!
2× editiert, zuletzt 20.10.11 08:47:51

alt Re: Return true if line from pos to pos is clear

Apache uwu
User Off Offline

Zitieren
btw there's no point in putting a semicolon, this isn't php or java

1
local tmpx = start_x local tmpy = start_y

or

1
2
local tmpx = start_x
	local tmpy = start_y

or

1
local tmpx,tmpy = start_x,start_y

@how to rotate image to position?

Could use tween_rotate. If you want to find the angle use

1
angle=Math.atan(y1-y2,x1-x2)

alt Re: Return true if line from pos to pos is clear

DannyDeth
User Off Offline

Zitieren
@Textual Context:
You don't know everything, putting:
1
local xincrement = (blablabla) local yincrement = (blablabla)
Will yield you nothing but an error. The semi-colon is there to separate the two statements.

Edit: Eh. Turns out I was wrong. NVMD! You do know everything.

Edit2: It's still bad form, though. The semi-colon makes it more readable.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht