0% found this document useful (0 votes)
25 views56 pages

Project Thesis Main .C Et Game Controller

c'est une documentation de projet (jeux 2D) utilisant le language de programmation c et la bibliotheque SDL 1.2. Tres utile pour ceux qui sont entrain d'apprendre le language c et souhaite travailler sur un projet

Uploaded by

amiratouil981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views56 pages

Project Thesis Main .C Et Game Controller

c'est une documentation de projet (jeux 2D) utilisant le language de programmation c et la bibliotheque SDL 1.2. Tres utile pour ceux qui sont entrain d'apprendre le language c et souhaite travailler sur un projet

Uploaded by

amiratouil981
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Project Thesis:

Anatomy Ascent : Wellness Wanderlust


Introduction
The main goal of this thesis is to provide comprehensive documentation of our
collective efforts throughout the development of our 2D game, proudly created
by our group, The Sentinels, as a university project. This thesis serves multiple
purposes:
1. Detailed Documentation: It meticulously records every aspect of our
project, from initial concept to final implementation, offering a complete
guide to our processes, challenges, and solutions.
2. Resource for Future Students: As SDL 1.2 is no longer in widespread use,
this document aims to be a valuable resource for future generations of
students at our university. We hope it will assist them in finding useful
information and techniques that can be applied to their own projects.
3. Guide for Game Development Beginners: This thesis is also designed to
aid beginners in game development. It includes practical insights and
step-by-step guides that can help newcomers understand the basics of
creating a game.
4. For Enthusiasts and Players: Finally, this document is for those who wish
to play our game and understand the behind-the-scenes work that
brought it to life. It provides an in-depth look at the creative and
technical journey we embarked on.
5. Honoring Our Professors: We wish to honor our professors and mentors
who have guided and supported us throughout this project. It is our hope
that this thesis makes them proud of our achievements and reflects the
knowledge and skills they have imparted to us.
We are incredibly proud of the work we've accomplished and hope that this
thesis not only showcases our achievements but also inspires and supports
others in their own game development endeavors.
Acknowledgements
We would like to express our deepest gratitude to everyone who has
supported us throughout this project. Our work would not have been possible
without the guidance, support, and inspiration we received from various
individuals and institutions.
Esprit School of Engineering
First and foremost, we extend our heartfelt thanks to Esprit School of
Engineering for providing us with the resources, environment, and
opportunities to develop our skills and work on this project.
Director and Founder
A special thanks to Mr. Tahar Ben Lakhdhar, the director and founder of Esprit
School of Engineering, for his vision and dedication in creating an institution
that fosters innovation and excellence in engineering education.
Professors
We are immensely grateful to our professors for their invaluable teachings and
guidance:
 APP Professors and Programming professors: For instilling in us the
fundamental principles of engineering and project management.
 Algorithmic Professors: For teaching us the logic and ways of thinking
that are crucial for problem-solving and software development.
 Project Professors: For supervising our work, providing us with insightful
advice and maintaining rigorous standards throughout the project. Your
guidance in both project management and C programming has been
indispensable.
 Arduino Professors: For introducing us to the world of controllers and
embedded systems, which broadened our understanding and capabilities
in hardware-software integration helping us devolp our game controller
 Graphic Design Professor: For teaching us the principles of graphic
design, which greatly enhanced the visual appeal and user interface of
our game.
Summary of Our Work

1. Concept of the game :


2. Coding Part

 Background Coding
 Player Coding
 Enemy Coding
 Minimap Code
 Enigma Coding
 Tic Tac Toe
3. Game Controller Idea and Code

 Concept and Implementation of


the Game Controller
Idea of the game
When we started working on our 2D game about well-being, we faced a
challenge. Our English professor wanted us to cover a range of health topics,
from diseases to mental and physical well-being. This was tricky to nail down
into one game concept.
Our journey began with extensive research, scouring various sources until we
stumbled upon inspiring projects like 'Remission: The Cancer Game,' 'Project
Remidium,' and the television series 'La Vie.' It was through exposure to
these innovative endeavors that the seed of our game idea was planted in
our minds

Storyline of the game


In a world where the boundaries between medical breakthroughs and
personal vendettas blur, the tale unfolds with three distinguished doctors: Dr.
Andre Murphy, Dr. Tom Keen, and Dr. Anna Croft. The narrative takes a
dramatic turn when Dr. Tom Keen, driven by vengeance after a near-fatal
accident and subsequent dismissal from his esteemed position, resorts to
tampering with Dr. Murphy's revolutionary invention – the nanobots.

These nanobots, conceived by Dr. Murphy, were designed to revolutionize


healthcare, offering precise monitoring and targeted treatment within the
human body. However, Dr. Keen's modifications pervert their purpose,
turning them into agents of destruction. Instead of aiding the body's
defenses, they wreak havoc, triggering a catastrophic pandemic that
threatens global health and stability.

As chaos spreads, Dr. Anna Croft emerges as a beacon of hope. Recognizing


the dire consequences of the corrupted nanobots, she assembles a team of
specialists known as the Sentinels. At the heart of this team is Emma, the
player's chosen avatar, and the most advanced of the Sentinels. With her
unique abilities, Emma delves into the intricacies of the human body,
navigating its complex systems under the watchful guidance of Lizzy, the
original nanobot created by Dr. Murphy.
As players embark on this perilous journey, they must navigate through the
body's intricate pathways, confronting challenges and adversaries along the
way. Their mission: to unravel the mystery behind the pandemic, restore the
integrity of Dr. Murphy's invention, and ultimately save humanity from the
brink of devastation. Will they succeed in their quest, or will the darkness
that lurks within prove insurmountable? The fate of the world hangs in the
balance as players embark on this gripping adventure of redemption and
resilience.

Main .c integration
#include <stdio.h>
#include <stdlib.h>
#include "menu.h" // Including the header file for the menu
#include <SDL/SDL.h> // Including the SDL library
#include <SDL/SDL_image.h> // Including the SDL image library for loading
image files
#include <SDL/SDL_mixer.h> // Including the SDL mixer library for sound
#include <SDL/SDL_ttf.h> // Including the SDL TrueType Fonts library for
rendering text
#include "joueur.h" // Including the header file for the player
#include "background.h" // Including the header file for the background
#include "minimap.h" // Including the header file for the minimap
#include "xo.h" // Including the header file for Tic Tac Toe
#include "enemie.h" // Including the header file for the enemy
#include "enig_fichier.h" // Including the header file for file-based puzzles

//////////////////tictactoe/////////////////////////////
void tictactoe(SDL_Surface *screen); // Function prototype for Tic Tac Toe
void tictactoe(SDL_Surface *screen){ // Definition of the Tic Tac Toe function
int contin=1; // Variable to control the main loop of the game
tic t; // Structure variable for Tic Tac Toe game state
int coup; // Variable to store the move made by the player
TTF_Init(); // Initialize SDL_TTF for text rendering
SDL_Event event; // Event variable for handling SDL events
int joueur = 1; // Variable to track which player's turn it is, assuming player 1
starts first

// Call the initialization function with the address of 't' as an argument


initialisation(&t);

int a, bb; // Variables to store mouse click coordinates

// Main loop of the game


while (contin)
{
// Display the game grid
affichage(t, screen);
// Update the screen
SDL_Flip(screen);

// Check if there are remaining turns to play and if nobody has won yet
if (t.tour < 9 && atilganer(t.tabsuivi) == 0)
{
// Check whose turn it is
if ((t.tour + joueur) % 2 == 0) // Computer's turn
{
// Calculate the computer's move
calcul_coup(t.tabsuivi);
t.tour++; // Increment the number of turns
}
else // Player's turn
{
// Wait for an SDL event
SDL_WaitEvent(&event);

// Handle events
switch (event.type)
{
case SDL_QUIT: // If the user closes the window
contin = 0; // Exit the loop
break;
case SDL_MOUSEBUTTONUP: // If the user clicks the mouse
// Calculate the click coordinates
a = event.button.x / 190;
bb = event.button.y / 190;
coup = 3 * bb + a; // Calculate the move to play
if (t.tabsuivi[coup] == 0) {
t.tabsuivi[coup] = -1; // Set the player's move in the tracking
array
t.tour++; // Increment the number of turns
}
break;
}
}
}
else
{
// Display the game result
Resultat(t, screen);
contin = 0; // Exit the loop
printf("%d", t.tour); // Display the number of turns played
}
}

// Free resources and quit SDL


SDL_Quit();
TTF_Quit();
liberationmemoire(t);
return;
}

/////////////////////fonction tictactoe//////////////////////////

int main()
{
// Initialize SDL and set up the screen
SDL_Surface *screen ,*ecrann ;

screen=SDL_SetVideoMode(1720,968,32,SDL_SWSURFACE|SDL_DOUBLEBUF);
SDL_Init(SDL_INIT_EVERYTHING);
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)==-1)
{
printf("could not initialize SDL:%s\n",SDL_GetError());
return -1;
}

Mix_Music *music; // Music variable for background music


Mix_Chunk *mus = NULL; // Sound effect variable
// Declaration of various image variables for UI elements
image
BB,IMAGE,back,backtt,bt1,mb,btBACK,start,settings,credits,quit,volume1,plus1
,moins1,volume2,plus2,moins2,btfull,btwind,quitterbt,sauvbt,mbcredits,sinpla
yer,multiplayer,newgame,loadgame,chperso,fleshe1,fleshe2,confi,chperso2,fle
she12,fleshe22,chperso3,fleshe13,fleshe23,stage,fleshechose1,fleshechose2,pa
usebt;

// Declaration of various text variables for UI elements


texte
txte,starttxt,settingstxt,creditstxt,quittxt,splayer,mplayer,choisir,ok,choisir2,ch
oisir3,ngame,lgame;

SDL_Event event; // Event variable for handling SDL events


int specifier; // Variable for specifying something
int boucle=1; // Variable to control the main loop

int state=0; // State variable


// Initialize background
Background b;
initBack(&b);

// Initialize player and bonus entities


perso p,p1,p2;
Bonus bb,bb1,bb2;
// Variables for time calculations
Uint32 t_prev, t_fin, dt;

// Initialize SDL_ttf
if (TTF_Init() == -1) {
printf("Unable to initialize SDL_ttf: %s\n", TTF_GetError());
SDL_Quit();
return 1;
}
// Load font for timer
TTF_Font *font = TTF_OpenFont("front/pepsi.ttf", 60); // Change "font.ttf" to
your font file
if (!font) {
printf("Unable to load font: %s\n", TTF_GetError());
TTF_Quit();
SDL_Quit();
return 1;
}

// Initialize the minimap and load the mask image


vie v;
minimap m;
SDL_Surface *mask;
initmap(&m);
mask=IMG_Load("source/backgroundMasque.bmp");

// Initialize the player


initperso(&p);
initperso1(&p1);
initperso2(&p2);

// Initialize bonuses
initBonus(&bb);
initBonus(&bb1);
initBonus(&bb2);

// Initialize the enemy


enemie e;
initennemi(&e);

// Variables for player movement


int acceleration = 0 , deceleration = 0 , up = 0;
int acceleration1 = 0 , deceleration1 = 0
// Initializing images for the background, buttons, etc.
intialiser_imgBACK(&IMAGE);
intialiser_img_backk(&back);
intialiser_img_backktt(&backtt);
intialiser_img_bouton(&bt1);
intialiser_img_miniback(&mb);
intialiser_img_BTBAC(&btBACK);
initialiser_texte(&txte);
intialiser_img_start(&start);
intialiser_img_settings(&settings);
intialiser_img_credits(&credits);
intialiser_img_quit(&quit);
intialiser_fleshe_to_chose_stage(&fleshechose1);
intialiser_fleshe_to_chose_stage2(&fleshechose2);

// Initializing text for buttons


initialiser_texte_bouton_start(&starttxt);
initialiser_texte_bouton_settings(&settingstxt);
initialiser_texte_bouton_credits(&creditstxt);
initialiser_texte_bouton_quitter(&quittxt);

// Initializing images for volume controls, fullscreen, etc.


intialiser_img_volume(&volume1);
intialiser_img_btvolume_plus(&plus1);
intialiser_img_btvolume_moins(&moins1);
intialiser_img_volume_charactere(&volume2);
intialiser_img_btvolume_plus_charactere(&plus2);
intialiser_img_btvolume_moins_charactere(&moins2);
intialiser_img_fullscreen(&btfull);
intialiser_img_windowed(&btwind);
intialiser_quitter(&quitterbt);
intialiser_sauv(&sauvbt);
intialiser_img_credits_screen(&mbcredits);
intialiser_singleplayer(&sinplayer);
intialiser_multiplayer(&multiplayer);
intialiser_new_game(&newgame);
intialiser_load_game(&loadgame);
intialiser_stage(&stage);

// Initializing audio for the game


initialiser_audio1(music);

// Initializing text for singleplayer, multiplayer buttons, etc.


initialiser_texte_singleplayer(&splayer);
initialiser_texte_bouton_multiplayer(&mplayer);
initialiser_texte_bouton_new_game(&ngame);
initialiser_texte_bouton_load_game(&lgame);

// Initializing images for character selection, confirmation, etc.


intialiser_img_perso(&chperso);
intialiser_fleshe1(&fleshe1);
intialiser_fleshe2(&fleshe2);
intialiser_img_perso2(&chperso2);
intialiser_fleshe12(&fleshe12);
intialiser_fleshe22(&fleshe22);
intialiser_img_perso3(&chperso3);
intialiser_fleshe13(&fleshe13);
intialiser_fleshe23(&fleshe23);
intialiser_img_confirmation(&confi);
initialiser_texte_bouton_confirmation(&ok);
initialiser_texte_choisir(&choisir);
initialiser_texte_choisir2(&choisir2);
initialiser_texte_choisir3(&choisir3);
intialiser_pause(&pausebt);

// Main loop
while(boucle)
{
// Code for different states of the game menu and gameplay
}
/////////////////////////////////////////////////////////////////////////////
//stage 1 ///////////////////////////////////////////////////////

