problème en C
Posté le 29/10/2020 13:57
bonjour, je développe mon add-in en c (avec gint),
mais je rencontre un problème,
je mats en argument d'une fonction une struct qui est ensuite modifié
, pourtant ça ne marche pas
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <gint/clock.h>
extern bopti_image_t img_player;
struct Player{
/* Position in map */
int x, y;
/* Direction currently facing */
int dir;// 1: left, 2: right
int animdata[10][5][2];
/* Animation and frame */
int twait;
int frame;
int anim;
int status; //1: normal, 2: roket, 3: code manipulation
};
void Player_init(struct Player *plr){
//plr.animdata[0] = {{0,0},{1,0},{2,0},{3,0},{4,0}};
//plr.animdata[1] = {{0,1},{1,1},{2,1},{3,1},{4,1}};
plr->animdata[0][0][0] = 0;
plr->animdata[0][0][1] = 0;
plr->animdata[0][1][0] = 1;
plr->animdata[0][1][1] = 0;
plr->animdata[0][2][0] = 2;
plr->animdata[0][2][1] = 0;
plr->animdata[0][3][0] = 3;
plr->animdata[0][3][1] = 0;
plr->animdata[0][4][0] = 4;
plr->animdata[0][4][1] = 0;
plr->animdata[1][0][0] = 0;
plr->animdata[1][0][1] = 1;
plr->animdata[1][1][0] = 1;
plr->animdata[1][1][1] = 1;
plr->animdata[1][2][0] = 2;
plr->animdata[1][2][1] = 1;
plr->animdata[1][3][0] = 3;
plr->animdata[1][3][1] = 1;
plr->animdata[1][4][0] = 4;
plr->animdata[1][4][1] = 1;
plr->status = 1;
}
void Player_check_anim(struct Player *plr){
if(plr->status==1){
if(plr->dir==1){plr->anim=0;}
if(plr->dir==2){plr->anim=1;}
}
if(plr->twait == 15){
plr->twait = 0;
plr->frame = plr->frame + 1;
if(plr->frame > 4){
plr->frame = 0;
}
}
plr->twait = plr->twait + 1;
}
void Player_print(struct Player plr){
dsubimage(plr.x, plr.y,&img_player,plr.animdata[plr.anim][plr.frame][0]*12, plr.animdata[plr.anim][plr.frame][1]*12,
11, 10, DIMAGE_NONE);
}
//int opt = GETKEY_DEFAULT & GETKEY_REP_ARROWS;
int select = 1;
int main(void){
extern bopti_image_t img_logo;
extern bopti_image_t img_button;
int playing = 1;
int key = 0;
struct Player player;
Player_init(&player);
int opt = GETKEY_DEFAULT & ~GETKEY_REP_ARROWS & GETKEY_MENU;
while(playing==1){
while(key != KEY_SHIFT){
dclear(C_WHITE);
dimage(25, 3, &img_logo);
//dsubimage(40, 40,&img_player,0* 11, 0, 11, 11, DIMAGE_NONE);
if(select==1){dsubimage(35, 33,&img_button,0, 10, 42, 10, DIMAGE_NONE);}
else{dsubimage(35, 33,&img_button,0, 0, 42, 10, DIMAGE_NONE);}
if(select==2){dsubimage(35, 45,&img_button,0, 30, 42, 10, DIMAGE_NONE);}
else{dsubimage(35, 45,&img_button,0, 20, 42, 10, DIMAGE_NONE);}
dupdate();
key = getkey_opt(opt, NULL).key;
if(key == KEY_UP){select=1;}
if(key == KEY_DOWN){select=2;}
}
while(1==1){
dclear(C_WHITE);
Player_check_anim(&player);
Player_print(player);
dupdate();
}
}
return 1;
}
mes fonctions arrive pas a modifier l'objet joueur
Fichier joint
Citer : Posté le 29/10/2020 15:07 | #
Aucun problème avec tes pointeurs. Minimise ton programme en supprimant le maximum de choses tout en conservant le bug, le problème devrait apparaître tout seul.