Browse Source

first commit

master
0x3F 1 year ago
commit
89e912bdad
26 changed files with 1142 additions and 0 deletions
  1. BIN
      Cool Text Demo(needs files)
  2. 16
    0
      Makefile
  3. BIN
      PolyGONE
  4. 5
    0
      README.md
  5. 76
    0
      boxengine.c
  6. 18
    0
      boxengine.h
  7. BIN
      game/font.png
  8. BIN
      game/font1.png
  9. 161
    0
      game/intro.c
  10. 3
    0
      game/intro.h
  11. 9
    0
      game/oldpolygone/player.c
  12. 0
    0
      game/oldpolygone/player.h
  13. 116
    0
      game/oldpolygone/polygone.c
  14. 4
    0
      game/oldpolygone/polygone.h
  15. 5
    0
      game/player.c
  16. 0
    0
      game/player.h
  17. 180
    0
      game/polygone.c
  18. 2
    0
      game/polygone.h
  19. 0
    0
      physics.c
  20. 0
    0
      physics.h
  21. 99
    0
      render.c
  22. 17
    0
      render.h
  23. 50
    0
      sprite.c
  24. 6
    0
      sprite.h
  25. 348
    0
      ui.c
  26. 27
    0
      ui.h

BIN
Cool Text Demo(needs files) View File


+ 16
- 0
Makefile View File

@@ -0,0 +1,16 @@
1
+#OBJS specifies which files to compile as part of the project
2
+OBJS = boxengine.c game/polygone.c render.c ui.c sprite.c game/intro.c physics.c
3
+
4
+#OBJ_NAME specifies the name of our exectuable
5
+OBJ_NAME = PolyGONE
6
+
7
+#This is the target that compiles our executable
8
+all : $(OBJS)
9
+	gcc $(OBJS) -w  -g -lSDL2 -lSDL2_image -lm -o $(OBJ_NAME)
10
+	
11
+	
12
+#g++ 01_hello_SDL.cpp -I{add correct path here}/include/SDL2 -L{add correct path here}/lib -lmingw32 -lSDL2main -lSDL2
13
+	
14
+	
15
+	
16
+	

BIN
PolyGONE View File


+ 5
- 0
README.md View File