if(state==2)
{
// Update time
t_prev = SDL_GetTicks();

// Render background, minimap, and pause button


afficherBack_partage(b,screen , stage.etat);
afficher_img(screen, pausebt);
afficherminimap(m,screen , stage.etat);
// Update minimap position for player 1
m.pos_joueur=MAJMinimap(p1.pos_perso,12,b.camera);

// Render player 1 and player 2


afficherperso(&p1, screen,chperso2.etat);
afficherperso(&p2, screen,chperso3.etat);

// Update score, life, and time


update_score(&v);
afficher_vie(&v,screen);
affichertemp(&elapsedTime, screen, font);

// Update player 2 movement


if (acceleration2 == 1)
p2.acceleration = p2.acceleration + 0.005;
if (deceleration2 == 1)
p2.acceleration = p2.acceleration - 0.01;
if (p2.acceleration < 0)
p2.acceleration = 0;

// Calculate time difference


t_fin = SDL_GetTicks();
dt = t_fin - t_prev;

// Animate player 1 and player 2


animerperso(&p1);
animerperso(&p2);

// Handle movement and collision for player 2


switch (p2.direction) {
case 1:
if (collisionPP_droite(p2.pos_perso, mask, b.backgroundPos2) == 0) {
scrolling(&b.backgroundPos2, 0, p2.dx);
move2(&p2, dt);
}
break;
case -1:
if (collisionPP_gauche(p2.pos_perso, mask, b.backgroundPos2) == 0) {
scrolling(&b.backgroundPos2, 1, p2.dx);
move2(&p2, dt);
}
break;
}

// Handle jumping for player 2


if (up2==1)
jump(&p2);
if (p2.up==0 )
{
p2.vitesse_saut+=15;
p2.ground=680;
}
if (p2.up==0 &&
collisionPP_down(p2.pos_perso,mask,b.backgroundPos2)==0)
{
p2.ground+=15;
}

if (collisionPP_down(p2.pos_perso,mask,b.backgroundPos2)==1)
{
p2.ground=p2.pos_perso.y;
}

p2.pos_perso.y = p2.pos_perso.y + p2.vitesse_saut ;


p2.vitesse_saut = p2.vitesse_saut + 10 ;

if (p2.pos_perso.y>=p2.ground)
{
p2.pos_perso.y=p2.ground;
p2.vitesse_saut=0;
p2.up=0;
}

// Handle movement and collision for player 1


switch (p1.direction) {
case 1:
if (collisionPP_droite(p1.pos_perso, mask, b.backgroundPos) == 0) {
scrolling(&b.backgroundPos, 0, p1.dx);
move1(&p1, dt);
}
break;
case -1:
if (collisionPP_gauche(p1.pos_perso, mask, b.backgroundPos) == 0) {
scrolling(&b.backgroundPos, 1, p1.dx);
move1(&p1, dt);
}
break;
}

// Handle jumping for player 1


if (up1==1)
jump(&p1);
if (p1.up==0 )
{
p1.vitesse_saut+=15;
p1.ground=680;
}
if (p1.up==0 && collisionPP_down(p1.pos_perso,mask,b.backgroundPos)==0)
{
p1.ground+=15;
}

if (collisionPP_down(p1.pos_perso,mask,b.backgroundPos)==1)
{
p1.ground=p1.pos_perso.y;
}

p1.pos_perso.y = p1.pos_perso.y + p1.vitesse_saut ;


p1.vitesse_saut = p1.vitesse_saut + 10 ;

if (p1.pos_perso.y>=p1.ground)
{
p1.pos_perso.y=p1.ground;
p1.vitesse_saut=0;
p1.up=0;
}
}

/////////////////////////////////////////////////////////////////////////////
//multiplayer

if(state==3)
{
// Render various elements for the multiplayer mode
}
///////////////////////////////////////////////////////////////////////////////////
// // pause
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
boucle =0;
break;
case SDL_MOUSEMOTION:
if(state==0 && BB.etat==0)
{
if(event.motion.x >= 710 && event.motion.x < 710 +
301 && event.motion.y >= 800 && event.motion.y < 800+ 161)
{
bt1.etat=1;
}
else
{
bt1.etat=0;
}//play
}

if(state==0 && BB.etat==4)


{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 400 && event.motion.x < 400 +
345 && event.motion.y >= 160 && event.motion.y < 160+ 160)
{
loadgame.etat=1;
}
else
{
loadgame.etat=0;
}//loadgame
if(event.motion.x >= 950 && event.motion.x < 950 +
345 && event.motion.y >= 160 && event.motion.y < 160+ 160)
{
newgame.etat=1;
}
else
{
newgame.etat=0;
}//new game
}
if(state==0 && BB.etat==5)
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 400 && event.motion.x < 400 +
345 && event.motion.y >= 400 && event.motion.y < 400+ 160)
{
sinplayer.etat=1;
}
else
{
sinplayer.etat=0;
}//singleplayer
if(event.motion.x >= 950 && event.motion.x < 950 +
345 && event.motion.y >= 400 && event.motion.y < 400+ 160)
{
multiplayer.etat=1;
}
else
{
multiplayer.etat=0;
}//multiplayer
if(event.motion.x >= 1100 && event.motion.x < 1100
+ 345 && event.motion.y >= 700 && event.motion.y < 700+ 160)
{
confi.etat=1;
}
else
{
confi.etat=0;
}//ok
}
if(state==0 && BB.etat==1)
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;

}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 687 && event.motion.x < 687 +
345 && event.motion.y >= 160 && event.motion.y < 160+ 160)
{
start.etat=1;
initialiser_audiobref(mus);
}
else
{
start.etat=0;
liberer_audiobref(mus);

}//start
if(event.motion.x >= 687 && event.motion.x < 687 +
345 && event.motion.y >= 330 && event.motion.y < 330+ 160)
{
settings.etat=1;
initialiser_audiobref(mus);

}
else
{
settings.etat=0;
}//settings
if(event.motion.x >= 687 && event.motion.x < 687 +
345 && event.motion.y >= 500 && event.motion.y < 500+ 160)
{
credits.etat=1;
initialiser_audiobref(mus);
}
else
{
credits.etat=0;
}//credits
if(event.motion.x >= 687 && event.motion.x < 687 +
345 && event.motion.y >= 680 && event.motion.y < 680+ 160)
{
quit.etat=1;
initialiser_audiobref(mus);
}
else
{
quit.etat=0;
}//quit
}
if(state==0 &&
BB.etat==2)///////////////////settings////////////////////////////////////
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 1170 && event.motion.x < 1170 +
101 && event.motion.y >= 220 && event.motion.y < 220+ 101)
{
plus1.etat=1;
//afficher_mini_texte(screen , minitxt);
}
else
{
plus1.etat=0;
}//boutons plus1
if(event.motion.x >= 400 && event.motion.x < 400 +
101 && event.motion.y >= 220 && event.motion.y < 220+ 101)
{
moins1.etat=1;
}
else
{
moins1.etat=0;
}//boutons moins1
if(event.motion.x >= 1170 && event.motion.x < 1170 +
101 && event.motion.y >= 400 && event.motion.y < 400+ 101)
{
plus2.etat=1;
}
else
{
plus2.etat=0;
}//boutons plus2
if(event.motion.x >= 400 && event.motion.x < 400 +
101 && event.motion.y >= 400 && event.motion.y < 400+ 101)
{
moins2.etat=1;
}
else
{
moins2.etat=0;
}//boutons moins2
if(event.motion.x >= 500 && event.motion.x < 500 +
356 && event.motion.y >= 600 && event.motion.y < 600+ 161)
{
btfull.etat=1;
}
else
{
btfull.etat=0;
}//boutons fullscreen
}
if(state==0 &&
BB.etat==3)//////////////////////////////////////credits//////////////////////////
////////
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
}

if(state==0 &&
BB.etat==6)//////////////////////////////////////load
game//////////////////////////////////
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 1100 && event.motion.x < 1100
+ 345 && event.motion.y >= 700 && event.motion.y < 700+ 160)
{
confi.etat=1;
}
else
{
confi.etat=0;
}//ok
}
if(state==0 &&
BB.etat==7)//////////////////////////////////////singleplayer////////////////////
//////////////
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 1100 && event.motion.x < 1100
+ 345 && event.motion.y >= 700 && event.motion.y < 700+ 160)
{
confi.etat=1;
}
else
{
confi.etat=0;
}//ok
}
if(state==0 &&
BB.etat==8)//////////////////////////////////////multiplayer/////////////////////
/////////////
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 1100 && event.motion.x < 1100
+ 345 && event.motion.y >= 700 && event.motion.y < 700+ 160)
{
confi.etat=1;
}
else
{
confi.etat=0;
}//ok
}
if(state==1 ||
state==2)//////////////////////////////////////pause/////////////////////////////
/////
{
if(event.motion.x >= 1550 && event.motion.x < 1550 +
150 && event.motion.y >= 10 && event.motion.y < 10+ 150)
{
pausebt.etat=1;
}
else
{
pausebt.etat=0;
}//pause

if(state==3)//////////////////////////////////////pause////////////////////
//////////////
{
if(event.motion.x >= 50 && event.motion.x < 50 + 151
&& event.motion.y >= 50 && event.motion.y < 50+ 127)
{
btBACK.etat=1;
}
else
{
btBACK.etat=0;
}//menu back
if(event.motion.x >= 550 && event.motion.x < 550 +
345 && event.motion.y >= 600 && event.motion.y < 600+ 160)
{
quitterbt.etat=1;
}
else
{
quitterbt.etat=0;
}//bt quitter
if(event.motion.x >= 900 && event.motion.x < 900 +
345 && event.motion.y >= 600 && event.motion.y < 600+ 160)
{
sauvbt.etat=1;
}
else
{
sauvbt.etat=0;
}//bt sauvgarde

}
break;
case SDL_MOUSEBUTTONDOWN:

if (event.button.button == SDL_BUTTON_LEFT)
{
int x = event.button.x;
int y = event.button.y;
if(state==0 && BB.etat==0)
{
if (x >= 710 && x < 710 + 301 && y >= 800 && y
< 800+ 161)
{
BB.etat=1;
}
}//play
if(state==0 && BB.etat==1)
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
BB.etat=0;
}//menu back
if (x >= 687 && x < 687 + 345 && y >= 680 && y
< 680+ 160)
{
boucle =0;
}//quit
if (x >= 687 && x < 687 + 345 && y >= 330 && y
< 330+ 160)
{
BB.etat=2;
}//settings
if (x >= 687 && x < 687 + 345 && y >= 500 && y
< 500+ 160)
{
BB.etat=3;
}//credits
if (x >= 687 && x < 687 + 345 && y >= 160 && y
< 160+ 160)
{
BB.etat=4;
}//start
}
if(state==0 && BB.etat==4)
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
BB.etat=1;
}//menu back
if (x >= 400 && x < 400 + 345 && y >= 160 && y
< 160+ 160)
{
BB.etat=5;
}//newgame
if (x >= 950 && x < 950 + 345 && y >= 160 && y
< 160+ 160)
{
BB.etat=6;
}//loadgame
if (stage.etat == 0 && ((x >= 450 && x < 450 + 70
&& y >= 550 && y < 550 + 44) || (x >= 1200 && x < 1200 + 70 && y >= 550 && y
< 550 + 44)))
{
stage.etat = 1;
}else if (stage.etat == 1 && ((x >= 450 && x <
450 + 70 && y >= 550 && y < 550 + 44) || (x >= 1200 && x < 1200 + 70 && y >=
550 && y < 550 + 44)))
{
stage.etat = 2;
}
else if (stage.etat == 2 && ((x >= 450 && x < 450
+ 70 && y >= 550 && y < 550 + 44) || (x >= 1200 && x < 1200 + 70 && y >= 550
&& y < 550 + 44)))
{
stage.etat = 0;
}//change stage
}
else if(state==0 && BB.etat==5)
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
BB.etat=4;
}//menu back
if (x >= 400 && x < 400 + 345 && y >= 400 && y
< 400+ 160)
{
BB.etat=7;
}//singleplayer
if (x >= 950 && x < 950 + 345 && y >= 400 && y
< 400+ 160)
{
BB.etat=8;
}//multiplayer

}
if(state==0 && BB.etat==6)
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
BB.etat=4;
}//menu back

}
if(state==0 && BB.etat==7)
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
BB.etat=5;
}//menu back
if (chperso.etat == 0 && ((x >= 600 && x < 600 +
70 && y >= 400 && y < 400 + 44) || (x >= 1100 && x < 1100 + 70 && y >= 400
&& y < 400 + 44)))
{
chperso.etat = 1;
}
else if (chperso.etat == 1 && ((x >= 600 && x <
600 + 70 && y >= 400 && y < 400 + 44) || (x >= 1100 && x < 1100 + 70 && y >=
400 && y < 400 + 44)))
{
chperso.etat = 2;
}else if (chperso.etat == 2 && ((x >= 600 && x <
600 + 70 && y >= 400 && y < 400 + 44) || (x >= 1100 && x < 1100 + 70 && y >=
400 && y < 400 + 44)))
{
chperso.etat = 0;
}// choisir
if (x >= 1100 && x < 1100 + 345 && y >= 700 &&
y < 700+ 160)
{
state=1;
specifier=1;
}//play stage 1
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////

}
if(state==0 && BB.etat==8)
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
BB.etat=5;
}//menu back
if (chperso2.etat == 0 && ((x >= 300 && x < 300
+ 70 && y >= 400 && y < 400 + 44) || (x >= 600 && x < 600 + 70 && y >= 400
&& y < 400 + 44)))
{
chperso2.etat = 1;
}
else if (chperso2.etat == 1 && ((x >= 300 && x <
300 + 70 && y >= 400 && y < 400 + 44) || (x >= 600 && x < 600 + 70 && y >=
400 && y < 400 + 44)))
{
chperso2.etat = 2;
}else if (chperso2.etat == 2 && ((x >= 300 && x <
300 + 70 && y >= 400 && y < 400 + 44) || (x >= 600 && x < 600 + 70 && y >=
400 && y < 400 + 44)))
{
chperso2.etat = 0;
}// choisir first character

