Ver código fonte

first commit

master
0x3F 1 ano atrás
commit
89e912bdad
26 arquivos alterados com 1142 adições e 0 exclusões
  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) Ver arquivo


+ 16
- 0
Makefile Ver arquivo

@@ -0,0 +1,16 @@
#OBJS specifies which files to compile as part of the project
OBJS = boxengine.c game/polygone.c render.c ui.c sprite.c game/intro.c physics.c

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = PolyGONE

#This is the target that compiles our executable
all : $(OBJS)
gcc $(OBJS) -w -g -lSDL2 -lSDL2_image -lm -o $(OBJ_NAME)
#g++ 01_hello_SDL.cpp -I{add correct path here}/include/SDL2 -L{add correct path here}/lib -lmingw32 -lSDL2main -lSDL2

BIN
PolyGONE Ver arquivo


+ 5
- 0
README.md Ver arquivo

@@ -0,0 +1,5 @@
# Box Engine
My first ever game engine that I made back in 2015 or 2016

## Screenshots:
![alt text](https://ssul.vertesine.com/1522320590120.png)

+ 76
- 0
boxengine.c Ver arquivo

@@ -0,0 +1,76 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "boxengine.h"
#include "render.h"
#include "ui.h"
#include "sprite.h"


/*Ideas

make each module be: spritehandler(working on), renderer(check), audio, data, inputoutput(work with keyboard and custm file format,
such as loadtexture(), or loadmap(), or loadfont(), etcfiles), networking, UI functinality and rendering(check, well eh...). UI rendered last for always on top

//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.

Utility next: Tile based editor.






*/









int setup(char *title, int width, int height, int dimension, int method, int framing){
//sets up plain old SDL
int status = 0;
window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
screenwidth = width;
screenheight = height;
printf("Title: %s\n", title);
if(method == HARDWARE){
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
} else{
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
}
//iffy code for setting up continuing modules. Correct this with error handling later
setuprender(window, renderer);
setupui(window, renderer);
return status;
}

int destroy(){
int status = 0;
//iffy code for destroying modules
destroyrender();
destroyui();
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
return status;
}

+ 18
- 0
boxengine.h Ver arquivo

@@ -0,0 +1,18 @@
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Event event;

int screenwidth;
int screenheight;

typedef enum rendermethod{
RENDER2D,
RENDER3D,
HARDWARE,
SOFTWARE,
FULLSCREEN,
WINDOWED
};

int setup(char *title, int width, int height, int dimension, int method, int framing);
int destroy();

BIN
game/font.png Ver arquivo

Antes Depois
Largura: 60  |  Altura: 200  |  Tamanho: 47KB

BIN
game/font1.png Ver arquivo

Antes Depois
Largura: 60  |  Altura: 200  |  Tamanho: 47KB

+ 161
- 0
game/intro.c Ver arquivo

@@ -0,0 +1,161 @@
#include <stdio.h>
#include <SDL2/SDL.h>
#include "intro.h"
#include "../boxengine.h"

int* stateptr = NULL;
int end = 0;
int timescalled = 0;
int brightness = 0;

void ievents(int* ptr){
stateptr = ptr;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
if(end == 1){
*stateptr = 1;
printf("Left Intro sequence\n");
}
}

void ilogic(){
//static int timescalled = 0; I'm only leaving this in here to prove that you can have this work, and it will increment suprisingly.
//--------------------------------------------------------------------------
static int positionx = 0;
if(timescalled == 0){
positionx = screenwidth;
}
if(timescalled < 300){
brightness++;
if(brightness > 255){
brightness = 255;
}
}
if(timescalled < 500){
positionx--;
}
printf("\n\nTIMES CALLED & BRIGHTNESS: %d %d \n\n", timescalled, brightness);
drawstring("Box Engine", positionx , screenheight / 2 - screenheight / 9, 30, 3);
if(timescalled > 550 && timescalled < 1500){
static int bouncefactor = -20;
static int hit = 0;
int size = 100;
int offset = 30;
static int vely = 0;
static int x = -200;
static int y = -500;
int gravity = 1;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
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);
if(y <= 0){
hit = 0;
y+=vely;
vely+=gravity;
if(y > 0){
y = 0;
hit = 1;
}
//drawstring("FALLING", 0 , 0, 30, 3);
}
if(hit == 1){
//drawstring("HIT", 0 , 0, 30, 3);
//vely = 0;
vely = bouncefactor;
bouncefactor += 2;
if(bouncefactor > 0){
bouncefactor = 0;
}
//bouncefactor
}
//SDL_RenderDrawLine(renderer, screenwidth / 2 - 100, screenheight / 2 - 100, screenwidth / 2 + 100, screenheight / 2 + 100);
//cube
SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 - size + y, screenwidth / 2 - size + x, screenheight / 2 + size + y);//left side front
SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 - size + y, screenwidth / 2 + size + x, screenheight / 2 - size + y);//top side front
SDL_RenderDrawLine(renderer, screenwidth / 2 + size + x, screenheight / 2 - size + y, screenwidth / 2 + size + x, screenheight / 2 + size + y);//right side front
SDL_RenderDrawLine(renderer, screenwidth / 2 - size + x, screenheight / 2 + size + y, screenwidth / 2 + size + x, screenheight / 2 + size + y);//bottom side front
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
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
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
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
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
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
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
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
}
if(timescalled > 1200){
brightness--;
if(brightness < 0){
brightness = 0;
}
}
if(timescalled == 1500){
end = 1;
}
SDL_SetRenderDrawColor(renderer, brightness, brightness, brightness, brightness);
//-------------------------------------------------------------------------
//SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
timescalled++;
}

void irender(){
pushscreen();
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
}

+ 3
- 0
game/intro.h Ver arquivo

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

+ 9
- 0
game/oldpolygone/player.c Ver arquivo

@@ -0,0 +1,9 @@
#include <stdio.h>
#include <SDL2/SDL.h>

int main(int argc, char* args[]){
return 0;
}

+ 0
- 0
game/oldpolygone/player.h Ver arquivo


+ 116
- 0
game/oldpolygone/polygone.c Ver arquivo

@@ -0,0 +1,116 @@
#include <stdio.h>
#include <SDL2/SDL.h>
#include <math.h>
#include "../boxengine.h"
#include "polygone.h"


float x, y, *x_ptr = &x, *y_ptr = &y;
int true = 0;
float i = 0.0f;
//THIS FILE IS AT THE TOP OF THE EXECUTION FILE
//THE TEXT IS 5x5
//TEST LATER IF YOU CH+AN USE FILES INCLUDED FROM OTHER FILES. COULD BE USEFUL



int main(int argc, char* args[]){
if(setup("PolyGONE", 800, 600, RENDER2D, HARDWARE, WINDOWED) == 0){//tests success, and sets up everything
printf("Successful start.\n");
} else{
printf("Error starting.\n");
return 1;
}
setupfont("game/font1.png", 12, 40);
//beginning
gameloop();
//end
if(destroy() == 0){//tests success
printf("Successful close.\n");
} else{
printf("Error closing. Memmory may not have been cleaned up.\n");
return 1;
}
return 0;
}

