
-----------------------------------
razrdude
Mon Oct 30, 2006 6:05 pm

[Help] Yet Again, proc and Loops, and loops in loops
-----------------------------------
Hey well whoever's been following my posts, Ive now added ship movements and have the ship moving around, but now the problem is that the scope is being drawn once only and its not moving with the mouse. I know its cuz of the cls and View Image but I do not know how to fix it. Ill post my code here, but its better if you dl the file cuz there are images. Thanks a lot for all help. 

btw I have to do these:
1. Get scope to show and moving 
2. Collision Detection, ship gets blasted 
3. Ship spawn 
4. Parameters maybe.
5. Instructions and Documentation 

%The GUI contains the predefined subprograms for creating & using a Graphical
%User Interface
import GUI
%Setcreen creates a window, enters graphic mode, changes the window to 1000
%x600 and turns of the cursor
setscreen ("graphics:1000;600,nocursor")

%This variable is an integers and allow the scope to be drawn anywhere
var x, y, button : int
var mspace1 : int
var spaceship : int
spaceship := Pic.FileNew ("shipf.bmp")
var spacex, spacey : int
var background : int
background := Pic.FileNew ("background.bmp")

spacex := 450
spacey := 300
% this loop is used to randomly generate direction of movement for the space ship
procedure draw (x, y : int)

    View.Set ("offscreenonly")
    loop
        randint (mspace1, 1, 4)
        if mspace1 = 1 then
            spacey := (spacey + 50)
        else
            if mspace1 = 2 then
                spacex := (spacex - 50)
            else
                if mspace1 = 3 then
                    spacey := (spacey - 50)
                else
                    if mspace1 = 4 then
                        spacex := (spacex + 50)
                    end if
                end if
            end if
        end if
        Pic.Draw (spaceship, spacex, spacey, picUnderMerge)
        delay (300)
        View.Update
        cls
        Pic.Draw (background, 0, 0, picUnderMerge)

        
        %Scope casting
        Draw.FillOval (x, y, 55, 55, black)
        Draw.FillOval (x, y, 50, 50, white)

        %Thick crosshair threads
        Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
        Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
        Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
        Draw.ThickLine (x, y + 50, x, y + 35, 3, black)

        %Thin threads
        Draw.Line (x - 20, y, x + 20, y, red)
        Draw.Line (x, y - 20, x, y + 20, red)
        
        
    end loop % this ends the loop of movement
end draw

loop
    Mouse.Where (x, y, button)
    draw (x, y)
   
end loop


If you want to test to see if the scope is being made, put ur mouse on the middle of the screen and press F1 (run).
Thanks

-----------------------------------
Piro24
Mon Oct 30, 2006 8:54 pm


-----------------------------------
I'm a noob in Turing too (started about 3-4 weeks ago), but...

What's the point in making your entire code a procedure?

If you are going to do it all in one loop, don't use a procedure...That way the Mouse.Where will apply to your scope...

-----------------------------------
razrdude
Mon Oct 30, 2006 9:01 pm


-----------------------------------
Yea i got a fix from Ultrahex %User Interface 
import GUI 
%Setcreen creates a window, enters graphic mode, changes the window to 1000 
%x600 and turns of the cursor 
setscreen ("graphics:1000;600,nocursor") 

%This variable is an integers and allow the scope to be drawn anywhere 
var x, y, button : int 
var mspace1 : int 
var spaceship : int 
spaceship := Pic.FileNew ("shipf.bmp") 
var spacex, spacey : int 
var background : int 
background := Pic.FileNew ("background.bmp") 

spacex := 450 
spacey := 300 
% this loop is used to randomly generate direction of movement for the space ship 
procedure draw (x, y : int) 

    View.Set ("offscreenonly") 
    randint (mspace1, 1, 10) 
    if mspace1 = 1 then 
        spacey := (spacey + 50) 
    else 
        if mspace1 = 2 then 
            spacex := (spacex - 50) 
        else 
            if mspace1 = 3 then 
                spacey := (spacey - 50) 
            else 
                if mspace1 = 4 then 
                    spacex := (spacex + 50) 
                end if 
            end if 
        end if 
    end if 
    Pic.Draw (spaceship, spacex, spacey, picUnderMerge) 
    %delay (300) 
    Pic.Draw (background, 0, 0, picUnderMerge) 


    %Scope casting 
    Draw.FillOval (x, y, 55, 55, black) 
    Draw.FillOval (x, y, 50, 50, white) 

    %Thick crosshair threads 
    Draw.ThickLine (x - 50, y, x - 35, y, 3, black) 
    Draw.ThickLine (x + 50, y, x + 35, y, 3, black) 
    Draw.ThickLine (x, y - 50, x, y - 35, 3, black) 
    Draw.ThickLine (x, y + 50, x, y + 35, 3, black) 

    %Thin threads 
    Draw.Line (x - 20, y, x + 20, y, red) 
    Draw.Line (x, y - 20, x, y + 20, red) 
    delay (20) 
    View.Update 
    cls 
end draw 

loop 
    Mouse.Where (x, y, button) 
    draw (x, y) 

end loop 



but now the scope appears on top of the spaceship, how do i fix that?
Also need help with collision detection.

-----------------------------------
Expirant
Mon Oct 30, 2006 11:10 pm


-----------------------------------
To get the spaceship to appear beneath the crosshair you need to draw the spaceship over the crosshair. 

I'm not really sure what picUnderMerge does exactly...but it looks like it moves that particular picture to the back?

Anyways, moving your drawing of the spaceship to the end of your code (so...drawing it last) should fix it. I would separate your code into a more organized fashion, though, to give you more flexibility with it.

Good luck,
Expirant

-----------------------------------
razrdude
Tue Oct 31, 2006 12:58 am


-----------------------------------
Hey people here is what i have so far. The only problem is that Now I need the mouse to click in a specific range to make the health go down. 

%User Interface
import GUI
%Setcreen creates a window, enters graphic mode, changes the window to 1000
%x600 and turns of the cursor
setscreen ("graphics:1000;600,nocursor")

%This variable is an integers and allow the scope to be drawn anywhere
var x, y, button : int
var mspace1 : int
var i : int


var spaceship : int
spaceship := Pic.FileNew ("ship.bmp")

var background : int
background := Pic.FileNew ("background.bmp")

var explosion : int
explosion := Pic.FileNew ("explosion.bmp")

var health1 : int
health1 := Pic.FileNew ("health1.bmp")

var health2 : int
health2 := Pic.FileNew ("health2.bmp")

var health3 : int
health3 := Pic.FileNew ("health3.bmp")

var health4 : int
health4 := Pic.FileNew ("health4.bmp")

var health5 : int
health5 := Pic.FileNew ("health5.bmp")

var health6 : int
health6 := Pic.FileNew ("health6.bmp")

var health7 : int
health7 := Pic.FileNew ("health7.bmp")

var health8 : int
health8 := Pic.FileNew ("health8.bmp")

var health9 : int
health9 := Pic.FileNew ("health9.bmp")

var health10 : int
health10 := Pic.FileNew ("health10.bmp")

var health11 : int
health11 := Pic.FileNew ("health11.bmp")

var health12 : int
health12 := Pic.FileNew ("health12.bmp")

var health13 : int
health13 := Pic.FileNew ("health13.bmp")

var health14 : int
health14 := Pic.FileNew ("health14.bmp")

var health15 : int
health15 := Pic.FileNew ("health15.bmp")

var health16 : int
health16 := Pic.FileNew ("health16.bmp")

var health17 : int
health17 := Pic.FileNew ("health17.bmp")

var health18 : int
health18 := Pic.FileNew ("health18.bmp")

var health19 : int
health19 := Pic.FileNew ("health19.bmp")

var health20 : int
health20 := Pic.FileNew ("health20.bmp")

var health21 : int
health21 := Pic.FileNew ("health21.bmp")

var pos : int
var spacex, spacey : int

spacex := 450
spacey := 300
i := 1
% this loop is used to randomly generate direction of movement for the space ship
procedure draw (x, y : int)

    View.Set ("offscreenonly")
    randint (mspace1, 1, 15)
    if mspace1 = 1 then
        spacey := (spacey + 30)
    else
        if mspace1 = 2 then
            spacex := (spacex - 30)
        else
            if mspace1 = 3 then
                spacey := (spacey - 30)
            else
                if mspace1 = 4 then
                    spacex := (spacex + 30)

                end if
            end if
        end if
    end if

    Pic.Draw (spaceship, spacex, spacey, picXor)
    %Pic.Draw (health1, 190, 525, picMerge)
    Pic.Draw (background, 0, 0, picMerge)
    %health counter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%something over here%%%%%%%%%%%%%%%%%%%%%%%%
if x=spacex+-500 and y=spacey+-500 and button=1 then
        i := i + 1
    end if
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if i = 1 then
        Pic.Draw (health1, 190, 525, picMerge)
    else
        if i = 2 then
            Pic.Draw (health2, 190, 525, picMerge)
        else
            if i = 3 then
                Pic.Draw (health3, 190, 525, picMerge)
            else
                if i = 4 then
                    Pic.Draw (health4, 190, 525, picMerge)
                else
                    if i = 5 then
                        Pic.Draw (health5, 190, 525, picMerge)
                    else
                        if i = 6 then
                            Pic.Draw (health6, 190, 525, picMerge)
                        else
                            if i = 7 then
                                Pic.Draw (health7, 190, 525, picMerge)
                            else
                                if i = 8 then
                                    Pic.Draw (health8, 190, 525, picMerge)
                                else
                                    if i = 9 then
                                        Pic.Draw (health9, 190, 525, picMerge)
                                    else
                                        if i = 10 then
                                            Pic.Draw (health10, 190, 525, picMerge)
                                        else
                                            if i = 11 then
                                                Pic.Draw (health11, 190, 525, picMerge)
                                            else
                                                if i = 12 then
                                                    Pic.Draw (health12, 190, 525, picMerge)
                                                else
                                                    if i = 13 then
                                                        Pic.Draw (health13, 190, 525, picMerge)
                                                    else
                                                        if i = 14 then
                                                            Pic.Draw (health14, 190, 525, picMerge)
                                                        else
                                                            if i = 15 then
                                                                Pic.Draw (health15, 190, 525, picMerge)
                                                            else
                                                                if i = 16 then
                                                                    Pic.Draw (health16, 190, 525, picMerge)
                                                                else
                                                                    if i = 17 then
                                                                        Pic.Draw (health17, 190, 525, picMerge)
                                                                    else
                                                                        if i = 18 then
                                                                            Pic.Draw (health18, 190, 525, picMerge)
                                                                        else
                                                                            if i = 19 then
                                                                                Pic.Draw (health19, 190, 525, picMerge)
                                                                            else
                                                                                if i = 20 then
                                                                                    Pic.Draw (health20, 190, 525, picMerge)
                                                                                else
                                                                                    if i = 21 then
                                                                                        Pic.Draw (health21, 190, 525, picMerge)
                                                                                        Pic.Draw (explosion, 500, 300, picMerge)
                                                                                        if i = 22 then
                                                                                            i := 1
                                                                                            cls
                                                                                        end if
                                                                                    end if
                                                                                end if
                                                                            end if
                                                                        end if
                                                                    end if
                                                                end if
                                                            end if
                                                        end if
                                                    end if

                                                end if
                                            end if

                                        end if
                                    end if
                                end if

                            end if
                        end if
                    end if
                end if
            end if

        end if
    end if

    %Scope casting
    Draw.Oval (x, y, 55, 55, black)
    Draw.Oval (x, y, 54, 54, black)
    Draw.Oval (x, y, 53, 53, black)
    Draw.Oval (x, y, 52, 52, black)
    Draw.Oval (x, y, 51, 51, black)
    Draw.Oval (x, y, 50, 50, black)
    Draw.Oval (x, y, 54, 54, black)
    Draw.Oval (x, y, 54, 53, black)
    Draw.Oval (x, y, 54, 52, black)
    Draw.Oval (x, y, 54, 51, black)
    Draw.Oval (x, y, 54, 50, black)
    Draw.Oval (x, y, 50, 51, black)
    Draw.Oval (x, y, 50, 52, black)
    Draw.Oval (x, y, 50, 53, black)
    Draw.Oval (x, y, 50, 54, black)
    Draw.Oval (x, y, 50, 55, black)
    Draw.Oval (x, y, 51, 50, black)
    Draw.Oval (x, y, 52, 50, black)
    Draw.Oval (x, y, 53, 50, black)
    Draw.Oval (x, y, 54, 50, black)
    Draw.Oval (x, y, 55, 50, black)
    %Thick crosshair threads
    Draw.ThickLine (x - 50, y, x - 35, y, 3, black)
    Draw.ThickLine (x + 50, y, x + 35, y, 3, black)
    Draw.ThickLine (x, y - 50, x, y - 35, 3, black)
    Draw.ThickLine (x, y + 50, x, y + 35, 3, black)

    %Thin threads
    Draw.Line (x - 20, y, x + 20, y, red)
    Draw.Line (x, y - 20, x, y + 20, red)
    delay (20)
    View.Update
    cls
end draw


loop
    Mouse.Where (x, y, button)
    draw (x, y)
end loop

% if x=spacex and y=space y and button =1



I put a lot of % where the part I am having problems with, to help you find it. Btw pls dont flame for the way I did this code, I am running out of time and couldnt do it the short way. All Help is appreciated.
btw if you guys require the whole folder i can attach it on my next post

-----------------------------------
[Gandalf]
Tue Oct 31, 2006 3:20 am


-----------------------------------
First off, you'll want to replace all these:
else
    if
with the proper elsif structue:
elsif
Then, read through my PM, if this is the topic you were referring to.

-----------------------------------
razrdude
Tue Oct 31, 2006 3:49 am


-----------------------------------
ok I did that but still having problem with getting the ship to stop drawing and moving, cuz on the 22nd click the explosion picture goes away and the ship keeps on moving. 

Here is the updated code:


%User Interface
import GUI
%Setcreen creates a window, enters graphic mode, changes the window to 1000
%x600 and turns of the cursor
setscreen ("graphics:1000;600,nocursor")
process music
    Music.PlayFile ("sound.mp3")
end music
fork music

%This variable is an integers and allow the scope to be drawn anywhere
var x, y, button : int
var mspace1 : int
var i : int
var pos : int
var spacex, spacey : int

var spaceship : int
spaceship := Pic.FileNew ("ship.bmp")
var background : int
background := Pic.FileNew ("background.bmp")
var explosion : int
explosion := Pic.FileNew ("explosion.bmp")
var health1 : int
health1 := Pic.FileNew ("health1.bmp")
var health2 : int
health2 := Pic.FileNew ("health2.bmp")
var health3 : int
health3 := Pic.FileNew ("health3.bmp")
var health4 : int
health4 := Pic.FileNew ("health4.bmp")
var health5 : int
health5 := Pic.FileNew ("health5.bmp")
var health6 : int
health6 := Pic.FileNew ("health6.bmp")
var health7 : int
health7 := Pic.FileNew ("health7.bmp")
var health8 : int
health8 := Pic.FileNew ("health8.bmp")
var health9 : int
health9 := Pic.FileNew ("health9.bmp")
var health10 : int
health10 := Pic.FileNew ("health10.bmp")
var health11 : int
health11 := Pic.FileNew ("health11.bmp")
var health12 : int
health12 := Pic.FileNew ("health12.bmp")
var health13 : int
health13 := Pic.FileNew ("health13.bmp")
var health14 : int
health14 := Pic.FileNew ("health14.bmp")
var health15 : int
health15 := Pic.FileNew ("health15.bmp")
var health16 : int
health16 := Pic.FileNew ("health16.bmp")
var health17 : int
health17 := Pic.FileNew ("health17.bmp")
var health18 : int
health18 := Pic.FileNew ("health18.bmp")
var health19 : int
health19 := Pic.FileNew ("health19.bmp")
var health20 : int
health20 := Pic.FileNew ("health20.bmp")
var health21 : int
health21 := Pic.FileNew ("health21.bmp")

spacex := 450
spacey := 300
i := 1
% this loop is used to randomly generate direction of movement for the space ship
procedure draw (x, y : int)

    View.Set ("offscreenonly")
    randint (mspace1, 1, 6)
    if mspace1 = 1 then
        spacey := (spacey + 60)
    else
        if mspace1 = 2 then
            spacex := (spacex - 60)
        else
            if mspace1 = 3 then
                spacey := (spacey - 60)
            else
                if mspace1 = 4 then
                    spacex := (spacex + 60)
                end if
            end if
        end if
    end if


    Pic.Draw (spaceship, spacex, spacey, picXor)
    %Pic.Draw (health1, 190, 525, picMerge)
    Pic.Draw (background, 0, 0, picMerge)
    %health counter
    %loop
    %   if button :=21


    if spacex 