Code: Select all
Procedure TileSprite(spritenum, offsetx, offsety, swidth, sheight, trans)
Protected cx, cy, btilewidth, btileheight
btilewidth = SpriteWidth(spritenum)
btileheight = SpriteHeight(spritenum)
cx = -btilewidth
cy = -btileheight
offsetx = offsetx % btilewidth
offsety = offsety % btileheight
Repeat
Repeat
If trans
DisplayTransparentSprite(spritenum,cx+offsetx,cy+offsety)
Else
DisplaySprite(spritenum,cx+offsetx,cy+offsety)
EndIf
cx + btilewidth
Until cx > swidth + btilewidth
cx = -btilewidth
cy + btileheight
Until cy > SHeight + btileheight
EndProcedureCode: Select all
; // TileSprite() Demo Jan 2005 by Griz //
Procedure Frame(x,y,width,height,thickness)
Protected n
DrawingMode(4)
For n = 0 To thickness-1
Box(x+n,y+n,width-n*2, height-n*2)
Next
EndProcedure
Procedure Initialization()
Global ScreenWidth : ScreenWidth = 1280
Global ScreenHeight : ScreenHeight = 1024
Global ExitGame : ExitGame = #False
Global tile1, tile2, tile3
Global backx, backy, backx2, backy2, backx3, backy3
; // initialize direct x and open a screen if possible //
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
End
EndIf
If OpenScreen(ScreenWidth,ScreenHeight,32, "Laser Gunner")
; // prevents full screen flicker //
Delay(1000)
Else
MessageRequester("Error", "Can't open screen : "+Str(ScreenWidth)+" x "+Str(ScreenHeight), 0)
End
EndIf
; // draw background tile sprites //
tile1 = CreateSprite(#pb_any,128,128)
StartDrawing(SpriteOutput(tile1))
FrontColor(0,32,64)
Circle(32,32,8)
Circle(96,96,8)
StopDrawing()
tile2 = CreateSprite(#pb_any,128,128)
StartDrawing(SpriteOutput(tile2))
FrontColor(0,0,64)
Box(0,0,128,128)
FrontColor(0,0,0)
Circle(64,64,58)
StopDrawing()
tile3 = CreateSprite(#pb_any,128,128)
StartDrawing(SpriteOutput(tile3))
FrontColor(0,0,128)
frame(0,0,128,128,4)
StopDrawing()
EndProcedure
Procedure UserInput()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
ExitGame=#True
EndIf
EndProcedure
Procedure TileSprite(spritenum, offsetx, offsety, swidth, sheight, trans)
Protected cx, cy, btilewidth, btileheight
btilewidth = SpriteWidth(spritenum)
btileheight = SpriteHeight(spritenum)
cx = -btilewidth
cy = -btileheight
offsetx = offsetx % btilewidth
offsety = offsety % btileheight
Repeat
Repeat
If trans
DisplayTransparentSprite(spritenum,cx+offsetx,cy+offsety)
Else
DisplaySprite(spritenum,cx+offsetx,cy+offsety)
EndIf
cx + btilewidth
Until cx > swidth + btilewidth
cx = -btilewidth
cy + btileheight
Until cy > SHeight + btileheight
EndProcedure
Procedure RenderScreen()
FlipBuffers()
If IsScreenActive()
ClearScreen(0,0,32)
tilesprite(tile1,backx,backy,screenwidth, screenheight,#true)
tilesprite(tile2,backx2,backy2,screenwidth, screenheight,#true)
tilesprite(tile3,backx3,backy3,screenwidth, screenheight,#true)
If StartDrawing(ScreenOutput())
FrontColor(0,0,64)
frame(0,0,screenwidth, screenheight, 32)
DrawingMode(1)
FrontColor(128,128,128)
m$ = "TILESPRITE Demo - Press ESC to exit"
Locate((screenwidth/2)-(TextLength(m$)/2),8)
DrawText(m$)
StopDrawing()
EndIf
Else
Delay(50)
EndIf
EndProcedure
Procedure ScrollLimit(num)
If num>screenwidth
num-screenwidth
EndIf
If num<-screenwidth
num+screenwidth
EndIf
ProcedureReturn num
EndProcedure
Procedure AI()
backy+2
backx2-1
backx3+1
backy3-1
backy = ScrollLimit(backy)
backx2 = ScrollLimit(backx2)
backx3 = ScrollLimit(backx3)
backy3 = ScrollLimit(backy3)
EndProcedure
Procedure DeInitialization()
FreeSprite(tile1)
FreeSprite(tile2)
FreeSprite(tile3)
EndProcedure
; // main loop //
initialization()
Repeat
AI()
UserInput()
RenderScreen()
Until ExitGame
deinitialization()
End