void gameloop(){
printf("Entered game loop\n");
SDL_SetRenderDrawColor(renderer, 20, 200, 58, 20);
SDL_PollEvent(&event);
while((event.type != SDL_QUIT)){ //(event.type != SDL_QUIT)
//printf("ok");
SDL_PollEvent(&event);
dostupidthing();
pushscreen();
SDL_Delay(17);
}
}
void dostupidthing(){
SDL_SetRenderDrawColor(renderer, 10, 240, 158, 40);
drawopeningscene();
//printf("got to herell");
SDL_RenderDrawLine(renderer, 100 + (int)x, 100 + (int)y, (800/2) + (int)x, (600/2 + 100) + (int)y + (int)x);
drawstring("TEST", (800/2) + (int)x, (600/2 + 100) + (int)y + (int)x, 20, 3 + (int)x);
drawstring("neat stuff", 100 + (int)x, 100 + (int)y, 50, 3);
drawstring("wow!", 570 + (int)x, 160 + (int)y, 50, 3);
//printf("\n\n\n------------DONE------------\n\n\n");
if(true){
drawstring("FAST", 100 + (int)x, 200 + (int)y, (int)x, 3);
true--;
} else {
drawstring("TEXT!", 100 + (int)x, 200 + (int)y, (int)y, 3);
true++;
}
i+= 0.1f;
SDL_SetRenderDrawColor(renderer, 20, 200, 58, 20);
rotate(x_ptr, y_ptr);
}
void rotate(float* c, float* d){
/*
float angle = 0.0;
float anglestepsize = 0.008;
while (angle < 2 * 3.14159265){
int x1 = x + width * cos(angle);
int y1 = y + height * sin(angle);
angle += anglestepsize;
}
*/
static float angle = 0.0;
float anglestepsize = 0.008;
*c = 100 * cos(angle);
*d = 100 * sin(angle);
angle += anglestepsize;
}

+ 4
- 0
game/oldpolygone/polygone.h Ver arquivo

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

+ 5
- 0
game/player.c Ver arquivo

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



+ 0
- 0
game/player.h Ver arquivo


+ 180
- 0
game/polygone.c Ver arquivo

@@ -0,0 +1,180 @@
#include <stdio.h>
#include <SDL2/SDL.h>
#include <math.h>
#include "../boxengine.h"
#include "polygone.h"
#include "intro.h"
//#include "title.h"

//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,
//when paused, I dont know if it will remember the positions of the entities and the progress. I guess static variables everywhere.
//TODO: make animation states and movement states
//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.




int main(int argc, char* args[]){
if(setup("PolyGONE", 800, 600, RENDER2D, HARDWARE, WINDOWED) == 0){//tests success, and sets up everything
printf("Successful start.\n");
} else{
printf("Error starting.\n");
return 1;
}
setupfont("game/font1.png", 12, 40);
//beginning
gameloop();
//end
if(destroy() == 0){//tests success
printf("Successful close.\n");
} else{
printf("Error closing. Memmory may not have been cleaned up.\n");
return 1;
}
return 0;
}

void gameloop(){
enum States{
INTRO,
TITLE,
PAUSED,
LEVEL1,
LEVEL2,
LEVEL3,
ENDCREDITS//can be accessed by the "credits" button in the pause/title screen
} state;
state = INTRO;
int copystate;//YOU NEED TO MAKE SURE AN ENUM CAN EQUAL AN INT
int* stateptr = &copystate;
*stateptr = state;
printf("Entered game loop\n");
SDL_PollEvent(&event);
while((event.type != SDL_QUIT)){ //(event.type != SDL_QUIT)
SDL_PollEvent(&event);
state = *stateptr;// send this to all enum using functions to increment between, or jump to.
printf("STATE: %d\n", state);
//-------------------------------------------------------------------------------------------------------------
switch(state){ //do the events
case INTRO:
ievents(stateptr);//pass the enum to it in the form of a pointer so it can increment it after it is done.
break;
case TITLE:
//tevents();
break;
case PAUSED:
//pevents();
break;
case LEVEL1:
//l1events();
break;
case LEVEL2:
//l2events();
break;
case LEVEL3:
//l3events();
break;
case ENDCREDITS:
//eevents();
break;
default:
printf("Error in gamestate state in the events\n");
break;
}
switch(state){ //do the logic
case INTRO:
ilogic();
break;
case TITLE:
//tlogic();
break;
case PAUSED:
//plogic();
break;
case LEVEL1:
//l1logic();
break;
case LEVEL2:
//l2logic();
break;
case LEVEL3:
//l3logic();
break;
case ENDCREDITS:
//elogic();
break;
default:
printf("Error in gamestate state in the logic\n");
break;
}
switch(state){ //do the rendering
case INTRO:
irender();
break;
case TITLE:
//trender();
break;
case PAUSED:
//prender();
break;
case LEVEL1:
//l1render();
break;
case LEVEL2:
//l2render();
break;
case LEVEL3:
//l3render();
break;
case ENDCREDITS:
//erender();
break;
default:
printf("Error in gamestate state in the renderer\n");
break;
}
//do timing

//-------------------------------------------------------------------------------------------------------------
SDL_Delay(17);
}
}


