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

Username:   Password: 
 RegisterRegister   
 Bullet gets fast when Shooter near border, why?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
riveryu




PostPosted: Fri Mar 07, 2008 7:54 pm   Post subject: Bullet gets fast when Shooter near border, why?

The shooter appears to be shooting faster as he gets closer to the border, why is that? How do you fix it so that the rate of bullet shooting remains constant no matter what? Also, how do you make it so that the shooter has the same movement speed while shooting? Please give specific answers, I'm just curious after I tested out the code below.

Below is code quoted from jamonathin, on Why You Should Avoid Processes

Turing:

View.Set ("offscreenonly")

var chars : array char of boolean
var x, y, bullety, bulletx : int := 100
var shot : int := 0
forward proc movement

proc shoot
    loop
        shot := 1
        bullety += 1
        exit when bullety -10> maxy
        movement
    end loop
    shot := 0
end shoot

body proc movement
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and y + 64 < maxy then
        y := y + 1
    elsif chars (KEY_DOWN_ARROW) and y -64> 0 then
        y := y - 1
    elsif chars (KEY_LEFT_ARROW) and x -64 > 0 then
        x := x - 1
    elsif chars (KEY_RIGHT_ARROW) and x + 64 < maxx then
        x := x + 1
    end if
    if chars (KEY_CTRL) and shot = 0 then
        bullety := y
        bulletx := x
        shoot
    end if
    cls
    if shot = 1 then
        drawoval (bulletx + 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx + 35, bullety, 10, 10, 7)
        drawoval (bulletx - 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx - 35, bullety, 10, 10, 7)
    end if
    drawfilloval (x, y, 20, 20, 7)
    View.Update
end movement

loop
    movement
end loop
Sponsor
Sponsor
Sponsor
sponsor
riveryu




PostPosted: Fri Mar 07, 2008 8:22 pm   Post subject: Re: Bullet gets fast when Shooter near border, why?

I answered one of my own questions, Bullet gets fast when Shooter near border, why? Because the shooter can only shoot again when the bullet hits the maxy -10, the shorter distance the faster the bullet gets to its destination, the faster the shooter can shoot again. I attempted to fix the problem by making the limit for the bullet further up the maxy. -500> maxy
Is there an already determined value for how far should the limit be for your bullet to remain constant?
Dan




PostPosted: Fri Mar 07, 2008 8:37 pm   Post subject: RE:Bullet gets fast when Shooter near border, why?

It's probly not a good idea to be calling movement from shoot and shoot from movement. That sets up some wired recursion that is realy not nessary.

Idealy you should be able to put most of that code in a singal loop that checks for key preses as well as moves the bulite and draws everything.

You could still break it down more in to procudures but it might be easyer to start with just a loop:

Turing:

............

loop
if shot = 1 then
   bullety += 1
   if bullety >= maxy - 10 then
     shot := 0
   end if
end if

 Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and y + 64 < maxy then
        y := y + 1
    elsif chars (KEY_DOWN_ARROW) and y -64> 0 then
        y := y - 1
    elsif chars (KEY_LEFT_ARROW) and x -64 > 0 then
        x := x - 1
    elsif chars (KEY_RIGHT_ARROW) and x + 64 < maxx then
        x := x + 1
    end if
    if chars (KEY_CTRL) and shot = 0 then
        bullety := y
        bulletx := x
        shot := 1
    end if
    cls
    if shot = 1 then
        drawoval (bulletx + 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx + 35, bullety, 10, 10, 7)
        drawoval (bulletx - 35, bullety - 1, 10, 10, 0)
        drawoval (bulletx - 35, bullety, 10, 10, 7)
    end if
    drawfilloval (x, y, 20, 20, 7)
    View.Update
end loop
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
riveryu




PostPosted: Sun Mar 09, 2008 1:00 pm   Post subject: RE:Bullet gets fast when Shooter near border, why?

Thanks a lot, Dan
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  [ 4 Posts ]
Jump to:   


Style:  
Search: