Author Topic: My Rally game  (Read 5092 times)

0 Members and 1 Guest are viewing this topic.

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
My Rally game
« on: August 14, 2007 »
I have coded a rally game... really not finished!
I just don't understand why the road wont stop going off the screen... I thought that the way I coded the check would prevent it by changing the direction!!!
The code is attached, and below is the check for the road.

Code: [Select]
    if ((road.x(i) + road.sliding) > 570 or (road.x(i) + road.sliding) < 70) then
      road.slide = road.slide + road.slide - (road.slide ^ 2) + 1
    fi

the 'road.slide + road.slide - (road.slide ^ 2) + 1' changes it from 1 to 2, 2 to 1... instead of 'road.slide = 1 - road.slide'
--> where road.slide is the direction (0 = straight, 1 = left, 2 = right)
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: My Rally game
« Reply #1 on: August 14, 2007 »
Looks cool but I'm not too sure how to fix your problem atm.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 319
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Re: My Rally game
« Reply #2 on: August 15, 2007 »
It does want to go left more than it wants to go right, you're just not seeing it, because you've set the lower limit below zero.

 if ((road.x(i) + road.sliding) > 570 or (road.x(i) + road.sliding) < 70) then
      road.slide = road.slide + road.slide - (road.slide ^ 2) + 1
    fi

lower limit should read: ... - road.sliding) <70)

also, the word 'curve' is a code word, if that makes a difference.

smooth game.

Have a Yahappy day.
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: My Rally game
« Reply #3 on: August 15, 2007 »
Lol, I recognise that car :) I made it for Christopher Rankine a long time ago.
Looking good so far Clanky!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: My Rally game
« Reply #4 on: August 16, 2007 »
Haha. Yeah.... geee! that looks like it'll work now. I'll test it out in a little bit.
As to the car - I loved it on Christopher's Lab Hunt. That was a classic Yabasic game! didn't know you made it Shock... thats cool. (Ok if I use it?)

I'll see what other stuff I can put in.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: My Rally game
« Reply #5 on: August 20, 2007 »
You need a sin wave that has a random frequency this will keep the bends in the road but it will make sure that at some point the road will return to the center

Code: [Select]
frequency.changeRate = ran(10)*3.14159/180
frequency = frequency + frequency.changeRate
road.x = sin(frequency) * maximum.offsetFromCenter

replace whatever you had used to define the center of the road with the above

Edit:
I put together an example for you to see how it works take a look a label main
Code: [Select]
screenX = 640
screenY = 512
maxRoadX = 160
bendRate = 3.14159/screenY
bendFrequency = 0
dim roadX(screenY)

open window screenX, screenY
window origin "cc"
setrgb 0, 000, 140, 000

for a = 0 to screenY
  roadX(a) = cos(bendFrequency) * maxRoadX
  bendFrequency = bendFrequency + bendRate
next a

label main
  drawScreen()
  roadX(screenY) = cos(bendFrequency) * maxRoadX
  bendFrequency = bendFrequency + bendRate
  goto main

sub drawScreen()
  setdispbuf draw
  draw = 1 - draw
  setdrawbuf draw
  clear window
  setrgb 1, 110, 80, 40
  for a = 1 to screenY
    b = 256 - a
    line roadX(a)-100,b to roadX(a)+100,b
  next a
  setrgb 1, 125, 90, 50
  for a = 1 to screenY
    b = 256 - a
    line roadX(a)-85,b to roadX(a)-15,b
    line roadX(a)+85,b to roadX(a)+15,b
  next a
  setrgb 1, 150, 100, 60
  for a = 1 to screenY
    b = 256 - a
    line roadX(a)-30,b to roadX(a)-70,b
    line roadX(a)+30,b to roadX(a)+70,b
    roadX(a-1) = roadX(a)
  next a
end sub
« Last Edit: August 20, 2007 by rain_storm »

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: My Rally game
« Reply #6 on: August 25, 2007 »
Very nice.
I guess there is a way to make it so the SIN turns random... so that the scroll is unpredictable?

Anyways! Thanks for the code! Much appreciated!
I've gotten tired of this game lol. I've started a new one... and for once - it is almost finished. I'll give you guys a shout when it's done.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: My Rally game
« Reply #7 on: August 26, 2007 »
No problem brother

Challenge Trophies Won: