Funktio & esimerkki:
Code: Select all
Global HitX, HitY
DrawToWorld ON //Primitiivien piirto maailmaan mahdolliseksi
//Kartta..
map = LoadMap("Media\cdm2.til", "Media\tileset.bmp")
Repeat
näkyvyys = ClearSight(0, 0, MouseWX(), MouseWY())
DrawGame
If Not näkyvyys Then
pointX = HitX
pointY = HitY
Color cbred
Circle pointX - 5, pointY + 5, 10, 0
EndIf
Color cbwhite
Line 0, 0, MouseWX(), MouseWY()
DrawScreen
Forever
Function ClearSight(AloitusX, AloitusY, LopetusX, LopetusY)
If AloitusX = LopetusX And AloitusY = LopetusY Then Return True //Palautetaan 1 jos koordinaatit ovat päällekäin.
If GetMap(2, AloitusX, AloitusY) Then HitX = LopetusX : HitY = LopetusY : Return False //Heti ekassa kohdassa oli seinää, palautetaan 0.
Hyppy = False
ErotusX = LopetusX - AloitusX
If ErotusX > 0 Then
HyppyX = 1
Else
HyppyX = -1
EndIf
ErotusY = LopetusY - AloitusY
If ErotusY > 0 Then
HyppyY = 1
Else
HyppyY = -1
EndIf
ErotusX = Abs(ErotusX)
ErotusY = Abs(ErotusY)
If ErotusY > ErotusX Then
Hyppy = True
RdX = AloitusX
AloitusX = AloitusY
AloitusY = RdX
RdX = ErotusX
ErotusX = ErotusY
ErotusY = RdX
RdX = HyppyX
HyppyX = HyppyY
HyppyY = RdX
EndIf
Erotus = (ErotusY + ErotusY) - ErotusX
For i = 0 To ErotusX
Color cbred
If Hyppy Then
If GetMap(2, AloitusY, AloitusX) Then HitX = AloitusY : HitY = AloitusX : Return False //O-ou tuli seinä vastaan palautetaan 0.
Else
If GetMap(2, AloitusX, AloitusY) Then HitX = AloitusX : HitY = AloitusY : Return False //Ja taas tuli seinä vastaan palautetaan 0.
EndIf
While Erotus => 0
AloitusY = AloitusY + HyppyY
Erotus = Erotus - (ErotusX + ErotusX)
Wend
AloitusX = AloitusX + HyppyX
Erotus = Erotus + (ErotusY + ErotusY)
Next i
//Jos päästiin tänne asti, niin näköyhteys on selvä ja palautetaan 1. \o/
Return True
EndFunction
Code: Select all
Function ClearSight(AloitusX, AloitusY, LopetusX, LopetusY)
If AloitusX = LopetusX And AloitusY = LopetusY Then Return True //Palautetaan 1 jos koordinaatit ovat päällekäin.
If GetMap(2, AloitusX, AloitusY) Then HitX = LopetusX : HitY = LopetusY : Return False //Heti ekassa kohdassa oli seinää, palautetaan 0.
Hyppy = False
ErotusX = LopetusX - AloitusX
If ErotusX > 0 Then
HyppyX = 1
Else
HyppyX = -1
EndIf
ErotusY = LopetusY - AloitusY
If ErotusY > 0 Then
HyppyY = 1
Else
HyppyY = -1
EndIf
ErotusX = Abs(ErotusX)
ErotusY = Abs(ErotusY)
If ErotusY > ErotusX Then
Hyppy = True
RdX = AloitusX
AloitusX = AloitusY
AloitusY = RdX
RdX = ErotusX
ErotusX = ErotusY
ErotusY = RdX
RdX = HyppyX
HyppyX = HyppyY
HyppyY = RdX
EndIf
Erotus = (ErotusY + ErotusY) - ErotusX
For i = 0 To ErotusX
Color cbred
If Hyppy Then
If GetMap(2, AloitusY, AloitusX) Then HitX = AloitusY : HitY = AloitusX : Return False //O-ou tuli seinä vastaan palautetaan 0.
Else
If GetMap(2, AloitusX, AloitusY) Then HitX = AloitusX : HitY = AloitusY : Return False //Ja taas tuli seinä vastaan palautetaan 0.
EndIf
While Erotus => 0
AloitusY = AloitusY + HyppyY
Erotus = Erotus - (ErotusX + ErotusX)
Wend
AloitusX = AloitusX + HyppyX
Erotus = Erotus + (ErotusY + ErotusY)
Next i
//Jos päästiin tänne asti, niin näköyhteys on selvä ja palautetaan 1. \o/
Return True
EndFunction