Can someone compile this for me, please? Debug off. Thanks!
Posted: Mon Mar 07, 2005 3:51 am
; ***********
; SPRITE TEST
; ***********
Gosub set_up
Gosub man_loop; MAIN LOOP
End
; ***********
; SUBROUTINES
; ***********
; 1 SET UP
set_up:
Gosub set_data
Gosub set_hardware
Gosub set_sprites
Return
; 1.1 Data
set_data:
Gosub set_constants
Gosub set_variables
Gosub set_lists
Declare spr_speed()
Return
; 1.1.1 CONSTANTS
set_constants:
#scr_width .l=1024
#scr_height .l= 768
#scr_depth .l= 32
#scr_freq .l= 60
#scr_hor_centre.l=#scr_width /2; SCREEN HORIZONTAL CENTRE
#scr_ver_centre.l=#scr_height/2
red .l=RGB(255, 0, 0)
green .l=RGB( 0,255, 0)
blue .l=RGB( 0, 0,255)
white .l=RGB(255,255,255)
purple .l=RGB(255, 0,255)
#ball .l= 1
#square .l= 2
#triangle .l= 3
#max_sprites .l=1000
#spd_spawn .l= 500; SPEED SPAWN
#spr_size .l= 32; SPRITE SIZE
#second .l=1000
Return
; 1.1.2 VARIABLES
set_variables:
ths_image .l; THIS IMAGE
num_sprites.l
lst_spawn .l; LAST SPAWN
num_frames .l
lst_second .l
fps .l
Return
; 1.1.3 LISTS and ARRAYS
set_lists:
Structure spr_info; SPRITE INFO
id .l
hor_position.l
ver_position.l
hor_speed .l
ver_speed .l
EndStructure
NewList spr.spr_info(); SPRITE
Dim image.l(3)
Return
; 1.2 HARDWARE
set_hardware:
LoadFont(#PB_Any,"fixedsys",16); The ID isn't needed!
InitSprite()
InitKeyboard()
SetRefreshRate(#scr_freq)
OpenScreen(#scr_width,#scr_height,#scr_depth,"Sprite test")
Return
; 1.3 IMAGES
set_sprites:
For ths_image=#ball To #triangle
image(ths_image)=CreateSprite(#PB_Any,32,32)
StartDrawing(SpriteOutput(image(ths_image)))
Select ths_image
Case #ball
Circle(15,15,15,red)
Case #square
Box(0,0,32,32,green)
Case #triangle
LineXY(15, 0, 0,31,purple)
LineXY( 0,31,31,31,purple)
LineXY(31,31,15, 0,purple)
FillArea(15,2,purple,purple)
EndSelect
StopDrawing()
Next ths_image
Return
; 2 MAIN LOOP
man_loop:
lst_second=ElapsedMilliseconds()
Repeat
ClearScreen(0,0,0)
Gosub spn_sprites; SPAWN SPRITES
Gosub drw_sprites; DRAW SPRITES
Gosub clc_fps ; CALCULATE FPS
Gosub prt_panel ; PRINT PANEL
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Return
; 2.1 SPAWN SPRITES
spn_sprites:
If num_sprites<#max_sprites
If ElapsedMilliseconds()-lst_spawn>=#spd_spawn
lst_spawn=ElapsedMilliseconds()
num_sprites+1
LastElement(spr())
AddElement(spr())
spr()\id=CopySprite(image(Random(2)+1),#PB_Any)
spr()\hor_position=#scr_hor_centre
spr()\ver_position=#scr_ver_centre
spr()\hor_speed=spr_speed()
spr()\ver_speed=spr_speed()
EndIf
EndIf
Return
; 2.2 DRAW SPRITES
drw_sprites:
ForEach spr()
spr()\hor_position+spr()\hor_speed
spr()\ver_position+spr()\ver_speed
DisplayTransparentSprite(spr()\id,spr()\hor_position,spr()\ver_position)
If spr()\hor_position<0 Or spr()\hor_position> #scr_width-#spr_size
spr()\hor_speed=-spr()\hor_speed
EndIf
If spr()\ver_position<0 Or spr()\ver_position>#scr_height-#spr_size
spr()\ver_speed=-spr()\ver_speed
EndIf
Next
Return
; 2.3 CALCULATE FPS
clc_fps:
num_frames+1
If ElapsedMilliseconds()-lst_second>=#second
fps=num_frames
num_frames=0
lst_second+#second
EndIf
Return
; 2.4 PRINT PANEL
prt_panel:
StartDrawing(ScreenOutput())
DrawingMode(1)
DrawingFont(FontID())
FrontColor(255,255,255)
Locate(0, 0)
DrawText("SCREEN WIDTH :"+RSet(Str( #scr_width),5))
Locate(0,12)
DrawText("SCREEN HEIGHT:"+RSet(Str(#scr_height),5))
Locate(0,24)
DrawText("SCREEN DEPTH :"+RSet(Str( #scr_depth),5))
Locate(0,36)
DrawText("N. OF SPRITES:"+RSet(Str(num_sprites),5))
Locate(0,48)
DrawText("PROGRAM FPS :"+RSet(Str( fps),5))
StopDrawing()
Return
; *********
; FUNCTIONS
; *********
Procedure.l spr_speed()
result.l
result=Random(5)+1
If Random(1)
result=-result
EndIf
ProcedureReturn result
EndProcedure
; SPRITE TEST
; ***********
Gosub set_up
Gosub man_loop; MAIN LOOP
End
; ***********
; SUBROUTINES
; ***********
; 1 SET UP
set_up:
Gosub set_data
Gosub set_hardware
Gosub set_sprites
Return
; 1.1 Data
set_data:
Gosub set_constants
Gosub set_variables
Gosub set_lists
Declare spr_speed()
Return
; 1.1.1 CONSTANTS
set_constants:
#scr_width .l=1024
#scr_height .l= 768
#scr_depth .l= 32
#scr_freq .l= 60
#scr_hor_centre.l=#scr_width /2; SCREEN HORIZONTAL CENTRE
#scr_ver_centre.l=#scr_height/2
red .l=RGB(255, 0, 0)
green .l=RGB( 0,255, 0)
blue .l=RGB( 0, 0,255)
white .l=RGB(255,255,255)
purple .l=RGB(255, 0,255)
#ball .l= 1
#square .l= 2
#triangle .l= 3
#max_sprites .l=1000
#spd_spawn .l= 500; SPEED SPAWN
#spr_size .l= 32; SPRITE SIZE
#second .l=1000
Return
; 1.1.2 VARIABLES
set_variables:
ths_image .l; THIS IMAGE
num_sprites.l
lst_spawn .l; LAST SPAWN
num_frames .l
lst_second .l
fps .l
Return
; 1.1.3 LISTS and ARRAYS
set_lists:
Structure spr_info; SPRITE INFO
id .l
hor_position.l
ver_position.l
hor_speed .l
ver_speed .l
EndStructure
NewList spr.spr_info(); SPRITE
Dim image.l(3)
Return
; 1.2 HARDWARE
set_hardware:
LoadFont(#PB_Any,"fixedsys",16); The ID isn't needed!
InitSprite()
InitKeyboard()
SetRefreshRate(#scr_freq)
OpenScreen(#scr_width,#scr_height,#scr_depth,"Sprite test")
Return
; 1.3 IMAGES
set_sprites:
For ths_image=#ball To #triangle
image(ths_image)=CreateSprite(#PB_Any,32,32)
StartDrawing(SpriteOutput(image(ths_image)))
Select ths_image
Case #ball
Circle(15,15,15,red)
Case #square
Box(0,0,32,32,green)
Case #triangle
LineXY(15, 0, 0,31,purple)
LineXY( 0,31,31,31,purple)
LineXY(31,31,15, 0,purple)
FillArea(15,2,purple,purple)
EndSelect
StopDrawing()
Next ths_image
Return
; 2 MAIN LOOP
man_loop:
lst_second=ElapsedMilliseconds()
Repeat
ClearScreen(0,0,0)
Gosub spn_sprites; SPAWN SPRITES
Gosub drw_sprites; DRAW SPRITES
Gosub clc_fps ; CALCULATE FPS
Gosub prt_panel ; PRINT PANEL
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Return
; 2.1 SPAWN SPRITES
spn_sprites:
If num_sprites<#max_sprites
If ElapsedMilliseconds()-lst_spawn>=#spd_spawn
lst_spawn=ElapsedMilliseconds()
num_sprites+1
LastElement(spr())
AddElement(spr())
spr()\id=CopySprite(image(Random(2)+1),#PB_Any)
spr()\hor_position=#scr_hor_centre
spr()\ver_position=#scr_ver_centre
spr()\hor_speed=spr_speed()
spr()\ver_speed=spr_speed()
EndIf
EndIf
Return
; 2.2 DRAW SPRITES
drw_sprites:
ForEach spr()
spr()\hor_position+spr()\hor_speed
spr()\ver_position+spr()\ver_speed
DisplayTransparentSprite(spr()\id,spr()\hor_position,spr()\ver_position)
If spr()\hor_position<0 Or spr()\hor_position> #scr_width-#spr_size
spr()\hor_speed=-spr()\hor_speed
EndIf
If spr()\ver_position<0 Or spr()\ver_position>#scr_height-#spr_size
spr()\ver_speed=-spr()\ver_speed
EndIf
Next
Return
; 2.3 CALCULATE FPS
clc_fps:
num_frames+1
If ElapsedMilliseconds()-lst_second>=#second
fps=num_frames
num_frames=0
lst_second+#second
EndIf
Return
; 2.4 PRINT PANEL
prt_panel:
StartDrawing(ScreenOutput())
DrawingMode(1)
DrawingFont(FontID())
FrontColor(255,255,255)
Locate(0, 0)
DrawText("SCREEN WIDTH :"+RSet(Str( #scr_width),5))
Locate(0,12)
DrawText("SCREEN HEIGHT:"+RSet(Str(#scr_height),5))
Locate(0,24)
DrawText("SCREEN DEPTH :"+RSet(Str( #scr_depth),5))
Locate(0,36)
DrawText("N. OF SPRITES:"+RSet(Str(num_sprites),5))
Locate(0,48)
DrawText("PROGRAM FPS :"+RSet(Str( fps),5))
StopDrawing()
Return
; *********
; FUNCTIONS
; *********
Procedure.l spr_speed()
result.l
result=Random(5)+1
If Random(1)
result=-result
EndIf
ProcedureReturn result
EndProcedure