Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
removed '#pragma once' as it is not standard, fixed sprite rotation, adde3d
  • Loading branch information
BBQGiraffe authored Oct 12, 2019
1 parent 6a11c3d commit 6db44ef
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 266 deletions.
53 changes: 53 additions & 0 deletions engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "engine.h"
#include "img.h"
#include "fileNames.h"
#include <tinyfiledialogs\tinyfiledialogs.h>

void Engine::startGame() {
//init window stuff
Engine::startGraphics("OpenNitemare3D", 640, 640);
bool quit = false;



}

void Engine::startGraphics(const char* Name, int displayWidth, int displayHeight) {
IMG img;
size_t numImages;
FileNames fileIndex;
img.Init("GAME.PAL", "IMG.1");
numImages = img.GetNumImages();
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(Name,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, displayWidth, displayHeight, 0);
renderer = SDL_CreateRenderer(window, -1, 0);
texture = SDL_CreateTextureFromSurface(renderer, img[fileIndex.getSprite("RED_WALL_SINGLE_PAINTING")]);
while (true)
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT:
SDL_DestroyTexture(texture);
//SDL_FreeSurface(image);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);

SDL_Quit();
return;
break;
}

SDL_Rect dstrect;
dstrect.x = (displayWidth - displayHeight) / 2 - 1;
dstrect.y = (displayHeight - displayWidth) / 2;
dstrect.w = displayHeight;
dstrect.h = displayWidth; //; // SDL_RenderCopyEx(renderer, texture, nullptr, &dstrect, 90, nullptr, SDL_FLIP_NONE);


SDL_RenderCopyEx(renderer, texture, nullptr, &dstrect, 90, nullptr, SDL_FLIP_NONE);
SDL_RenderPresent(renderer);
}

}
31 changes: 31 additions & 0 deletions engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef __ENGINE_H__
#define __ENGINE_H__
#include <string>
#include <SDL2/SDL.h>
class Engine
{
public:
std::string title;
std::string getTitle();
float version;
float getVersion();

int width;
int height;

void startGame();
void startGraphics(const char* Name, int displayWidth, int displayHeight);


//SDL2 stuff
SDL_Event event;
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Texture* texture;



};

#endif

28 changes: 28 additions & 0 deletions fileNames.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "fileNames.h"

#include <string>

/*this function makes it so you don't have to remember sprite indexes.
Note: not yet complete, incorrectly labled
I unfortunatly have to go through each sprite and label it
*/
int FileNames::getSprite(std::string index) {
if (index == "RED_WALL_DOUBLE_PLAIN") {
return 0;
}
else if (index == "RED_WALL_SINGLE_PAINTING") {
return 1;

}
else if (index == "RED_WALL_DOUBLE_CANDLE_FR1") {
return 2;
}
else if (index == "RED_WALL_DOUBLE_CANDLE_FR2") {
return 3;
}

}
11 changes: 11 additions & 0 deletions fileNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __FILENAMES_H__
#define __FILENAMES_H__
#include <string>
class FileNames
{
public:
int getSprite(std::string index);
};

#endif

Loading

0 comments on commit 6db44ef

Please sign in to comment.