+ 2
- 0
game/polygone.h Ver arquivo

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

+ 0
- 0
physics.c Ver arquivo


+ 0
- 0
physics.h Ver arquivo


+ 99
- 0
render.c Ver arquivo

@@ -0,0 +1,99 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "render.h"







void setuprender(SDL_Window* win, SDL_Renderer* ren){
printf("Set up renderer.\n");
window = win;//THESE TWO ARE CORRECT. THE RENDERER AND WINDOW EQUAL THE ABBREVIATED VERSIONS
renderer = ren;
//IMG_Init(IMG_INIT_PNG);
}

void destroyrender(){
printf("Destroyed renderer.\n");
SDL_FreeSurface(loadingsurface);
SDL_DestroyTexture(loadingtexture);
}


//void drawsprite(int xpos, int ypos, int width, int height, float rotation, int midpointx, int midpointy){
//SDL_RenderCopyEx(renderer, grass, NULL, &startup_rect);
//}

void drawbackground(){
}
void drawdebug(){
}
void drawopeningscene(){
static float iii = 0.0f;
static int finalend = 0;
if(finalend == 1024){
return;
}
static int reverse = 0;
//SDL_RenderClear(renderer);
//SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
//SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
int i;
int ii;
for(i = 0; i < 255; i++){
//printf("draw: %d", i);
for(ii = 0; ii < 255; ii++){
SDL_RenderDrawPoint(renderer, iii + i, iii + ii);
SDL_SetRenderDrawColor(renderer, 10, 56, 255, 255);
//SDL_RenderDrawLine(renderer, 0, 0, iii + i, iii);
SDL_SetRenderDrawColor(renderer, 100, 0, 55, 255);
//SDL_RenderDrawLine(renderer, 0, 0, iii, iii + ii);
SDL_SetRenderDrawColor(renderer, 120, iii, ii, 255);
//printf("kookokokok.");
}
SDL_SetRenderDrawColor(renderer, 20, 200, 58, 20);//set all to 0 for black refresh
}
//SDL_RenderPresent(renderer);
if(iii == 255){
reverse = 1;
}
if(iii == 0){
reverse = 0;
}
if(reverse == 0){
iii+= 0.5f;
} else {
iii-= 0.5f;
}
//printf("%f\n", iii);
finalend++;
}

void pushscreen(){
SDL_RenderPresent(renderer);
SDL_RenderClear(renderer);
}

+ 17
- 0
render.h Ver arquivo

@@ -0,0 +1,17 @@
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Surface* loadingsurface;
SDL_Texture* loadingtexture;


void setuprender(SDL_Window* win, SDL_Renderer* ren);

void destroyrender();


//void drawsprite(int xpos, int ypos, int width, int height, float rotation, int midpointx, int midpointy);

void drawbackground();
void drawdebug();
void drawopeningscene();
void pushscreen();

+ 50
- 0
sprite.c Ver arquivo

@@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "sprite.h"

//WORK ON SPRITE HANDLER AND MAP HANDLER TOMORROW
//TODO: work on physics file with collision and gravity. Let it calculate angles too, and *draw* debug angles n such with lines
//TODO: make sprites dynamic? malloc. Scenegraph?
int maxs;

typedef struct Sprite{
int priority;
int type;
float angle;
float velx;
float vely;
float x;
float y;
SDL_Texture* spritesheet;
int currentframe;
};

void setupspritehandler(SDL_Renderer* ren, int maxsprites){
renderer = ren;
maxs = maxsprites;
}

void destroyspritehandler(){
int i;
for(i = 0; i <= maxs; i++){//for deleting sprite textures;
//SDL_DestroyTexture(
}
SDL_DestroyTexture(texture);
printf("The double free error is just for the occasion where something isn't freed the first time. It is an acceptable error.\n");
SDL_DestroyRenderer(renderer);
}
void addsprite(){
}

//void drawsprite(int x, int y){

+ 6
- 0
sprite.h Ver arquivo

@@ -0,0 +1,6 @@
SDL_Renderer* renderer;
SDL_Texture* texture;

void setupspritehandler(SDL_Renderer* ren, int maxsprites);
void destroyspritehandler();
void addsprite();

+ 348
- 0
ui.c Ver arquivo

@@ -0,0 +1,348 @@
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "ui.h"

int rows, columns, lengthpix, heightpix;
int *rowptr = &rows, *columnptr = &columns;

void setupui(SDL_Window* win, SDL_Renderer* ren){
printf("Set up UI handler.\n");
window = win;//THESE TWO ARE CORRECT. THE RENDERER AND WINDOW EQUAL THE ABBREVIATED VERSIONS
renderer = ren;
IMG_Init(IMG_INIT_PNG);
flippy = SDL_FLIP_NONE;
}

void destroyui(){
printf("Destroyed UI handler.\n");
SDL_FreeSurface(loadingsurface);
SDL_DestroyTexture(loadingtexture);
}

void drawstring(char *message, int posx, int posy, int scale, int spacing){//scale, if in pixels and square, is what the value is.
int i;
int len = (strlen(message) - 1);
int currow = 0;
int curcolumn = 0;
int value;
//both of the rects below will be updated in a loop. THis just starts them out.
//the internal selector rect
letter.x = 0;
letter.y = 0;
letter.w = lengthpix / rows;//rows = 12
letter.h = heightpix / columns;//colums = 40
//the representation of the internal selector
letterfinal.x = posx;
letterfinal.y = posy;
letterfinal.w = scale;
letterfinal.h = scale;
for(i = 0; i <= len; i++){
//printf("\n%c\n:", message[i]);
currow = 0;
curcolumn = 0;
value = 0;
//get the ascii value and convert it to a value from the font sheet
switch (message[i]){
case 'A':
value = 0;
break;
case 'B':
value = 1;
break;
case 'C':
value = 2;
break;
case 'D':
value = 3;
break;
case 'E':
value = 4;
break;
case 'F':
value = 5;
break;
case 'G':
value = 6;
break;
case 'H':
value = 7;
break;
case 'I':
value = 8;
break;
case 'J':
value = 9;
break;
case 'K':
value = 10;
break;
case 'L':
value = 11;
break;
case 'M':
value = 12;
break;
case 'N':
value = 13;
break;
case 'O':
value = 14;
break;
case 'P':
value = 15;
break;
case 'Q':
value = 16;
break;
case 'R':
value = 17;
break;
case 'S':
value = 18;
break;
case 'T':
value = 19;
break;
case 'U':
value = 20;
break;
case 'V':
value = 21;
break;
case 'W':
value = 22;
break;
case 'X':
value = 23;
break;
case 'Y':
value = 24;
break;
case 'Z':
value = 25;
break;
case ' ':
value = 26;
break;
case 'a':
value = 27;
break;
case 'b':
value = 28;
break;
case 'c':
value = 29;
break;
case 'd':
value = 30;
break;
case 'e':
value = 31;
break;
case 'f':
value = 32;
break;
case 'g':
value = 33;
break;
case 'h':
value = 34;
break;
case 'i':
value = 35;
break;
case 'j':
value = 36;
break;
case 'k':
value = 37;
break;
case 'l':
value = 38;
break;
case 'm':
value = 39;
break;
case 'n':
value = 40;
break;
case 'o':
value = 41;
break;
case 'p':
value = 42;
break;
case 'q':
value = 43;
break;
case 'r':
value = 44;
break;
case 's':
value = 45;
break;
case 't':
value = 46;
break;
case 'u':
value = 47;
break;
case 'v':
value = 48;
break;
case 'w':
value = 49;
break;
case 'x':
value = 50;
break;
case 'y':
value = 51;
break;
case 'z':
value = 52;
break;
case '1':
value = 53;
break;
case '2':
value = 54;
break;
case '3':
value = 55;
break;
case '4':
value = 56;
break;
case '5':
value = 57;
break;
case '6':
value = 58;
break;
case '7':
value = 59;
break;
case '8':
value = 60;
break;
case '9':
value = 61;
break;
case '0':
value = 62;
break;
case '.':
value = 63;
break;
case ',':
value = 64;
break;
case '!':
value = 65;
break;
case 0x3F:
value = 66;
break;
}
//end of switch statement
//THE LAST THING YOU WERE WORKING ON GOT A FLOATING POINT EXCEPTION, YOU DIVIDED BY ZERO SOMEWHERE :/
//highly unstable, written at night, needs to betested tomorrow, reading loop?:
//REMEMBER, ALL OF THIS IS ALREADY IN A LOOP
//printf("\n\n\n this is rows before: %d. \n\n\n", rows);
//int colcount;
//int rowcount;
int num = 0;
for(curcolumn = 0; curcolumn <= columns; curcolumn++){
//printf(" COLUMN: %d.", colcount);
for(currow = 0; currow <= rows; currow++, num++){
//printf(" ROW: %d.", currow);
if(num == value){
//printf("broken in row");
break;
}
//num++;
//currow++;
}
if(num == value){
//printf("broken in column");
break;
}
//curcolumn++;
}
letter.x = 5 * currow;
letter.y = 5 * curcolumn;
//printf(".ROW: %d, COLUMN: %d.", currow, curcolumn);
//letter.w = lengthpix / rows;//rows = 12
//letter.h = heightpix / columns;//colums = 40
SDL_RenderCopyEx(renderer, fonttexture, &letter, &letterfinal, 0.0f, NULL, flippy);
//END OF LOOP
//the representation of the internal selector
letterfinal.x += spacing * (scale /2);//USE THIS ONLY
//letterfinal.y = posy + 0;
//letterfinal.w += (scale + 3);
//letterfinal.h = posy + scale;
}
}

void setupfont(char *url, int rows, int columns){
//printf("got to here\n");
loadingsurface = IMG_Load(url);
*rowptr = rows - 1;
*columnptr = columns - 1;
fonttexture = SDL_CreateTextureFromSurface(renderer, loadingsurface);
SDL_QueryTexture(fonttexture, NULL, NULL, &lengthpix, &heightpix);
}
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
}


+ 27
- 0
ui.h Ver arquivo

@@ -0,0 +1,27 @@
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Surface* loadingsurface;
SDL_Texture* loadingtexture;
SDL_Texture* fonttexture;
SDL_Rect letter;
SDL_Rect letterfinal;
SDL_RendererFlip flippy;


typedef enum windowstyle{
TITLE,
NOTITLE,
BUTTONS,
NOBUTTONS
};


void setupui(SDL_Window* win, SDL_Renderer* ren);

void destroyui();

void drawstring(char *message, int posx, int posy, int scale, int spacing);

void setupfont(char *url, int rows, int columns);

void drawwindow(char *title, char *message, int ifbuttons, int iftitle, int xpos, int ypos, int timeonscreen);

Carregando…
Cancelar
Salvar