
-----------------------------------
tttptiago
Thu Jun 07, 2007 11:29 am

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 = 30 and y = 3
end loop

-----------------------------------
DifinityRJ
Sat Jun 16, 2007 11:44 pm

Re: Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help
-----------------------------------

loop
    Char
    Keys
    Collision
    if x = 190 and y >= 30 and y = 3
end loop

Well two things wrong with 

if x = 190 and y >=30 and y= 30 and y = 3
end loop

Well two things wrong with 

if x = 190 and y >=30 and y 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 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
Sun Jun 17, 2007 11:24 am

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  :lol:  this way is more challenging  :P  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
Sun Jun 17, 2007 12:31 pm

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.

-----------------------------------
HeavenAgain
Sun Jun 17, 2007 6:36 pm

Re: 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.

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?  :(

-----------------------------------
Clayton
Sun Jun 17, 2007 7:11 pm

RE:Racing Game !!! Complete game with a lap counter problem !!!!!!! Please Help
-----------------------------------

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
Sun Jun 17, 2007 7:56 pm

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.
