
-----------------------------------
Tamaranian
Wed Jun 12, 2013 8:00 pm

Collision problems - Need Lasers to hit and destroy enemies
-----------------------------------
What is it you are trying to achieve?
I'm trying to make lasers shoot out of the player's sprite by pressing the space bar (So far, I've got that right). Then, the lasers should collide with enemies, and make them disappear, while also adding 25 points to the score.

What is the problem you are having?
When the lasers hit the enemies, they don't disappear and nothing is added to the score. The coordinates of the two sprites appear to be correct, but I can't get anything to happen when they touch. Also, when the user clicks "main menu" to restart the game when they lose, collision doesn't work at all in the new game. 


Describe what you have tried to solve this problem
I've tried changing collision coordinates and moving loops and code around, but I just don't understand how to fix it. I'm fairly new to this :/


Please specify what version of Turing you are using
Turing 4.1.1

-----------------------------------
Insectoid
Wed Jun 12, 2013 8:38 pm

RE:Collision problems - Need Lasers to hit and destroy enemies
-----------------------------------
[code]if (LaserX + 60 > planeX - 60) and (LaserX - 60 < planeX + 60) and (LaserY + 35 > planeY - 40) and (LaserY - 35 < planeY + 40) then
		     score := score + 25
		     
		    
		     end if[/code]

Right now your laser isn't doing anything because you haven't told it to (other than to increase the score). Your code here looks fine to me, but since you didn't provide any images I can't test it. To confirm that it is actually working, add a put statement inside that if statement, and if it writes to the screen you know the collision is indeed detected.

So now you need to add the code to destroy an enemy. It looks like right now you only have one plane on the screen at a time, so I'm guessing that you want to spawn a new plane when the current one dies. This can be done simply by changing the plane's coordinates to some predefined spawning location (off-screen perhaps?) and drawing it there instead.

I found a few issues in your code other than collision.
[code]picGAME := Pic.FileNew ("NEW GAME BACKGROUND.JPG")
	picGAME := Pic.Scale (picGAME, maxx, maxy)[/code]

You have these lines several times in the same loop, even though they haven't changed. Why? This will slow your program down quite a bit. Just load it once at the beginning, scale it, and then use it in the loop.

-----------------------------------
Tamaranian
Wed Jun 12, 2013 8:50 pm

Re: RE:Collision problems - Need Lasers to hit and destroy enemies
-----------------------------------


Sorry about the pictures, is there a way I can still post them? It looks like I can only attach things one at a time atm.

-----------------------------------
Insectoid
Wed Jun 12, 2013 8:59 pm

RE:Collision problems - Need Lasers to hit and destroy enemies
-----------------------------------
Upload it as a zip file.

-----------------------------------
Tamaranian
Wed Jun 12, 2013 8:59 pm

RE:Collision problems - Need Lasers to hit and destroy enemies
-----------------------------------
[code] if (LaserX + 60 > planeX - 60) and (LaserX - 60 < planeX + 60) and (LaserY + 35 > planeY - 40) and (LaserY - 35 < planeY + 40) then
                     score := score + 25
                     Sprite.SetPosition (Plane, 10000, 10000, true)
                    
                     end if[/code]

This doesn't seem to work either. Have I done this wrong?

-----------------------------------
Tamaranian
Wed Jun 12, 2013 9:03 pm

Re: Collision problems - Need Lasers to hit and destroy enemies
-----------------------------------
Alright, here it is.

-----------------------------------
Insectoid
Wed Jun 12, 2013 9:56 pm

Re: RE:Collision problems - Need Lasers to hit and destroy enemies
-----------------------------------


You moved the sprite, but you didn't change it's X or Y variables, so the next time the loop iterates it's going to run Sprite.SetPosition (Plane, planeX, planeY, true) and move right back to where it was. 
Also, this is going to move your plane to a ridiculous location (10000, 10000), which means you'll probably never see it again. Can you think of a better place to put it when it gets hit?

Also, I suggest putting the game over screen into its own loop. As it is, I can still move and shoot lasers in the game over screen even though the sprite is hidden. Your code should look like this:

[code]
%set up variables

procedure mainMenu
    loop
    %draw buttons, detect clicks, etc
    if 'start game' is clicked then
        %run instruction procedure
        %run game procedure
        %run game over screen procedure (or win screen, as required)
    end if
    if 'quit' button is clicked then
        exit
    end if
    %continue for other buttons
    end loop
end mainMenu

procedure instructions
    loop
        %draw instructions
        %exit when start button is clicked
    end loop
end instructions

procedure gameOverScreen
    loop
        %draw the screen
        %exit when 'main menu' button is clicked
    end loop
end gameOverScreen

procedure game
    %initialize all X & Y values, score, etc. Variables that need to reset every time the game is restarted.
    loop
    cls
    %check for input, adjust x/y values accordingly
    %move AI characters
    %check for collisions and deal with them
    %draw everything
    View.Update
    %delay as necessary
    exit when life 