소스 검색

v0.1

- Fonctional
- Random generation0
- show dead cell
- Spacebar to pause
- Escape to quit

To do :
- add cycles settings
- add merged sprites
coldiary 6 년 전
부모
커밋
7d3872ffbe

+ 54
- 9
Life.xcodeproj/project.pbxproj 파일 보기

@@ -7,27 +7,50 @@
7 7
 	objects = {
8 8
 
9 9
 /* Begin PBXBuildFile section */
10
+		6A364541194D85E60072C818 /* SDL2_image.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = 6AED72B1194AB2AB00C47B6F /* SDL2_image.framework */; };
11
+		6A364542194D86000072C818 /* SDL2.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = 6AED72AF194AB22800C47B6F /* SDL2.framework */; };
10 12
 		6AED72A7194AB16C00C47B6F /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AED72A6194AB16C00C47B6F /* main.c */; };
11
-		6AED72A9194AB16C00C47B6F /* Life.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 6AED72A8194AB16C00C47B6F /* Life.1 */; };
13
+		6AED72B0194AB22800C47B6F /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AED72AF194AB22800C47B6F /* SDL2.framework */; };
14
+		6AED72B2194AB2AB00C47B6F /* SDL2_image.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AED72B1194AB2AB00C47B6F /* SDL2_image.framework */; };
15
+		6AED72B8194AB9E700C47B6F /* sim.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AED72B7194AB9E700C47B6F /* sim.c */; };
16
+		6AED72BB194AE63600C47B6F /* menu.c in Sources */ = {isa = PBXBuildFile; fileRef = 6AED72BA194AE63600C47B6F /* menu.c */; };
12 17
 /* End PBXBuildFile section */
13 18
 
14 19
 /* Begin PBXCopyFilesBuildPhase section */
15
-		6AED72A1194AB16C00C47B6F /* CopyFiles */ = {
20
+		6A36454C194D87C60072C818 /* CopyFiles */ = {
16 21
 			isa = PBXCopyFilesBuildPhase;
17
-			buildActionMask = 2147483647;
18
-			dstPath = /usr/share/man/man1/;
19
-			dstSubfolderSpec = 0;
22
+			buildActionMask = 12;
23
+			dstPath = sprites;
24
+			dstSubfolderSpec = 7;
25
+			files = (
26
+			);
27
+			runOnlyForDeploymentPostprocessing = 0;
28
+		};
29
+		6AED72A1194AB16C00C47B6F /* Copy Files */ = {
30
+			isa = PBXCopyFilesBuildPhase;
31
+			buildActionMask = 8;
32
+			dstPath = "";
33
+			dstSubfolderSpec = 10;
20 34
 			files = (
21
-				6AED72A9194AB16C00C47B6F /* Life.1 in CopyFiles */,
35
+				6A364542194D86000072C818 /* SDL2.framework in Copy Files */,
36
+				6A364541194D85E60072C818 /* SDL2_image.framework in Copy Files */,
22 37
 			);
38
+			name = "Copy Files";
23 39
 			runOnlyForDeploymentPostprocessing = 1;
24 40
 		};
25 41
 /* End PBXCopyFilesBuildPhase section */
26 42
 
27 43
 /* Begin PBXFileReference section */
44
+		6A364557194D92340072C818 /* sprites */ = {isa = PBXFileReference; lastKnownFileType = folder; path = sprites; sourceTree = "<group>"; };
28 45
 		6AED72A3194AB16C00C47B6F /* Life */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Life; sourceTree = BUILT_PRODUCTS_DIR; };
29 46
 		6AED72A6194AB16C00C47B6F /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
30
-		6AED72A8194AB16C00C47B6F /* Life.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Life.1; sourceTree = "<group>"; };
47
+		6AED72AF194AB22800C47B6F /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = ../../../../Library/Frameworks/SDL2.framework; sourceTree = "<group>"; };
48
+		6AED72B1194AB2AB00C47B6F /* SDL2_image.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_image.framework; path = ../../../../Library/Frameworks/SDL2_image.framework; sourceTree = "<group>"; };
49
+		6AED72B4194AB36500C47B6F /* constante.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = constante.h; sourceTree = "<group>"; };
50
+		6AED72B7194AB9E700C47B6F /* sim.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sim.c; sourceTree = "<group>"; };
51
+		6AED72B9194AB9F600C47B6F /* sim.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sim.h; sourceTree = "<group>"; };
52
+		6AED72BA194AE63600C47B6F /* menu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = menu.c; sourceTree = "<group>"; };
53
+		6AED72C0194AF5BA00C47B6F /* menu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = menu.h; sourceTree = "<group>"; };
31 54
 /* End PBXFileReference section */
32 55
 
33 56
 /* Begin PBXFrameworksBuildPhase section */
@@ -35,6 +58,8 @@
35 58
 			isa = PBXFrameworksBuildPhase;
36 59
 			buildActionMask = 2147483647;
37 60
 			files = (
61
+				6AED72B2194AB2AB00C47B6F /* SDL2_image.framework in Frameworks */,
62
+				6AED72B0194AB22800C47B6F /* SDL2.framework in Frameworks */,
38 63
 			);
39 64
 			runOnlyForDeploymentPostprocessing = 0;
40 65
 		};
@@ -44,6 +69,8 @@
44 69
 		6AED729A194AB16B00C47B6F = {
45 70
 			isa = PBXGroup;
46 71
 			children = (
72
+				6AED72B1194AB2AB00C47B6F /* SDL2_image.framework */,
73
+				6AED72AF194AB22800C47B6F /* SDL2.framework */,
47 74
 				6AED72A5194AB16C00C47B6F /* Life */,
48 75
 				6AED72A4194AB16C00C47B6F /* Products */,
49 76
 			);
@@ -60,8 +87,13 @@
60 87
 		6AED72A5194AB16C00C47B6F /* Life */ = {
61 88
 			isa = PBXGroup;
62 89
 			children = (
90
+				6A364557194D92340072C818 /* sprites */,
91
+				6AED72B4194AB36500C47B6F /* constante.h */,
92
+				6AED72B7194AB9E700C47B6F /* sim.c */,
93
+				6AED72B9194AB9F600C47B6F /* sim.h */,
63 94
 				6AED72A6194AB16C00C47B6F /* main.c */,
64
-				6AED72A8194AB16C00C47B6F /* Life.1 */,
95
+				6AED72BA194AE63600C47B6F /* menu.c */,
96
+				6AED72C0194AF5BA00C47B6F /* menu.h */,
65 97
 			);
66 98
 			path = Life;
67 99
 			sourceTree = "<group>";
@@ -75,7 +107,8 @@
75 107
 			buildPhases = (
76 108
 				6AED729F194AB16C00C47B6F /* Sources */,
77 109
 				6AED72A0194AB16C00C47B6F /* Frameworks */,
78
-				6AED72A1194AB16C00C47B6F /* CopyFiles */,
110
+				6AED72A1194AB16C00C47B6F /* Copy Files */,
111
+				6A36454C194D87C60072C818 /* CopyFiles */,
79 112
 			);
80 113
 			buildRules = (
81 114
 			);
@@ -118,6 +151,8 @@
118 151
 			buildActionMask = 2147483647;
119 152
 			files = (
120 153
 				6AED72A7194AB16C00C47B6F /* main.c in Sources */,
154
+				6AED72B8194AB9E700C47B6F /* sim.c in Sources */,
155
+				6AED72BB194AE63600C47B6F /* menu.c in Sources */,
121 156
 			);
122 157
 			runOnlyForDeploymentPostprocessing = 0;
123 158
 		};
@@ -190,6 +225,7 @@
190 225
 				GCC_WARN_UNUSED_FUNCTION = YES;
191 226
 				GCC_WARN_UNUSED_VARIABLE = YES;
192 227
 				MACOSX_DEPLOYMENT_TARGET = 10.9;
228
+				ONLY_ACTIVE_ARCH = NO;
193 229
 				SDKROOT = macosx;
194 230
 			};
195 231
 			name = Release;
@@ -197,6 +233,10 @@
197 233
 		6AED72AD194AB16C00C47B6F /* Debug */ = {
198 234
 			isa = XCBuildConfiguration;
199 235
 			buildSettings = {
236
+				FRAMEWORK_SEARCH_PATHS = (
237
+					"$(inherited)",
238
+					"$(LOCAL_LIBRARY_DIR)/Frameworks",
239
+				);
200 240
 				PRODUCT_NAME = "$(TARGET_NAME)";
201 241
 			};
202 242
 			name = Debug;
@@ -204,6 +244,10 @@
204 244
 		6AED72AE194AB16C00C47B6F /* Release */ = {
205 245
 			isa = XCBuildConfiguration;
206 246
 			buildSettings = {
247
+				FRAMEWORK_SEARCH_PATHS = (
248
+					"$(inherited)",
249
+					"$(LOCAL_LIBRARY_DIR)/Frameworks",
250
+				);
207 251
 				PRODUCT_NAME = "$(TARGET_NAME)";
208 252
 			};
209 253
 			name = Release;
@@ -227,6 +271,7 @@
227 271
 				6AED72AE194AB16C00C47B6F /* Release */,
228 272
 			);
229 273
 			defaultConfigurationIsVisible = 0;
274
+			defaultConfigurationName = Release;
230 275
 		};
231 276
 /* End XCConfigurationList section */
232 277
 	};

+ 2
- 1
Life.xcodeproj/xcuserdata/Coldiary.xcuserdatad/xcschemes/Life.xcscheme 파일 보기

@@ -43,7 +43,8 @@
43 43
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
44 44
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
45 45
       launchStyle = "0"
46
-      useCustomWorkingDirectory = "NO"
46
+      useCustomWorkingDirectory = "YES"
47
+      customWorkingDirectory = "/Users/Coldiary/Projets Code/Life/Life"
47 48
       buildConfiguration = "Debug"
48 49
       ignoresPersistentStateOnLaunch = "NO"
49 50
       debugDocumentVersioning = "YES"

+ 0
- 79
Life/Life.1 파일 보기

@@ -1,79 +0,0 @@
1
-.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
2
-.\"See Also:
3
-.\"man mdoc.samples for a complete listing of options
4
-.\"man mdoc for the short list of editing options
5
-.\"/usr/share/misc/mdoc.template
6
-.Dd 2014-06-13               \" DATE 
7
-.Dt Life 1      \" Program name and manual section number 
8
-.Os Darwin
9
-.Sh NAME                 \" Section Header - required - don't modify 
10
-.Nm Life,
11
-.\" The following lines are read in generating the apropos(man -k) database. Use only key
12
-.\" words here as the database is built based on the words here and in the .ND line. 
13
-.Nm Other_name_for_same_program(),
14
-.Nm Yet another name for the same program.
15
-.\" Use .Nm macro to designate other names for the documented program.
16
-.Nd This line parsed for whatis database.
17
-.Sh SYNOPSIS             \" Section Header - required - don't modify
18
-.Nm
19
-.Op Fl abcd              \" [-abcd]
20
-.Op Fl a Ar path         \" [-a path] 
21
-.Op Ar file              \" [file]
22
-.Op Ar                   \" [file ...]
23
-.Ar arg0                 \" Underlined argument - use .Ar anywhere to underline
24
-arg2 ...                 \" Arguments
25
-.Sh DESCRIPTION          \" Section Header - required - don't modify
26
-Use the .Nm macro to refer to your program throughout the man page like such:
27
-.Nm
28
-Underlining is accomplished with the .Ar macro like this:
29
-.Ar underlined text .
30
-.Pp                      \" Inserts a space
31
-A list of items with descriptions:
32
-.Bl -tag -width -indent  \" Begins a tagged list 
33
-.It item a               \" Each item preceded by .It macro
34
-Description of item a
35
-.It item b
36
-Description of item b
37
-.El                      \" Ends the list
38
-.Pp
39
-A list of flags and their descriptions:
40
-.Bl -tag -width -indent  \" Differs from above in tag removed 
41
-.It Fl a                 \"-a flag as a list item
42
-Description of -a flag
43
-.It Fl b
44
-Description of -b flag
45
-.El                      \" Ends the list
46
-.Pp
47
-.\" .Sh ENVIRONMENT      \" May not be needed
48
-.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
49
-.\" .It Ev ENV_VAR_1
50
-.\" Description of ENV_VAR_1
51
-.\" .It Ev ENV_VAR_2
52
-.\" Description of ENV_VAR_2
53
-.\" .El                      
54
-.Sh FILES                \" File used or created by the topic of the man page
55
-.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
56
-.It Pa /usr/share/file_name
57
-FILE_1 description
58
-.It Pa /Users/joeuser/Library/really_long_file_name
59
-FILE_2 description
60
-.El                      \" Ends the list
61
-.\" .Sh DIAGNOSTICS       \" May not be needed
62
-.\" .Bl -diag
63
-.\" .It Diagnostic Tag
64
-.\" Diagnostic informtion here.
65
-.\" .It Diagnostic Tag
66
-.\" Diagnostic informtion here.
67
-.\" .El
68
-.Sh SEE ALSO 
69
-.\" List links in ascending order by section, alphabetically within a section.
70
-.\" Please do not reference files that do not exist without filing a bug report
71
-.Xr a 1 , 
72
-.Xr b 1 ,
73
-.Xr c 1 ,
74
-.Xr a 2 ,
75
-.Xr b 2 ,
76
-.Xr a 3 ,
77
-.Xr b 3 
78
-.\" .Sh BUGS              \" Document known, unremedied bugs 
79
-.\" .Sh HISTORY           \" Document history if command behaves in a unique manner

+ 26
- 0
Life/constante.h 파일 보기

@@ -0,0 +1,26 @@
1
+//
2
+//  constante.h
3
+//  Life
4
+//
5
+//  Created by Benoit Sida on 2014-06-13.
6
+//  Copyright (c) 2014 Benoit Sida. All rights reserved.
7
+//
8
+
9
+#ifndef Life_constante_h
10
+#define Life_constante_h
11
+
12
+#include <stdlib.h>
13
+#include <SDL2/SDL.h>
14
+#include <SDL2_image/SDL_image.h>
15
+
16
+#define TAILLE_BLOC 34
17
+#define NB_BLOCS 12
18
+#define LARGEUR_ECRAN TAILLE_BLOC*NB_BLOCS
19
+#define HAUTEUR_ECRAN TAILLE_BLOC*NB_BLOCS
20
+#define CYCLES 20
21
+#define WAIT 0
22
+#define MAXMAP (NB_BLOCS*NB_BLOCS)
23
+
24
+enum {HAUT, BAS, GAUCHE, DROITE};
25
+
26
+#endif

+ 31
- 4
Life/main.c 파일 보기

@@ -7,12 +7,39 @@
7 7
 //
8 8
 
9 9
 #include <stdio.h>
10
+#include "constante.h"
11
+#include "menu.h"
12
+#include "sim.h"
10 13
 
11 14
 int main(int argc, const char * argv[])
12 15
 {
13
-
14
-    // insert code here...
15
-    printf("Hello, World!\n");
16
-    return 0;
16
+    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
17
+        printf("Erreur lors de l'initialisation du module SDL. Erreur : %s", SDL_GetError());
18
+        exit(EXIT_FAILURE);
19
+    }
20
+    int choice = 0;
21
+    SDL_Window *ecran;
22
+    SDL_Surface *screen, *icon;
23
+    ecran = SDL_CreateWindow("LIFE", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, LARGEUR_ECRAN, HAUTEUR_ECRAN, SDL_WINDOW_SHOWN);
24
+    screen = SDL_GetWindowSurface(ecran);
25
+    icon = IMG_Load("sprites/icon.png");
26
+    SDL_SetWindowIcon(ecran, icon);
27
+    while (choice == 0) {
28
+        choice = menu(ecran, screen);
29
+        switch (choice) {
30
+            case 1:
31
+                sim(ecran, screen, CYCLES);
32
+                choice = 0;
33
+                break;
34
+            case 2:
35
+                exit(EXIT_SUCCESS);
36
+                break;
37
+            default :
38
+                choice = 0;
39
+                break;
40
+        }
41
+    }
42
+    SDL_Quit();
43
+    return EXIT_SUCCESS;
17 44
 }
18 45
 

+ 71
- 0
Life/menu.c 파일 보기

@@ -0,0 +1,71 @@
1
+//
2
+//  menu.c
3
+//  Life
4
+//
5
+//  Created by Benoit Sida on 2014-06-13.
6
+//  Copyright (c) 2014 Benoit Sida. All rights reserved.
7
+//
8
+
9
+#include <stdio.h>
10
+#include "constante.h"
11
+#include "menu.h"
12
+
13
+static void eventChoice(int* choice, int* running, int* current);
14
+
15
+int menu(SDL_Window *ecran, SDL_Surface *screen)
16
+{
17
+    int running = 1, choice = 0, current = 1;
18
+    SDL_Rect select, position, element1 = {4,7}, element2={5,9};
19
+    SDL_Surface *menu = NULL, *arrow = NULL, *wall = NULL;
20
+    menu = IMG_Load("sprites/menu.png");
21
+    arrow = IMG_Load("sprites/arrow.png");
22
+    wall = IMG_Load("sprites/wall.png");
23
+    while (running) {
24
+        position.x = position.y = 0;
25
+        SDL_BlitSurface(wall, NULL, screen, &position);
26
+        SDL_BlitSurface(menu, NULL, screen, &position); // Affiche le menu
27
+        (current == 1) ? (select.x = element1.x * TAILLE_BLOC) : (select.x = element2.x * TAILLE_BLOC);
28
+        (current == 1) ? (select.y = element1.y * TAILLE_BLOC) : (select.y = element2.y * TAILLE_BLOC);
29
+        SDL_BlitSurface(arrow, NULL, screen, &select);
30
+        SDL_UpdateWindowSurface(ecran);
31
+        eventChoice(&choice, &running, &current);
32
+    }
33
+    return choice;
34
+}
35
+
36
+static void eventChoice(int* choice, int* running, int* current)
37
+{
38
+    SDL_Event event;
39
+    SDL_WaitEvent(&event);
40
+    switch (event.type){
41
+        case SDL_QUIT:
42
+            exit(EXIT_SUCCESS);
43
+            break;
44
+        case SDL_KEYDOWN:
45
+            switch (event.key.keysym.sym) {
46
+                case SDLK_ESCAPE:
47
+                    exit(EXIT_SUCCESS);
48
+                    break;
49
+                case SDLK_1:
50
+                    *choice = 1;
51
+                    running = 0;
52
+                    break;
53
+                case SDLK_2:
54
+                    *choice = 2;
55
+                    running = 0;
56
+                    break;
57
+                case SDLK_UP:
58
+                    *current = 1;
59
+                    break;
60
+                case SDLK_DOWN:
61
+                    *current = 2;
62
+                    break;
63
+                case SDLK_RETURN:
64
+                    *running = 0;
65
+                    *choice = *current;
66
+                    break;
67
+                    
68
+            }
69
+            break;
70
+    }
71
+}

+ 14
- 0
Life/menu.h 파일 보기

@@ -0,0 +1,14 @@
1
+//
2
+//  menu.h
3
+//  Life
4
+//
5
+//  Created by Benoit Sida on 2014-06-13.
6
+//  Copyright (c) 2014 Benoit Sida. All rights reserved.
7
+//
8
+
9
+#ifndef Life_menu_h
10
+#define Life_menu_h
11
+
12
+int menu(SDL_Window *ecran, SDL_Surface *screen);
13
+
14
+#endif

+ 151
- 0
Life/sim.c 파일 보기

