diff options
author | tom <tom@ground-control> | 2015-04-30 22:20:53 -0500 |
---|---|---|
committer | tom <tom@ground-control> | 2015-04-30 22:20:53 -0500 |
commit | e1d75dfdf0727776adf0b3d44995ccf0e03487b3 (patch) | |
tree | f26074b8e9c598df33c66b1c57aad1e4dcd51f03 |
first commit
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | images/basic.png | bin | 0 -> 3081 bytes | |||
-rw-r--r-- | src/entity.cpp | 25 | ||||
-rw-r--r-- | src/entity.h | 21 | ||||
-rw-r--r-- | src/event.cpp | 32 | ||||
-rw-r--r-- | src/event.h | 21 | ||||
-rw-r--r-- | src/main.cpp | 25 | ||||
-rw-r--r-- | src/main.h | 8 | ||||
-rw-r--r-- | src/window.cpp | 31 | ||||
-rw-r--r-- | src/window.h | 24 |
12 files changed, 202 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74f8efc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +nature diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9f346de --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +OBJS = src/main.cpp src/window.cpp src/entity.cpp src/event.cpp + +CC = g++ + +COMPILER_FLAGS = -w + +LINKER_FLAGS = -lSDL2 -lSDL2_image + +all : $(OBJS) + $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o nature diff --git a/README.md b/README.md new file mode 100644 index 0000000..383e625 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Nature's Course - Tom Barrett + +For librarys ~ +sudo apt-get install libsdl* diff --git a/images/basic.png b/images/basic.png Binary files differnew file mode 100644 index 0000000..6d1f592 --- /dev/null +++ b/images/basic.png diff --git a/src/entity.cpp b/src/entity.cpp new file mode 100644 index 0000000..5533975 --- /dev/null +++ b/src/entity.cpp @@ -0,0 +1,25 @@ +#include "entity.h" + +Entity::Entity(Window m, std::string s) +{ + texture = loadTexture(s, m); + renderer = m.getRenderer(); + x=y=200; +} + +void Entity::Place() +{ + SDL_Rect rect = {x, y, width/8, height/8}; + SDL_RenderCopyEx(renderer,texture,NULL,&rect,degrees,NULL,SDL_FLIP_NONE); +} + +SDL_Texture* Entity::loadTexture(std::string path, Window main) +{ + SDL_Surface* surface = IMG_Load(path.c_str()); + SDL_SetColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, 255, 255, 255)); + height = surface->h; + width = surface->w; + SDL_Texture* texture = SDL_CreateTextureFromSurface(main.getRenderer(),surface); + SDL_FreeSurface(surface); + return texture; +} diff --git a/src/entity.h b/src/entity.h new file mode 100644 index 0000000..1d1f876 --- /dev/null +++ b/src/entity.h @@ -0,0 +1,21 @@ +#ifndef entity_h +#define entity_h + +#include "window.h" + +class Entity +{ + public: + Entity(Window m, std::string s); + void Place(); + SDL_Texture* loadTexture(std::string path, Window main); + + protected: + int x, y; + int height, width; + int degrees = 0; + SDL_Texture* texture; + SDL_Renderer* renderer; +}; + +#endif diff --git a/src/event.cpp b/src/event.cpp new file mode 100644 index 0000000..369edbc --- /dev/null +++ b/src/event.cpp @@ -0,0 +1,32 @@ +#include "event.h" + +Event::Event() +{ + run = true; +}; + +int Event::Poll() +{ + SDL_PollEvent(&v); +}; + +void Event::off() +{ + run = false; +} + +bool Event::gRun() +{ + return run; +}; + +SDL_Event& Event::gEvent() +{ + SDL_Event* x = &v; + return *x; +}; + +int Event::gEventType() +{ + return v.type; +}; diff --git a/src/event.h b/src/event.h new file mode 100644 index 0000000..9ba7eea --- /dev/null +++ b/src/event.h @@ -0,0 +1,21 @@ +#ifndef event_h +#define event_h + +#include "window.h" + +class Event +{ + public: + Event(); + int Poll(); + void off(); + bool gRun(); + SDL_Event& gEvent(); + int gEventType(); + + private: + bool run; + SDL_Event v; +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..5ab78b3 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,25 @@ +#include "main.h"
+
+int main()
+{
+ Window main;
+ Entity ship(main, "images/basic.png");
+ Event e;
+
+ while(e.gRun())
+ {
+ while(e.Poll())
+ {
+ if(e.gEventType() == SDL_QUIT)
+ e.off();
+ //else if(e.gEventType() == SDL_KEYDOWN)
+ // eventHandle(e.gEvent());
+ }
+ main.Clear();
+ ship.Place();
+ main.Render();
+ }
+
+ main.Destroy();
+ return 0;
+}
diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..9a1a64d --- /dev/null +++ b/src/main.h @@ -0,0 +1,8 @@ +#ifndef main_h +#define main_h + +#include "window.h" +#include "entity.h" +#include "event.h" + +#endif diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..2ebc9c5 --- /dev/null +++ b/src/window.cpp @@ -0,0 +1,31 @@ +#include "window.h" + +Window::Window() +{ + SDL_Init(SDL_INIT_VIDEO); + main = SDL_CreateWindow("main",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,1280,800,SDL_WINDOW_SHOWN); + renderer = SDL_CreateRenderer(main,-1,SDL_RENDERER_ACCELERATED); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); +}; + +void Window::Destroy() +{ + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(main); + SDL_Quit(); +}; + +void Window::Clear() +{ + SDL_RenderClear(renderer); +}; + +void Window::Render() +{ + SDL_RenderPresent(renderer); +}; + +SDL_Renderer* Window::getRenderer() +{ + return renderer; +}; diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..fb1cf67 --- /dev/null +++ b/src/window.h @@ -0,0 +1,24 @@ +#ifndef window_h +#define window_h + +#include <SDL2/SDL.h> +#include <SDL2/SDL_image.h> +#include <string> +#include <cmath> + +class Window +{ + public: + Window(); + void Destroy(); + + void Clear(); + void Render(); + SDL_Renderer* getRenderer(); + + private: + SDL_Window* main; + SDL_Renderer* renderer; +}; + +#endif |