Pre-makefile
This commit is contained in:
parent
adaa5142c2
commit
afa9d79731
11 changed files with 228 additions and 24 deletions
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/usr/include/c++/8",
|
||||
"/usr/include/x86_64-linux-gnu/c++/9"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "gnu18",
|
||||
"cppStandard": "gnu++14",
|
||||
"intelliSenseMode": "gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"exception": "c"
|
||||
}
|
||||
}
|
23
.vscode/tasks.json
vendored
Normal file
23
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "C/C++: gcc build active file + SLD2",
|
||||
"command": "/usr/bin/gcc",
|
||||
"args": [
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}",
|
||||
"-lSDL2",
|
||||
"-lSDL2main"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": ["$gcc"],
|
||||
"group": "build"
|
||||
}
|
||||
]
|
||||
}
|
BIN
balle2.bmp
Normal file
BIN
balle2.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.7 KiB |
BIN
joueur1.bmp
Normal file
BIN
joueur1.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
BIN
joueur2.bmp
Normal file
BIN
joueur2.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 44 KiB |
147
main.cpp
147
main.cpp
|
@ -1,17 +1,137 @@
|
|||
// Leopold Clement
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
#include "SDL2/SDL.h"
|
||||
|
||||
/*#include <exception.h>
|
||||
#include <string.h>
|
||||
#include <iostream.h>*/
|
||||
|
||||
struct timeval tv;
|
||||
|
||||
const int16_t LONGUEURE_TERRAIN = 800;
|
||||
const int16_t LARGEUR_TERRAIN = 600;
|
||||
const int16_t LARGEUR_BUT = 200;
|
||||
|
||||
const float VITESSE_TRANSLATION = 0.2;
|
||||
const float VITESSE_ROTATION = 0.02;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int up_key;
|
||||
int down_key;
|
||||
int right_key;
|
||||
int left_key;
|
||||
} Controlleur;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float theta;
|
||||
} Vecteur;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Vecteur position;
|
||||
char nom[25];
|
||||
Controlleur *control;
|
||||
} Robot;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Vecteur position;
|
||||
Vecteur vitesse;
|
||||
Robot *possession;
|
||||
} Balle;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int point_vert;
|
||||
int point_violet;
|
||||
int balle_en_jeu;
|
||||
} Score;
|
||||
|
||||
void rendut_robot(Robot robot)
|
||||
{
|
||||
}
|
||||
void rendut_balle(Balle balle)
|
||||
{
|
||||
}
|
||||
void rendut_global(Robot robots[2], Balle balle)
|
||||
{
|
||||
}
|
||||
float distance_vecteurs(Vecteur vect1, Vecteur vect2)
|
||||
{
|
||||
return (sqrtf32(powf(vect1.x - vect2.x, 2) + powf(vect1.y - vect2.y, 2)));
|
||||
}
|
||||
Vecteur addition_vecteur(Vecteur vect1, Vecteur vect2)
|
||||
{
|
||||
Vecteur vecteur_somme = {vect1.x + vect2.y, vect1.y + vect2.y, vect1.theta + vect2.theta};
|
||||
return vecteur_somme;
|
||||
}
|
||||
|
||||
Vecteur projecteur_base_fixe(Vecteur vect, float theta)
|
||||
{
|
||||
Vecteur vect_fixe = {0, 0, 0};
|
||||
vect_fixe.x = vect.x * cosf32(theta) - vect.y * sinf32(theta);
|
||||
vect_fixe.y = vect.x * sinf32(theta) + vect.y * cosf32(theta);
|
||||
return vect_fixe;
|
||||
}
|
||||
|
||||
void deplacement_robot(SDL_Event events, Robot robot)
|
||||
{
|
||||
if (events.key.keysym.sym == robot.control->up_key)
|
||||
{
|
||||
Vecteur avance_ref_robot = {VITESSE_TRANSLATION, 0, 0};
|
||||
Vecteur avance_ref_fixe = projecteur_base_fixe(avance_ref_robot, -robot.position.theta);
|
||||
robot.position = addition_vecteur(robot.position, avance_ref_fixe);
|
||||
}
|
||||
else if (events.key.keysym.sym == robot.control->down_key)
|
||||
{
|
||||
Vecteur avance_ref_robot = {-VITESSE_TRANSLATION, 0, 0};
|
||||
Vecteur avance_ref_fixe = projecteur_base_fixe(avance_ref_robot, -robot.position.theta);
|
||||
robot.position = addition_vecteur(robot.position, avance_ref_fixe);
|
||||
}
|
||||
if (events.key.keysym.sym == robot.control->left_key)
|
||||
{
|
||||
Vecteur rotation = {0, 0, VITESSE_ROTATION};
|
||||
robot.position = addition_vecteur(robot.position, rotation);
|
||||
}
|
||||
else if (events.key.keysym.sym == robot.control->right_key)
|
||||
{
|
||||
Vecteur rotation = {0, 0, -VITESSE_ROTATION};
|
||||
robot.position = addition_vecteur(robot.position, rotation);
|
||||
}
|
||||
}
|
||||
void pulsation_du_jeu(SDL_Renderer *prenderer, SDL_Event events, Robot robots[2], Balle balle, int *pisOpen)
|
||||
{
|
||||
while (SDL_PollEvent(&events))
|
||||
{
|
||||
switch (events.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
*pisOpen = 0;
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
char i;
|
||||
for(i = 0; i<2; i++) deplacement_robot(events, robots[i]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *pwindow;
|
||||
SDL_Renderer *prenderer;
|
||||
SDL_Event events;
|
||||
int isOpen = 1;
|
||||
unsigned long long last_tic = 0;
|
||||
|
||||
SDL_Rect rectangle1 = {20, 20, 100, 50};
|
||||
// SDL_Rect rectangle1 = {20, 20, 100, 50};
|
||||
|
||||
//Initialisation de SDL avec la vidéo
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
|
@ -34,30 +154,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
while (isOpen)
|
||||
{
|
||||
gettimeofday(&tv, NULL);
|
||||
unsigned long long millisecondsSinceEpoch = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000;
|
||||
/* évènements de votre jeu */
|
||||
while (SDL_PollEvent(&events))
|
||||
{
|
||||
|
||||
switch (events.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
isOpen = 0;
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
if (events.key.keysym.sym == SDLK_v)
|
||||
{
|
||||
SDL_SetRenderDrawColor(prenderer, 00, 255, 00, 255);
|
||||
SDL_RenderFillRect(prenderer, &rectangle1);
|
||||
}
|
||||
if (events.key.keysym.sym == SDLK_b)
|
||||
{
|
||||
SDL_SetRenderDrawColor(prenderer, 00, 00, 255, 255);
|
||||
SDL_RenderFillRect(prenderer, &rectangle1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(prenderer); // mets à jour la fenêtre
|
||||
}
|
||||
|
|
BIN
sand_box
Executable file
BIN
sand_box
Executable file
Binary file not shown.
59
sand_box.c
Normal file
59
sand_box.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include "SDL2/SDL.h"
|
||||
|
||||
struct timeval tv;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float theta;
|
||||
} Vecteur;
|
||||
// typedef struct {Vecteur position; Vecteur vitesse; char[25] nom} Robot;
|
||||
void print_nl()
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
void print_vecteur(Vecteur vec)
|
||||
{
|
||||
printf("(%f;%f;%f)", vec.x, vec.y, vec.theta);
|
||||
}
|
||||
|
||||
Vecteur addition_vecteur(Vecteur vect1, Vecteur vect2)
|
||||
{
|
||||
Vecteur vecteur_somme = {vect1.x + vect2.y, vect1.y + vect2.y, vect1.theta + vect2.theta};
|
||||
return vecteur_somme;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Vecteur A = {1, 2, 3};
|
||||
Vecteur B = {1, 0, 3};
|
||||
Vecteur C;
|
||||
C = addition_vecteur(A, B);
|
||||
/*int i = 0;
|
||||
unsigned long long last_tic = 0;
|
||||
while (i <= 1000)
|
||||
{
|
||||
gettimeofday(&tv, NULL);
|
||||
unsigned long long millisecondsSinceEpoch = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000;
|
||||
if ((millisecondsSinceEpoch - last_tic) >= 10)
|
||||
{
|
||||
printf("%llu\n", millisecondsSinceEpoch);
|
||||
last_tic = millisecondsSinceEpoch;
|
||||
i++;
|
||||
}
|
||||
}*/
|
||||
|
||||
print_vecteur(A);
|
||||
print_nl();
|
||||
print_vecteur(B);
|
||||
print_nl();
|
||||
print_vecteur(C);
|
||||
print_nl();
|
||||
C.x = -10;
|
||||
print_vecteur(C);
|
||||
print_nl();
|
||||
return 0;
|
||||
}
|
BIN
victoire_joueur1.bmp
Normal file
BIN
victoire_joueur1.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
BIN
victoire_joueur2.bmp
Normal file
BIN
victoire_joueur2.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
Loading…
Reference in a new issue