I'm a beginner in C, maybee I don't understand arrays in C because as Webdeveloper I used Languages like ASP, Python, PHP, Javascript and Actionscript it was easier.
My Goal is a two-dimensional array. First dimension: should contain the current level of the game, second dimension: object structure.
When I compile and execute it seems, the first dimension is used as a structure.
C:\_dev>gcc struct_def.c -o struct_def.exe -lmingw32
C:\_dev>struct_def.exe
result
x = 420.000000
x = 0.000000 < instead of 1200.000000
C:\_dev>
The Game is very small and I would like to hardcode all the level data. without having to load the levels dynamically and without malloc.
I want to iterate the array and refresh all the positions and making collision checks etc.
then iterate the array again to calculate wich object are inside the camera to draw.
How can I use the array as I would like it? First dimension: Level, second dimension: all the struct data?
thank's for helping ?
C ISO C98
<code>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct dynamic_pfl{
bool player;
int type;
int pause_time;
int moving_dir;
float mspeed;
float hspeed;
float vspeed;
float x;
float y;
float friction;
int width;
int height;
int state;
};
int main(){
int level = 5; //max levels of the game
struct dynamic_pfl arr_dynamic_pfl[level][20] = {
{false,1,4,2,40,0,0,420,580,0,128,64,0},
{false,2,4,2,40,0,0,1200,580,0,128,64,0},
{false,1,4,2,40,0,0,111,580,0,128,64,0},
{false,2,4,2,40,0,0,2222,580,0,128,64,0},
{false,2,4,2,40,0,0,666,580,0,128,64,0}
};
printf("result\n");
printf("x = %f\n",arr_dynamic_pfl[0][0].x);
printf("x = %f",arr_dynamic_pfl[0][1].x);
return 0;
}
</code>