C_Rect::C_Rect(const C_Vec2& start, const C_Vec2& end) { double startx, endx, starty, endy; Start = start; End = end; startx = start.X(); starty = start.Y(); endx = end.X(); endy = end.Y(); if (start.X() > end.X()) { startx = end.X(); endx = start.X(); } if (start.Y() > end.Y()) { starty = end.Y(); endy = start.Y(); } Start = C_Vec2(startx, starty); End = C_Vec2(endx, endy); }
void SM_Scores::draw() { //draw the images background->pushToScreen(renderer, C_Vec2(), dimensions); scoresBackground->pushToScreen(renderer, C_Vec2(dimensions.x * 0.125f, dimensions.y * 0.05f), dimensions * 0.75); //draw score text for (int i = 0; i < 5; i++) { scoresText[i]->pushToScreen(C_Vec2(dimensions.x * 0.365f, (i+2) * (dimensions.y * 0.1f))); } //Draw the two coins outside the button coin->pushToScreen( renderer, C_Vec2((dimensions.x * 0.2f) - (coinDim.x * 0.5f), buttonYPos), coinDim); coin->pushToScreen( renderer, C_Vec2((dimensions.x * 0.8f) - (coinDim.x * 0.5f), buttonYPos), coinDim); //draw the button exitButton->draw(renderer); }
//DO * Rechteck-Klasse *********************************************** C_Rect::C_Rect() { double startx, endx, starty, endy; startx = 0.0f; starty = 0.0f; endx = 0.0f; endy = 0.0f; Start = C_Vec2(startx, starty); End = C_Vec2(endx, endy); }
EE_StormCloud::EE_StormCloud(C_Texture* sprite, C_Vec2 pos, C_Vec2 dimensions, float* universalSpeed) : EB_VelocityAnimated(sprite, pos, dimensions, C_Vec2(-500.0f, 0.0f), 3, C_Vec2(562, 401), 0.075f, "EE_StormCloud", universalSpeed), dead(false), deathParticles(false), cloudDim(C_Vec2(562.0f, 298.0f)) { //Initialise the sprite position int spriteYindex = rand() % 4; spriteIndex = C_Vec2(0, spriteYindex); //Work out the percentage of the cloud height in the sprite float cloudPercent = (cloudDim.y / 401.0f) * 100.0f; //Work out 1% of the sprite height float onePercent = dimensions.y * 0.01f; //Work out the cloud height float cloudHeight = cloudPercent * onePercent; //Scale the cloud dimensions cloudDim = C_Vec2(dimensions.x, cloudHeight); }
EP_Player::EP_Player(C_Texture* sprite, C_Vec2 pos, C_Vec2 dimensions, C_Texture* archerSprite, C_Vec2 archerPos, C_Vec2 archerDimensions, C_Vec2 screenDimensions, C_Texture* fireSprite, SDL_Colour minTint, SDL_Colour maxTint, float* universalSpeed) : EB_Animated(sprite, pos, dimensions, 5, C_Vec2(699, 436), 0.1f, "EP_Player", universalSpeed), screenDimensions(screenDimensions), pressed(false), health(3), maxHealth(3), coins(0), maxCoins(999999999), archer(new EP_PlayerArcher(archerSprite, archerPos, archerDimensions, universalSpeed)), archerOffset(archerPos - pos), flamingPowerUp(false), flamingPowerUpTimer(30), timeSlowPowerUp(false), timeSlowPowerUpTimer(10), fireEffectOffset(C_Vec2(screenDimensions.x * 0.022f, screenDimensions.y * 0.05f)), fireEffect(new PS_ParticleEffect(fireSprite, pos + fireEffectOffset, true, 5.0f, 15.0f, 0.1f, minTint, maxTint)), shieldLossSound(new C_Audio("Assets/Audio/shieldLoss.ogg")) { //set the fire effect to not be emitting fireEffect->setEmitting(false); //Initialise array sounds healthLossSounds[0] = new C_Audio("Assets/Audio/death.ogg"); healthLossSounds[1] = new C_Audio("Assets/Audio/damage2.ogg"); healthLossSounds[2] = new C_Audio("Assets/Audio/damage.ogg"); }
SM_Scores::SM_Scores(S_StateManager* stateManager, SDL_Renderer* renderer, C_Vec2 dimensions, C_Music* backgroundMusic) : S_State(stateManager, renderer, dimensions), backgroundMusic(backgroundMusic), background(new C_Texture("Assets/Images/nongamebackground.png", renderer)), scoresBackground(new C_Texture("Assets/Images/scoresBackground.png", renderer)), buttonBackground(new C_Texture("Assets/Images/buttonBackground981x174.png", renderer)), coin(new C_Texture("Assets/Images/coin.png", renderer)), coinDim(C_Vec2(dimensions.y * 0.125f, dimensions.y * 0.125f)), buttonYPos((dimensions.y * 0.075f) * 11.0f) { //Initialise universal speed universalSpeed = new float(0.0f); //Initialise Button exitButton = new UI_Button( buttonBackground, //Button Sprite C_Vec2(981.0f, 174.0f), //Sprite Dimensions C_Vec2(dimensions.x * 0.3f, buttonYPos), //Position "Back", "Assets/Font/MonogramsToolbox.ttf", //Text & font location (int)(dimensions.y * 0.06f), //Font size 206, 158, 0, //Font colour renderer, //The renderer dimensions.y * 0.025f, //Border C_Vec2(dimensions.x * 0.4f, dimensions.y * 0.125f), //Minimum dimensions of the button universalSpeed //Universal Speed ); //Load the scores loadScores(); //Initialise score text for (int i = 0; i < 5; i++) { scoresText.push_back(new C_Text(scores[i], "Assets/Font/MonogramsToolbox.ttf", (int)(dimensions.y * 0.075f), renderer, 206, 158, 0)); } }
C_Rect::C_Rect(const double startX,const double startY, const double endX, const double endY) { double startx, endx, starty, endy; startx = startX; starty = startY; endx = endX; endy = endY; if (startX > endX) { startx = endX; endx = startX; } if (startY > endY) { starty = endY; endy = startY; } Start = C_Vec2(startx, starty); End = C_Vec2(endx, endy); }
EB_Animated::EB_Animated(C_Texture* sprite, C_Vec2 pos, C_Vec2 dimensions, int animationFrames, C_Vec2 spriteDimensions, float animationLength, std::string iD, float* universalSpeed) : EB_Entity(sprite, pos, dimensions, iD, universalSpeed), animationFrames(animationFrames), spriteDimensions(spriteDimensions), animationTimer(animationLength), spriteIndex(C_Vec2()) { }
C_Vec2 operator / (double v,const C_Vec2& w) { return C_Vec2(double(w.x/v), double(w.y/v)); }
void EB_Entity::setHeight(float height) { dimensions = C_Vec2(dimensions.x, height); }
void EB_Entity::setWidth(float width) { dimensions = C_Vec2(width, dimensions.y); }
void EB_Entity::setY(float y) { pos = C_Vec2(pos.x, y); }
void EB_Entity::setX(float x) { pos = C_Vec2(x, pos.y); }
int main(int argc, char *argv[]) { //Set the window title std::string title = "Sky Zone Omega"; //Set the window and target resolutions C_Vec2 targetRes = C_Vec2(1080, 608); C_Vec2 windowRes = C_Vec2(1080, 608); //Initialise SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) { //Failed initialisation C_Utilities::logE("SDL failed to initialise: " + std::string(SDL_GetError())); return -1; } //Initialise SDL_ttf if (TTF_Init() < 0) { //Failed initialisation C_Utilities::logE("SDL_ttf failed to initialise: " + std::string(TTF_GetError())); return -1; } //Initialise SDL_mixer if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) { C_Utilities::logE("SDL_mixer failed to initialise: " + std::string(Mix_GetError())); return -1; } //Time Check unsigned int lastTime = SDL_GetTicks(); #if !defined(_DEBUG) //Create Window C_Vec2 windowPos = C_Vec2(100, 100); SDL_Window *window = SDL_CreateWindow(title.c_str(), (int)windowPos.x, (int)windowPos.y, (int)windowRes.x, (int)windowRes.y, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP); #else //Create Window C_Vec2 windowPos = C_Vec2(100, 100); SDL_Window *window = SDL_CreateWindow(title.c_str(), (int)windowPos.x, (int)windowPos.y, (int)windowRes.x, (int)windowRes.y, SDL_WINDOW_SHOWN); #endif //Create Renderer from the window SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); //Set the renderer to work out the render at this resolution and then scale it up the //closest resolution it can to the windows resolution (adds bars of the render colour) SDL_RenderSetLogicalSize(renderer, (int)targetRes.x, (int)targetRes.y); //The background music C_Music* backgroundMusic = new C_Music("Assets/Audio/gameplayLoop.ogg"); //Setup state manager and initial state S_StateManager * stateManager = new S_StateManager(); stateManager->addState(new S_Splash(stateManager, renderer, targetRes, backgroundMusic)); //Start Game Loop bool go = true; while (go) { //Time Check unsigned int current = SDL_GetTicks(); float deltaTime = (float)(current - lastTime) / 1000.0f; lastTime = current; //Handle the current state inputs go = stateManager->input(); //Update the current state stateManager->update(deltaTime); //set draw colour to black SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); //Clear the entire screen to the set colour SDL_RenderClear(renderer); //Draw the states stateManager->draw(); //display renderer SDL_RenderPresent(renderer); //Time Limiter if (deltaTime < (1.0f / 50.0f)) { SDL_Delay((unsigned int)(((1.0f / 50.0f) - deltaTime)*1000.0f)); } } //destroy data delete stateManager; //Stop music backgroundMusic->stopMusic(); //Delete audio pointers delete backgroundMusic; SDL_DestroyWindow(window); SDL_Quit(); return 0; }
C_Vec2 operator * (double v,const C_Vec2& w) { return C_Vec2(double(w.x*v), double(w.y*v)); }
C_Vec2 C_Vec2::operator - () { return C_Vec2(-x, -y); }
C_Vec2 operator - (const C_Vec2& w,const C_Vec2& v) { return C_Vec2(w.x-v.x, w.y-v.y); }
C_Vec2 operator + (const C_Vec2& w,const C_Vec2& v) { return C_Vec2(w.x+v.x, w.y+v.y); }