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

Username:   Password: 
 RegisterRegister   
 Why are the players speeding up when shooting?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
STLearning




PostPosted: Sat Jun 12, 2010 2:03 pm   Post subject: Why are the players speeding up when shooting?

What is it you are trying to achieve?
I am trying to ensure speeds stay the same even if they are shooting.

What is the problem you are having?
When the opposing player shoots, the other player slows down. However when the player shoots and moves at the same time, they go incredibly fast. When both players are shooting at the same time, and moving as well, it seems to go back to normal speeds.


Describe what you have tried to solve this problem
I've tried tinkering with delays and just about everything I could think of to make it normal, but I just can't get it right. (I also have no idea why its occurring.)
I've also tried to get rid of the processes in general, since I have a feeling that is what causing the randomness, but I completely failed at figuring out a method of doing that without bugging the entire code.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:

%Developer :
%Program Title: Dodgeball
%Version Number : 1.00
%Creation Date : May 27, 2010



%----------------------------------------------------------------------
%STARTING MENU + START BUTTON
%----------------------------------------------------------------------


import GUI                            %Required to set up GUI
setscreen ("graphics:500;400")        %Resolution
View.Set ("offscreenonly")            %Required to remove flickering

procedure hello (ch : char)
    if ch = "x" or ch = "X" then      %What happens when button is pressed -> Goes to Credits
        GUI.Quit
    end if
end hello

var quitButton : int := GUI.CreateButton (175, 50, 0, "press here when  ready", GUI.Quit)  %Creates Button
GUI.SetKeyEventHandler (hello)

View.Update

loop
    exit when GUI.ProcessEvent                %Keeps screen at button until it is clicked
end loop

%--------------------------------------------
%Credit Screen
%--------------------------------------------
cls

var font : int
font := Font.New ("Castellar:28")           %Sets font size and type for Load Bar
var loadbar : int := 50

put "Developer :
put "
Program Title: Dodgeball"
put "
Version Number : 1.00"
put "
Creation Date : May 27, 2010"
put "
With thanks to, Compsci.ca and its members
put " "
put "Please wait while the game loads"
View.Update

for count : 1 .. 5                              %Load Bar
    Font.Draw ("LOADING", 150, 155, font, black)
    drawbox (150, 100, 350, 150, black)
    drawfillbox (150, 100, 100 + loadbar, 150, green)
    View.Update
    loadbar += 50
    delay (1000)
end for

delay (1000)

%------------------------------------------------------
%GLOBAL VARIABLES
var speed : int := 0
%------------------------------------------------------

%------------------------------------------------------
%Asking for Game Speed
%------------------------------------------------------
cls

put "Please choose your game speed"
put "For a good computer please, enter a speed from 3 to 6, depending on the speed you wish the game to run at"
put "For weaker computers, please put a delay of 1 to 2"
put "After typping in your number, please press enter "

View.Update

get speed

%---------------------------------------------------
%VARIABLES FOR MOVEMENT
var x, y : int          %stores coordinates for right player
x := 400
y := 200

var a, b : int          %stores coordinates for left player
a := 100
b := 200

var bulletx1, bulleta2, bullety1, bulletb2 : int  %Stores Bullet coordinates
var shot1, shot2 : int := 0
forward proc player1movement
forward proc player2movement
%---------------------------------------------------


%---------------------------------------------------
%Process
%---------------------------------------------------
process movement1
    player1movement
end movement1
process movement2
    player2movement
end movement2

%----------------------------------------------------
%PROCEDURES
%----------------------------------------------------
proc draw
    drawfillbox (0, 0, 50, 50, gray)
    drawbox (0, 0, maxx, maxy, black)        %Boundaries
    drawline (250, 0, 250, maxy, black)
end draw


proc shoot1
    loop
        shot1 := 1                                  %Fuifills condition to draw bullet
        bulletx1 -= 1                               %Moves location of bullet
        exit when bulletx1 + 20 < 0                %exits loop after bullet leaves screen
        player1movement
    end loop
    shot1 := 0                                     %resets bullet loop
end shoot1


proc shoot2
    loop
        shot2 := 1                          %Fuifills condition to draw bullet
        bulleta2 += 1                       %Moves location of bullet
        exit when bulleta2 + 20 > maxx      %exits loop after bullet leaves screen
        player2movement

    end loop
    shot2 := 0
end shoot2


body proc player1movement

    var chars : array char of boolean         %Movement right Player
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) and y <= maxy then %Up Button
        y := y + 1
    end if
    if chars (KEY_DOWN_ARROW) and y >= 0 then  %Down Button
        y := y - 1
    end if
    if x = 250 then                             %Middle Boundary
        x := x + 0
    elsif chars (KEY_LEFT_ARROW) and x >= 0 then  %Left Button
        x := x - 1
    end if

    if chars (KEY_RIGHT_ARROW) and x <= maxx then  %Right Button
        x := x + 1
    end if
    if chars (KEY_CTRL) and shot1 = 0 then                  %Starts Shoot Procedure and sets bullet start location where player is
        bullety1 := y
        bulletx1 := x
        shoot1
    end if
   
    if shot1 = 1 then
        drawoval (bulletx1 + 35, bullety1 - 1, 10, 10, 0)           %Removes bullet trail
        drawoval (bulletx1 + 35, bullety1, 10, 10, 7)               %Draws Bullet
        drawoval (bulletx1 - 35, bullety1 - 1, 10, 10, 0)           %Removes bullet trail
        drawoval (bulletx1 - 35, bullety1, 10, 10, 7)               %Draws Bullet
    end if
    draw
    drawoval (a, b, 10, 10, red)
    drawoval (x, y, 10, 10, red)         %Draw Location of Player
    View.Update
end player1movement


body proc player2movement

    var char1 : array char of boolean  % Movement left Player
    Input.KeyDown (char1)
    if char1 ('w') and b <= maxy then %Up button
        b := b + 1
    end if
    if char1 ('s') and b >= 0 then     %Down Button
        b := b - 1
    end if
    if char1 ('a') and a >= 0 then       %Left Button
        a := a - 1
    end if
    if a = 250 then                        %Middle Boundary
        a := a + 0
    elsif char1 ('d') and a <= maxx then  %Right Button
        a := a + 1
    end if
    if char1 (KEY_SHIFT) and shot2 = 0 then             %Starts Shoot Procedure and sets bullet start location where player is
        bulletb2 := b
        bulleta2 := a
        shoot2
    end if

    if shot2 = 1 then
        drawoval (bulleta2 + 35, bulletb2 - 1, 10, 10, 0)           %Removes bullet trail
        drawoval (bulleta2 + 35, bulletb2, 10, 10, 7)               %Draws Bullet
        drawoval (bulleta2 - 35, bulletb2 - 1, 10, 10, 0)           %Removes bullet trail
        drawoval (bulleta2 - 35, bulletb2, 10, 10, 7)               %Draws Bullet
    end if
    draw
    drawoval (a, b, 10, 10, red)   %Draw Location of Player
    drawoval (x, y, 10, 10, red)
    View.Update

end player2movement


%---------------------------------------------------------------------------
% Main Loop - Everything that needs to be repeated
%---------------------------------------------------------------------------

loop
   
    fork movement1              %Allows both movements to run at same time
    fork movement2


    %View.Update     %gets rid of flickering
    delay (speed)  %sets rate of game speed
    cls             %clears screen to get rid of previous frames
    %View.Update
end loop




Please specify what version of Turing you are using
4.11
BooHoo BooHoo
Sponsor
Sponsor
Sponsor
sponsor
USEC_OFFICER




PostPosted: Sat Jun 12, 2010 2:06 pm   Post subject: RE:Why are the players speeding up when shooing?

It may have something to do with the fact the processes are messy. Having two processes run at the same time does not mean that they will run the same number of times. Try to redo your program without processes.
STLearning




PostPosted: Sat Jun 12, 2010 2:09 pm   Post subject: RE:Why are the players speeding up when shooting?

Ah, could I please get a hint of how to do that? I've tried leading the two movement procedures into each other, but it completely messes up the shooting code =/
USEC_OFFICER




PostPosted: Sat Jun 12, 2010 2:14 pm   Post subject: RE:Why are the players speeding up when shooting?

Frankly, the easiest way would be to move all the movement-related code into the main loop.
Unnamed.t




PostPosted: Sat Jun 12, 2010 9:23 pm   Post subject: Re: Why are the players speeding up when shooting?

My suggestion is to change your two body procs. I'm not entirely sure, but rather than having a separate if structure for each input (e.g. KEY_UP_ARROW) use elsif to merge everything in one control flow statement. This should help the shooting and moving coordination a great deal.

Even though this may help, still experiencing minor problems like having an increase of speed randomly should be expected because of the weak capabilities Turing has.
Cezna




PostPosted: Sun Jun 13, 2010 9:31 am   Post subject: RE:Why are the players speeding up when shooting?

I would recommend that instead of using:
Turing:

delay (1000)


You use:

Turing:


This will ensure similar performance across computers with varying speeds.
For an explanation of how Time.DelaySinceLast works, you can click on the word in the code box above.

Also, I would recommend avoiding processes, as they are inherently unpredictable and random in Turing.
Kharybdis




PostPosted: Mon Jun 14, 2010 8:34 am   Post subject: RE:Why are the players speeding up when shooting?

It has to do with frame rate and memory usage, if you want to get really technical about it Smile
USEC_OFFICER




PostPosted: Mon Jun 14, 2010 12:00 pm   Post subject: RE:Why are the players speeding up when shooting?

Which is a result of using Turing Processes. So don't use them.
Sponsor
Sponsor
Sponsor
sponsor
chrisbrown




PostPosted: Mon Jun 14, 2010 12:47 pm   Post subject: Re: Why are the players speeding up when shooting?

Unnamed.t @ Sat Jun 12, 2010 9:23 pm wrote:
still experiencing minor problems like having an increase of speed randomly should be expected because of the weak capabilities Turing has.

So very untrue. Turing may have its flaws, but it does exactly what it is instructed to do.

"Unexpected behaviour" invariably stems from the assumptions, oversights, faulty logic and/or inexperience of the programmer.
andrew.




PostPosted: Mon Jun 14, 2010 6:18 pm   Post subject: RE:Why are the players speeding up when shooting?

The problem in your code is that you're using processes. NEVER use processes. Instead, make them procedures and call them from within your loop. e.g.

Turing:
procedure movement1
    % do stuff
end movement1

procedure movement2
    % do stuff
end movement2

loop
    movement1
    movement2
    delay(speed)
end loop


This may not be exactly how you want to do it, but it's a general outline of how the main loop in a game works.

Oh and if you're wondering how it does 2 things at once, well, it doesn't. The computer processes it so fast that it appears to do it at once. I hope this clears up your problem.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: