look at the code below. I have 2timers 1 for 60 and 1 for 10.
Problem i have is that the targets move very fast on the screen. Using both timers makes no difference that I can see. Using just timer 1 makes the mouse move slow.
I want the mouse to move full speed but be able to control the speed of the targets with a timer. How can I do this please?
Problem i have is that the targets move very fast on the screen. Using both timers makes no difference that I can see. Using just timer 1 makes the mouse move slow.
I want the mouse to move full speed but be able to control the speed of the targets with a timer. How can I do this please?
;========================================================================================== ;#Region setup ;create globals for video display Global gfx_x=640 Global gfx_y=480 Global gfx_colour_depth=16 ;========================================================================================== ;create window Graphics gfx_x,gfx_y,gfx_colour_depth,2 ;screen =640,480,16 bit colour AppTitle="Shape Shoot" SetBuffer BackBuffer() SeedRnd MilliSecs();get better random result HidePointer ;hide the mouse arrow ;#End Region ;========================================================================================== ;create rest of globals ;#Region globals and things Global target_image_width=40 Global target_image_height=40 Global target_found=0 Global target_id=0 Global target_mouseover=0 Global mouse_hit=0 Global level_complete=0 Global explode=0 ;is target ready for exploding? ;load pics and sound etc Global mouse_crosshair_image=LoadImage("gfx\crosshair.bmp") MaskImage(mouse_crosshair_image,255,0,255) Global gfx_back=LoadImage("gfx\back.bmp") Global sfx_hit=LoadSound("sfx\hit.wav") Global sfx_fire=LoadSound("sfx\fire.wav") Global splash=LoadImage("gfx\splash.bmp") Global explosion=LoadAnimImage("gfx\explosion_frames.bmp",40,40,0,11) ;#End Region ;========================================================================================== ;create types Type target Field x=0 ;x pos Field y=0 ; y pos Field id ; id number of target Field hit=0 ;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 Field moveup=0 ;is the target moving up or down? 0 down 1 up 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=0 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 target_1\moveup=0 MaskImage (target_1\image,255,0,255) ;get rid of the surrounding white of the image target_2.target=New target target_2\x=target_image_width*2 target_2\y=target_image_height*2 target_2\id=2 target_2\hit=0 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 target_2\moveup=0 MaskImage (target_2\image,255,0,255) ;get rid of the surrounding white of the image target_3.target=New target target_3\x=target_image_width*4 target_3\y=target_image_height*4 target_3\id=3 target_3\hit=0 target_3\xmax=gfx_x-(target_image_width*2) target_3\ymax=gfx_y-(target_image_height*2) target_3\xmin=0+(target_image_width) target_3\ymin=0+(target_image_height) target_3\image=LoadImage("gfx\target3.bmp") ;x40,y40 pixels target_3\moveleft=0 target_3\moveup=0 MaskImage (target_3\image,255,0,255) ;get rid of the surrounding white of the image ;#End Region ;========================================================================================== ;main loop Gosub initialise timer=CreateTimer(60) timer2=CreateTimer(10) 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 ;check for mouse button being pressed and get value mouse_hit= MouseHit (1) target_found=0 ;reset target found flag Gosub draw_objects ;draw objects onto screen Gosub mouse_chk ;keep the mouse on the screen! Gosub move_targets ;move the targets Gosub check_targets ;check if mouse over target Gosub check_all_targets_destroyed ;check to see if level complete Gosub target_debug ;display debug info ;flip the buffer screen Flip WaitTimer timer ;are all targets destroyed? If level_complete=1 Then Delay(1000):Goto end_game 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 ;get id of the target for debug target_id=target\id If target\hit =0 Then ;if target not already been hit ;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 for debug ;check to see if mouse button 1 is down If mouse_hit =True Then target\hit=1 ;target been hit PlaySound sfx_hit ;play hit sound explode_target(target_id) ;explode the target End If target_found=1 ;we found it so no need to look anymore ElseIf mouse_hit=True Then ;if fire pressed and not over any targets PlaySound sfx_fire ;play fire sound Else ;if mouse is not over any of the targets target_id=0 ;no target to find id of for debug End If End If 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 Function explode_target(id) Local target.target=Null target=get_target_id.target(id) target\image=explosion frame=1 While frame<10 Cls DrawImage gfx_back,0,0 DrawImage explosion,target\x,target\y,frame ;DrawImage target_1\image,target_1\x,target_1\y ;DrawImage target_2\image,target_2\x,target_2\y ;DrawImage target_3\image,target_3\x,target_3\y ;DrawImage mouse_crosshair_image, MouseX(), MouseY() Delay(50) Flip frame=frame+1 Wend End Function Function random_numbers(a,b) c=Rand(a,b) Return c End Function ;========================================================================================== ;subroutines etc ;#Region initialise .initialise ;clear screen and display splash logo Cls While Not MouseDown(1) ;press mouse to clear splash DrawImage(splash,0,0) Wend MoveMouse(0,280); position mouse at 0,280 bottom left corner Return ;#End Region ;draw the targets on the screen ;#Region draw objects .draw_objects DrawImage gfx_back,0,0 ;only draw targets that have not been hit If target_1\hit=0 Then DrawImage target_1\image,target_1\x,target_1\y If target_2\hit=0 Then DrawImage target_2\image,target_2\x,target_2\y If target_3\hit=0 Then DrawImage target_3\image,target_3\x,target_3\y DrawImage mouse_crosshair_image, MouseX(), MouseY() Return ;#End Region ;check mouse doesnt go out of screen area ;#Region mouse check .mouse_chk If MouseX()>=(620) Then MoveMouse((620),MouseY()) If MouseX()<0 Then MoveMouse(0,MouseY()) If MouseY()>=(290) Then MoveMouse(MouseX(),(290)) If MouseY()<=1 Then MoveMouse(MouseX(),1) Return ;#End Region ;move the targets around the screen ;#Region move targets .move_targets target_num=1 ;first target to move WaitTimer timer2 For target.target=Each target ;go through each target Local moveup=random_numbers(0,1) Local moveleft=random_numbers(0,1) Local movedistx=random_numbers(1,20) Local movedisty=random_numbers(1,10) If target\hit=0 Then Select target_num Case 1 ;target 1 If moveleft=0 Then ;if moving to right target\x=target\x+movedistx ;add 1 to x If target\x=>target\xmax Then ;if target at max right of screen target\x=target\xmax ;move target to max right position so dont go off screen End If Else target\x=target\x-movedistx ;otherwise if target is moving to the left take 1 off x If target\x<=target\xmin Then ;if target at far left of screen target\x=target\xmin ;keep at far left End If End If If moveup=0 Then ;if moving to right target\y=target\y+movedisty ;add 1 to x If target\y=>target\ymax Then ;if target at max right of screen target\y=target\ymax ;move target to max right position so dont go off screen End If Else target\y=target\y-movedisty ;otherwise if target is moving to the left take 1 off x If target\y<=target\ymin Then ;if target at far left of screen target\y=target\ymin ;keep at far left End If End If Case 2 ;target 2 If moveleft=0 Then ;if moving to right target\x=target\x+movedistx ;add 1 to x If target\x=>target\xmax Then ;if target at max right of screen target\x=target\xmax ;move target to max right position so dont go off screen End If Else target\x=target\x-movedistx ;otherwise if target is moving to the left take 1 off x If target\x<=target\xmin Then ;if target at far left of screen target\x=target\xmin ;keep at far left End If End If If moveup=0 Then ;if moving to right target\y=target\y+movedisty ;add 1 to x If target\y=>target\ymax Then ;if target at max right of screen target\y=target\ymax ;move target to max right position so dont go off screen End If Else target\y=target\y-movedisty ;otherwise if target is moving to the left take 1 off x If target\y<=target\ymin Then ;if target at far left of screen target\y=target\ymin ;keep at far left End If End If Case 3 ;target 3 If moveleft=0 Then ;if moving to right target\x=target\x+movedistx ;add 1 to x If target\x=>target\xmax Then ;if target at max right of screen target\x=target\xmax ;move target to max right position so dont go off screen End If Else target\x=target\x-movedistx ;otherwise if target is moving to the left take 1 off x If target\x<=target\xmin Then ;if target at far left of screen target\x=target\xmin ;keep at far left End If End If If moveup=0 Then ;if moving to right target\y=target\y+movedisty ;add 1 to x If target\y=>target\ymax Then ;if target at max right of screen target\y=target\ymax ;move target to max right position so dont go off screen End If Else target\y=target\y-movedisty ;otherwise if target is moving to the left take 1 off x If target\y<=target\ymin Then ;if target at far left of screen target\y=target\ymin ;keep at far left End If End If End Select End If target_num=target_num+1 ;move to next target Next Return ;#End Region ;check if mouse is over the position of targets ;#Region check targets .check_targets If target_found=0 Then check_target_pos(1) If target_found=0 Then check_target_pos(2) If target_found=0 Then check_target_pos(3) Return ;#End Region ;check if all targets in level destroyed ;#Region check all targets destroyed . check_all_targets_destroyed total_targets=0 ;total number of targets targets_hit=0 ;how many targets are hit? For i.target= Each target If i\hit=1 Then ;if target is hit targets_hit=targets_hit+1 ;add one to total number hit End If total_targets=total_targets+1 ;get number of total targets Next If total_targets=targets_hit Then level_complete=1 ;set flag if all targets shot Return ;#End Region ;end of game routine ;#Region end of game .end_game ;clear images from memory FreeImage mouse_crosshair_image FreeImage gfx_back FreeSound sfx_hit FreeSound sfx_fire FreeImage splash FreeImage explosion ;exit game End ;#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 +" target hit=" +target\hit +" 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 +" mousehit ="+mouse_hit) y=y+10 Text(20,y,"target id="+target_id+" target_found="+ target_found) Return ;#End Region