@@ -0,0 +1,5 @@
1
+# Box Engine
2
+My first ever game engine that I made back in 2015 or 2016
3
+
4
+## Screenshots:
5
+![alt text](https://ssul.vertesine.com/1522320590120.png)

+ 76
- 0
boxengine.c View File

@@ -0,0 +1,76 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+#include <SDL2/SDL.h>
4
+#include <SDL2/SDL_image.h>
5
+#include "boxengine.h"
6
+#include "render.h"
7
+#include "ui.h"
8
+#include "sprite.h"
9
+
10
+
11
+/*Ideas
12
+
13
+make each module be: spritehandler(working on), renderer(check), audio, data, inputoutput(work with keyboard and custm file format, 
14
+such as loadtexture(), or loadmap(), or loadfont(), etcfiles), networking, UI functinality and rendering(check, well eh...). UI rendered last for always on top
15
+
16
+//when I figure out the algorithms for this all, I will make it all render to a texture for color and efect manipulation. The custom file format needs to be done first.
17
+
18
+Utility next: Tile based editor.
19
+
20
+
21
+
22
+
23
+
24
+
25
+*/
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+int setup(char *title, int width, int height, int dimension, int method, int framing){
36
+	//sets up plain old SDL
37
+	int status = 0;
38
+	
39
+	window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
40
+	screenwidth = width;
41
+	screenheight = height;
42
+	printf("Title: %s\n", title);
43
+	if(method == HARDWARE){
44
+		renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
45
+	} else{
46
+		renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
47
+	}
48
+	//iffy code for setting up continuing modules. Correct this with error handling later
49
+	
50
+	
51
+	
52
+	
53
+	setuprender(window, renderer);
54
+	
55
+	setupui(window, renderer);
56
+	
57
+	
58
+	
59
+	return status;
60
+}
61
+
62
+int destroy(){
63
+	int status = 0;
64
+	
65
+	//iffy code for destroying modules
66
+	
67
+	destroyrender();
68
+	destroyui();
69
+	
70
+	SDL_DestroyWindow(window);
71
+	SDL_DestroyRenderer(renderer);
72
+	SDL_Quit();
73
+	
74
+	
75
+	return status;
76
+}

+ 18
- 0
boxengine.h View File

@@ -0,0 +1,18 @@
1
+SDL_Window* window;
2
+SDL_Renderer* renderer;
3
+SDL_Event event;
4
+
5
+int screenwidth;
6
+int screenheight;
7
+
8
+typedef enum rendermethod{
9
+	RENDER2D,
10
+	RENDER3D,
11
+	HARDWARE,
12
+	SOFTWARE,
13
+	FULLSCREEN,
14
+	WINDOWED
15
+};
16
+
17
+int setup(char *title, int width, int height, int dimension, int method, int framing);
18
+int destroy();

BIN
game/font.png View File


BIN
game/font1.png View File


+ 161
- 0
game/intro.c View File

@@ -0,0 +1,161 @@
1
+#include <stdio.h>
2
+#include <SDL2/SDL.h>
3
+#include "intro.h"
4
+#include "../boxengine.h"
5
+
6
+int* stateptr = NULL;
7
+int end = 0;
8
+int timescalled = 0;
9
+int brightness = 0;
10
+
11
+void ievents(int* ptr){
12
+	stateptr = ptr;
13
+	//------------------------------------------------------------------------
14
+	
15
+	
16
+	
17
+	
18
+	
19
+	
20
+	
21
+	
22
+	
23
+	
24
+	
25
+	//------------------------------------------------------------------------
26
+	if(end == 1){
27
+		*stateptr = 1;
28
+		printf("Left Intro sequence\n");
29
+	}
30
+}
31
+
32
+void ilogic(){
33
+	//static int timescalled = 0; I'm only leaving this in here to prove that you can have this work, and it will increment suprisingly.
34
+	
35
+	//--------------------------------------------------------------------------
36
+	static int positionx = 0;
37
+	if(timescalled == 0){
38
+		positionx = screenwidth;
39
+		
40
+	}
41
+	
42
+	if(timescalled < 300){
43
+		brightness++;
44
+		if(brightness > 255){
45
+			brightness = 255;
46
+		}
47
+	}
48
+	
49
+	if(timescalled < 500){
50
+		positionx--;
51
+		
52
+	}
53
+	
54
+	
55
+	
56
+	printf("\n\nTIMES CALLED & BRIGHTNESS: %d %d \n\n", timescalled, brightness);
57
+	
58
+	drawstring("Box Engine", positionx , screenheight / 2 - screenheight / 9, 30, 3);
59
+	
60
+	
61
+	
62
+	
63
+	
64
+	
65
+	
66
+	if(timescalled > 550 && timescalled < 1500){
67
+		static int bouncefactor = -20;
68
+		static int hit = 0;
69
+		int size = 100;
70
+		int offset = 30;
71
+		static int vely = 0;
72
+		static int x = -200;
73
+		static int y = -500;
74
+		int gravity = 1;
75
+		SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
76
+		
77
+		printf("\n\n\n\n\n\n\n\n\n\nbounce: %d vely: %d y: %d\n\n\n\n\n\n\n\n\n\n", bouncefactor, vely, y);
78
+		
79
+		if(y <= 0){
80
+			hit = 0;
81
+			y+=vely;
82
+			vely+=gravity;
83
+			if(y > 0){
84
+				y = 0;
85
+				hit = 1;
86
+			}
87
+			//drawstring("FALLING", 0 , 0, 30, 3);
88
+		}
89
+		if(hit == 1){
90
+			//drawstring("HIT", 0 , 0, 30, 3);
91
+			//vely = 0;
92
+			vely = bouncefactor;
93
+			bouncefactor += 2;
94
+			if(bouncefactor > 0){
95
+				bouncefactor = 0;
96
+			}
97
+			//bouncefactor 
98
+			
99
+			
100
+		}
101
+		
102
+		
103
+		
104
+		//SDL_RenderDrawLine(renderer, screenwidth / 2 - 100, screenheight / 2 - 100, screenwidth / 2 + 100, screenheight / 2 + 100);
105
+		//cube
106
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 - size + y, screenwidth / 2 - size + x, screenheight / 2 + size + y);//left side front
107
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 - size + y, screenwidth / 2 + size + x, screenheight / 2 - size + y);//top side front
108
+		SDL_RenderDrawLine(renderer, screenwidth / 2 + size + x, screenheight / 2 - size + y, screenwidth / 2 + size + x, screenheight / 2 + size + y);//right side front
109
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 + size + y, screenwidth / 2 + size + x, screenheight / 2 + size + y);//bottom side front
110
+		
111
+		
112
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 - size + y, screenwidth / 2 - size - 30 + x, screenheight / 2 - size - offset + y);//left top corner front to back
113
+		SDL_RenderDrawLine(renderer, screenwidth / 2 + size + x, screenheight / 2 - size + y, screenwidth / 2 + size - 30 + x, screenheight / 2 - size - offset + y);//right top corner front to back
114
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 + size + y, screenwidth / 2 - size - 30 + x, screenheight / 2 + size - offset + y);//left bottom corner front to back
115
+		SDL_RenderDrawLine(renderer, screenwidth / 2 + size + x, screenheight / 2 + size + y, screenwidth / 2 + size - 30 + x, screenheight / 2 + size - offset + y);//right bottom corner front to back
116
+		
117
+		
118
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size - offset + x, screenheight / 2 - size - offset + y, screenwidth / 2 - size - offset + x, screenheight / 2 + size - offset + y);//left side back
119
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size - offset + x, screenheight / 2 - size - offset + y, screenwidth / 2 + size - offset + x, screenheight / 2 - size - offset + y);//top side back
120
+		SDL_RenderDrawLine(renderer, screenwidth / 2 + size - offset + x, screenheight / 2 - size - offset + y, screenwidth / 2 + size - offset + x, screenheight / 2 + size - offset + y);//right side back
121
+		SDL_RenderDrawLine(renderer, screenwidth / 2 - size - offset + x, screenheight / 2 + size - offset + y, screenwidth / 2 + size - offset + x, screenheight / 2 + size - offset + y);//bottom side back
122
+		
123
+	}
124
+	
125
+	
126
+	
127
+	
128
+	
129
+	
130
+	
131
+	
132
+	
133
+	
134
+	
135
+	if(timescalled > 1200){
136
+		brightness--;
137
+		if(brightness < 0){
138
+			brightness = 0;
139
+		}
140
+	}
141
+	
142
+	
143
+	if(timescalled == 1500){
144
+		
145
+		end = 1;
146
+		
147
+	}
148
+	
149
+	SDL_SetRenderDrawColor(renderer, brightness, brightness, brightness, brightness);
150
+	
151
+	//-------------------------------------------------------------------------
152
+	//SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
153
+	timescalled++;
154
+}
155
+
156
+void irender(){
157
+	
158
+	pushscreen();
159
+	SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
160
+	
161
+}

+ 3
- 0
game/intro.h View File

@@ -0,0 +1,3 @@
1
+void ievents(int* ptr);
2
+void ilogic();
3
+void irender();

+ 9
- 0
game/oldpolygone/player.c View File

@@ -0,0 +1,9 @@
1
+#include <stdio.h>
2
+#include <SDL2/SDL.h>
3
+
4
+int main(int argc, char* args[]){
5
+	
6
+	
7
+	
8
+	return 0;
9
+}

+ 0
- 0
game/oldpolygone/player.h View File


+ 116
- 0
game/oldpolygone/polygone.c View File

@@ -0,0 +1,116 @@
1
+#include <stdio.h>
2
+#include <SDL2/SDL.h>
3
+#include <math.h>
4
+#include "../boxengine.h"
5
+#include "polygone.h"
6
+
7
+
8
+float x, y, *x_ptr = &x, *y_ptr = &y;
9
+int true = 0;
10
+float i = 0.0f;
11
+//THIS FILE IS AT THE TOP OF THE EXECUTION FILE
12
+//THE TEXT IS 5x5
13
+//TEST LATER IF YOU CH+AN USE FILES INCLUDED FROM OTHER FILES. COULD BE USEFUL
14
+
15
+
16
+
17
+int main(int argc, char* args[]){
18
+	if(setup("PolyGONE", 800, 600, RENDER2D, HARDWARE, WINDOWED) == 0){//tests success, and sets up everything
19
+		printf("Successful start.\n");
20
+	} else{
21
+		printf("Error starting.\n");
22
+		return 1;
23
+	}
24
+	setupfont("game/font1.png", 12, 40);
25
+	//beginning
26
+	
27
+	
28
+	gameloop();
29
+	
30
+	
31
+	
32
+	//end
33
+	if(destroy() == 0){//tests success
34
+		printf("Successful close.\n");
35
+	} else{
36
+		printf("Error closing. Memmory may not have been cleaned up.\n");
37
+		return 1;
38
+	}
39
+	return 0;
40
+}
41
+
42
+void gameloop(){
43
+	printf("Entered game loop\n");
44
+	
45
+	
46
+	
47
+	SDL_SetRenderDrawColor(renderer, 20, 200, 58, 20);
48
+	
49
+	SDL_PollEvent(&event);
50
+	while((event.type != SDL_QUIT)){ //(event.type != SDL_QUIT)
51
+		//printf("ok");
52
+		SDL_PollEvent(&event);
53
+		
54
+		dostupidthing();
55
+		
56
+		
57
+		pushscreen();
58
+		SDL_Delay(17);
59
+	}
60
+	
61
+	
62
+	
63
+	
64
+	
65
+}
66
+void dostupidthing(){
67
+	
68
+	SDL_SetRenderDrawColor(renderer, 10, 240, 158, 40);
69
+	
70
+	drawopeningscene();
71
+	//printf("got to herell");
72
+	SDL_RenderDrawLine(renderer, 100 + (int)x, 100 + (int)y, (800/2) + (int)x, (600/2 + 100) + (int)y + (int)x);
73
+	drawstring("TEST", (800/2) + (int)x, (600/2 + 100) + (int)y + (int)x, 20, 3 + (int)x);
74
+	drawstring("neat stuff", 100 + (int)x, 100 + (int)y, 50, 3);
75
+	drawstring("wow!", 570 + (int)x, 160 + (int)y, 50, 3);
76
+	//printf("\n\n\n------------DONE------------\n\n\n");
77
+	
78
+	if(true){
79
+		drawstring("FAST", 100 + (int)x, 200 + (int)y, (int)x, 3);
80
+		true--;
81
+	} else {
82
+		drawstring("TEXT!", 100 + (int)x, 200 + (int)y, (int)y, 3);
83
+		true++;
84
+	}
85
+	
86
+	i+= 0.1f;
87
+	SDL_SetRenderDrawColor(renderer, 20, 200, 58, 20);
88
+	
89
+	
90
+	rotate(x_ptr, y_ptr);
91
+	
92
+	
93
+}
94
+void rotate(float* c, float* d){
95
+	/*
96
+	float angle = 0.0;
97
+	float anglestepsize = 0.008;
98
+	
99
+	while (angle < 2 * 3.14159265){
100
+		int x1 = x + width * cos(angle);
101
+		int y1 = y + height * sin(angle);
102
+		
103
+		angle += anglestepsize;
104
+		
105
+		
106
+	}
107
+	*/
108
+	
109
+	static float angle = 0.0;
110
+	float anglestepsize = 0.008;
111
+	
112
+	*c = 100 * cos(angle);
113
+	*d = 100 * sin(angle);
114
+	angle += anglestepsize;
115
+	
116
+}

