Skip to content

Commit

Permalink
new struct for ghosts, deleted some file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostia Kotliarov committed Aug 30, 2017
1 parent 98f28d6 commit 552bdcc
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 478 deletions.
8 changes: 4 additions & 4 deletions drawMap.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ void drawMap(t_pacman *pacman)
SDL_RenderCopy(pacman->sdl.renderer, pacman->pacTexture, NULL, &(pacman->pacRect));
}
else if (map[y][x] == 5) //red ghost
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->ghostRedTexture : pacman->ghostEatTexture, NULL, &(pacman->ghostRedRect));
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->red.ghostTexture : pacman->ghostEatTexture, NULL, &(pacman->red.ghostRect));
else if (map[y][x] == 6) //blue ghost
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->ghostBlueTexture : pacman->ghostEatTexture, NULL, &(pacman->ghostBlueRect));
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->blue.ghostTexture : pacman->ghostEatTexture, NULL, &(pacman->blue.ghostRect));
else if (map[y][x] == 7) //pink ghost
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->ghostPinkTexture : pacman->ghostEatTexture, NULL, &(pacman->ghostPinkRect));
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->pink.ghostTexture : pacman->ghostEatTexture, NULL, &(pacman->pink.ghostRect));
else if (map[y][x] == 8) //yellow ghost
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->ghostYellowTexture : pacman->ghostEatTexture, NULL, &(pacman->ghostYellowRect));
SDL_RenderCopy(pacman->sdl.renderer, (pacman->eat == 0) ? pacman->yellow.ghostTexture : pacman->ghostEatTexture, NULL, &(pacman->yellow.ghostRect));
rect.x += 30;
rect = (SDL_Rect) {rect.x, rect.y, rect.h, rect.w};
}
Expand Down
8 changes: 4 additions & 4 deletions intro.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ void intro(t_pacman *pacman, int *introOff)
while(i < 7)
{
rect.x += 30;
SDL_RenderCopy(pacman->sdl.renderer, pacman->ghostYellowTexture, NULL, &(rect));
SDL_RenderCopy(pacman->sdl.renderer, pacman->yellow.ghostTexture, NULL, &(rect));
rect.x += 30;
SDL_RenderCopy(pacman->sdl.renderer, pacman->ghostPinkTexture, NULL, &(rect));
SDL_RenderCopy(pacman->sdl.renderer, pacman->pink.ghostTexture, NULL, &(rect));
rect.x += 30;
SDL_RenderCopy(pacman->sdl.renderer, pacman->ghostBlueTexture, NULL, &(rect));
SDL_RenderCopy(pacman->sdl.renderer, pacman->blue.ghostTexture, NULL, &(rect));
rect.x += 30;
SDL_RenderCopy(pacman->sdl.renderer, pacman->ghostRedTexture , NULL, &(rect));
SDL_RenderCopy(pacman->sdl.renderer, pacman->red.ghostTexture , NULL, &(rect));
rect.x += 60;
pacman->pacTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->pacImageRight);
if (i % 2)
Expand Down
56 changes: 31 additions & 25 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ int map[22][19] = {
void setDefaultPosition(t_pacman *pacman)
{
pacman->pac = (t_pos){17, 20};
pacman->ghostRed = (t_pos){6, 8};
pacman->ghostYellow = (t_pos){10, 10};
pacman->ghostBlue = (t_pos){1, 4};
pacman->ghostPink = (t_pos){16, 4};
pacman->red.ghostPos = (t_pos){6, 8};
pacman->yellow.ghostPos = (t_pos){10, 10};
pacman->blue.ghostPos = (t_pos){1, 4};
pacman->pink.ghostPos = (t_pos){16, 4};
}

static void initDefault(t_pacman *pacman, int *stop)
Expand All @@ -47,10 +47,15 @@ static void initDefault(t_pacman *pacman, int *stop)
setDefaultPosition(pacman);
pacman->pacmanLives = 3;

pacman->ghostRedMapPreviousValue = 0;
pacman->ghostBlueMapPreviousValue = 1;
pacman->ghostPinkMapPreviousValue = 1;
pacman->ghostYellowMapPreviousValue = 0;
pacman->red.ghostMapPreviousValue = 0;
pacman->blue.ghostMapPreviousValue = 1;
pacman->pink.ghostMapPreviousValue = 1;
pacman->yellow.ghostMapPreviousValue = 0;

pacman->red.id = 5;
pacman->blue.id = 6;
pacman->pink.id = 7;
pacman->yellow.id = 8;

pacman->pacImage = IMG_Load("image/pacman.png");
pacman->pacImageUp = IMG_Load("image/pacmanUp.png");
Expand All @@ -59,17 +64,17 @@ static void initDefault(t_pacman *pacman, int *stop)
pacman->pacImageRight = IMG_Load("image/pacmanRight.png");
pacman->pacTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->pacImageLeft);

pacman->ghostRedImage = IMG_Load("image/red.png");
pacman->ghostRedTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->ghostRedImage);
pacman->red.ghostImage = IMG_Load("image/red.png");
pacman->red.ghostTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->red.ghostImage);

pacman->ghostBlueImage = IMG_Load("image/blue.png");
pacman->ghostBlueTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->ghostBlueImage);
pacman->blue.ghostImage = IMG_Load("image/blue.png");
pacman->blue.ghostTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->blue.ghostImage);

pacman->ghostYellowImage = IMG_Load("image/yellow.png");
pacman->ghostYellowTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->ghostYellowImage);
pacman->yellow.ghostImage = IMG_Load("image/yellow.png");
pacman->yellow.ghostTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->yellow.ghostImage);

pacman->ghostPinkImage = IMG_Load("image/pink.png");
pacman->ghostPinkTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->ghostPinkImage);
pacman->pink.ghostImage = IMG_Load("image/pink.png");
pacman->pink.ghostTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->pink.ghostImage);

pacman->ghostEatImage = IMG_Load("image/ghost.png");
pacman->ghostEatTexture = SDL_CreateTextureFromSurface(pacman->sdl.renderer, pacman->ghostEatImage);
Expand Down Expand Up @@ -121,16 +126,17 @@ int main(void)
drawMap(pacman);
if (ghostOffset % 2)
{
putGhostRed(pacman);
putGhostYellow(pacman);
ghostOffset = 0;
}
else
{
putGhostBlue(pacman);
putGhostPink(pacman);
ghostOffset = 1;
putGhostRed(pacman, &pacman->red);
putGhostRed(pacman, &pacman->yellow);
// ghostOffset = 0;
// }
// else
// {
putGhostRed(pacman, &pacman->blue);
putGhostRed(pacman, &pacman->pink);

}
ghostOffset++;
SDL_RenderPresent(pacman->sdl.renderer);
SDL_Delay(250);
}
Expand Down
44 changes: 16 additions & 28 deletions pacman.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ typedef struct s_pos
int y;
} t_pos;

typedef struct s_ghost
{
t_pos ghostPos;
t_pos ghostMove;
SDL_Surface *ghostImage;
SDL_Texture *ghostTexture;
SDL_Rect ghostRect;
int ghostMapPreviousValue;
int id;
} t_ghost;

typedef struct s_pacman
{
t_sdl sdl;
Expand All @@ -45,33 +56,10 @@ typedef struct s_pacman
SDL_Rect pacRect;
int pacmanLives;

t_pos ghostRed;
t_pos ghostRedMove;
SDL_Surface *ghostRedImage;
SDL_Texture *ghostRedTexture;
SDL_Rect ghostRedRect;
int ghostRedMapPreviousValue;

t_pos ghostBlue;
t_pos ghostBlueMove;
SDL_Surface *ghostBlueImage;
SDL_Texture *ghostBlueTexture;
SDL_Rect ghostBlueRect;
int ghostBlueMapPreviousValue;

t_pos ghostYellow;
t_pos ghostYellowMove;
SDL_Surface *ghostYellowImage;
SDL_Texture *ghostYellowTexture;
SDL_Rect ghostYellowRect;
int ghostYellowMapPreviousValue;

t_pos ghostPink;
t_pos ghostPinkMove;
SDL_Surface *ghostPinkImage;
SDL_Texture *ghostPinkTexture;
SDL_Rect ghostPinkRect;
int ghostPinkMapPreviousValue;
t_ghost red;
t_ghost blue;
t_ghost pink;
t_ghost yellow;


SDL_Surface *buttonImage;
Expand All @@ -98,7 +86,7 @@ void drawMap(t_pacman *pacman);
void putPacman(t_pacman *pacman);
void putScore(t_pacman *pacman);
void setLivesLevel(t_pacman *pacman);
void putGhostRed(t_pacman *pacman);
void putGhostRed(t_pacman *pacman, t_ghost *red);
void putGhostBlue(t_pacman *pacman);
void putGhostYellow(t_pacman *pacman);
void putGhostPink(t_pacman *pacman);
Expand Down
12 changes: 0 additions & 12 deletions pacman.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
8A5D12C31F51F2FA001CEFD3 /* putText.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A5D12C21F51F2FA001CEFD3 /* putText.c */; };
8A5D12C51F52A5A2001CEFD3 /* putPinkGhost.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A5D12C41F52A5A2001CEFD3 /* putPinkGhost.c */; };
D26026211F51612C00D5000A /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = D26026201F51612C00D5000A /* main.c */; };
D26026271F51615D00D5000A /* initSdl.c in Sources */ = {isa = PBXBuildFile; fileRef = D26026251F51615D00D5000A /* initSdl.c */; };
D26026291F51644E00D5000A /* drawMap.c in Sources */ = {isa = PBXBuildFile; fileRef = D26026281F51644E00D5000A /* drawMap.c */; };
Expand All @@ -17,8 +16,6 @@
D26517E51F5404CB00F302C2 /* SDL2_ttf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A5D12C01F51F0DC001CEFD3 /* SDL2_ttf.framework */; };
D26517E61F5404CB00F302C2 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D26026231F51614E00D5000A /* SDL2.framework */; };
D26517EA1F540F3900F302C2 /* putRedGhost.c in Sources */ = {isa = PBXBuildFile; fileRef = D26517E91F540F3900F302C2 /* putRedGhost.c */; };
D26517EC1F540F6100F302C2 /* putYellowGhost.c in Sources */ = {isa = PBXBuildFile; fileRef = D26517EB1F540F6100F302C2 /* putYellowGhost.c */; };
D26517EE1F54109900F302C2 /* putBlueGhost.c in Sources */ = {isa = PBXBuildFile; fileRef = D26517ED1F54109900F302C2 /* putBlueGhost.c */; };
D26517F21F542A1000F302C2 /* intro.c in Sources */ = {isa = PBXBuildFile; fileRef = D26517F11F542A0F00F302C2 /* intro.c */; };
/* End PBXBuildFile section */

Expand All @@ -37,7 +34,6 @@
/* Begin PBXFileReference section */
8A5D12C01F51F0DC001CEFD3 /* SDL2_ttf.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SDL2_ttf.framework; sourceTree = "<group>"; };
8A5D12C21F51F2FA001CEFD3 /* putText.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = putText.c; sourceTree = "<group>"; };
8A5D12C41F52A5A2001CEFD3 /* putPinkGhost.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = putPinkGhost.c; sourceTree = "<group>"; };
8A5D12C61F52BE17001CEFD3 /* SDL2_image.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SDL2_image.framework; sourceTree = "<group>"; };
D26026161F5160DF00D5000A /* pacman */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = pacman; sourceTree = BUILT_PRODUCTS_DIR; };
D26026201F51612C00D5000A /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
Expand All @@ -47,8 +43,6 @@
D26026281F51644E00D5000A /* drawMap.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = drawMap.c; sourceTree = "<group>"; };
D260262A1F51B0CB00D5000A /* putPacman.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = putPacman.c; sourceTree = "<group>"; };
D26517E91F540F3900F302C2 /* putRedGhost.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = putRedGhost.c; sourceTree = "<group>"; };
D26517EB1F540F6100F302C2 /* putYellowGhost.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = putYellowGhost.c; sourceTree = "<group>"; };
D26517ED1F54109900F302C2 /* putBlueGhost.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = putBlueGhost.c; sourceTree = "<group>"; };
D26517F11F542A0F00F302C2 /* intro.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = intro.c; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -73,12 +67,9 @@
D26026251F51615D00D5000A /* initSdl.c */,
D26517F11F542A0F00F302C2 /* intro.c */,
D26026201F51612C00D5000A /* main.c */,
D26517ED1F54109900F302C2 /* putBlueGhost.c */,
D260262A1F51B0CB00D5000A /* putPacman.c */,
8A5D12C41F52A5A2001CEFD3 /* putPinkGhost.c */,
D26517E91F540F3900F302C2 /* putRedGhost.c */,
8A5D12C21F51F2FA001CEFD3 /* putText.c */,
D26517EB1F540F6100F302C2 /* putYellowGhost.c */,
D26026261F51615D00D5000A /* pacman.h */,
D26026221F51614E00D5000A /* Frameworks */,
D26026171F5160DF00D5000A /* Products */,
Expand Down Expand Up @@ -160,13 +151,10 @@
buildActionMask = 2147483647;
files = (
D26026211F51612C00D5000A /* main.c in Sources */,
8A5D12C51F52A5A2001CEFD3 /* putPinkGhost.c in Sources */,
D260262B1F51B0CB00D5000A /* putPacman.c in Sources */,
D26517EE1F54109900F302C2 /* putBlueGhost.c in Sources */,
D26517F21F542A1000F302C2 /* intro.c in Sources */,
D26026271F51615D00D5000A /* initSdl.c in Sources */,
8A5D12C31F51F2FA001CEFD3 /* putText.c in Sources */,
D26517EC1F540F6100F302C2 /* putYellowGhost.c in Sources */,
D26026291F51644E00D5000A /* drawMap.c in Sources */,
D26517EA1F540F3900F302C2 /* putRedGhost.c in Sources */,
);
Expand Down
Binary file not shown.
116 changes: 0 additions & 116 deletions putBlueGhost.c

This file was deleted.

Loading

0 comments on commit 552bdcc

Please sign in to comment.