@@ -0,0 +1,151 @@
1
+//
2
+//  sim.c
3
+//  Life
4
+//
5
+//  Created by Benoit Sida on 2014-06-13.
6
+//  Copyright (c) 2014 Benoit Sida. All rights reserved.
7
+//
8
+
9
+#include <stdio.h>
10
+#include "constante.h"
11
+#include "sim.h"
12
+
13
+static void randmap(Cell map[]);
14
+static void drawmap(SDL_Surface *screen, Cell map[]);
15
+static void eventWatch();
16
+static void next(Cell map[]);
17
+static void drawCell(SDL_Surface *screen, SDL_Rect position, Cell Cell);
18
+//static void blitSprite(int orig, SDL_Surface *screen, SDL_Rect position);
19
+
20
+void sim(SDL_Window *ecran, SDL_Surface *screen, int cycles)
21
+{
22
+    Cell map[MAXMAP];
23
+    randmap(map);
24
+    int remaining = cycles;
25
+    while (remaining != 0){
26
+        drawmap(screen, map);
27
+        SDL_UpdateWindowSurface(ecran);
28
+        eventWatch(&remaining);
29
+        SDL_Delay(WAIT);
30
+        next(map);
31
+        remaining--;
32
+    }
33
+}
34
+
35
+static void randmap(Cell map[])
36
+{
37
+    for (int i = 0 ; i < MAXMAP ; i++)
38
+    {
39
+        map[i].x = i%NB_BLOCS;
40
+        map[i].y = i/NB_BLOCS;
41
+        map[i].type = rand()%2;
42
+        map[i].voisines = 0;
43
+    }
44
+}
45
+
46
+static void drawmap(SDL_Surface *screen, Cell map[])
47
+{
48
+    SDL_Rect position;
49
+    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
50
+    for (int i = 0 ; i < MAXMAP ; i++)
51
+    {
52
+            position.x = map[i].x * TAILLE_BLOC;
53
+            position.y = map[i].y * TAILLE_BLOC;
54
+            drawCell(screen, position, map[i]);
55
+    }
56
+}
57
+
58
+static void eventWatch()
59
+{
60
+    SDL_Event event;
61
+    int pause = 0;
62
+    SDL_PollEvent(&event);
63
+    switch(event.type)
64
+    {
65
+        case SDL_QUIT:
66
+            exit(EXIT_SUCCESS);
67
+            break;
68
+        case SDL_KEYDOWN:
69
+            switch(event.key.keysym.sym)
70
+        {
71
+            case SDLK_ESCAPE:
72
+                exit(EXIT_SUCCESS);
73
+                break;
74
+            case SDLK_SPACE:
75
+                pause = 1;
76
+                while (pause) {
77
+                    SDL_WaitEvent(&event);
78
+                    switch(event.type)
79
+                    {
80
+                        case SDL_KEYDOWN:
81
+                            switch(event.key.keysym.sym)
82
+                        {
83
+                                case SDLK_SPACE:
84
+                                    pause = 0;
85
+                                    break;
86
+                        }
87
+                    }
88
+                }
89
+                break;
90
+        }
91
+        break;
92
+    }
93
+}
94
+
95
+static void next(Cell map[])
96
+{
97
+    for (int i = 0 ; i < MAXMAP ; i++)
98
+    {
99
+        map[i].voisines = 0;
100
+        map[i].voisines = i%NB_BLOCS == 0 ? map[i].voisines : (map[i-1].type == 1 ? ++map[i].voisines : map[i].voisines);
101
+        map[i].voisines = i%(NB_BLOCS) == 11 ? map[i].voisines : (map[i+1].type == 1 ? ++map[i].voisines : map[i].voisines);
102
+        map[i].voisines = i-NB_BLOCS < 0 ? map[i].voisines : (map[i-NB_BLOCS].type == 1 ? ++map[i].voisines : map[i].voisines);
103
+        map[i].voisines = i+NB_BLOCS > MAXMAP ? map[i].voisines : (map[i+NB_BLOCS].type == 1 ? ++map[i].voisines : map[i].voisines);
104
+    }
105
+    
106
+    for (int i = 0 ; i < MAXMAP ; i++)
107
+    {
108
+        map[i].type = map[i].type == 1 ? (map[i].voisines == 2 || map[i].voisines == 3 ? 1 : 2) : (map[i].voisines == 3 ? 1 : 0);
109
+    }
110
+}
111
+
112
+static void drawCell(SDL_Surface *screen, SDL_Rect position, Cell Cell)
113
+{
114
+    SDL_Surface *cell = NULL, *deadcell = NULL, *alivecell = NULL;
115
+    cell = IMG_Load("sprites/cell.png");
116
+    alivecell = IMG_Load("sprites/alivecell.png");
117
+    deadcell = IMG_Load("sprites/deadcell.png");
118
+    
119
+    if (Cell.type == 0)
120
+        SDL_BlitSurface(cell, NULL, screen, &position);
121
+    else if (Cell.type == 2)
122
+        SDL_BlitSurface(deadcell, NULL, screen, &position);
123
+    else {
124
+        SDL_BlitSurface(alivecell, NULL, screen, &position);
125
+    }
126
+}
127
+
128
+/*static void blitSprite(int orig, SDL_Surface *screen, SDL_Rect position)
129
+{
130
+    SDL_Surface *cellsheet;
131
+    cellsheet = IMG_Load("sprites/cellsheet.png");
132
+    
133
+    SDL_Rect clip[9];
134
+    clip[0].x = clip[0].y = 0;
135
+    clip[1].x = 34;clip[1].y = 0;
136
+    clip[2].x = 68;clip[2].y = 0;
137
+    clip[3].x = 0;clip[3].y = 34;
138
+    clip[4].x = clip[4].y = 34;
139
+    clip[5].x = 68;clip[5].y = 34;
140
+    clip[6].x = 0;clip[6].y = 68;
141
+    clip[7].x = 34;clip[7].y = 68;
142
+    clip[8].x = clip[8].y = 68;
143
+    for (int i = 0; i > 9; i++)
144
+        clip[i].h = clip[i].w = 34;
145
+    
146
+    SDL_BlitSurface(cellsheet, &clip[orig], screen, &position);
147
+}
148
+
149
+static void switchType(Cell map[])
150
+{
151
+}*/

+ 25
- 0
Life/sim.h 파일 보기

@@ -0,0 +1,25 @@
1
+//
2
+//  sim.h
3
+//  Life
4
+//
5
+//  Created by Benoit Sida on 2014-06-13.
6
+//  Copyright (c) 2014 Benoit Sida. All rights reserved.
7
+//
8
+
9
+#ifndef Life_sim_h
10
+#define Life_sim_h
11
+
12
+void sim(SDL_Window *ecran, SDL_Surface *screen, int cycles);
13
+
14
+enum {CELL, ALIVE, DEAD};
15
+
16
+typedef struct Cell Cell;
17
+struct Cell
18
+{
19
+    int x;
20
+    int y;
21
+    int type;
22
+    int voisines;
23
+};
24
+
25
+#endif

BIN
Life/sprites/alivecell.png 파일 보기


BIN
Life/sprites/arrow.png 파일 보기


BIN
Life/sprites/cell.png 파일 보기


BIN
Life/sprites/cellsheet.png 파일 보기


BIN
Life/sprites/deadcell.png 파일 보기


BIN
Life/sprites/downcell.png 파일 보기


BIN
Life/sprites/icon.png 파일 보기


BIN
Life/sprites/leftcell.png 파일 보기


BIN
Life/sprites/lowerleftcell.png 파일 보기


BIN
Life/sprites/lowerrightcell.png 파일 보기


BIN
Life/sprites/menu.png 파일 보기


BIN
Life/sprites/plaincell.png 파일 보기


BIN
Life/sprites/rightcell.png 파일 보기


BIN
Life/sprites/upcell.png 파일 보기


BIN
Life/sprites/upperleftcell.png 파일 보기


BIN
Life/sprites/upperrightcell.png 파일 보기


BIN
Life/sprites/wall.png 파일 보기