Commit 952e5af5 authored by guillaume's avatar guillaume

ça bug...

parent 4a468980
...@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) ...@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
project(networld LANGUAGES C) project(networld LANGUAGES C)
# Activate C99 standard: # Activate C99 standard:
SET(CMAKE_C_FLAGS "-std=c99 -Wall -Wextra" ) SET(CMAKE_C_FLAGS "-g -std=c99 -Wall -Wextra" )
# RayLib: # RayLib:
find_package(raylib 2.0 REQUIRED) find_package(raylib 2.0 REQUIRED)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "networld.h" #include "networld.h"
#include "raylib.h" #include "raylib.h"
#include <stdlib.h>
// Program attributes // Program attributes
//------------------- //-------------------
...@@ -14,8 +15,8 @@ const int screenWidth = 800; ...@@ -14,8 +15,8 @@ const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 450;
const int targetFPS = 60; const int targetFPS = 60;
void game_update(); void game_update(NetWorld * world);
void game_draw(); void game_draw(NetWorld * world);
// Game attributes // Game attributes
//----------------- //-----------------
...@@ -24,8 +25,6 @@ bool game_end; ...@@ -24,8 +25,6 @@ bool game_end;
int main(int nbArg, char ** arg) int main(int nbArg, char ** arg)
{ {
test();
// Raylib Initialization // Raylib Initialization
//---------------------- //----------------------
InitWindow(screenWidth, screenHeight, "NetWorld basic viewer"); InitWindow(screenWidth, screenHeight, "NetWorld basic viewer");
...@@ -34,32 +33,44 @@ int main(int nbArg, char ** arg) ...@@ -34,32 +33,44 @@ int main(int nbArg, char ** arg)
// Game Initialization // Game Initialization
//-------------------- //--------------------
game_end= false; game_end= false;
NetWorld * world= NetWorld_new(3);
NetWorld_initNodePosition( world, 0, 10.4, 12.8 );
NetWorld_initNodePosition( world, 1, 110.4, 52.8 );
NetWorld_initNodePosition( world, 2, 384.5, 422.2 );
// Main game loop // Main game loop
while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key
{ {
game_update(); game_update(world);
game_draw(); game_draw(world);
} }
// proper closing // proper closing
//--------------- //---------------
NetWorld_delete(world);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
return 0; return 0;
} }
void game_update() void game_update(NetWorld * world)
{ {
} }
void game_draw() void game_draw(NetWorld * world)
{ {
BeginDrawing(); BeginDrawing();
puts("Draw...\n");
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
for(int i= 0 ; i < world->size ; ++i )
{
Vector2 nodePosition= { world->nodes[i].x, world->nodes[i].y };
printf("[%f, %f]\n", world->nodes[i].x, world->nodes[i].y);
DrawCircleV(nodePosition, 50, MAROON);
}
EndDrawing(); EndDrawing();
} }
\ No newline at end of file
#include "networld.h" #include "networld.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int test(){ // Constructor / Destructor
puts("hello"); NetWorld * NetWorld_new(int size)
return 0; {
NetWorld * p = malloc( sizeof(NetWorld) );
p->size= size;
p->nodes= malloc( p->size * sizeof(Node) );
return p;
}
void NetWorld_delete(NetWorld * self)
{
free( self->nodes );
free( self );
}
// Initialization
void NetWorld_initNodePosition(
NetWorld * self, int iNode,
float x, float y)
{
self->nodes[iNode].x= x;
self->nodes[iNode].y= y;
} }
#ifndef NETWORLD_H #ifndef NETWORLD_H
#define NETWORLD_H #define NETWORLD_H
int test(); struct Str_Node {
float x, y;
};
typedef struct Str_Node Node;
struct Str_NetWorld {
int size;
Node * nodes;
};
typedef struct Str_NetWorld NetWorld;
// Constructor / Destructor
NetWorld * NetWorld_new(int aSize);
void NetWorld_delete(NetWorld * aWorld);
// Initialization
void NetWorld_initPosition(NetWorld * self, float ** position); // position must be an float[size][2] array...
#endif //NETWORLD_H #endif //NETWORLD_H
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment