Skip to content
Snippets Groups Projects
Commit 0efef6b7 authored by Kaan.Korucan's avatar Kaan.Korucan
Browse files

query functions added

parent a0bbc8a9
No related branches found
No related tags found
4 merge requests!8Modele,!7Modele,!6Modele,!5Modele Version 1
GAME/cmake-build-debug/ressource/begin.png

5.61 KiB

......@@ -19,6 +19,9 @@
#include <SDL2/SDL.h>
#include "personnage.h"
#include "prof.h"
#include "DS.h"
#include "map.h"
/*!
* \def WINDOW_WIDTH
......@@ -40,5 +43,8 @@
SDL_Texture * query_hero(Personnage * hero, SDL_Rect * hero_rect, SDL_Renderer * renderer , SDL_Window * window);
SDL_Texture * query_teacher(Prof * prof, SDL_Rect * teacher_rect, SDL_Renderer * renderer, SDL_Window * window );
SDL_Texture * query_exam(DS * exam, SDL_Rect * exam_rect, SDL_Renderer * renderer, SDL_Window * window);
SDL_Texture * query_map(MAP * map, SDL_Renderer * renderer, SDL_Window * window);
#endif /*INSAGAME_GAME_H*/
......@@ -36,94 +36,46 @@ int main(int argc, char* args[])
SDL_Quit();
return 1;
}
//Create Map and give it the functional matrix
MAP map_game;
init_map(&map_game,"ressource/colored.bmp","ressource/mapvis.bmp");
map_game.functional = maptomatrix(&map_game);
//Create a texture for map
SDL_Texture * texture_map = IMG_LoadTexture(renderer, map_game.visual_path);
if (!texture_map)
//texture for beginning page
SDL_Texture* texture_begin_page;
texture_begin_page = IMG_LoadTexture(renderer,"ressource/begin.png");
if (!texture_begin_page)
{
printf("error creating texture for map: %s\n", SDL_GetError());
printf("error creating texture: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
//create a Personnage "hero" and query his texture
SDL_RenderCopy(renderer, texture_begin_page, NULL, NULL);
SDL_RenderPresent(renderer);
SDL_Delay(2000);
SDL_DestroyTexture(texture_begin_page);
//Create the Map and query its texture
MAP map_game;
SDL_Texture * texture_map = query_map(&map_game, renderer, window);
//create a Personnage "hero" and query its texture
Personnage hero;
SDL_Rect hero_rect;
SDL_Texture *texture_hero = query_hero(&hero,&hero_rect,renderer,window);
if(!texture_hero){
return 1;
}
//create a Prof "teacher" and query his texture
//create a Prof "teacher" and query its texture
Prof teacher;
init_prof(&teacher,350,380,40,25,SPEED,"ressource/prof.png");
// load the image data into the graphics hardware's memory
SDL_Texture* texture_teacher = IMG_LoadTexture(renderer, teacher.image_prof);
if (!texture_teacher)
{
printf("Cannot create texture for prof: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// struct to hold the position and size of prof
SDL_Rect teacher_rect;
// get and scale the dimensions of texture
SDL_QueryTexture(texture_teacher, NULL, NULL, &teacher_rect.w, &teacher_rect.h);
teacher_rect.w = teacher.larg_prof;
teacher_rect.h = teacher.long_prof;
teacher_rect.x = teacher.x_prof;
teacher_rect.y = teacher.y_prof;
SDL_Rect teacher_rect;
SDL_Texture* texture_teacher = query_teacher(&teacher, &teacher_rect, renderer, window);
//Create a DS "exam" and its texture
DS exam;
fflush(stdin);
int r = 2 + rand() % 9; //random [2,10] because bug door 1 impossible => for complete 11->30
init_DS(&exam,r,"ressource/DS.png");
// load the image data into the graphics hardware's memory
SDL_Texture* texture_DS = IMG_LoadTexture(renderer, exam.image_DS);
SDL_Rect exam_rect;
SDL_Texture * texture_exam = query_exam(&exam, &exam_rect, renderer, window);
if (!texture_DS)
{
printf("error creating texture: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
if(!texture_map || !texture_hero || !texture_teacher || !texture_exam){
return 1;
}
SDL_Rect exam_rect;
SDL_QueryTexture(texture_DS, NULL, NULL, &exam_rect.w, &exam_rect.h);
exam_rect.w /= 30;
exam_rect.h /= 35;
exam_rect.x=exam.x_DS;
exam_rect.y=exam.y_DS;
// collision detection
int collision;
//result variable
......@@ -226,7 +178,7 @@ int main(int argc, char* args[])
SDL_RenderCopy(renderer, texture_map, NULL, NULL);
SDL_RenderCopy(renderer, texture_hero, NULL, &hero_rect);
SDL_RenderCopy(renderer, texture_teacher, NULL, &teacher_rect);
SDL_RenderCopy(renderer, texture_DS, NULL, &exam_rect);
SDL_RenderCopy(renderer, texture_exam, NULL, &exam_rect);
SDL_RenderPresent(renderer);
// wait 17ms
......@@ -236,7 +188,7 @@ int main(int argc, char* args[])
SDL_DestroyTexture(texture_map);
SDL_DestroyTexture(texture_hero);
SDL_DestroyTexture(texture_teacher);
SDL_DestroyTexture(texture_DS);
SDL_DestroyTexture(texture_exam);
//texture for endgame
SDL_Texture* texture_endgame;
......
......@@ -49,3 +49,81 @@ SDL_Texture * query_hero(Personnage * hero, SDL_Rect * hero_rect, SDL_Renderer *
}
SDL_Texture * query_teacher(Prof * teacher, SDL_Rect * teacher_rect, SDL_Renderer * renderer, SDL_Window * window ){
SDL_Texture * texture_teacher;
init_prof(teacher,350,380,40,25,SPEED,"ressource/prof.png");
// load the image data into the graphics hardware's memory
texture_teacher = IMG_LoadTexture(renderer, teacher->image_prof);
if (!texture_teacher)
{
printf("Cannot create texture for prof: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return NULL;
}
// get and scale the dimensions of texture
SDL_QueryTexture(texture_teacher, NULL, NULL, &teacher_rect->w, &teacher_rect->h);
teacher_rect->w = teacher->larg_prof;
teacher_rect->h = teacher->long_prof;
teacher_rect->x = teacher->x_prof;
teacher_rect->y = teacher->y_prof;
return texture_teacher;
}
SDL_Texture * query_exam(DS * exam, SDL_Rect * exam_rect, SDL_Renderer * renderer, SDL_Window * window){
fflush(stdin);
int r = 2 + rand() % 9; //random [2,10] because bug door 1 impossible => for complete 11->30
SDL_Texture * texture_exam;
init_DS(exam,r,"ressource/DS.png");
// load the image data into the graphics hardware's memory
texture_exam = IMG_LoadTexture(renderer, exam->image_DS);
if (!texture_exam)
{
printf("error creating texture: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return NULL;
}
SDL_QueryTexture(texture_exam, NULL, NULL, &exam_rect->w, &exam_rect->h);
exam_rect->w /= 30;
exam_rect->h /= 35;
exam_rect->x=exam->x_DS;
exam_rect->y=exam->y_DS;
return texture_exam;
}
SDL_Texture * query_map(MAP * map_game, SDL_Renderer * renderer, SDL_Window * window){
init_map(map_game,"ressource/colored.bmp","ressource/mapvis.bmp");
map_game->functional = maptomatrix(map_game);
//Create a texture for map
SDL_Texture * texture_map = IMG_LoadTexture(renderer, map_game->visual_path);
if (!texture_map)
{
printf("error creating texture for map: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return NULL;
}
return texture_map;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment