Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 summative project
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
little_secrets




PostPosted: Mon Jun 16, 2008 10:25 am   Post subject: summative project

for my summative project i was going to do ddr but it was to hard for me so, now im trying to make a space, shooting game. but im having problems with it. i cant make the random objects come up, ti tried many things but as usual they dont work for me.

Turing:
var camx, camy, camz : real
var done, hit : boolean := false
var x, y : int
var h, v, button : int := 0
var rand_x, rand_y, z, count : int := 0
var width, height : int := 20

function Pt_In_Rect (x, y, x1, y1, x2, y2 : int) : boolean
    result (x > x1) and (x < x2) and (y > y1) and (y < y2)
end Pt_In_Rect


%sparkle.........................................................................
camx := maxx / 2
camy := maxy / 2
camz := 0
class Drop
    import camx, camy, camz
    export init_, move, draw, delete
    var x, y, z, zv, z2, screen_x, screen_y, screen_x2, screen_y2, zl : real
    proc init_ (x_, y_, z_, zl_ : real)
        x := x_
        y := y_
        z := z_
        zv := 0.2
        zl := zl_
    end init_
    proc move
        z += zv
        z2 := z + zl
        screen_x := (x - camx) * 5 / (z - camz + 1e-3) + camx
        screen_y := (y - camy) * 5 / (z - camz + 1e-3) + camy
        screen_x2 := (x - camx) * 5 / (z2 - camz + 1e-3) + camx
        screen_y2 := (y - camy) * 5 / (z2 - camz + 1e-3) + camy
    end move
    proc draw
        Draw.Line (round (screen_x), round (screen_y), round (screen_x2), round (screen_y2), brightblue)
    end draw
    fcn delete () : boolean
        result z > 9
    end delete
end Drop
View.Set ("position:center;center,offscreenonly")
setscreen ("graphics: 1000,500")


var drops : flexible array 1 .. 0 of ^Drop


colourback (7)
cls

process sparkle
    loop
        for n : 1 .. 4
            new drops, upper (drops) + 1
            new Drop, drops (upper (drops))
            drops (upper (drops)) -> init_ (Rand.Int (0, maxx), Rand.Int (0, maxy), 0, 0.3)
        end for
        for i : 1 .. upper (drops)
            exit when i > upper (drops)
            if drops (i) -> delete () then
                free drops (i)
                drops (i) := drops (upper (drops))
                new drops, upper (drops) - 1
            else
                drops (i) -> move
                drops (i) -> draw
            end if
        end for
        View.Update
        delay (15)
        cls
        end loop
    end sparkle

    fork sparkle
    %fork target

    loop
        Mouse.Where (h, v, button)
        Pic.ScreenLoad ("target.bmp", h - 31, v - 30, picMerge)
        %Pic.ScreenLoad ("pit2.jpg", 0,0, picMerge)
        drawfilloval (maxx div 2, maxy div 205, 18, 18, red)
        %drawoval (maxx div 2, maxy div 205, 16, 16, brightred)
        drawoval (maxx div 2, maxy div 205, 22, 22, brightred)
        drawline (maxx div 2, maxy div 205, h, v, 89)
        %y -= 1
        View.Update
        delay (10)
        %exit when x = 50
        cls

    end loop
    %end loop

    %random objects
    %snake game ???????
    %skyscraper thing
    %animations read form another file

%random objects..........................................................   
    loop

        Mouse.Where (h, v, button)
        hit := false                                        % reset hit at the beginning of each turn
        randint (rand_x, 0, maxx)
        randint (rand_y, 0, maxy)
        drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, yellow)
        drawfilloval (maxx div 2, 2, 18, 18, red)
        drawoval (maxx div 2, 2, 22, 22, brightred)
        %draw box in randon location
        loop
            buttonwait ("down", h, v, z, z)                 % user must click on box to exit this loop
            if Pt_In_Rect (h, v, rand_x, rand_y, rand_x + width, rand_y + height) then
                hit := true
            end if
            exit when hit
        end loop
        drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, black)


        count := count + 1
        if count = 6 then                            % count the number of hits
            done := true
        end if
end loop

%target..........................................................   

    loop

        Mouse.Where (h, v, button)
        hit := false                                        % reset hit at the beginning of each turn
        randint (rand_x, 0, maxx)
        randint (rand_y, 0, maxy)
        drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, yellow)
        drawfilloval (maxx div 2, 2, 18, 18, red)
        drawoval (maxx div 2, 2, 22, 22, brightred)
        %draw box in randon location
        loop
            buttonwait ("down", h, v, z, z)                 % user must click on box to exit this loop
            if Pt_In_Rect (h, v, rand_x, rand_y, rand_x + width, rand_y + height) then
                hit := true
            end if
            exit when hit
        end loop
        drawfillbox (rand_x, rand_y, rand_x + width, rand_y + height, black)


        count := count + 1
        if count = 6 then                            % count the number of hits
            done := true
        end if


    end loop


[Mod edit: Lets use syntax tags and the edit button]



target.bmp
 Description:
the target image
 Filesize:  10.96 KB
 Viewed:  2307 Time(s)

target.bmp



rainv3.t
 Description:
the game

Download
 Filename:  rainv3.t
 Filesize:  4.24 KB
 Downloaded:  94 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Mon Jun 16, 2008 11:51 pm   Post subject: RE:summative project

See the loop where you have:

Turing:

loop
    Mouse.Where (h, v, button)
    Pic.ScreenLoad ("target.bmp", h - 31, v - 30, picMerge)
    %Pic.ScreenLoad ("pit2.jpg", 0,0, picMerge)
    drawfilloval (maxx div 2, maxy div 205, 18, 18, red)
    ...

end loop


That loop never exits. Since the code to make random objects is after that, you will never execute it. You get "stuck" in the infinite loop, and never get past it.

You'll have to figure out some way of combining the code for random-object-showing with the code for your player input...or else fork another process. Personally, I'd go for the first one: a little more work up-front, but way fewer Turing multithreading headaches down the road.
little_secrets




PostPosted: Tue Jun 17, 2008 5:51 pm   Post subject: RE:summative project

iv tried that but it always doesnt work for me. could you give me any ideas on how to combine them.
Reality Check




PostPosted: Tue Jun 17, 2008 8:50 pm   Post subject: Re: summative project

Consider that you don't want to make random objects or enemies pop up through every iteration. That'd fill up the screen pretty fast. Think about how you're going to implement your random enemy generator only some times. Also, this'll help for progressing the game and making it harder. As you progress in the game (say when you reach a certain score?) enemies will generate more often than they did. I wonder what time it is Laughing
riveryu




PostPosted: Tue Jun 17, 2008 9:00 pm   Post subject: RE:summative project

Reality Check just reminded me how the many bugs I'ved killed on my disk, but more just come out of nowhere , the difficulty is increasing...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: