add background and simple track

This commit is contained in:
Mats van Reenen 2019-04-24 21:50:03 +02:00
parent 067c6030f2
commit 6ed58da7f1
3 changed files with 34 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
*.o
game

BIN
game Executable file

Binary file not shown.

37
game.c
View File

@ -63,7 +63,7 @@ int init(void){
return 0;
}
int createCar(){
int createCar(void){
// create surface
SDL_Surface* Car_surface = IMG_Load("img/car.png");
if(!Car_surface){
@ -88,6 +88,34 @@ int createCar(){
return 0;
}
void drowTrack(void){
Uint32 w = WINDOW_WIDTH / 10;
Uint32 h = WINDOW_HEIGHT / 10;
SDL_Rect track[4];
// left
track[0].x = w;
track[0].y = h;
track[0].w = w;
track[0].h = h*8;
// top
track[1].x = w;
track[1].y = h;
track[1].w = w*8;
track[1].h = h;
// right
track[2].x = w*8;
track[2].y = h;
track[2].w = w;
track[2].h = h*8;
// bottom
track[3].x = w;
track[3].y = h*8;
track[3].w = w*8;
track[3].h = h;
SDL_SetRenderDrawColor(renderer, 119, 119, 119, 255);
SDL_RenderFillRects(renderer, &track, 4);
}
int main(void){
if(init() != 0) return 1;
if(createCar() != 0) return 2;
@ -156,8 +184,11 @@ int main(void){
}
// clear the window
SDL_SetRenderDrawColor(renderer, 126, 200, 80, 255);
SDL_RenderClear(renderer);
drowTrack();
// update position
if(car_moving == 1){
if(direction == 1){
@ -190,11 +221,11 @@ int main(void){
Car_pos.x = (int) car_pos[0];
Car_pos.y = (int) car_pos[1];
/*
printf("heading: %f\t%d\n", (heading), direction);
printf("car posf: %f, %f\n", car_pos[0], car_pos[1]);
printf("car pos: %u, %u\t%d\n", Car_pos.x, Car_pos.y, car_moving);
*/
// drow image
SDL_RenderCopyEx(renderer, Car_texture, NULL, &Car_pos, 180-(heading*(180/PI)), NULL, SDL_FLIP_NONE);
SDL_RenderPresent(renderer);