+ 4
- 0
game/oldpolygone/polygone.h View File

@@ -0,0 +1,4 @@
1
+int main(int argc, char* args[]);
2
+void gameloop();
3
+void dostupidthing();
4
+void rotate(float* c, float* d);

+ 5
- 0
game/player.c View File

@@ -0,0 +1,5 @@
1
+#include <stdio.h>
2
+#include <SDL2/SDL.h>
3
+#include "player.h"
4
+
5
+

+ 0
- 0
game/player.h View File


+ 180
- 0
game/polygone.c View File

@@ -0,0 +1,180 @@
1
+#include <stdio.h>
2
+#include <SDL2/SDL.h>
3
+#include <math.h>
4
+#include "../boxengine.h"
5
+#include "polygone.h"
6
+#include "intro.h"
7
+//#include "title.h"
8
+
9
+//Oh crap, just rememberred. You need global variables for things like player position, and player inventory stuff, so it transferres from one state to the next. Also,
10
+//when paused, I dont know if it will remember the positions of the entities and the progress. I guess static variables everywhere.
11
+//TODO: make animation states and movement states
12
+//TODO: scenedata. Like, make it be a place in memory that contains all of the scene variables, and make a decoder file for it to extract details.
13
+
14
+
15
+
16
+
17
+int main(int argc, char* args[]){
18
+	if(setup("PolyGONE", 800, 600, RENDER2D, HARDWARE, WINDOWED) == 0){//tests success, and sets up everything
19
+		printf("Successful start.\n");
20
+	} else{
21
+		printf("Error starting.\n");
22
+		return 1;
23
+	}
24
+	setupfont("game/font1.png", 12, 40);
25
+	//beginning
26
+	
27
+	
28
+	gameloop();
29
+	
30
+	
31
+	
32
+	//end
33
+	if(destroy() == 0){//tests success
34
+		printf("Successful close.\n");
35
+	} else{
36
+		printf("Error closing. Memmory may not have been cleaned up.\n");
37
+		return 1;
38
+	}
39
+	return 0;
40
+}
41
+
42
+void gameloop(){
43
+	
44
+	enum States{
45
+		INTRO,
46
+		TITLE,
47
+		PAUSED,
48
+		LEVEL1,
49
+		LEVEL2,
50
+		LEVEL3,
51
+		ENDCREDITS//can be accessed by the "credits" button in the pause/title screen
52
+	} state;
53
+	state = INTRO;
54
+	int copystate;//YOU NEED TO MAKE SURE AN ENUM CAN EQUAL AN INT
55
+	int* stateptr = &copystate;
56
+	*stateptr = state;
57
+	
58
+	printf("Entered game loop\n");
59
+	SDL_PollEvent(&event);
60
+	while((event.type != SDL_QUIT)){ //(event.type != SDL_QUIT)
61
+		SDL_PollEvent(&event);
62
+		state = *stateptr;// send this to all enum using functions to increment between, or jump to.
63
+		printf("STATE: %d\n", state);
64
+		//-------------------------------------------------------------------------------------------------------------
65
+		switch(state){ //do the events
66
+			case INTRO:
67
+			ievents(stateptr);//pass the enum to it in the form of a pointer so it can increment it after it is done.
68
+			break;
69
+			
70
+			case TITLE:
71
+			//tevents();
72
+			break;
73
+			
74
+			case PAUSED:
75
+			//pevents();
76
+			break;
77
+			
78
+			case LEVEL1:
79
+			//l1events();
80
+			break;
81
+			
82
+			case LEVEL2:
83
+			//l2events();
84
+			break;
85
+			
86
+			case LEVEL3:
87
+			//l3events();
88
+			break;
89
+			
90
+			case ENDCREDITS:
91
+			//eevents();
92
+			break;
93
+			
94
+			default:
95
+			printf("Error in gamestate state in the events\n");
96
+			break;
97
+		}
98
+		switch(state){ //do the logic
99
+			case INTRO:
100
+			ilogic();
101
+			break;
102
+			
103
+			case TITLE:
104
+			//tlogic();
105
+			break;
106
+			
107
+			case PAUSED:
108
+			//plogic();
109
+			break;
110
+			
111
+			case LEVEL1:
112
+			//l1logic();
113
+			break;
114
+			
115
+			case LEVEL2:
116
+			//l2logic();
117
+			break;
118
+			
119
+			case LEVEL3:
120
+			//l3logic();
121
+			break;
122
+			
123
+			case ENDCREDITS:
124
+			//elogic();
125
+			break;
126
+			
127
+			default:
128
+			printf("Error in gamestate state in the logic\n");
129
+			break;
130
+		}
131
+		switch(state){ //do the rendering
132
+			case INTRO:
133
+			irender();
134
+			break;
135
+			
136
+			case TITLE:
137
+			//trender();
138
+			break;
139
+			
140
+			case PAUSED:
141
+			//prender();
142
+			break;
143
+			
144
+			case LEVEL1:
145
+			//l1render();
146
+			break;
147
+			
148
+			case LEVEL2:
149
+			//l2render();
150
+			break;
151
+			
152
+			case LEVEL3:
153
+			//l3render();
154
+			break;
155
+			
156
+			case ENDCREDITS:
157
+			//erender();
158
+			break;
159
+			
160
+			default:
161
+			printf("Error in gamestate state in the renderer\n");
162
+			break;
163
+		}
164
+		//do timing
165
+		
166
+		
167
+		
168
+
169
+		
170
+		//-------------------------------------------------------------------------------------------------------------
171
+		
172
+		SDL_Delay(17);
173
+	}
174
+	
175
+	
176
+	
177
+	
178
+	
179
+}
180
+

+ 2
- 0
game/polygone.h View File

@@ -0,0 +1,2 @@
1
+int main(int argc, char* args[]);
2
+void gameloop();

+ 0
- 0
physics.c View File


+ 0
- 0
physics.h View File


+ 99
- 0
render.c View File

@@ -0,0 +1,99 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+#include <SDL2/SDL.h>
4
+#include <SDL2/SDL_image.h>
5
+#include "render.h"
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+void setuprender(SDL_Window* win, SDL_Renderer* ren){
14
+	printf("Set up renderer.\n");
15
+	window = win;//THESE TWO ARE CORRECT. THE RENDERER AND WINDOW EQUAL THE ABBREVIATED VERSIONS
16
+	renderer = ren;
17
+	//IMG_Init(IMG_INIT_PNG);
18
+	
19
+	
20
+}
21
+
22
+void destroyrender(){
23
+	printf("Destroyed renderer.\n");
24
+	SDL_FreeSurface(loadingsurface);
25
+	SDL_DestroyTexture(loadingtexture);
26
+	
27
+}
28
+
29
+
30
+//void drawsprite(int xpos, int ypos, int width, int height, float rotation, int midpointx, int midpointy){
31
+	
32
+	
33
+	
34
+	
35
+	//SDL_RenderCopyEx(renderer, grass, NULL, &startup_rect);
36
+//}
37
+
38
+void drawbackground(){
39
+	
40
+	
41
+	
42
+	
43
+	
44
+}
45
+void drawdebug(){
46
+	
47
+	
48
+	
49
+	
50
+	
51
+}
52
+void drawopeningscene(){
53
+	static float iii = 0.0f;
54
+	static int finalend = 0;
55
+	if(finalend == 1024){
56
+		return;
57
+	}
58
+	static int reverse = 0;
59
+	//SDL_RenderClear(renderer);
60
+	//SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
61
+	//SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
62
+	int i;
63
+	int ii;
64
+	for(i = 0; i < 255; i++){
65
+		//printf("draw: %d", i);
66
+		for(ii = 0; ii < 255; ii++){
67
+			SDL_RenderDrawPoint(renderer, iii + i, iii + ii);
68
+			SDL_SetRenderDrawColor(renderer, 10, 56, 255, 255);
69
+			//SDL_RenderDrawLine(renderer, 0, 0, iii + i, iii);
70
+			SDL_SetRenderDrawColor(renderer, 100, 0, 55, 255);
71
+			//SDL_RenderDrawLine(renderer, 0, 0, iii, iii + ii);
72
+			SDL_SetRenderDrawColor(renderer, 120, iii, ii, 255);
73
+			//printf("kookokokok.");
74
+			
75
+		}
76
+		SDL_SetRenderDrawColor(renderer, 20, 200, 58, 20);//set all to 0 for black refresh
77
+	}
78
+	
79
+	//SDL_RenderPresent(renderer);
80
+	if(iii == 255){
81
+		reverse = 1;
82
+	}
83
+	if(iii == 0){
84
+		reverse = 0;
85
+	}
86
+	if(reverse == 0){
87
+		iii+= 0.5f;
88
+	} else {
89
+		iii-= 0.5f;
90
+	}
91
+	//printf("%f\n", iii);
92
+	finalend++;
93
+}
94
+
95
+void pushscreen(){
96
+	SDL_RenderPresent(renderer);
97
+	
98
+	SDL_RenderClear(renderer);
99
+}

+ 17
- 0
render.h View File

@@ -0,0 +1,17 @@
1
+SDL_Window* window;
2
+SDL_Renderer* renderer;
3
+SDL_Surface* loadingsurface;
4
+SDL_Texture* loadingtexture;
5
+
6
+
7
+void setuprender(SDL_Window* win, SDL_Renderer* ren);
8
+
9
+void destroyrender();
10
+
11
+
12
+//void drawsprite(int xpos, int ypos, int width, int height, float rotation, int midpointx, int midpointy);
13
+
14
+void drawbackground();
15
+void drawdebug();
16
+void drawopeningscene();
17
+void pushscreen();

+ 50
- 0
sprite.c View File

@@ -0,0 +1,50 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+#include <SDL2/SDL.h>
4
+#include <SDL2/SDL_image.h>
5
+#include "sprite.h"
6
+
7
+//WORK ON SPRITE HANDLER AND MAP HANDLER TOMORROW
8
+//TODO: work on physics file with collision and gravity. Let it calculate angles too, and *draw* debug angles n such with lines
9
+//TODO: make sprites dynamic? malloc. Scenegraph?
10
+int maxs;
11
+
12
+typedef struct Sprite{
13
+	int priority;
14
+	int type;
15
+	float angle;
16
+	float velx;
17
+	float vely;
18
+	float x;
19
+	float y;
20
+	SDL_Texture* spritesheet;
21
+	int currentframe;
22
+};
23
+
24
+void setupspritehandler(SDL_Renderer* ren, int maxsprites){
25
+	renderer = ren;
26
+	maxs = maxsprites;
27
+	
28
+}
29
+
30
+void destroyspritehandler(){
31
+	int i;
32
+	for(i = 0; i <= maxs; i++){//for deleting sprite textures;
33
+		//SDL_DestroyTexture(
34
+		
35
+	}
36
+	
37
+	
38
+	
39
+	SDL_DestroyTexture(texture);
40
+	printf("The double free error is just for the occasion where something isn't freed the first time. It is an acceptable error.\n");
41
+	SDL_DestroyRenderer(renderer);
42
+}
43
+void addsprite(){
44
+	
45
+	
46
+	
47
+	
48
+}
49
+
50
+//void drawsprite(int x, int y){

+ 6
- 0
sprite.h View File

@@ -0,0 +1,6 @@
1
+SDL_Renderer* renderer;
2
+SDL_Texture* texture;
3
+
4
+void setupspritehandler(SDL_Renderer* ren, int maxsprites);
5
+void destroyspritehandler();
6
+void addsprite();

+ 348
- 0
ui.c View File

@@ -0,0 +1,348 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+#include <SDL2/SDL.h>
4
+#include <SDL2/SDL_image.h>
5
+#include "ui.h"
6
+
7
+int rows, columns, lengthpix, heightpix;
8
+int *rowptr = &rows, *columnptr = &columns;
9
+
10
+void setupui(SDL_Window* win, SDL_Renderer* ren){
11
+	printf("Set up UI handler.\n");
12
+	window = win;//THESE TWO ARE CORRECT. THE RENDERER AND WINDOW EQUAL THE ABBREVIATED VERSIONS
13
+	renderer = ren;
14
+	IMG_Init(IMG_INIT_PNG);
15
+	flippy = SDL_FLIP_NONE;
16
+	
17
+	
18
+}
19
+
20
+void destroyui(){
21
+	printf("Destroyed UI handler.\n");
22
+	SDL_FreeSurface(loadingsurface);
23
+	SDL_DestroyTexture(loadingtexture);
24
+	
25
+}
26
+
27
+void drawstring(char *message, int posx, int posy, int scale, int spacing){//scale, if in pixels and square, is what the value is.
28
+	
29
+	int i;
30
+	int len = (strlen(message) - 1);
31
+	int currow = 0;
32
+	int curcolumn = 0;
33
+	int value;
34
+	
35
+	//both of the rects below will be updated in a loop. THis just starts them out.
36
+	//the internal selector rect
37
+	letter.x = 0;
38
+	letter.y = 0;
39
+	letter.w = lengthpix / rows;//rows = 12
40
+	letter.h = heightpix / columns;//colums = 40
41
+	
42
+	//the representation of the internal selector
43
+	letterfinal.x = posx;
44
+	letterfinal.y = posy;
45
+	letterfinal.w = scale;
46
+	letterfinal.h = scale;
47
+	
48
+	
49
+	for(i = 0; i <= len; i++){
50
+		//printf("\n%c\n:", message[i]);
51
+		currow = 0;
52
+		curcolumn = 0;
53
+		value = 0;
54
+		//get the ascii value and convert it to a value from the font sheet
55
+		switch (message[i]){
56
+			case 'A':
57
+			value = 0;
58
+			break;
59
+			case 'B':
60
+			value = 1;
61
+			break;
62
+			case 'C':
63
+			value = 2;
64
+			break;
65
+			case 'D':
66
+			value = 3;
67
+			break;
68
+			case 'E':
69
+			value = 4;
70
+			break;
71
+			case 'F':
72
+			value = 5;
73
+			break;
74
+			case 'G':
75
+			value = 6;
76
+			break;
77
+			case 'H':
78
+			value = 7;
79
+			break;
80
+			case 'I':
81
+			value = 8;
82
+			break;
83
+			case 'J':
84
+			value = 9;
85
+			break;
86
+			case 'K':
87
+			value = 10;
88
+			break;
89
+			case 'L':
90
+			value = 11;
91
+			break;
92
+			case 'M':
93
+			value = 12;
94
+			break;
95
+			case 'N':
96
+			value = 13;
97
+			break;
98
+			case 'O':
99
+			value = 14;
100
+			break;
101
+			case 'P':
102
+			value = 15;
103
+			break;
104
+			case 'Q':
105
+			value = 16;
106
+			break;
107
+			case 'R':
108
+			value = 17;
109
+			break;
110
+			case 'S':
111
+			value = 18;
112
+			break;
113
+			case 'T':
114
+			value = 19;
115
+			break;
116
+			case 'U':
117
+			value = 20;
118
+			break;
119
+			case 'V':
120
+			value = 21;
121
+			break;
122
+			case 'W':
123
+			value = 22;
124
+			break;
125
+			case 'X':
126
+			value = 23;
127
+			break;
128
+			case 'Y':
129
+			value = 24;
130
+			break;
131
+			case 'Z':
132
+			value = 25;
133
+			break;
134
+			case ' ':
135
+			value = 26;
136
+			break;
137
+			
138
+			case 'a':
139
+			value = 27;
140
+			break;
141
+			case 'b':
142
+			value = 28;
143
+			break;
144
+			case 'c':
145
+			value = 29;
146
+			break;
147
+			case 'd':
148
+			value = 30;
149
+			break;
150
+			case 'e':
151
+			value = 31;
152
+			break;
153
+			case 'f':
154
+			value = 32;
155
+			break;
156
+			case 'g':
157
+			value = 33;
158
+			break;
159
+			case 'h':
160
+			value = 34;
161
+			break;
162
+			case 'i':
163
+			value = 35;
164
+			break;
165
+			case 'j':
166
+			value = 36;
167
+			break;
168
+			case 'k':
169
+			value = 37;
170
+			break;
171
+			case 'l':
172
+			value = 38;
173
+			break;
174
+			case 'm':
175
+			value = 39;
176
+			break;
177
+			case 'n':
178
+			value = 40;
179
+			break;
180
+			case 'o':
181
+			value = 41;
182
+			break;
183
+			case 'p':
184
+			value = 42;
185
+			break;
186
+			case 'q':
187
+			value = 43;
188
+			break;
189
+			case 'r':
190
+			value = 44;
191
+			break;
192
+			case 's':
193
+			value = 45;
194
+			break;
195
+			case 't':
196
+			value = 46;
197
+			break;
198
+			case 'u':
199
+			value = 47;
200
+			break;
201
+			case 'v':
202
+			value = 48;
203
+			break;
204
+			case 'w':
205
+			value = 49;
206
+			break;
207
+			case 'x':
208
+			value = 50;
209
+			break;
210
+			case 'y':
211
+			value = 51;
212
+			break;
213
+			case 'z':
214
+			value = 52;
215
+			break;
216
+			case '1':
217
+			value = 53;
218
+			break;
219
+			case '2':
220
+			value = 54;
221
+			break;
222
+			case '3':
223
+			value = 55;
224
+			break;
225
+			case '4':
226
+			value = 56;
227
+			break;
228
+			case '5':
229
+			value = 57;
230
+			break;
231
+			case '6':
232
+			value = 58;
233
+			break;
234
+			case '7':
235
+			value = 59;
236
+			break;
237
+			case '8':
238
+			value = 60;
239
+			break;
240
+			case '9':
241
+			value = 61;
242
+			break;
243
+			case '0':
244
+			value = 62;
245
+			break;
246
+			case '.':
247
+			value = 63;
248
+			break;
249
+			case ',':
250
+			value = 64;
251
+			break;
252
+			case '!':
253
+			value = 65;
254
+			break;
255
+			case 0x3F:
256
+			value = 66;
257
+			break;
258
+		}
259
+		
260
+		
261
+		
262
+		//end of switch statement
263
+		//THE LAST THING YOU WERE WORKING ON GOT A FLOATING POINT EXCEPTION, YOU DIVIDED BY ZERO SOMEWHERE :/
264
+		
265
+		//highly unstable, written at night, needs to betested tomorrow, reading loop?:
266
+		//REMEMBER, ALL OF THIS IS ALREADY IN A LOOP
267
+		//printf("\n\n\n this is rows before: %d. \n\n\n", rows);
268
+		
269
+		
270
+		
271
+		//int colcount;
272
+		//int rowcount;
273
+		int num = 0;
274
+		
275
+		
276
+		
277
+		for(curcolumn = 0; curcolumn <= columns; curcolumn++){
278
+		
279
+		//printf(" COLUMN: %d.", colcount);
280
+		
281
+			for(currow = 0; currow <= rows; currow++, num++){
282
+			
283
+			//printf(" ROW: %d.", currow);
284
+				
285
+				if(num == value){
286
+				//printf("broken in row");
287
+					break;
288
+					
289
+				}
290
+				
291
+				//num++;
292
+				//currow++;
293
+				
294
+			}
295
+			if(num == value){
296
+				//printf("broken in column");
297
+					break;
298
+					
299
+				}
300
+			
301
+			//curcolumn++;
302
+		}
303
+		
304
+		
305
+		
306
+		
307
+		letter.x = 5 * currow;
308
+		letter.y = 5 * curcolumn;
309
+		
310
+		//printf(".ROW: %d, COLUMN: %d.", currow, curcolumn);
311
+		//letter.w = lengthpix / rows;//rows = 12
312
+		//letter.h = heightpix / columns;//colums = 40
313
+		
314
+		
315
+			
316
+		SDL_RenderCopyEx(renderer, fonttexture, &letter, &letterfinal, 0.0f, NULL, flippy);
317
+		//END OF LOOP
318
+		
319
+		//the representation of the internal selector
320
+		letterfinal.x += spacing * (scale /2);//USE THIS ONLY
321
+		//letterfinal.y = posy + 0;
322
+		//letterfinal.w += (scale + 3);
323
+		//letterfinal.h = posy + scale;
324
+	}
325
+	
326
+	
327
+	 
328
+}
329
+
330
+void setupfont(char *url, int rows, int columns){
331
+	//printf("got to here\n");
332
+	loadingsurface = IMG_Load(url);
333
+	
334
+	*rowptr = rows - 1;
335
+	*columnptr = columns - 1;
336
+	
337
+	fonttexture = SDL_CreateTextureFromSurface(renderer, loadingsurface);
338
+	
339
+	SDL_QueryTexture(fonttexture, NULL, NULL, &lengthpix, &heightpix);
340
+	
341
+}
342
+void drawwindow(char *title, char *message, int ifbuttons, int iftitle, int xpos, int ypos, int timeonscreen){//the title and buttons, if both gone, will just make the window with the backdrop window
343
+	
344
+	
345
+	
346
+	
347
+}
348
+

+ 27
- 0
ui.h View File

@@ -0,0 +1,27 @@
1
+SDL_Window* window;
2
+SDL_Renderer* renderer;
3
+SDL_Surface* loadingsurface;
4
+SDL_Texture* loadingtexture;
5
+SDL_Texture* fonttexture;
6
+SDL_Rect letter;
7
+SDL_Rect letterfinal;
8
+SDL_RendererFlip flippy;
9
+
10
+
11
+typedef enum windowstyle{
12
+	TITLE,
13
+	NOTITLE,
14
+	BUTTONS,
15
+	NOBUTTONS
16
+};
17
+
18
+
19
+void setupui(SDL_Window* win, SDL_Renderer* ren);
20
+
21
+void destroyui();
22
+
23
+void drawstring(char *message, int posx, int posy, int scale, int spacing);
24
+
25
+void setupfont(char *url, int rows, int columns);
26
+
27
+void drawwindow(char *title, char *message, int ifbuttons, int iftitle, int xpos, int ypos, int timeonscreen);

Loading…
Cancel
Save