|
corwin
|
Posté le 07 Juin 2009 à 16:58
|
|

Messages : 459
GCPoints : 63647
|
Après les sources d'un fps voici les bases d'un jeu de course, la en particulier d'une course de moto.
fait :
-mouvement moto
-penchement de la moto
-blur selon la vitesse
-collision glissante
-dérapage
-vie
à faire :
-IA adversaire
source:
Set display mode 1024, 768, 32
sync on : sync rate 60
rem -- CREER TERRAIN
make object plain 2,10000,10000
rotate object 2,-90,0,0
position object 2,5000,-1,5000
color object 2,RGB(0,255,0)
rem -- CREER MOTO
make object box 10,25,50,115
set ambient light 30
set shadow shading on 10
set object light 10, 1
make light 1
set light range 1,600
set shadow position 1,2500,2500,90
position light 1,3000,2000,3000
color light 1,0,0,0
hide light 1
rem -- CREER CUBE DE MOUVEMENT
make object cube 1,5
hide object 1
glue object to limb 10,1,0
spd# = 0 : rem --
spd_max# = 24 : rem -- Vitesse max. 240 Km/h
spd_acc# = 0.1 : rem -- Acceleration
bank# = 0 : rem --
bank_max# = 2 : rem -- Angle de rotation max
bank_inc# = 20 : rem -- Suspention - 1 HARD - 10 LOSE
skida# = 1 : rem -- Derapage
vue=1
vie#=100
rem -- CREER OBSTACLE
for g=200 to 400
if object exist(g)
else
make object cube g,100
position object g,rnd(10000),50,rnd(10000)
color object g,RGB(255,0,0)
endif
next
color backdrop RGB(0,0,0)
do
rem -- SELON LA VITESSE LE BLUR AUGMENTE
blur=200-(spd#*6)
rem -- BLUR
set camera to image 0,1,1024,1024
sprite 1,0,0,1
set sprite 1,0,1
size sprite 1,screen width(),screen height()
set sprite alpha 1,blur
rem -- CAMERA
if vue=1
set camera to follow object position x(1),object position y(1),object position z(1),a#,90,90,10,0
point camera object position x(1),object position y(1),object position z(1)
endif
rem -- VALEUR POUR COLLISION
x4 = object position x(1)
y4 = object position y(1)
z4 = object position z(1)
angle4 = object angle y(1)
rem -- AUGMENTE VITESSE
if upkey() = 1
if spd# < spd_max#
inc spd#,spd_acc#
endif
endif
rem -- DIMINUE VITESSE
if upkey() = 0
if spd# > 0
dec spd#,(spd_acc#/2)
endif
if spd# < 0
spd# = 0
endif
endif
rem -- BRAKE
if spacekey()=1
if spd# > 0
dec spd#,(spd_acc#*2)
endif
if spd# < 0
spd# = 0
endif
skid = 1
endif
rem -- TOURNE A GAUCHE
if leftkey() = 1
if spd#>0
if bank# > (0-bank_max#)
bank# = curvevalue((0-bank_max#),bank#,10)
endif
endif
if upkey() = 0
skid = 1
else
skid = 0
endif
endif
rem -- TOURNE A DROITE
if rightkey() = 1
if spd#>0
if bank# < bank_max#
bank# = curvevalue(bank_max#,bank#,20)
endif
endif
if upkey() = 0
skid = 1
else
skid = 0
endif
endif
if leftkey() = 0 AND rightkey() = 0
bank# = curvevalue(0,bank#,10)
skida# = curvevalue(0,skida#,10)
endif
rem -- VALEUR POUR COLLISION
oldx4 = object position x(1)
oldy4 = object position y(1)
oldz4 = object position z(1)
oldangle4 = object angle y(1)
rem -- GLISSADE
if skid = 1 and spd#>0
if leftkey() = 1 and spd#>0
skida# = curvevalue(0-(spd#*2),skida#,60)
endif
if rightkey() = 1 and spd#>0
skida# = curvevalue((spd#*2),skida#,60)
endif
dec spd#,(spd_acc#/2)
text 0,40,"GLISSE!!!"
else
skida# = curvevalue(0,skida#,10)
endif
rem -- MISE A JOUR DES VALEURS
x#=newxvalue(x#,a#,spd#) : z#=newzvalue(z#,a#,spd#)
a# = wrapvalue(a#+bank#)
rem -- MISE A JOUR DE LA POSITION ET L4ANGLE DE LA MOTO
position object 1,x#,y#+25,z#
yrotate object 1,a#+180
zrotate object 10,(bank#*bank_inc#*(spd#/20))
yrotate object 10,skida#
rem -- ECRIT LES VALUEUR
set cursor 0,0
text 0,0,"vitesse : "+str$(spd#*10)+" Km/h"
text 0,10,"Banking : "+str$(bank#)
text 0,20,"fps : "+str$(screen fps())
text 0,30,"blur : "+str$(blur)
text 0,50,"vie : "+str$(vie#)
rem -- COLLISION GLISSANTE
for o=200 to 400
if object exist(o)
if object collision(10, o)>0
position object 1, oldx4, y4, z4
vie#=vie#-((spd#*10)/2)
spd#=0
spd#=-2
if object collision(10, o)>0
position object 1, x4, y4, oldz4
vie#=vie#+((spd#*10)/2)
spd#=0
spd#=-2
if object collision(10, o)>0
position object 1, oldx4, y4, oldz4
vie#=vie#-((spd#*10)/2)
spd#=0
spd#=-2
endif
endif
endif
endif
next o
rem -- VIE
if vie#=<0
ink RGB(255,0,0),0
text screen width()/2,screen height()/2,"CRACH"
endif
sync
loop
bonne chance avec tous sa ;)
Dernière édition le 08 Juin 2009 à 19:07
|
|
Darktib
|
Posté le 07 Juin 2009 à 18:16
|
|

Messages : 4017
GCPoints : 347288
|
Wow... J'aime beaucoup ! A part les collisions, tout marche nickel, très fluide et sympa à conduire.
Et le code est très propre, meme si le spoiler à enlevé l'indentation.
Par contre, niveau perf, ca peut encore etre amélioré en enlevant les print et en les remplacant par text
Vraiment un très bon code en tout cas
Merci
|
|
corwin
|
Posté le 08 Juin 2009 à 08:13
|
|

Messages : 459
GCPoints : 63647
|
Merci ;) print a été remplacé et les collisions vont etre modifié. Si vous avez d'autre idées dite le moi :)
|
|
Darktib
|
Posté le 08 Juin 2009 à 12:35
|
|

Messages : 4017
GCPoints : 347288
|
En fait, pour les collisions, je pense qu'il faut modifier la vitesse. Quand on rentre dans un mur, il faut mettre la vitesse à 0...
Voir même calculer l'accélération subie par le véhicule lors de la collision, puis, après avoir ajouté des points de vie à la voiture, lui enlever ces points de vie en fonction du choc. A 0, on quitte^^
|
|
bebou007
|
Posté le 08 Juin 2009 à 13:00
|
|

Messages : 238
GCPoints : 43228
|
salut pas mal du tous
j'aurais pencher un peut plus la moto a haute vitesse
quand on accélère pas la moto tourne plus vite que quand on accélère
voila si non c'est deja un bon debut
|
|
corwin
|
Posté le 08 Juin 2009 à 18:23
|
|

Messages : 459
GCPoints : 63647
|
La collision marche très bien maintenant. La moto est plus pencher à haute vitesse et la moto tourne moins vite quand on dérape. La vie est aussi fait. Merci a vous pour vos idées j'espère aussi qu'il y en aura d'autre ou une idée sur quel autre sorte de source je peux faire ;)
Dernière édition le 08 Juin 2009 à 19:09
|
|
bebou007
|
Posté le 08 Juin 2009 à 19:31
|
|

Messages : 238
GCPoints : 43228
|
salut c'est franchement mieux regarde aussi quand on ralentie si on reste appuyer sur droite ou gauche la moto s'arrête mais tourne encore
|
|
corwin
|
Posté le 08 Juin 2009 à 19:40
|
|

Messages : 459
GCPoints : 63647
|
Oui j'avait essayer de rectifier sa mais faut que je regarde encore de plus proche merci :)
|