if (chperso3.etat == 0 && ((x >= 950 && x < 950


+ 70 && y >= 400 && y < 400 + 44) || (x >= 1250 && x < 1250 + 70 && y >= 400
&& y < 400 + 44)))
{
chperso3.etat = 1;
}
else if (chperso3.etat == 1 && ((x >= 950 && x <
950 + 70 && y >= 400 && y < 400 + 44) || (x >= 1250 && x < 1250 + 70 && y >=
400 && y < 400 + 44)))
{
chperso3.etat = 2;
}else if (chperso3.etat == 2 && ((x >= 950 && x <
950 + 70 && y >= 400 && y < 400 + 44) || (x >= 1250 && x < 1250 + 70 && y >=
400 && y < 400 + 44)))
{
chperso3.etat = 0;
}// choisir second character
if(event.motion.x >= 1100 && event.motion.x <
1100 + 345 && event.motion.y >= 700 && event.motion.y < 700+ 160)
{
state=2;
specifier=2;
}

}
if((state==0 && BB.etat==2) || (state==3))
{

if ((state==0 && BB.etat==2) && (x >= 50 && x <


50 + 151 && y >= 50 && y < 50+ 127))
{
BB.etat=1;
}//menu back
/////////////////////////////boutons moins 1
://////////////////////////////////
if(volume1.etat==0 && x >= 400 && x < 400 +
101 && y >= 220 && y < 220+ 101)
{
initialiser_audio2(music);
volume1.etat=1;

}else if(volume1.etat==1 && x >= 400 && x <


400 + 101 && y >= 220 && y < 220+ 101)
{
initialiser_audio3(music);
volume1.etat=2;

}else if(volume1.etat==2 && x >= 400 && x <


400 + 101 && y >= 220 && y < 220+ 101)
{
initialiser_audio4(music);
volume1.etat=3;

}else if(volume1.etat==3 && x >= 400 && x <


400 + 101 && y >= 220 && y < 220+ 101)
{
initialiser_audio5(music);
volume1.etat=4;
}
////////////////////////////boutons plus 1
:////////////////////////////////////
if(volume1.etat==4 && x >= 1170 && x < 1170 +
101 && y >= 220 && y < 220+ 101)
{
initialiser_audio5(music);
volume1.etat=3;

}else if(volume1.etat==3 && x >= 1170 && x <


1170 + 101 && y >= 220 && y < 220+ 101)
{
initialiser_audio4(music);
volume1.etat=2;
}else if(volume1.etat==2 && x >= 1170 && x <
1170 + 101 && y >= 220 && y < 220+ 101)
{
initialiser_audio3(music);
volume1.etat=1;

}else if(volume1.etat==1 && x >= 1170 && x <


1170 + 101 && y >= 220 && y < 220+ 101)
{
initialiser_audio2(music);
volume1.etat=0;

/////////////////////////////boutons moins 2
://////////////////////////////////
if(volume2.etat==0 && x >= 400 && x < 400 +
101 && y >= 400 && y < 400+ 101)
{
volume2.etat=1;

}else if(volume2.etat==1 && x >= 400 && x <


400 + 101 && y >= 400 && y < 400+ 101)
{
volume2.etat=2;

}else if(volume2.etat==2 && x >= 400 && x <


400 + 101 && y >= 400 && y < 400+ 101)
{
volume2.etat=3;

}else if(volume2.etat==3 && x >= 400 && x <


400 + 101 && y >= 400 && y < 400+ 101)
{
volume2.etat=4;
}
////////////////////////////boutons plus 2
:////////////////////////////////////
if(volume2.etat==4 && x >= 1170 && x < 1170 +
101 && y >= 400 && y < 400+ 101)
{
volume2.etat=3;

}else if(volume2.etat==3 && x >= 1170 && x <


1170 + 101 && y >= 400 && y < 400+ 101)
{
volume2.etat=2;

}else if(volume2.etat==2 && x >= 1170 && x <


1170 + 101 && y >= 400 && y < 400+ 101)
{
volume2.etat=1;

}else if(volume2.etat==1 && x >= 1170 && x <


1170 + 101 && y >= 400 && y < 400+ 101)
{
volume2.etat=0;

}
}
if(state==0 && BB.etat==3)/////////////////////////////
credits /////////////////////////////////
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
BB.etat=1;
}
}
if(state==1 || state== 2)/////////////////////////////
pause /////////////////////////////////
{
if (x >= 1550 && x < 1550 + 150 && y >= 10 && y
< 10+ 150)
{
state=3;
}
}
if(state==3)///////////////////////////// pause
/////////////////////////////////
{
if (x >= 50 && x < 50 + 151 && y >= 50 && y <
50+ 127)
{
if(specifier==1)
state=1;
if(specifier==2)
state=2;
}
if (x >= 500 && x < 500 + 345 && y >= 600 && y
< 600+ 160)
{
state=0;
}
}
}
break;
case SDL_KEYDOWN:
if ((state == 1 || state == 2) && event.key.keysym.sym
== SDLK_ESCAPE)
state =3;
if (event.key.keysym.sym == SDLK_u)
boucle =0;
if (event.key.keysym.sym == SDLK_p && BB.etat==1)
BB.etat=4;
if (event.key.keysym.sym == SDLK_ESCAPE &&
BB.etat==4 || BB.etat==2 || BB.etat==3 )
BB.etat=1;
if (event.key.keysym.sym == SDLK_s && BB.etat==1)
BB.etat=2;
if (event.key.keysym.sym == SDLK_c && BB.etat==1)
BB.etat=3;
if (event.key.keysym.sym == SDLK_RIGHT)
{
p.direction = 1;
p.vitesse = 2;

if (event.key.keysym.sym == SDLK_LEFT)
{
p.direction = -1;
p.vitesse = 2;

if (event.key.keysym.sym == SDLK_UP)
{
up = 1;
}

if (event.key.keysym.sym == SDLK_a) // la lettre a pour


accelerer
{
acceleration = 1;
p.vitesse = 5;
}

if (event.key.keysym.sym == SDLK_z) // la lettre z pour


decelerer
{
deceleration = 1;
p.vitesse = 1;
}
/////////////////////////////////////////////////// PERSO
2///////////////////////////////////////////////////
if (event.key.keysym.sym == SDLK_d)
{
p2.direction = 1;
p2.vitesse = 2;

if (event.key.keysym.sym == SDLK_q)
{
p2.direction = -1;
p2.vitesse = 2;

if (event.key.keysym.sym == SDLK_s)
{
up2 = 1;
}

if (event.key.keysym.sym == SDLK_w) // la lettre a


pour accelerer
{
acceleration2 = 1;
p2.vitesse = 5;
}

if (event.key.keysym.sym == SDLK_x) // la lettre z pour


decelerer
{
deceleration2 = 1;
p2.vitesse = 1;
}
/////////////////////////////////////////////////// PERSO
1///////////////////////////////////////////////////
if (event.key.keysym.sym == SDLK_RIGHT)
{
p1.direction = 1;
p1.vitesse = 2;

if (event.key.keysym.sym == SDLK_LEFT)
{
p1.direction = -1;
p1.vitesse = 2;

if (event.key.keysym.sym == SDLK_UP)
{
up1 = 1;
}

if (event.key.keysym.sym == SDLK_a) // la lettre a pour


accelerer
{
acceleration1 = 1;
p1.vitesse = 5;
}

if (event.key.keysym.sym == SDLK_z) // la lettre z pour


decelerer
{
deceleration1 = 1;
p1.vitesse = 1;
}
break;

case SDL_KEYUP:

if (event.key.keysym.sym == SDLK_RIGHT)
{
p.direction = 0;
p.vitesse = 0;
}
if (event.key.keysym.sym == SDLK_LEFT)
{
p.direction = 0;
p.vitesse = 0;
}

if (event.key.keysym.sym == SDLK_UP)
{
up = 0;
}

if (event.key.keysym.sym == SDLK_a)
{
acceleration = 0;
p.vitesse = 2;
}

if (event.key.keysym.sym == SDLK_z)
{
deceleration = 0;
p.vitesse = 2;
}
/////////////////////////////////////////////////// PERSO multijoueur
///////////////////////////////////////////////////

if (event.key.keysym.sym == SDLK_d)
{
p2.direction = 0;
p2.vitesse = 0;
}

if (event.key.keysym.sym == SDLK_q)
{
p2.direction = 0;
p2.vitesse = 0;
}

if (event.key.keysym.sym == SDLK_s)
{
up2 = 0;
}

if (event.key.keysym.sym == SDLK_w)
{
acceleration2 = 0;
p2.vitesse = 2;
}

if (event.key.keysym.sym == SDLK_x)
{
deceleration2 = 0;
p2.vitesse = 2;
}
/////////////////////////////////////////////////////

if (event.key.keysym.sym == SDLK_RIGHT)
{
p1.direction = 0;
p1.vitesse = 0;
}

if (event.key.keysym.sym == SDLK_LEFT)
{
p1.direction = 0;
p1.vitesse = 0;
}

if (event.key.keysym.sym == SDLK_UP)
{
up1 = 0;
}

if (event.key.keysym.sym == SDLK_a)
{
acceleration1 = 0;
p1.vitesse = 2;
}
if (event.key.keysym.sym == SDLK_z)
{
deceleration = 0;
p1.vitesse = 2;
}
break;
}
}

SDL_Flip(screen);
}

liberer_img(IMAGE);
liberer_img(back);
liberer_img(backtt);
liberer_img(bt1);
liberer_img(mb);
liberer_texte(txte);
liberer_texte(starttxt);
liberer_texte(settingstxt);
liberer_texte(creditstxt);
liberer_texte(quittxt);
liberer_texte(splayer);
liberer_texte(mplayer);
liberer_texte(ngame);
liberer_texte(lgame);
//liberer_texte(minitxt);
liberer_img(start);
liberer_img(settings);
liberer_img(credits);
liberer_img(quit);
liberer_img(volume1);
liberer_img(plus1);
liberer_img(moins1);
liberer_img(volume2);
liberer_img(plus2);
liberer_img(moins2);
liberer_img(sinplayer);
liberer_img(multiplayer);
liberer_img(btfull);
liberer_img(btwind);
liberer_img(quitterbt);
liberer_img(sauvbt);
liberer_img(mbcredits);
liberer_img(loadgame);
liberer_img(newgame);
liberer_img(stage);
liberer_img(chperso);
liberer_img(fleshe1);
liberer_img(fleshe2);
liberer_img(chperso2);
liberer_img(fleshe12);
liberer_img(fleshe22);
liberer_img(chperso3);
liberer_img(fleshe13);
liberer_img(fleshe23);
liberer_img(pausebt);
liberer_img(confi);
liberer_texte(ok);
liberer_texte(choisir);
liberer_texte(choisir2);
liberer_texte(choisir3);
liberer_musique(music);
Free_background(&b);
Free_perso(&p);
Free_perso(&p2);
Free_minimap(&m);
TTF_CloseFont(font);
SDL_FreeSurface(e.spritesheet);
SDL_Quit();
return 0;

}
Game Controller Code Explained
#include <Arduino.h>

// Pins for joystick axes


const int joyXPin = A0; // Define pin A0 for joystick X-axis
const int joyYPin = A1; // Define pin A1 for joystick Y-axis

// Pins for buttons


const int buttonPin1 = 2; // Define pin 2 for button 1
const int buttonPin2 = 3; // Define pin 3 for button 2
const int buttonPin3 = 4; // Define pin 4 for button 3
const int buttonPin4 = 5; // Define pin 5 for button 4

void setup() {
// Initialize serial communication
Serial.begin(9600); // Start serial communication at 9600 baud

// Set button pins as input with internal pull-up resistors


pinMode(buttonPin1, INPUT_PULLUP); // Set pin 2 as input with internal pull-
up resistor
pinMode(buttonPin2, INPUT_PULLUP); // Set pin 3 as input with internal pull-
up resistor
pinMode(buttonPin3, INPUT_PULLUP); // Set pin 4 as input with internal pull-
up resistor
pinMode(buttonPin4, INPUT_PULLUP); // Set pin 5 as input with internal pull-
up resistor
}

void loop() {
// Read joystick positions
int joyX = analogRead(joyXPin); // Read analog value from joystick X-axis
int joyY = analogRead(joyYPin); // Read analog value from joystick Y-axis

// Read button states


bool button1 = digitalRead(buttonPin1) == LOW; // Read state of button 1
bool button2 = digitalRead(buttonPin2) == LOW; // Read state of button 2
bool button3 = digitalRead(buttonPin3) == LOW; // Read state of button 3
bool button4 = digitalRead(buttonPin4) == LOW; // Read state of button 4

// Print messages based on joystick movements


if (joyX < 300) {
Serial.println("Joystick Moved Left"); // Print message if joystick moved
left
} else if (joyX > 600) {
Serial.println("Joystick Moved Right"); // Print message if joystick moved
right
}

if (joyY < 300) {


Serial.println("Joystick Moved Down"); // Print message if joystick moved
down
} else if (joyY > 600) {
Serial.println("Joystick Moved Up"); // Print message if joystick moved up
}

// Print messages when buttons are pressed


if (button1) {
Serial.println("Button 1 pressed - Move up"); // Print message if button 1
is pressed
}
if (button2) {
Serial.println("Button 2 pressed - Move right"); // Print message if
button 2 is pressed
}
if (button3) {
Serial.println("Button 3 pressed - Move Down"); // Print message if button
3 is pressed
}
if (button4) {
Serial.println("Button 4 pressed - Move left"); // Print message if button
4 is pressed
}

// Add a small delay to avoid flooding the serial output


delay(100); // Delay for 100 milliseconds
}

You might also like