Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Yabasic => Topic started by: Clanky 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.
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)
-
Looks cool but I'm not too sure how to fix your problem atm.
-
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.
-
Lol, I recognise that car :) I made it for Christopher Rankine a long time ago.
Looking good so far Clanky!
-
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.
-
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
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
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
-
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.
-
No problem brother