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

Username:   Password: 
 RegisterRegister   
 Help - The speed at which my game runs on different computers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
plato




PostPosted: Sun Jun 08, 2014 11:04 pm   Post subject: Help - The speed at which my game runs on different computers

What is it you are trying to achieve?
For my comp sci summative project, I made a game in which the user controls a car on a 3-lane road, where other cars come from the top of the screen and the user has to dodge the cars to stay alive.


What is the problem you are having?
When working at school, the game seems to run fine and the controls seem good and the speed at which the cars move is good. However at home on my much more powerful computer, the program runs much quicker, making the enemy cars as well as the user's car move so quick it is impossible to control it.


Describe what you have tried to solve this problem
I've tried to use delays and changing the values to find some middle-ground, however I've had no luck.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is a bare bones version of the program.

Turing:


var chars : array char of boolean
var y1 := 400
var y2 := 450
var xrand : int := 0
var carx : int := 191
var carx2 : int := 226
var roady1 : int := 400 %yellow
var roady2 : int := 350 %yellow
View.Set ("offscreenonly")
procedure Background
    Draw.ThickLine (180, 400, 180, 0, 1, 7) %road line
    Draw.ThickLine (390, 400, 390, 0, 1, 7) %road line
    if y2 <= 0 then
        xrand := Rand.Int (1, 3) %Gets a random integer, depending on the int the car will be in different lanes
    end if
    %Road %Lanes: 1st: 180,250, 2nd: 250,320, 3rd: 320,390
    Draw.ThickLine (250, roady1, 250, roady2, 5, yellow)
    Draw.ThickLine (320, roady1, 320, roady2, 5, yellow)
    roady1 -= 2
    roady2 -= 2
    if roady1 <= 0 then
        roady1 := 400
        roady2 := 350
    end if
    drawfillbox (carx, 25, carx2, 75, blue)
    if xrand = 1 or xrand = 0 then       %First Lane
        drawfillbox (190, y1, 235, y2, 12)
        y1 -= 1
        y2 -= 1
        if y2 <= 0 then
            y1 := 400
            y2 := 450
            xrand := Rand.Int (1, 3)
        end if
    elsif xrand = 2 then         %Second Lane
        drawfillbox (260, y1, 305, y2, 12)
        y1 -= 1
        y2 -= 1
        if y2 <= 0 then
            y1 := 400
            y2 := 450
            xrand := Rand.Int (1, 3)
        end if
    elsif xrand = 3 then         %Third Lane
        drawfillbox (330, y1, 375, y2, 12)
        y1 -= 1
        y2 -= 1
        if y2 <= 0 then
            y1 := 400
            y2 := 450
            xrand := Rand.Int (1, 3)
        end if
    end if
    View.Update
end Background

loop
    Background
    %User Car Movement
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        if carx2 >= 380 then         %Prevents going off the road (right)
        else
            carx := carx + 3
            carx2 := carx2 + 3
        end if
    elsif chars (KEY_LEFT_ARROW) then
        if carx2 <= 225 then         %Prevents going off the road (right)
        else
            carx := carx - 3
            carx2 := carx2 - 3
        end if
    end if
    Background
    View.Update
    cls
end loop




Please specify what version of Turing you are using
<4.1.1>
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jun 09, 2014 12:46 am   Post subject: RE:Help - The speed at which my game runs on different computers

The posted code doesn't show your delay attempt. From the wording, I will guess that it was just a delay for a static amount, but try to reason through this:
code:

loop
   do_something() // slow on one machine, fast on another
   delay(100)
end loop


What you want is different delay amount for different machines.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
amz_best




PostPosted: Sun Sep 07, 2014 6:57 pm   Post subject: RE:Help - The speed at which my game runs on different computers

Time.DelaySinceLast (1000 div 60)
the number 60 is the fps, put this after cls but before end loop and it should slow down ur game just right
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  [ 3 Posts ]
Jump to:   


Style:  
Search: