Fly Swatter Mini Game 
	 
	
		| Author | 
		Message | 
	 
		 
		andrew.
 
 
 
    
		 | 
		
		
			
				  Posted: Sun May 11, 2008 10:27 am    Post subject: Fly Swatter Mini Game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Hi guys,
 
 
I'm having a bit of trouble with my fly swatter mini game. I have the code (which I will clean up, refine, and make it prettier later) but I just can't figure out how kep the the glass looking like it is cracked. Look at my code, you'll see that when you click somewhere, it draws a crack, but I can't think of anyway to keep the crack there. Any help?
 
 
	  | Turing: | 	 		  setscreen ("graphics:800,600,offscreenonly,nobuttonbar")
var flyx, flyy, shoofly  : array 1 ..  5 of int
var Colour  : array 1 ..  5 of int := init (black,  black,  black,  black,  black)
var mousex, mousey, button  : int
var flycounter, hitcount  : int := 0
var crack1, crack2, crack3, crack  : int
var cracknum  : int := 1
var crackx, cracky  : array 1 ..  21 of int
crackx  (1) := 0
cracky  (1) := 0
crack1  := Pic.FileNew ("crack1.jpg")
crack2  := Pic.FileNew ("crack2.jpg")
crack3  := Pic.FileNew ("crack3.jpg")
var fly  : int := Pic.FileNew ("fly.jpg")
crack  := 0
const flyspeed  := 10
for i  : 1 ..  5
    shoofly  (i ) := 1
end for
process splat
     Music.PlayFile ("splat.mp3")
end splat
 process swat
     Music.PlayFile ("swat.mp3")
end swat
 for i  : 1 ..  5
    randint (flyx  (i ), 0,  maxx)
    randint (flyy  (i ), 0,  maxy)
end for
loop
    Mouse.Where (mousex, mousey, button )
    cls
    drawline (maxx div 2 -  250,  50,  maxx div 2 +  150,  maxy -  50,  30)
    drawline (maxx div 2 -  200,  50,  maxx div 2 +  200,  maxy -  50,  30)
    if button  = 1 then
        fork splat
 
        crackx  (cracknum ) := mousex
 
        cracky  (cracknum ) := mousey
         randint (crack,  1,  3)
        % I want this picture to stay drawn.
        if crack  = 1 then
            Pic.Draw (crack1, crackx  (cracknum ) -  (Pic.Width (crack1 )) div 2, cracky  (cracknum ) -  (Pic.Height (crack1 )) div 2,  picMerge)
        elsif crack  = 2 then
            Pic.Draw (crack2, crackx  (cracknum ) -  (Pic.Width (crack2 )) div 2, cracky  (cracknum ) -  (Pic.Height (crack2 )) div 2,  picMerge)
        elsif crack  = 3 then
            Pic.Draw (crack3, crackx  (cracknum ) -  (Pic.Width (crack3 )) div 2, cracky  (cracknum ) -  (Pic.Height (crack3 )) div 2,  picMerge)
        end if
        cracknum + = 1
        hitcount + = 1
    end if
    for i  : 1 ..  5
        Pic.Draw (fly, flyx  (i ), flyy  (i ), picMerge)
        flyx  (i ) + = Rand.Int  (-flyspeed, flyspeed )
        flyy  (i ) + = Rand.Int  (-flyspeed, flyspeed )
        if not shoofly  (i ) = 1 then
            if flyy  (i ) >=  maxy then
                flyy  (i ) := maxy
            elsif flyy  (i ) <=  0 then
                flyy  (i ) := 0
            elsif flyx  (i ) >=  maxx then
                flyx  (i ) := maxx
            elsif flyx  (i ) <=  0 then
                flyx  (i ) := 0
            end if
        end if
        if mousex > flyx  (i ) -  20 and mousex < flyx  (i ) +  20 and mousey > flyy  (i ) -  20 and mousey < flyy  (i ) +  20 and button  = 1 then
            flycounter + = 1
            flyx  (i ) := - 1000
            shoofly  (i ) := 1
            fork swat
         end if
    end for
    delay (50)
    View.Update
    if flycounter  = 5 then
        cls
        put "You win!"
        exit
        elsif hitcount  = 20 then
        cls
        put "You lose. You broke the glass."
        exit
    end if
end loop
  | 	  
 
 
Thanks a lot,
 
andrew. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		Dan
 
  
 
    
		 | 
		
		
			
				  Posted: Sun May 11, 2008 8:00 pm    Post subject: RE:Fly Swatter Mini Game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				It's hard to debug the code with out the pictuers but my guses is that you are clearing the screen and it clears away the images of the cracks. 
 
 
What you will have to do is keep track of the where the cracks are and redraw them all every loop. Or you could store a pic of the background befor anything is drawn above it in memeory and redraw that affter the screen is cleared. | 
			 
			
				| Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!  | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		andrew.
 
 
 
    
		 | 
		
		
			
				  Posted: Mon May 12, 2008 6:05 pm    Post subject: RE:Fly Swatter Mini Game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| I've been trying to firgure out a way to have it remember where the cracks were. I'm pretty sure the code was right but the number stored in the array was turning into 0 each loop. Anyways, that's a good idea Dan, I'll just get the screen, draw the crack and save the screen. The only problem is the flies. It will save the flies too. Hmm.... | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		andrew.
 
 
 
    
		 | 
		
		
			
				  Posted: Mon May 12, 2008 6:17 pm    Post subject: RE:Fly Swatter Mini Game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Question: Can you draw the same picture more than once at a time? I got it to work, but now it replaces the old one with the new one.
 
 
EDIT:: Fixed it with a for loop. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |