Add basic structure to program, namespaces, gitignore, makefile

master
ExeVirus 2021-01-28 21:56:35 -05:00
parent e492d848cd
commit bc58ccb3b3
7 changed files with 168 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
sdl_tree

21
makefile Normal file
View File

@ -0,0 +1,21 @@
#OBJS specifies which files to compile as part of the project
OBJS = src/main.cpp src/main_window.cpp
#CC specifies which compiler we're using
CC = g++
#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
COMPILER_FLAGS = -w
INC=-I/usr/local/include/SDL2
#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lSDL2
#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = sdl_tree
#This is the target that compiles our executable
all : $(OBJS)
$(CC) $(OBJS) $(INC) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

6
src/controls.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CONTROLS_H
#define CONTROLS_H
#endif

23
src/main.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <SDL.h>
#include <stdio.h>
#include "main_window.h"
#include "random_gen.h"
//Screen dimension constants
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 800;
int main( int argc, char* args[] )
{
//ran::args the_args = ran::parse(argc, args)
ran::args the_args;
if (mainw::initialize(&the_args)) return 1;
mainw::loop();
mainw::quit();
return 0;
}

59
src/main_window.cpp Normal file
View File

@ -0,0 +1,59 @@
#include "main_window.h"
#include "controls.h"
#include <SDL.h>
#include <iostream>
//globals for main_window
SDL_Window* window;
SDL_Surface* screenSurface;
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
bool run = true;
int mainw::initialize(ran::args* arg)
{
window = NULL;
screenSurface = NULL;()
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )()
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
return 1;
}
//Create window
window = SDL_CreateWindow( "SDL Tree", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Error during window creation, SDL_Error: %s\n", SDL_GetError() );
return 1;
}
return 0;
}
void mainw::loop()
{
con::control_struct controls;
while(run)
{
con::do_controls(&control_struct);
//If quit is pressed
if(control_struct.quit)
break; //out of while loop
//respond to controls
respond(&control_struct); //sets player position, toggles check
if(timeHasPassed)
tick(); //renders screen, runs the toggled check
}
}
void mainw::quit()
{
//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
}

42
src/main_window.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#include <SDL.h>
#include "controls.h"
#include "random_gen.h"
namespace mainw {
//-------------------------
// mainw::initialize()
//
// Starts SDL2
//
// Returns 1 on Error
//
int initialize(ran::args* arg);
//-------------------------
// mainw::initialize()
//
// Runs main game loop
//
void loop();
//-------------------------
// mainw::quit()
// Quits SDL
//
void quit();
//-------------------------
// mainw::respond()
// Uses controls from keyboard to
// move the player, change the current check, etc.
//
void respond(con::control_struct controls);
} //End mainw namespace
#endif

16
src/random_gen.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef RANDOM_GEN_H
#define RANDOM_GEN_H
namespace ran {
struct args {
int num_clusters;
int num_total_points;
float spread_multiplier;
};
}
#endif