Source Code: Proximity Mines
rating: 0+x

Explanation

This is a simple proximity mine demo. The proximity mines will explode if they are within 40 pixels of the dot or within each other.

Instructions

Use the arrow keys to move the dot.

Source Code

SetFPS 60

screenHeight = GetScreenHeight()
screenWidth  = GetScreenWidth()

Type Obj
    x#
    y#
    alv
    boom
EndType

Dim player As Obj

player.x# = screenWidth / 2
player.y# = screenHeight / 2

Dim mines(20) As Obj

For i = 1 to GetArrayElements(mines(),1)
    mines(i).x# = RndRange#(0,screenWidth)
    mines(i).y# = RndRange#(0,screenHeight)
    mines(i).alv = True
    mines(i).boom = False
Next

Do

    If UpKey() Then player.y# = player.y# + -2
    If DownKey() Then player.y# = player.y# + 2
    If LeftKey() Then player.x# = player.x# + -2
    If RightKey() Then player.x# = player.x# + 2

    For x = 1 to GetArrayElements(mines(),1)
        distance = GetDistance2D(mines(x).x#, mines(x).y#, player.x#, player.y#)
        If Range(distance, 0, 40) Then mines(x).boom = True
        For y = 1 to GetArrayElements(mines(),1)
            If x <> y
                distance = GetDistance2D(mines(x).x#,mines(x).y#,mines(y).x#,mines(y).y#)
                If Range(distance, 0, 40) Then mines(x).boom = True
            EndIf
        Next
    Next     

    Cls 0

        For i = 1 to GetArrayElements(mines(),1)
            If mines(i).alv
                If mines(i).boom
                    CircleC mines(i).x#,mines(i).y#, 40, True, $FF0000
                    mines(i).alv = False
                Else
                    CircleC mines(i).x#, mines(i).y#, 5, False, $AA0000
                EndIf
            EndIf
        Next

        Dot player.x#, player.y#        
    Sync
Loop

Related Pages

Categories: A.I. : Source Code