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

Username:   Password: 
 RegisterRegister   
 Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tttptiago




PostPosted: Thu Jun 07, 2007 11:29 am   Post subject: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

The Code is complete, and the game works. The only problems that i am having is making the lap counter work. When the "racer" crosses the finish line my lap procedue does no work. i want the "racer" to do 3 laps.

Any help is greatly appreciated !
Mess with the code all you want , as long as positive production is completed.

THNX !





setscreen ("graphics")

var font1 : int
var keys : array char of boolean
var x, y : int
var lap : int := 0
font1 := Font.New ("Arial :20")
x := 230
y := 40

colorback (255)
cls
procedure Track

drawline (190, 30, 190, 60, 70) % finishline

drawline (1, 1, maxx, 1, 79) %Border
drawline (maxx - 1, 1, maxx - 1, maxy - 1, 79) %Border
drawline (maxx - 1, maxy - 1, 1, maxy - 1, 79) %Boreder
drawline (1, maxy - 1, 1, 1, 79) %Border

drawline (75, 30, 500, 30, 0) %Track Outside
drawline (500, 30, 500, 100, 0) %Track Outside
drawline (500, 100, 560, 100, 0) %Track Outside
drawline (560, 100, 560, 300, 0) %Track Outside
drawline (560, 300, 480, 300, 0) %Track Outside
drawline (480, 300, 480, 370, 0) %Track Outside
drawline (480, 370, 300, 370, 0) %Track Outside
drawline (300, 370, 300, 270, 0) %Track Outside
drawline (300, 270, 240, 270, 0) %Track Outside
drawline (240, 270, 240, 350, 0) %Track Outside
drawline (240, 350, 75, 350, 0) %Track Outside
drawline (75, 350, 75, 30, 0) %Track Outside


drawline (105, 60, 470, 60, 0) %Track Inside
drawline (470, 60, 470, 130, 0) %Track Inside
drawline (470, 130, 530, 130, 0) %Track Inside
drawline (530, 130, 530, 270, 0) %Track Inside
drawline (530, 270, 450, 270, 0) %Track Inside
drawline (450, 270, 450, 340, 0) %Track Inside
drawline (450, 340, 330, 340, 0) %Track Inside
drawline (330, 340, 330, 240, 0) %Track Inside
drawline (330, 240, 210, 240, 0) %Track Inside
drawline (210, 240, 210, 310, 0) %Track Inside
drawline (210, 310, 105, 310, 0) %Track Inside
drawline (105, 310, 105, 60, 0) %Track Inside


end Track

procedure Char

Draw.FillBox (x, y, x + 10, y + 5, 10)
Draw.FillBox (x, y + 5, x, y, 255)
Draw.FillBox (x + 10, y, x, y, 255)
Draw.FillBox (x, y, x + 10, y, 255)
Draw.FillBox (x + 10, y, x + 10, y + 5, 255)
Draw.FillBox (x + 10, y, x, y, 255)
Draw.FillBox (x, y + 5, x + 10, y + 5, 255)

end Char


procedure Keys

Input.KeyDown (keys)

if keys (KEY_RIGHT_ARROW)
then
delay (4) % Sets Speed
x += 1

elsif keys (KEY_LEFT_ARROW)
then
delay (4)
x -= 1

elsif keys (KEY_UP_ARROW)
then
delay (4)
y += 1

elsif keys (KEY_DOWN_ARROW)
then
delay (4)
y -= 1

end if

end Keys

procedure Collision



if whatdotcolour (x + 5, y + 5) = 8
or whatdotcolour (x + 10, y) = 8
or whatdotcolour (x - 1, y) = 8
or whatdotcolour (x + 5, y + 5) = 0
or whatdotcolour (x + 10, y) = 0
or whatdotcolour (x - 1, y) = 0

then
Font.Draw ("YOU HAVE CRASHED!", 170, 190, font1, 8)
delay (1000)

Font.Draw ("GAME OVER!", 220, 130, font1, red)
delay (1000)





end if

end Collision


if x = 190 and y >= 30 and y <= 60 then
lap := lap + 1
end if

color (white)
put "Laps : " , lap


Track


loop

Char
Keys
Collision
end loop
Sponsor
Sponsor
Sponsor
sponsor
Jerrik




PostPosted: Sat Jun 16, 2007 10:09 pm   Post subject: Re: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

Please use code tags or syntax tags when posting code.

Your problem is that you aren't checking to see if the car crossed the finish line. You only check once, and then your main loop starts. You just have to put the code in your main loop and it works. I've edited your main loop for you.

You also have a small glitch. When you 'lose' you can keep going; with the wall destroyed. In other words, you can't lose, and you can go through walls. Although there is a large delay every time you do. I'll let you handle that problem on your own though, goodluck! = D

Turing:
loop
    Char
    Keys
    Collision
    if x = 190 and y >= 30 and y <= 60 then
        lap := lap + 1
    end if
    locate (1, 1)
    put "Laps : ", lap
    exit when lap >= 3
end loop
DifinityRJ




PostPosted: Sat Jun 16, 2007 11:44 pm   Post subject: Re: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

Jerrik @ Sun Jun 17, 2007 4:09 pm wrote:

Turing:
loop
    Char
    Keys
    Collision
    if x = 190 and y >= 30 and y <= 60 then
        lap := lap + 1
    end if
    locate (1, 1)
    put "Laps : ", lap
    exit when lap >= 3
end loop


Well two things wrong with
code:

if x = 190 and y >=30 and y<=60 then
lap:=lap+1
end if


1.) What if x is increasing to fast that it skips over 190, and it wont even Count it as a lap.

2.) if the car stays at 190, the lap will keep increasing, so that will ruin the game easily.
Jerrik




PostPosted: Sun Jun 17, 2007 12:17 am   Post subject: Re: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

DifinityRJ @ Sat Jun 16, 2007 11:44 pm wrote:
Jerrik @ Sun Jun 17, 2007 4:09 pm wrote:

Turing:
loop
    Char
    Keys
    Collision
    if x = 190 and y >= 30 and y <= 60 then
        lap := lap + 1
    end if
    locate (1, 1)
    put "Laps : ", lap
    exit when lap >= 3
end loop


Well two things wrong with
code:

if x = 190 and y >=30 and y<=60 then
lap:=lap+1
end if


1.) What if x is increasing to fast that it skips over 190, and it wont even Count it as a lap.

2.) if the car stays at 190, the lap will keep increasing, so that will ruin the game easily.


Second point is valid (you can even just back up into the lap and wait, you win instantly), but the first isn't true in this case, as the speed is set to one so there is no chance of passing the line without physically going over 190. If the speed changed it would need to be addressed of course.
AFG34




PostPosted: Sun Jun 17, 2007 9:12 am   Post subject: Re: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

you can do
Quote:
if x > 190 and y >= 30 and y <= 60 then
lap += 1
end if


if x is greater than 90... so even if you change your speed it doesnt matter

also instead of writing

Quote:
lap := lap +1

you can do it in less characters
Quote:
lap += 1
Jerrik




PostPosted: Sun Jun 17, 2007 10:57 am   Post subject: Re: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

AFG34 @ Sun Jun 17, 2007 9:12 am wrote:
you can do
Quote:
if x > 190 and y >= 30 and y <= 60 then
lap += 1
end if


if x is greater than 90... so even if you change your speed it doesnt matter

also instead of writing

Quote:
lap := lap +1

you can do it in less characters
Quote:
lap += 1


That won't work. You will automatically win because your x value starts > 190, and you are between 30 and 60 on the y-axis.

There are a number of ways to fix this problem. You could have a second spot on the map (a half way point perhaps) that you need to cross before you can get a "lap". Or you could check to see which direction the person is coming from and effect the lap number that way (+1, -1). The list of solutions goes on, its all upto the programmer. These are certainly not the only solutions

