mejdzer Temat założony przez niniejszego użytkownika |
problem z grą » 2012-01-15 20:36:13 Witam serdecznie, piszę grę na studia i mam pewien problem, nie mogę poradzic sobie z losowym pojawianiem sie elementu na 'torach' i jego ruchem (samochod się 'zacina'), czy mógłby mi ktoś na szybko pomóc z tym ? Oto kod: #include <windows.h> #include <graphics.h> #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <time.h> #define SLEEP 100 #define POKAZ 1 #define UKRYJ 0 #define ESCAPE 27 #include "samochod.cpp"
int main() { int errorcode; int x, y; initwindow( getmaxwidth() / 2, getmaxheight() / 2 ); errorcode = graphresult(); if( errorcode != grOk ) { printf( "Blad BGI: %s\n", grapherrormsg( errorcode ) ); printf( "Wcisnij dowolny klawisz, zeby zakonczyc:" ); getch(); } else { x = getmaxx() / 2 - SZER / 2; y = getmaxy() / 2 - WYS / 2; line( 200, 0, 200, 250 ); line( 250, 0, 250, 150 ); line( 300, 0, 300, 150 ); line( 350, 0, 350, 150 ); line( 400, 0, 400, 250 ); line( 200, 250, 400, 250 ); line( 250, 215, 250, 250 ); line( 300, 215, 300, 250 ); line( 350, 215, 350, 250 ); int m = 0, tor, wspolrzedna; while( 1 ) { samochod( x, y, POKAZ ); char znak; do { tor = 1 + rand() /( float( RAND_MAX ) + 1 ) * 4; if( tor == 1 || tor == 2 || tor == 3 || tor == 4 ) { if( tor == 1 || tor == 2 || tor == 3 ) { if( tor == 1 || tor == 2 ) { if( tor == 1 ) { wspolrzedna = 225; } else { wspolrzedna = 275; } } else { wspolrzedna = 325; } } else { wspolrzedna = 375; } } if( kbhit() == 1 ) { znak = getch(); circle( tor, m, 10 ); Sleep( 50 ); setcolor( BLACK ); circle( tor, m, 10 ); setcolor( WHITE ); m = m + 5; if( znak == 75 || znak == 77 ) { if( znak == 75 ) { if( x > 205 ) { samochod( x, y, UKRYJ ); x = x - 4; samochod( x, y, POKAZ ); } else { x = x; } } else { if( x < 380 ) { samochod( x, y, UKRYJ ); x = x + 4; samochod( x, y, POKAZ ); } else { x = x; } } } } } while( znak != 27 ); } closegraph(); } }
|