(AGK version: 108.15)
Submitted: 2013-07-11 02:30:30
Setvirtualresolution(640,480)
ResetTimer()
//Create an example image
id=_CreateImage(25,0,255,0)
//Set Background Color
SetClearColor(50,50,100)
//Create Sprtes, ID's 1 and 2
For i=1 to 2
    CreateSprite(i,id)
    SetSpriteX(i,i*100)
    SetSpriteY(i,200)
Next i
Do
    For i=1 to 100
        SetSpriteX(1,Mod(i,100)+150)
        If GetSpriteCollision(1,2)
            Print("HIT!")
        EndIf
        Sync()
    Next i
    If Timer()>15 Then Exit
Loop
End

Function _CreateImage(size,r,g,b)
    swap()
    Drawline(0,0,size,size,r,g,b)
    Update(0)
    Render()
    Drawline(0,size,size,0,r,g,b)
    Update(0)
    Render()
    giid=GetImage(0,0,size,size)
EndFunction giid
(AGK version: 108.19)
Submitted: 2014-03-22 15:57:27
rem
rem AGK Application 108 19
rem MR 22.03.2014

rem Landscape App
SetDisplayAspect( 4.0/3.0 )

type TBullet
    dx#
    dy#
    speed#
    spr
endtype

type TTarget
    spr
endtype

dim Bullets[10] AS TBullet
global BulletCount
BulletCount=0

dim Targets[10] AS TTarget
global TargetCount

MainLoop()
end

function MainLoop()

    Targets[0].spr=TargetNew(25,25)
    Targets[1].spr=TargetNew(50,25)
    Targets[2].spr=TargetNew(75,25)
    TargetCount=2

    do

     x#=getpointerx()
     y#=getpointery()

     if getpointerpressed()=1
        dx#=random(0,2)-1.0
        dy#=-random(1,2)
        speed#=0.25
        BulletAdd(spr,x#,y#,dx#,dy#,speed#)
     endif

     BulletCollision()
     BulletUpdate()

     Print("hello world")
     Sync()
    loop
endfunction

Function BulletNew(x#,y#)

    spr=createsprite(0)
    setspritepositionbyoffset(spr,x#,y#)
    setspritesize(spr,5,5)

endfunction spr

function BulletAdd(spr,x#,y#,dx#,dy#,speed#)

    free=-1
    for i=0 to BulletCount
        if Bullets[i].spr=0
            free=i
            exit
        endif
    next

    if free>=0
        spr=BulletNew(x#,y#)
        Bullets[free].spr=spr
        Bullets[free].dx#=dx#
        Bullets[free].dy#=dy#
        Bullets[free].speed#=speed#
        if BulletCount<10 then BulletCount=BulletCount+1
    endif

endfunction

Function BulletUpdate()

    for i=0 to BulletCount
        spr=Bullets[i].spr
        if spr
            setspritepositionbyoffset(spr,getspritexbyoffset(spr)+Bullets[i].dx#*Bullets[i].speed#,getspriteybyoffset(spr)+Bullets[i].dy#*Bullets[i].speed#)
        endif
    next

endfunction

Function BulletCollision()

    for i=0 to BulletCount
        spr=Bullets[i].spr
        if spr
            for t=0 to TargetCount
                target=Targets[t].spr
                hit=GetSpriteCollision( spr ,target)
                if hit=1
                 setspritecolor(target,255,0,0,255)
                 deletesprite(spr)
                 Bullets[i].spr=0
                 spr=0
                 exit
                endif
            next
        endif
    next

endfunction

function TargetNew(x#,y#)

    spr=createsprite(0)
    setspritepositionbyoffset(spr,x#,y#)

endfunction spr
(AGK version: 2.0.14)
Submitted: 2015-10-07 08:30:30
//AGK V2.0.14b
//Play with Blocks
//MR 07.10.2015

#option_explicit

type TBlock
	spr
	del
endtype

type TPlayer
	spr
	score
endtype

global Blocks as TBlock[1000]
global BlocksNum=0

MainLoop()
end

Function MainLoop()

	local player as TPlayer
	player.spr=CreateSprite(0)
	player.score=0
	SetSpriteSize(player.spr,10,10)
	SetSpritePositionByOffset(player.spr,20,25)

	local spr as integer
	spr=CreateDeathBlock(random(5,95),random(5,95))

	do
		print("Use Cursor Keys")
		print(str(player.score))

		SetSpritePositionByOffset(player.spr,GetSpriteXByOffset(player.spr)+GetDirectionX(),GetSpriteYByOffset(player.spr)+GetDirectionY())

		player.score=player.score+CollisionTest(player.spr)

		sync()
	loop

endfunction

function CollisionTest(spr1)

	local score as integer

	local spr as integer
	local spr2 as integer
	local i as integer

		for i=1 to BlocksNum
			spr2=Blocks[i].spr
			if spr2<>0 and Blocks[i].del=0
				if getspritecollision(spr1,spr2)

					spr=CreateDeathBlock(random(5,95),random(5,95))

					SetSpriteColor(spr2,128,128,128,128)

					Blocks[i].del=60*5

					inc score,1
				endif
			endif
			if Blocks[i].del>0
				Blocks[i].del=Blocks[i].del-1
				if Blocks[i].del=0
					DeleteSprite(spr2)
					Blocks[i].spr=0
				endif
			endif
		next
	
endfunction score

function CreateDeathBlock(x#,y#)

	if BlocksNum<1000

		local spr as integer

		spr=createsprite(0)
		SetSpritePosition(spr,x#,y#)
		SetSpriteSize(spr,5,5)
		
		MemoryDeathBlock(spr)
	
	endif

endfunction spr

function MemoryDeathBlock(spr)

	BlocksNum=BlocksNum+1
	Blocks[BlocksNum].spr=spr
	Blocks[BlocksNum].del=0
	
endfunction
 
  




Help make AGK better by submitting an example for this command!
(All examples are subject to approval)
Login to post an example of your own.