I will also note that this [+=] works for other variable types as well (such as strings), which is something I found quite a few people miss (namely, my entire ICS class).

code:
name += " Smith"

Is completely valid, if name is string type.

Less characters doesn't necessarily mean its better; its just a different way to do things. For some people it's easier to find bugs if they type it all out, especially if you have many long equations and you are getting a very subtle error.
HeavenAgain




PostPosted: Sun Jun 17, 2007 11:24 am   Post subject: Re: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

umm.. let me give you a few hints for all these summed up.

first : your Collision procedure, should be a process, why? because a process can run itself while other procedure or functions are running. because you want to check, if the player crashed or not, not with any delay at all, becuase if the delay is longer, it will be a bug, but in your case, i dont see this is a big proble

sencond : procedure Keys, it is better, if you give it a parameter, make a good use of them, and in this case, procedure Keys, is the best example. as you can tell, you can move your charater after its dead, with a little delay, so, now add in a parameter of boolean, if you are dead/won, then you cannot move arrows,else if you are alive you can move.

third : as for the laps, i suggest you do 4 imaginary lines, put this 4 imaginary lines in your lap (seprate them) and then, if your char pass the first line, make the boolean true, meaning the player have came here, and pass the 2nd, pass the 3rd, and finally, the finishing line, with all boolean true, this way the lap # can increase by 1, and just as soon as the player cross the finishing line, set all the boolean to false again (this gets ready for the 2nd lap) i beleive this method will work better than all of above, but again, this is all up to you

and one suggestion to your program, try make a timer for it Laughing this way is more challenging Razz good luck

sorry i cannot post the codes because of the exam, but these should be pretty helpful, any questions feel free to ask
CodeMonkey2000




PostPosted: Sun Jun 17, 2007 12:31 pm   Post subject: RE:Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

You collision procedure should not be a process. And adding laps is easy, just check the total distance traveled. If they go forwards, increase the distance, if they go the wrong way decrease it. Then check if the player's distance is greater than or equal to the length of the track. If it is then lap:=lap+1. Once the player crosses the finish line, set the distance to zero.
Sponsor
Sponsor
Sponsor
sponsor
HeavenAgain




PostPosted: Sun Jun 17, 2007 6:36 pm   Post subject: Re: RE:Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

CodeMonkey2000 @ Sun Jun 17, 2007 12:31 pm wrote:
You collision procedure should not be a process. And adding laps is easy, just check the total distance traveled. If they go forwards, increase the distance, if they go the wrong way decrease it. Then check if the player's distance is greater than or equal to the length of the track. If it is then lap:=lap+1. Once the player crosses the finish line, set the distance to zero.


well, your distance idea is good, but i dont think in this case will work the best, since the user can move left and right, and there are many different "distance" to finish the game, so if the user sticks to the wall really close (therefore less distance traveled) then the lap will be counted after a while when finished the finishing line.

and also, why not put the collision in a process? you do want to check when you crashed at any given time, plus, there is a VERY SHORT delay, whenever the "car" is moved, but once you put it into a process, you dont have to wait for the delay anymore?

but again, i'm not 100% sure which is the best, what do you have to say about it? Sad
Clayton




PostPosted: Sun Jun 17, 2007 7:11 pm   Post subject: RE:Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

HeavenAgain wrote:

and also, why not put the collision in a process?


Because you never know when your process will execute. Really, stop looking for ways to incorporate processes into programs. There's no such thing as two things running concurrently. At all. The better idea is to have everything run in one main line.
HeavenAgain




PostPosted: Sun Jun 17, 2007 7:56 pm   Post subject: RE:Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help

ohh, ok thanks for clearing that up, but i think i'll go read the process tut, just to get a better idea of it.
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  [ 11 Posts ]
Jump to:   


Style:  
Search: