Add project files.
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
#include "cText.hpp"
|
||||
|
||||
/*** SDL Header Files ***/
|
||||
#include <SDL2_gfxPrimitives.h>
|
||||
#include <SDL2_gfxPrimitives_font.h>
|
||||
|
||||
/*** Custom Header Files ***/
|
||||
#include "../VideoEngine/cRenderer.hpp"
|
||||
#include "../FXEngine/cGFX.hpp"
|
||||
#include "../UtilityEngine/cUtility.hpp"
|
||||
|
||||
using TextTypeEngine::cText;
|
||||
using VideoEngine::cRenderer;
|
||||
using FXEngine::cGFX;
|
||||
using UtilityEngine::cUtility;
|
||||
|
||||
cText::cText( const cString& text, const unsigned long int size /*= 16*/ )
|
||||
: mpp_font(nullptr), m_text(text), m_size(size), m_render(eRender::Solid)
|
||||
{
|
||||
White();
|
||||
}
|
||||
|
||||
cText::cText( SDL_Colour& colour, TextTypeEngine::cFont** font /*= nullptr*/, const cString& text /*= ""*/, const unsigned long int size /*= 16*/, const eRender& render /*= eRender::Solid*/ )
|
||||
: mpp_font(font), m_text(text), m_size(size), m_render(render)
|
||||
{
|
||||
setColour(colour);
|
||||
}
|
||||
|
||||
cText::cText( TextTypeEngine::cFont** font /*= nullptr*/, const cString& text /*= ""*/, const unsigned long int size /*= 16*/,
|
||||
const unsigned long int red /*= 0*/, const unsigned long int green /*= 0*/, const unsigned long int blue /*= 0*/, const eRender& render /*= eRender::Solid*/ )
|
||||
: mpp_font(font), m_text(text), m_size(size), m_render(render)
|
||||
{
|
||||
setColour(red, green, blue);
|
||||
}
|
||||
|
||||
cText::cText( const cText& copy )
|
||||
: mpp_font(nullptr), m_text(copy.getText()), m_render(copy.getRender())
|
||||
{
|
||||
setColour(copy.getColour());
|
||||
}
|
||||
|
||||
cText::~cText()
|
||||
{}
|
||||
|
||||
///Function
|
||||
void cText::White()
|
||||
{
|
||||
setColour(255, 255, 255);
|
||||
}
|
||||
|
||||
void cText::Black()
|
||||
{
|
||||
setColour();
|
||||
}
|
||||
|
||||
void cText::Blue()
|
||||
{
|
||||
setColour(0, 0, 255);
|
||||
}
|
||||
|
||||
void cText::Green()
|
||||
{
|
||||
setColour(0, 255);
|
||||
}
|
||||
|
||||
void cText::Red()
|
||||
{
|
||||
setColour(255);
|
||||
}
|
||||
|
||||
///Sets
|
||||
void cText::setSize(const unsigned long int size /*= 16*/)
|
||||
{
|
||||
(*mpp_font)->setSize(size);
|
||||
}
|
||||
|
||||
void cText::setFont( TextTypeEngine::cFont** font )
|
||||
{
|
||||
mpp_font = font;
|
||||
Text();
|
||||
}
|
||||
|
||||
void cText::setText( const cString& text )
|
||||
{
|
||||
if (m_text != text) {
|
||||
m_text = text;
|
||||
Text();
|
||||
}
|
||||
}
|
||||
|
||||
void cText::setColour( const SDL_Colour& colour )
|
||||
{
|
||||
m_colour = colour;
|
||||
Text();
|
||||
}
|
||||
|
||||
void cText::setColour( const unsigned long int red /*= 0*/, const unsigned long int green /*= 0*/, const unsigned long int blue /*= 0*/, unsigned long int alpha /*= 255*/ )
|
||||
{
|
||||
SDL_Colour colour = {Uint8(red), Uint8(green), Uint8(blue), Uint8(alpha)};
|
||||
setColour(colour);
|
||||
}
|
||||
|
||||
void cText::setRender( const eRender& render /*= eRender::Solid*/ )
|
||||
{
|
||||
m_render = render;
|
||||
Text();
|
||||
}
|
||||
|
||||
///Gets
|
||||
const unsigned long int cText::getSize() const
|
||||
{
|
||||
unsigned long int rtn = 8;
|
||||
if ((mpp_font != nullptr) && ((*mpp_font) != nullptr))
|
||||
return (*mpp_font)->getSize();
|
||||
return rtn;
|
||||
}
|
||||
|
||||
TextTypeEngine::cFont* cText::getFont() const
|
||||
{
|
||||
return (*mpp_font);
|
||||
}
|
||||
|
||||
const cString& cText::getText() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
const SDL_Colour& cText::getColour() const
|
||||
{
|
||||
return m_colour;
|
||||
}
|
||||
|
||||
void cText::getColour( unsigned long int& red, unsigned long int& green, unsigned long int& blue, unsigned long int& alpha ) const
|
||||
{
|
||||
red = m_colour.r;
|
||||
green = m_colour.g;
|
||||
blue = m_colour.b;
|
||||
alpha = m_colour.a;
|
||||
}
|
||||
|
||||
const cText::eRender& cText::getRender() const
|
||||
{
|
||||
return m_render;
|
||||
}
|
||||
|
||||
//Private
|
||||
void cText::Text()
|
||||
{
|
||||
if((mpp_font != nullptr) && (*mpp_font != nullptr)) {
|
||||
SDL_Surface* sur = nullptr;
|
||||
switch (m_render)
|
||||
{
|
||||
case Solid:
|
||||
if ((sur = TTF_RenderText_Solid((*mpp_font)->getFont(m_size), m_text.c_str(), m_colour) ) == nullptr)
|
||||
cUtility::Inst().Message("Unable to render text. TTF_RenderText_Solid():", __AT__, cUtility::eTypeSDL::TTF);
|
||||
break;
|
||||
case Shaded:
|
||||
//sur = TTF_RenderText_Shaded(mp_font, text.c_str(), m_colour,
|
||||
break;
|
||||
case Blended:
|
||||
if ((sur = TTF_RenderText_Blended((*mpp_font)->getFont(m_size), m_text.c_str(), m_colour) ) == nullptr)
|
||||
cUtility::Inst().Message("Unable to render text. TTF_RenderText_Blended():", __AT__, cUtility::eTypeSDL::TTF);
|
||||
break;
|
||||
}
|
||||
setImage(sur);
|
||||
} else {
|
||||
SDL_Rect pos = { 0, 0, 0, 0 };
|
||||
//m_size == 25;
|
||||
SDL_Texture* texture = cRenderer::Inst().NewTexture(8 * m_text.length(), 8, SDL_TEXTUREACCESS_TARGET);
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
//int t = SDL_SetTextureColorMod(texture, 0, 255, 0);
|
||||
|
||||
// 376840196
|
||||
|
||||
|
||||
|
||||
//t = SDL_SetTextureAlphaMod(texture, 0);
|
||||
//SDL_fill
|
||||
//cRenderer::Inst().SetRenderTarget(texture);
|
||||
//SDL_Colour col = { 0, 255, 255, 255};
|
||||
//SDL_Rect re= { 0, 0, 100, 100};
|
||||
//cGFX::Inst().RoundedRectangle(pos, 4, col, texture);
|
||||
//cRenderer::Inst().RenderDrawColor(col);
|
||||
//cRenderer::Inst().RenderDrawRect(re, texture);
|
||||
|
||||
//cGFX::Inst().RoundedRectangle(pos, 4, col, texture);
|
||||
|
||||
//cRenderer::Inst().Render( texture, nullptr, nullptr);
|
||||
//SDL_RenderCopy(cRenderer::Inst().getRenderer(), texture, nullptr, nullptr);
|
||||
|
||||
//cRenderer::Inst().Render(texture, nullptr, nullptr);
|
||||
//cRenderer::Inst().ResetRenderTarget();
|
||||
|
||||
if (texture != nullptr) {
|
||||
|
||||
//cGFX::Inst().StringDefault(m_text, pos, m_colour);
|
||||
cGFX::Inst().StringDefault(m_text, pos, m_colour, texture);
|
||||
setImage(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "cPanel.hpp"
|
||||
|
||||
|
||||
using GUIEngine::cPanel;
|
||||
|
||||
/*static*/ const UtilityEngine::cString cPanel::sNAME = "panel";
|
||||
|
||||
cPanel::cPanel( cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, const GUIHelpers::eOrientation& orientation /*= sORIENTATION*/, const GUIHelpers::eAlign& align /*= sALIGN*/,
|
||||
const GUIHelpers::eLayout& layout /*= sLAYOUT*/, const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/,
|
||||
const GUIHelpers::Padding& padding /*= sPADDING*/, const cString& name /*= sNAME*/ )
|
||||
{
|
||||
Create( parent, id, orientation, align, layout, pos, size, padding, name );
|
||||
}
|
||||
|
||||
/*virtual*/ cPanel::~cPanel()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
/*virtual*/ void cPanel::Create(cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, const GUIHelpers::eOrientation& orientation /*= sORIENTATION*/, const GUIHelpers::eAlign& align /*= sALIGN*/,
|
||||
const GUIHelpers::eLayout& layout /*= sLAYOUT*/, const GUIHelpers::Position& pos /*= sPOSITION*/, const GUIHelpers::Size& size /*= sSIZE*/,
|
||||
const GUIHelpers::Padding& padding /*= sPADDING*/, const cString& name /*= sNAME*/)
|
||||
{
|
||||
cLayout::Create( parent, id, orientation, align, layout, pos, size, { 0,0,0,0 }, name );
|
||||
}
|
||||
|
||||
/*virtual*/ void cPanel::Display()
|
||||
{
|
||||
cLayout::Display();
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::eType cPanel::getType() const
|
||||
{
|
||||
return GUIHelpers::eType::CPANEL;
|
||||
}
|
||||
|
||||
/*virtual*/ const GUIHelpers::RGBA cPanel::getDebugColour() const
|
||||
{
|
||||
return GUIHelpers::RED;
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#include "cCourt.hpp"
|
||||
|
||||
using Equipment::cCourt;
|
||||
using Equipment::cBall;
|
||||
using Equipment::cPaddle;
|
||||
|
||||
using MathEngine::cCollision;
|
||||
using MathEngine::Vector4;
|
||||
using MathEngine::Vector2;
|
||||
|
||||
cCourt::cCourt( cBall* ball /*= nullptr*/, cPaddle* player1 /*= nullptr*/, cPaddle* player2 /*= nullptr*/, VideoEngine::cImage** image /*= nullptr*/ )
|
||||
: cSprite( 0, 0, 0, 0, 640, 480, image), mp_ball(ball), m_pause(false)
|
||||
{
|
||||
m_topWall.x = 0.0f;
|
||||
m_topWall.y = 0.0f;
|
||||
m_topWall.z = 640.0f;
|
||||
m_topWall.w = 14.0f;
|
||||
|
||||
m_bottomWall.x = 0.0f;
|
||||
m_bottomWall.y = 464.0f;
|
||||
m_bottomWall.z = 640.0f;
|
||||
m_bottomWall.w = 14.0f;
|
||||
|
||||
m_leftOff.x = 0.0f;
|
||||
m_leftOff.y = 0.0f;
|
||||
m_leftOff.z = 480.0f;
|
||||
m_leftOff.w = 1.0f;
|
||||
|
||||
m_rightOff.x = 640.0f;
|
||||
m_rightOff.y = 0.0f;
|
||||
m_rightOff.z = 480.0f;
|
||||
m_rightOff.w = 1.0f;
|
||||
|
||||
m_court.x = 0.0f;
|
||||
m_court.y = 15.0f;
|
||||
m_court.z = 640.0f;
|
||||
m_court.w = 450.0f;
|
||||
|
||||
mp_player[0] = player1;
|
||||
mp_player[1] = player2;
|
||||
|
||||
setImageArea();
|
||||
}
|
||||
|
||||
cCourt::~cCourt()
|
||||
{}
|
||||
|
||||
///Functions
|
||||
void cCourt::CheckCollision()
|
||||
{
|
||||
if (m_pause == false)
|
||||
{
|
||||
CheckPaddles();
|
||||
CheckWalls();
|
||||
CheckOffCourt();
|
||||
}
|
||||
}
|
||||
|
||||
void cCourt::Quit()
|
||||
{
|
||||
}
|
||||
|
||||
const bool cCourt::isPause() const
|
||||
{
|
||||
return m_pause;
|
||||
}
|
||||
|
||||
void cCourt::Pause()
|
||||
{
|
||||
m_pause = !m_pause;
|
||||
|
||||
mp_ball->Pause();
|
||||
mp_player[0]->Pause();
|
||||
mp_player[1]->Pause();
|
||||
}
|
||||
|
||||
//private:
|
||||
//Checks to see if the ball has hit a paddles and then if the paddles have hit a wall.
|
||||
void cCourt::CheckPaddles()
|
||||
{
|
||||
for (int count = 0; count <= 1; ++count)
|
||||
{
|
||||
//Check to see if the ball hit the Paddles.
|
||||
if (cCollision::BoundingBox(mp_player[count]->getPosition(), mp_ball->getPosition()) == true)
|
||||
mp_ball->BounceX();
|
||||
|
||||
//Check to see if the Paddles hit the top wall.
|
||||
if (cCollision::BoundingBox(mp_player[count]->getPosition(), m_topWall) == true)
|
||||
mp_player[count]->setPosY((long)m_topWall.w + 1);
|
||||
|
||||
//Check to see if the Paddles hit the bottom wall.
|
||||
if (cCollision::BoundingBox(mp_player[count]->getPosition(), m_bottomWall) == true)
|
||||
mp_player[count]->setPosY((long)m_bottomWall.y - 1);
|
||||
}
|
||||
}
|
||||
|
||||
//Cheaks to see if the ball has hit the provide wall.
|
||||
void cCourt::CheckWall(const Vector4& wall)
|
||||
{
|
||||
if (cCollision::BoundingBox(mp_ball->getPosition(), wall) == true)
|
||||
mp_ball->BounceY();
|
||||
}
|
||||
|
||||
//Cheaks to see if the ball has hit the wall.
|
||||
void cCourt::CheckWalls()
|
||||
{
|
||||
CheckWall(m_topWall);
|
||||
CheckWall(m_bottomWall);
|
||||
}
|
||||
|
||||
//Checks to see if the ball is off the provide side of the court.
|
||||
const bool cCourt::CheckOffCourt(const Vector4& offside)
|
||||
{
|
||||
bool rtn = false;
|
||||
|
||||
if (cCollision::BoundingBox(mp_ball->getPosition(), offside) == true)
|
||||
{
|
||||
mp_ball->setSpeed(0,0);
|
||||
rtn = true;
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
//Checks to see if the ball is off the court
|
||||
void cCourt::CheckOffCourt()
|
||||
{
|
||||
MathEngine::Vector2 mov = cCollision::Inside(m_court, mp_ball->getPosition());
|
||||
|
||||
if (mov.x != 0.0f)
|
||||
{
|
||||
// if (mov.x > 0.0f);
|
||||
// //point to player 1
|
||||
// if (mov.x < 0.0f);
|
||||
// //point to player 2
|
||||
}
|
||||
|
||||
if (mov.y != 0.0f)
|
||||
mp_ball->AddPosY((long)mov.y);
|
||||
|
||||
//if (CheckOffCourt(m_leftOff) == true)
|
||||
// ;
|
||||
//if (CheckOffCourt(m_rightOff) == true)
|
||||
// ;
|
||||
}
|
||||
Reference in New Issue
Block a user