Can anyone help with the below?
When the crosshair image and the target 1 image are both loaded and displayed they are the same image. When going through the debugger they have the same id. Is this a bug within blitz itself?
if you need images etc I can email the whole program
thanks
;==========================================================================================
;create globals
Global gfx_x=640
Global gfx_y=480
Global gfx_colour_depth=16
Global target_image_width=40
Global target_image_height=40
Global target_found=0
Global target_id=0
Global target_mouseover=0
Global mouse_crosshair_image=LoadImage("gfx\crosshair.bmp")
;==========================================================================================
;create window
Graphics gfx_x,gfx_y,gfx_colour_depth,0 ;screen =640,480,16 bit colour
AppTitle="Shape Shoot"
SetBuffer BackBuffer()
;SeedRnd MilliSecs();get better random result
;==========================================================================================
;create types
Type target
Field x=0 ;x pos
Field y=0 ; y pos
Field id ; id number of target
Field hit=False ;target hit/miss
Field image ;target graphic
Field xmax ;max x postion of graphic on screen
Field ymax ;max y postion of graphic on screen
Field xmin ;min x postion of graphic on screen
Field ymin ;min y postion of graphic on screen
Field moveleft=0 ;is the target moving left or right? 0 right 1 left
End Type
;==========================================================================================
;create objects from types
;#Region create target objects
target_1.target=New target
target_1\x=target_image_width
target_1\y=target_image_height
target_1\id=1
target_1\hit=False
target_1\xmax=gfx_x-(target_image_width*2)
target_1\ymax=gfx_y-(target_image_height*2)
target_1\xmin=0+(target_image_width)
target_1\ymin=0+(target_image_height)
target_1\image=LoadImage("gfx\target.bmp") ;x40,y40 pixels
target_1\moveleft=0
MaskImage (target_1\image,255,255,255) ;get rid of the surrounding white of the image
target_2.target=New target
target_2\x=target_image_width*4
target_2\y=target_image_height*4
target_2\id=2
target_2\hit=False
target_2\xmax=gfx_x-(target_image_width*2)
target_2\ymax=gfx_y-(target_image_height*2)
target_2\xmin=0+(target_image_width)
target_2\ymin=0+(target_image_height)
target_2\image=LoadImage("gfx\target2.bmp") ;x40,y40 pixels
target_2\moveleft=0
MaskImage (target_2\image,255,255,255) ;get rid of the surrounding white of the image
;#End Region
;==========================================================================================
;main loop
While Not KeyHit (1) ;do below until ESC is press then quit
If KeyDown (57) Then WaitKey ;if spacebar is pressed then pause
;clear the screen
Cls
;draw the targets on the screen
DrawImage target_1\image,target_1\x,target_1\y
DrawImage target_2\image,target_2\x,target_2\y
DrawImage mouse_crosshair_image, MouseX(), MouseY()
Gosub move_targets
;check if mouse if over the position of targets
If target_found=0 Then check_target_pos(1)
If target_found=0 Then check_target_pos(2)
target_found=0 ;reset target found flag
Gosub target_debug ;display debug info
;flip the buffer screen
Flip
Wend
End
;==========================================================================================
;functions
Function check_target_pos(id)
;used to check the position of any targets on screen and find out if mouse is over/target shot
Local target.target=Null
target=get_target_id(id) ; try and find 'number'
If target <> Null ; check to see whether it's found it.
;ok so i found the target number
;check if the mouse is over the target
target_mouseover=ImageRectCollide (target\image, target\x, target\y,0, MouseX(),MouseY(),1, 1)
;if it is then get then find out which target it is over
If target_mouseover=1 Then
target_id=target\id ;get id of the target
;check to see if mouse button 1 is down
If MouseDown(1) And target_mouseover=1 Then
target\hit=1
target\image =LoadImage("gfx\target_hit.bmp")
;FreeImage target\image ;remove the target from the screen
End If
target_found=True ;we found it so no need to look anymore
Else
;if mouse is not over any of the targets
target_id=0 ;no target to find id of of
target_found=False ;not found a target so keep looking until mouse is over a target
End If
;target\x=Rand (target\xmin,target\xmax);move x pos of target to random x pos
;target\y=Rand (target\ymin,target\ymax);move y pos of target to random y pos
Else
EndIf
End Function
Function get_target_id.target(id)
;cycle through all available targets and return the id
For i.target=Each target
If i\id = id Then Return i ;return the id of the target we find
Next
End Function
;==========================================================================================
;subroutines etc
;move the targets around the screen
;#Region move targets
.move_targets
target_num=1
For target.target=Each target
Select target_num
Case 1
If target\moveleft=0 Then
target\x=target\x+3
If target\x=>target\xmax Then
target\moveleft=1
target\x=target\xmax
End If
Else
target\x=target\x-3
If target\x<=target\xmin Then
target\moveleft=0
target\x=target\xmin
End If
End If
Case 2
If target\moveleft=0 Then
target\x=target\x+5
If target\x=>target\xmax Then
target\moveleft=1
target\x=target\xmax
End If
Else
target\x=target\x-5
If target\x<=target\xmin Then
target\moveleft=0
target\x=target\xmin
End If
End If
End Select
target_num=target_num+1
Next
Return
;#End Region
;debug
;#Region debug
.target_debug
;display mouse and target info for debug purpose
y=390
For target.target=Each target
Text(20,y,"target "+target\id +" x="+target\x+" y="+target\y+" xmin="+target\xmin +" xmax="+target\xmax+" ymin="+target\ymin +" ymax="+target\ymax)
y=y+10
Next
Text(20,y,"mouse x=" +MouseX() +" y=" +MouseY() +" button1=" +MouseDown(1) +" collide=" +target_mouseover)
y=y+10
Text(20,y,"target id="+target_id)
Return
;#End Region
When the crosshair image and the target 1 image are both loaded and displayed they are the same image. When going through the debugger they have the same id. Is this a bug within blitz itself?
if you need images etc I can email the whole program
thanks
;==========================================================================================
;create globals
Global gfx_x=640
Global gfx_y=480
Global gfx_colour_depth=16
Global target_image_width=40
Global target_image_height=40
Global target_found=0
Global target_id=0
Global target_mouseover=0
Global mouse_crosshair_image=LoadImage("gfx\crosshair.bmp")
;==========================================================================================
;create window
Graphics gfx_x,gfx_y,gfx_colour_depth,0 ;screen =640,480,16 bit colour
AppTitle="Shape Shoot"
SetBuffer BackBuffer()
;SeedRnd MilliSecs();get better random result
;==========================================================================================
;create types
Type target
Field x=0 ;x pos
Field y=0 ; y pos
Field id ; id number of target
Field hit=False ;target hit/miss
Field image ;target graphic
Field xmax ;max x postion of graphic on screen
Field ymax ;max y postion of graphic on screen
Field xmin ;min x postion of graphic on screen
Field ymin ;min y postion of graphic on screen
Field moveleft=0 ;is the target moving left or right? 0 right 1 left
End Type
;==========================================================================================
;create objects from types
;#Region create target objects
target_1.target=New target
target_1\x=target_image_width
target_1\y=target_image_height
target_1\id=1
target_1\hit=False
target_1\xmax=gfx_x-(target_image_width*2)
target_1\ymax=gfx_y-(target_image_height*2)
target_1\xmin=0+(target_image_width)
target_1\ymin=0+(target_image_height)
target_1\image=LoadImage("gfx\target.bmp") ;x40,y40 pixels
target_1\moveleft=0
MaskImage (target_1\image,255,255,255) ;get rid of the surrounding white of the image
target_2.target=New target
target_2\x=target_image_width*4
target_2\y=target_image_height*4
target_2\id=2
target_2\hit=False
target_2\xmax=gfx_x-(target_image_width*2)
target_2\ymax=gfx_y-(target_image_height*2)
target_2\xmin=0+(target_image_width)
target_2\ymin=0+(target_image_height)
target_2\image=LoadImage("gfx\target2.bmp") ;x40,y40 pixels
target_2\moveleft=0
MaskImage (target_2\image,255,255,255) ;get rid of the surrounding white of the image
;#End Region
;==========================================================================================
;main loop
While Not KeyHit (1) ;do below until ESC is press then quit
If KeyDown (57) Then WaitKey ;if spacebar is pressed then pause
;clear the screen
Cls
;draw the targets on the screen
DrawImage target_1\image,target_1\x,target_1\y
DrawImage target_2\image,target_2\x,target_2\y
DrawImage mouse_crosshair_image, MouseX(), MouseY()
Gosub move_targets
;check if mouse if over the position of targets
If target_found=0 Then check_target_pos(1)
If target_found=0 Then check_target_pos(2)
target_found=0 ;reset target found flag
Gosub target_debug ;display debug info
;flip the buffer screen
Flip
Wend
End
;==========================================================================================
;functions
Function check_target_pos(id)
;used to check the position of any targets on screen and find out if mouse is over/target shot
Local target.target=Null
target=get_target_id(id) ; try and find 'number'
If target <> Null ; check to see whether it's found it.
;ok so i found the target number
;check if the mouse is over the target
target_mouseover=ImageRectCollide (target\image, target\x, target\y,0, MouseX(),MouseY(),1, 1)
;if it is then get then find out which target it is over
If target_mouseover=1 Then
target_id=target\id ;get id of the target
;check to see if mouse button 1 is down
If MouseDown(1) And target_mouseover=1 Then
target\hit=1
target\image =LoadImage("gfx\target_hit.bmp")
;FreeImage target\image ;remove the target from the screen
End If
target_found=True ;we found it so no need to look anymore
Else
;if mouse is not over any of the targets
target_id=0 ;no target to find id of of
target_found=False ;not found a target so keep looking until mouse is over a target
End If
;target\x=Rand (target\xmin,target\xmax);move x pos of target to random x pos
;target\y=Rand (target\ymin,target\ymax);move y pos of target to random y pos
Else
EndIf
End Function
Function get_target_id.target(id)
;cycle through all available targets and return the id
For i.target=Each target
If i\id = id Then Return i ;return the id of the target we find
Next
End Function
;==========================================================================================
;subroutines etc
;move the targets around the screen
;#Region move targets
.move_targets
target_num=1
For target.target=Each target
Select target_num
Case 1
If target\moveleft=0 Then
target\x=target\x+3
If target\x=>target\xmax Then
target\moveleft=1
target\x=target\xmax
End If
Else
target\x=target\x-3
If target\x<=target\xmin Then
target\moveleft=0
target\x=target\xmin
End If
End If
Case 2
If target\moveleft=0 Then
target\x=target\x+5
If target\x=>target\xmax Then
target\moveleft=1
target\x=target\xmax
End If
Else
target\x=target\x-5
If target\x<=target\xmin Then
target\moveleft=0
target\x=target\xmin
End If
End If
End Select
target_num=target_num+1
Next
Return
;#End Region
;debug
;#Region debug
.target_debug
;display mouse and target info for debug purpose
y=390
For target.target=Each target
Text(20,y,"target "+target\id +" x="+target\x+" y="+target\y+" xmin="+target\xmin +" xmax="+target\xmax+" ymin="+target\ymin +" ymax="+target\ymax)
y=y+10
Next
Text(20,y,"mouse x=" +MouseX() +" y=" +MouseY() +" button1=" +MouseDown(1) +" collide=" +target_mouseover)
y=y+10
Text(20,y,"target id="+target_id)
Return
;#End Region