Skip to content
Snippets Groups Projects
Commit 445cebbd authored by antoinemeyer5's avatar antoinemeyer5
Browse files

Merge branch 'player' into main

parents 32149716 78048149
Branches
No related tags found
No related merge requests found
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
......
File added
......@@ -8,8 +8,5 @@ int main(){
running = 1;
gameState = MENU;
readMapFromFile("map.txt");
initPlayer();
mainLoop();
}
\ No newline at end of file
......@@ -2,42 +2,126 @@
player_t player;
void initPlayer(){
player.x = 0;
player.x = 18*32;
player.y = 0;
player.w = CELLSIZE*0.8;
player.h = CELLSIZE*0.8;
player.waterLevel = 0;
player.speed = 1;
player.isMoving = 0;
}
int giveCaseBelowPosition(int x, int y){
int x2 = x/CELLSIZE;
int y2 = y/CELLSIZE;
return map[y2][x2];
}
int collisionsLeftPlayer(){
int collision = 0;
int dotTopLeft = giveCaseBelowPosition(player.x, player.y);
int dotDownLeft = giveCaseBelowPosition(player.x, player.y+player.h);
//collision window
if(player.x <= 0){
collision = 1;
}
//collision tree
if(dotTopLeft==1 || dotDownLeft==1){
collision = 1;
}
return collision;
}
int collisionsRightPlayer(){
int collision = 0;
int dotTopRight = giveCaseBelowPosition(player.x+player.w, player.y);
int dotDownRight = giveCaseBelowPosition(player.x+player.w, player.y+player.h);
//collision window
if(player.x + player.w >= MAPSIZE * CELLSIZE){
collision = 1;
}
//collision tree
if(dotTopRight==1 || dotDownRight==1){
collision = 1;
}
return collision;
}
int collisionsUpPlayer(){
int collision = 0;
int dotTopRight = giveCaseBelowPosition(player.x+player.w, player.y);
int dotTopLeft = giveCaseBelowPosition(player.x, player.y);
//collision window
if(player.y <= 0){
collision = 1;
}
//collision tree
if(dotTopRight==1 || dotTopLeft==1){
collision = 1;
}
return collision;
}
int collisionsDownPlayer(){
int collision = 0;
int dotDownRight = giveCaseBelowPosition(player.x+player.w, player.y+player.h);
int dotDownLeft = giveCaseBelowPosition(player.x, player.y+player.h);
//collision window
if(player.y + player.h >= MAPSIZE * CELLSIZE){
collision = 1;
}
//collision tree
if(dotDownRight==1 || dotDownLeft==1){
collision = 1;
}
return collision;
}
void moveRightPlayer(){
if(!collisionsRightPlayer()){
player.x = player.x + player.speed;
}
}
void moveLeftPlayer(){
if(!collisionsLeftPlayer()){
player.x = player.x - player.speed;
}
}
void moveUpPlayer(){
if(!collisionsUpPlayer()){
player.y = player.y - player.speed;
}
}
void moveDownPlayer(){
if(!collisionsDownPlayer()){
player.y = player.y + player.speed;
}
}
void manageMovement(){
if(keys[PLAYER_UP]){
moveUpPlayer();
player.isMoving = 1;
}
if(keys[PLAYER_DOWN] == 1){
if(keys[PLAYER_DOWN]){
moveDownPlayer();
player.isMoving = 1;
}
if(keys[PLAYER_LEFT] == 1){
if(keys[PLAYER_LEFT]){
moveLeftPlayer();
player.isMoving = 1;
}
if(keys[PLAYER_RIGHT] == 1){
if(keys[PLAYER_RIGHT]){
moveRightPlayer();
player.isMoving = 1;
}
player.isMoving = 0;
}
int selectStateHover(){
......
......@@ -12,8 +12,11 @@
typedef struct player{
int x;
int y;
int w;
int h;
int waterLevel;
int speed;
int isMoving;
} player_t;
extern player_t player;
......
......@@ -143,6 +143,7 @@ void drawGame(){
void mainLoop(){
createWindow();
initPlayer();
grassSurface = IMG_Load("Res/grass.png");
grassTexture = SDL_CreateTextureFromSurface(renderer, grassSurface);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment