Generic Rectangle Function. by Steve Ancell19th Oct 2011 21:10
|
---|
Summary A work-around for suppporting the lack of a rectangle function in AGK. It will work, as is, without the need for loading any media. Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com SetVirtualResolution(480, 480) type Rectangle x#, y# w#, h# r, g, b, a leftLine topLine rightLine bottomLine filledRect flag listSize endtype dim rectList[0] AS Rectangle rectList[0].listSize = 0 for row = 0 to 5 for column = 0 to 5 CreateRectangle(column * 50, row * 50, 50, 50, 255, 255, 255, 0) CreateRectangle((column * 50) + 1, (row * 50) + 1, 48, 48, 255, 0, 0, 1) next next do if GetRawKeyPressed(27) = 1 then exit Sync() loop function CreateRectangle(x#, y#, width#, height#, r, g, b, filled) flag = 0 for i = 1 to rectList[0].listSize if rectList[i].flag = 0 flag = 1 exit endif next if flag = 0 rectList[0].listSize = (rectList[0].listSize + 1) dim rectList[rectList[0].listSize] i = rectList[0].listSize endif if filled = 0 rectList[i].leftLine = CreateSprite(dummy) SetSpritePosition(rectList[i].leftLine, x#, y#) SetSpriteSize(rectList[i].leftLine, 1, Height#) SetSpriteColor(rectList[i].leftLine, r, g, b, 255) rectList[i].rightLine = CreateSprite(dummy) SetSpritePosition(rectList[i].rightLine, (x# + width#) - 1, y#) SetSpriteSize(rectList[i].rightLine, 1, height#) SetSpriteColor(rectList[i].rightLine, r, g, b, 255) rectList[i].topLine = CreateSprite(dummy) SetSpritePosition(rectList[i].topLine, x#, y#) SetSpriteSize(rectList[i].topLine, width#, 1) SetSpriteColor(rectList[i].topLine, r, g, b, 255) rectList[i].bottomLine = CreateSprite(dummy) SetSpritePosition(rectList[i].bottomLine, x#, (y# + height#) - 1) SetSpriteSize(rectList[i].bottomLine, width#, 1) SetSpriteColor(rectList[i].bottomLine, r, g, b, 255) endif if filled = 1 rectList[i].filledRect = CreateSprite(dummy) SetSpritePosition(rectList[i].filledRect, x#, y#) SetSpriteSize(rectList[i].filledRect, width#, height#) SetSpriteColor(rectList[i].filledRect, r, g, b, 255) endif endfunction result |