Rev 4 | Rev 7 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 3 | tom | 1 | #include "SDL/SDL.h" |
| 4 | tom | 2 | #include "SDL/SDL_image.h" |
| 3 | tom | 3 | #include "SDL/SDL_opengl.h" |
| 4 | |||
| 4 | tom | 5 | #include <iostream> |
| 6 | tom | 6 | #include <vector> |
| 7 | #include <map> |
||
| 4 | tom | 8 | |
| 9 | using namespace std; |
||
| 10 | |||
| 11 | #include "texture.hpp" |
||
| 1 | tom | 12 | #include "sssnakesss.hpp" |
| 13 | |||
| 14 | SSSNAKESSS::SSSNAKESSS() |
||
| 15 | { |
||
| 2 | tom | 16 | running = false; |
| 1 | tom | 17 | } |
| 18 | |||
| 19 | SSSNAKESSS::~SSSNAKESSS() |
||
| 20 | { |
||
| 21 | |||
| 22 | } |
||
| 23 | |||
| 24 | bool SSSNAKESSS::init() |
||
| 25 | { |
||
| 26 | if (!initSDL()) |
||
| 27 | { |
||
| 28 | return false; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (!initOpenGL()) |
||
| 32 | { |
||
| 33 | return false; |
||
| 34 | } |
||
| 35 | |||
| 36 | initData(); |
||
| 37 | |||
| 38 | return true; |
||
| 39 | } |
||
| 40 | |||
| 41 | bool SSSNAKESSS::initSDL() |
||
| 42 | { |
||
| 3 | tom | 43 | if (SDL_Init(SDL_INIT_EVERYTHING) != 0) |
| 44 | { |
||
| 45 | return false; |
||
| 46 | } |
||
| 47 | |||
| 48 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
||
| 49 | |||
| 50 | screen = SDL_SetVideoMode(640, 480, 16, SDL_OPENGL); |
||
| 51 | if (!screen) |
||
| 52 | { |
||
| 53 | return false; |
||
| 54 | } |
||
| 55 | |||
| 1 | tom | 56 | return true; |
| 57 | } |
||
| 58 | |||
| 59 | bool SSSNAKESSS::initOpenGL() |
||
| 60 | { |
||
| 3 | tom | 61 | glEnable(GL_TEXTURE_2D); |
| 62 | |||
| 63 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
||
| 64 | |||
| 65 | glViewport(0, 0, 640, 480); |
||
| 66 | |||
| 67 | glClear(GL_COLOR_BUFFER_BIT); |
||
| 68 | |||
| 69 | glMatrixMode(GL_PROJECTION); |
||
| 70 | glLoadIdentity(); |
||
| 71 | |||
| 72 | glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f); |
||
| 73 | |||
| 74 | glMatrixMode(GL_MODELVIEW); |
||
| 75 | glLoadIdentity(); |
||
| 76 | |||
| 1 | tom | 77 | return true; |
| 78 | } |
||
| 79 | |||
| 80 | void SSSNAKESSS::initData() |
||
| 81 | { |
||
| 6 | tom | 82 | string dataDir = "data/"; |
| 83 | |||
| 84 | string graphicsDir = dataDir + "graphics/"; |
||
| 85 | vector<string> graphicsList = listDir(graphicsDir); |
||
| 86 | for (unsigned int i = 0; i < graphicsList.size(); i++) |
||
| 87 | { |
||
| 88 | string file = graphicsList[i]; |
||
| 89 | string fullfilename = graphicsDir + file; |
||
| 90 | |||
| 91 | textures[file] = new Texture(fullfilename); |
||
| 92 | } |
||
| 1 | tom | 93 | } |
| 94 | |||
| 95 | void SSSNAKESSS::run() |
||
| 96 | { |
||
| 2 | tom | 97 | running = true; |
| 98 | |||
| 99 | while (running) |
||
| 100 | { |
||
| 101 | checkEvents(); |
||
| 102 | update(); |
||
| 103 | draw(); |
||
| 104 | } |
||
| 1 | tom | 105 | } |
| 106 | |||
| 2 | tom | 107 | void SSSNAKESSS::checkEvents() |
| 108 | { |
||
| 3 | tom | 109 | SDL_Event event; |
| 110 | |||
| 111 | while (SDL_PollEvent(&event)) |
||
| 112 | { |
||
| 113 | switch (event.type) |
||
| 114 | { |
||
| 115 | case SDL_QUIT: |
||
| 116 | running = false; |
||
| 117 | break; |
||
| 118 | } |
||
| 119 | } |
||
| 2 | tom | 120 | } |
| 121 | |||
| 122 | void SSSNAKESSS::update() |
||
| 123 | { |
||
| 124 | } |
||
| 125 | |||
| 126 | void SSSNAKESSS::draw() |
||
| 127 | { |
||
| 128 | } |
||
| 129 | |||
| 1 | tom | 130 | void SSSNAKESSS::end() |
| 131 | { |
||
| 132 | } |
||
| 6 | tom | 133 | |
| 134 | vector<string> SSSNAKESSS::listDir(string dir) |
||
| 135 | { |
||
| 136 | vector<string> list; |
||
| 137 | |||
| 138 | return list; |
||
| 139 | } |