Skip to content
Snippets Groups Projects
Commit d62af224 authored by Le-Bao-Tin.Ha's avatar Le-Bao-Tin.Ha
Browse files

random DS entre 1 et 10, a faire entre 11 et 30, no bugs ^^

parent 06e075a6
No related branches found
No related tags found
4 merge requests!8Modele,!7Modele,!6Modele,!5Modele Version 1
......@@ -13,10 +13,14 @@
#include "map.h"
#include "DS.h"
int testposition(Personnage * pers, Prof * prof, DS * exam, MAP * map,int ,int ,int, int); // return 0 if nothing, 1 if wall, 2 if exam, 3 if prof, 4 if bounds
int testposition(Personnage * pers, Prof * prof, DS * exam, MAP * map); // return 0 if nothing, 1 if wall, 2 if exam, 3 if prof, 4 if bounds
int testboundscol(Personnage * pers);
int testprofcol(Personnage * pers, Prof * prof,int x_A,int y_A, int x_B, int y_B);
int testmapcol(Personnage * pers, MAP * map, DS * exam,int x_A,int y_A, int x_B, int y_B);
int testprofcol(Personnage * pers, Prof * prof);
int testmapcol(Personnage * pers, MAP * map, DS * exam);
int testpointwithprof(int x, int y, Prof *prof);
int testpointwithmap(int x, int y, MAP *map, DS * exam);
#endif /*INSAGAME_GAME_H*/
......@@ -22,14 +22,22 @@
*/
typedef struct {
int x_pers; /**< Position : abscissa */
int y_pers; /**< Position : ordinate */
int x_pers; /**< Position : x hight-left point */
int y_pers; /**< Position : y hight-left point */
int long_pers; /**< Size : length */
int larg_pers; /**< Size : width */
int x_hr; /**< Position : x hight-right point */
int y_hr; /**< Position : y hight-right point */
int x_ll; /**< Position : x low-left point */
int y_ll; /**< Position : y low-left point */
int x_lr; /**< Position : x low-right point */
int y_lr; /**< Position : y low-right point */
int speed_pers; /**< Charater speed */
char * image_pers; /**< Source image of the character. */
}Personnage;
void init_pers(Personnage * character, int x, int y, int length, int width, int speed, char * path);
void calculpointspers(Personnage * character);
#endif /*GAME_INSA_PROJECT_PERSONNAGE_H*/
......@@ -35,112 +35,105 @@ void init_DS(DS * exam, int door_DS, char * path){
switch (exam->door)
{
case 1:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
break;
case 2:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 144;
exam->y_DS= 48;
exam->larg_DS= 21;
exam->long_DS= 14;
break;
case 3:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 369;
exam->y_DS= 41;
exam->larg_DS= 21;
exam->long_DS= 10;
break;
case 4:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 564;
exam->y_DS= 38;
exam->larg_DS= 23;
exam->long_DS= 12;
break;
case 5:
exam->x_DS = 48;
exam->y_DS= 90;
exam->larg_DS= 13;
exam->long_DS= 5;
exam->x_DS = 43;
exam->y_DS= 85;
exam->larg_DS= 24;
exam->long_DS= 14;
break;
case 6:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 237;
exam->y_DS= 98;
exam->larg_DS= 11;
exam->long_DS= 19;
break;
case 7:
exam->x_DS = 149;
exam->y_DS= 54;
exam->x_DS = 460;
exam->y_DS= 74;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->long_DS= 17;
break;
case 8:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 75;
exam->y_DS= 172;
exam->larg_DS= 19;
exam->long_DS= 11;
break;
case 9:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 316;
exam->y_DS= 162;
exam->larg_DS= 13;
exam->long_DS= 18;
break;
case 10:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 454;
exam->y_DS= 149;
exam->larg_DS= 20;
exam->long_DS= 10;
break;
case 11:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 197;
exam->y_DS= 208;
exam->larg_DS= 10;
exam->long_DS= 3;
break;
case 12:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 549;
exam->y_DS= 205;
exam->larg_DS= 5;
exam->long_DS= 12;
break;
case 13:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 637;
exam->y_DS= 185;
exam->larg_DS= 5;
exam->long_DS= 14;
break;
case 14:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 235;
exam->y_DS= 269;
exam->larg_DS= 4;
exam->long_DS= 11;
break;
case 15:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 320;
exam->y_DS= 267;
exam->larg_DS= 8;
exam->long_DS= 4;
break;
case 16:
exam->x_DS = 149;
exam->y_DS= 54;
exam->larg_DS= 12;
exam->long_DS= 5;
exam->x_DS = 88;
exam->y_DS= 361;
exam->larg_DS= 3;
exam->long_DS= 15;
break;
case 17:
......@@ -157,8 +150,8 @@ void init_DS(DS * exam, int door_DS, char * path){
break;
case 19:
exam->x_DS = 149;
exam->y_DS= 54;
exam->x_DS = 499;
exam->y_DS= 324;
exam->larg_DS= 12;
exam->long_DS= 5;
break;
......
/*
// Created by Tiny on 3/3/2021.
*/
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "GAME.h"
......@@ -12,42 +13,10 @@
#define WINDOW_WIDTH (700)
#define WINDOW_HEIGHT (700)
int testposition(Personnage * pers, Prof * prof, DS * exam, MAP * map, int up,int down, int left, int right){
int x_A=0,x_B=0,y_A=0,y_B=0;
//calculer les points
if (up && !down && !right && !left) {
x_A= pers->x_pers;
y_A = pers->y_pers;
x_B = pers->x_pers + pers->larg_pers;
y_B = pers->y_pers;
}
if (!up && down && !right && !left) {
x_A= pers->x_pers;
y_A = pers->y_pers + pers->long_pers;
x_B = pers->x_pers + pers->larg_pers;
y_B = pers->y_pers + pers->long_pers;
}
if (!up && !down && !right && left) {
x_A= pers->x_pers;
y_A = pers->y_pers;
x_B= pers->x_pers;
y_B = pers->y_pers + pers->long_pers;
}
if (!up && !down && right && !left) {
x_A = pers->x_pers + pers->larg_pers;
y_A = pers->y_pers;
x_B = pers->x_pers + pers->larg_pers;
y_B = pers->y_pers + pers->long_pers;
}
int testposition(Personnage * pers, Prof * prof, DS * exam, MAP * map){
//test variables
int testbounds = testboundscol(pers); ;
int testprof = testprofcol(pers,prof,x_A,y_A,x_B,y_B);
int testprof = testprofcol(pers,prof);
//test bounds collision
......@@ -59,7 +28,7 @@ int testposition(Personnage * pers, Prof * prof, DS * exam, MAP * map, int up,in
//return the map test position
return testmapcol(pers,map,exam,x_A,y_A,x_B,y_B); // = 0 if nothing , 1 if wall, 2 if exam
return testmapcol(pers,map,exam); // = 0 if nothing , 1 if wall, 2 if exam
}
......@@ -70,44 +39,74 @@ int testboundscol(Personnage * pers){
return 0;
}
int testprofcol(Personnage * pers, Prof * prof,int x_A,int y_A, int x_B, int y_B){
int testprofcol(Personnage * pers, Prof * prof){
int testhl;
int testhr;
int testll;
int testlr;
testhl=testpointwithprof(pers->x_pers, pers->y_pers,prof);
testhr=testpointwithprof(pers->x_hr, pers->y_hr,prof) ;
testll=testpointwithprof(pers->x_ll, pers->y_ll,prof);
testlr=testpointwithprof(pers->x_lr, pers->y_lr,prof) ;
if(testhl){
return 1;
}
else if (testhr){
return 1;
}
else if (testll){
return 1;
}
else if (testlr){
return 1;
}
return 0;
}
//test position vs prof
if (( x_A > prof->x_prof) && (x_A<prof->x_prof+prof->larg_prof)) {
if (( y_A > prof->y_prof) && (y_A < prof->y_prof + prof->long_prof)) {
return 1;
}
}
if (( x_B > prof->x_prof) && (x_B<prof->x_prof+prof->larg_prof)) {
if (( y_B > prof->y_prof) && (y_B < prof->y_prof + prof->long_prof)) {
int testpointwithprof(int x, int y, Prof *prof){
if (( x > prof->x_prof) && (x<prof->x_prof+prof->larg_prof)) {
if (( y > prof->y_prof) && (y < prof->y_prof + prof->long_prof)) {
return 1;
}
}
return 0;
return 0;
}
int testmapcol(Personnage * pers, MAP * map, DS * exam ,int x_A,int y_A, int x_B, int y_B){
if (map->functional[y_A][x_A] == 2){ //if zone exams
//test exam collision
if ((x_A > exam->x_DS) && (x_A < exam->x_DS+exam->larg_DS)) {
return 2;
}
}
else if (map->functional[y_A][x_A] == 1){ //if zone wall
return 1;
}
int testmapcol(Personnage * pers, MAP * map, DS * exam ){
int testhl = testpointwithmap(pers->x_pers,pers->y_pers,map,exam);
int testhr = testpointwithmap(pers->x_hr,pers->y_hr,map,exam) ;
int testll = testpointwithmap(pers->x_ll,pers->y_ll,map,exam) ;
int testlr = testpointwithmap(pers->x_lr,pers->y_lr,map,exam) ;
if(testhl==2 || testhr==2 || testll==2 || testlr==2) {
return 2;
}
else if(testhl==1 || testhr==1 || testll==1 || testlr==1){
return 1;
}
else return 0;
}
if (map->functional[y_B][x_B] == 2){ //if zone exams
int testpointwithmap(int x, int y, MAP *map, DS * exam){
if (map->functional[y][x] == 2){ //if zone exams
//test exam collision
if ((x_B > exam->x_DS) && (x_B < exam->x_DS+exam->larg_DS)) {
if ((x > exam->x_DS) && (x < exam->x_DS+exam->larg_DS)) {
if(((y > exam->y_DS) && (y < exam->y_DS+exam->long_DS))){
return 2;
}
}
}
else if (map->functional[y_B][x_B] == 1){ //if zone wall
else if (map->functional[y][x] == 1){ //if zone wall
return 1;
}
return 0; //if nothing
return 0;
}
\ No newline at end of file
......@@ -70,7 +70,6 @@ int **maptomatrix(MAP *map){
int i;
FILE *bin;
printf("Open : %s \n",map->path);
if(!(bin=fopen(map->path,"rb"))){
puts("Error to open the map !");
return NULL;
......@@ -149,6 +148,9 @@ int **maptomatrix(MAP *map){
fprintf(outout,"\n");
}
fclose(bin);
fclose(outout);
return fonc;
}
\ No newline at end of file
......@@ -39,4 +39,14 @@ void init_pers(Personnage * character, int x, int y, int length, int width, int
character->speed_pers=speed;
character->image_pers = malloc(strlen(path));
strcpy(character->image_pers, path);
}
void calculpointspers(Personnage * character){
//calculate 3 others points of rectangle
character->x_hr = character->x_pers + character->larg_pers ;
character->y_hr = character->y_pers;
character->x_ll = character->x_pers;
character->y_ll = character->y_pers + character->long_pers;
character->x_lr = character->x_pers + character->larg_pers;
character->y_lr = character->y_pers + character->long_pers;
}
\ No newline at end of file
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