TGC Codebase Backup



race demo by Sven B

20th Mar 2005 15:04
Summary

A little demo. This shows how to turn a car correct. Not just turn left or right when a key is pressed.



Description

Basic controls:
up: speed up
down: brakes
left/right: turn



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `*** race damo ***
sync on

`make player
make object box 1,10,7.5,20
position object 1,500,3.75,500

`make tile texture
ink rgb(0,100,0),0
box 0,0,50,50
for x=1 to 50
	ink rgb(0,100+rnd(155),0),0
	dot rnd(50),rnd(50)
next x
get image 1,0,0,50,50

`make and texture matrix
make matrix 1,1000,1000,50,50
prepare matrix texture 1,1,1,1

`values
traction#=0.95
radius#=100.5
pi#=3.141

do

	`player data
	posx#=object position x(1)
	posz#=object position z(1)
	angley#=object angle y(1)

	`controls
	if upkey()=1 and speed#<15 then inc speed#
	if downkey()=1 then speed#=speed#*0.85

	`physics
	speed#=speed#*traction#
	posx#=newxvalue(posx#,angley#,speed#)
	posz#=newzvalue(posz#,angley#,speed#)

	`turning the car
	if leftkey()=1
		yrotate object 1,wrapvalue(angley#-(180*speed#/(pi#*radius#)))
	endif
	if rightkey()=1
		yrotate object 1,wrapvalue(angley#+(180*speed#/(pi#*radius#)))
	endif

	`stop car at minimum speed
	if speed#<0.5 then speed#=0.0

	`camera position
	position camera 500,280,500
	point camera posx#,0,posz#

	`update player
	position object 1,posx#,3.75,posz#

	sync
loop