peter
16-10-2012, 13:42
Hi,
A little bit collision.
Uses "ui"
DWord hdc,hwin
hwin=Canvas_Window("Collision Test",1,1,640,480)
Canvas_Attach(hwin,0,%TRUE)
Canvas_Font("georgia",18,%CANVAS_FONTSTYLE_BOLD)
Single px1,py1,px2,py2
py1=200:px2=640:py2=200
While IsWindow(hwin)
Canvas_Clear(0)
Canvas_Circle(px1,py1,20,1,Rgb(255,0,0))
Triangle(px2,py2-40,60,80,0,255,0)
If Collision(px1,py1,px2,py2,30,30)=1 Then
SetText(240,16,"BUMMS!",Rgb(255,255,255),0)
End If
px1 +=1: If px1 >=640 Then px1= -32
px2 -=1: If px2 <=-64 Then px2= 660
Canvas_Redraw
If GetAsyncKeyState(27) Then Exit While
Wend
Canvas_Window End
Sub SetText(x,y As Long, txt As String, xkol,ykol As Long)
Canvas_Color(xkol,ykol)
Canvas_SetPos(x,y)
Canvas_Print(txt)
End Sub
Function Collision(x1,y1,x2,y2,r1,r2 As Single) As Long
If Sqr((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) < r1+r2 Then
Return 1
End If
End Function
Sub Triangle(x1,y1,x2,y2,r,g,b As Long)
Canvas_Line( (x1,y1),(x1+x2,y1+y2),Rgb(r,g,b) )
Canvas_Line( (x1,y1),(x1-x2,y1+y2),Rgb(r,g,b) )
Canvas_Line( (x1-x2,y1+y2),(x1+x2,y1+y2),Rgb(r,g,b) )
End Sub
A little bit collision.
Uses "ui"
DWord hdc,hwin
hwin=Canvas_Window("Collision Test",1,1,640,480)
Canvas_Attach(hwin,0,%TRUE)
Canvas_Font("georgia",18,%CANVAS_FONTSTYLE_BOLD)
Single px1,py1,px2,py2
py1=200:px2=640:py2=200
While IsWindow(hwin)
Canvas_Clear(0)
Canvas_Circle(px1,py1,20,1,Rgb(255,0,0))
Triangle(px2,py2-40,60,80,0,255,0)
If Collision(px1,py1,px2,py2,30,30)=1 Then
SetText(240,16,"BUMMS!",Rgb(255,255,255),0)
End If
px1 +=1: If px1 >=640 Then px1= -32
px2 -=1: If px2 <=-64 Then px2= 660
Canvas_Redraw
If GetAsyncKeyState(27) Then Exit While
Wend
Canvas_Window End
Sub SetText(x,y As Long, txt As String, xkol,ykol As Long)
Canvas_Color(xkol,ykol)
Canvas_SetPos(x,y)
Canvas_Print(txt)
End Sub
Function Collision(x1,y1,x2,y2,r1,r2 As Single) As Long
If Sqr((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) < r1+r2 Then
Return 1
End If
End Function
Sub Triangle(x1,y1,x2,y2,r,g,b As Long)
Canvas_Line( (x1,y1),(x1+x2,y1+y2),Rgb(r,g,b) )
Canvas_Line( (x1,y1),(x1-x2,y1+y2),Rgb(r,g,b) )
Canvas_Line( (x1-x2,y1+y2),(x1+x2,y1+y2),Rgb(r,g,b) )
End Sub