Commit daa246a8 authored by Gerstrong's avatar Gerstrong

Added scroll and sound effects to the status screen. Now it's complete

parent 22ade2ee
......@@ -7,6 +7,9 @@
#include "CInventory.h"
#include "common/CBehaviorEngine.h"
#include "graphics/CGfxEngine.h"
#include "sdl/CVideoDriver.h"
#include "graphics/effects/CScrollEffect.h"
#include "CStatusScreenGalaxyEp4.h"
//#include "CStatusScreenGalaxyEp5.h"
//#include "CStatusScreenGalaxyEp6.h"
......@@ -16,6 +19,7 @@ CInventory::CInventory(Uint8& difficulty, const std::string& levelname) :
Item(difficulty),
m_HUD(Item.m_points, Item.m_lifes, Item.m_bullets),
mp_StatusScreen(NULL),
mp_StatusBgrnd(NULL),
m_LevelName(levelname)
{
reset();
......@@ -40,7 +44,19 @@ void CInventory::toggleStatusScreen()
mp_StatusScreen->m_showstatus = !mp_StatusScreen->m_showstatus;
if(mp_StatusScreen->m_showstatus)
{
mp_StatusScreen->GenerateStatus();
g_pVideoDriver->collectSurfaces();
mp_StatusBgrnd = SDL_DisplayFormat(g_pVideoDriver->mp_VideoEngine->getBlitSurface());
g_pGfxEngine->pushEffectPtr(new CScrollEffect(mp_StatusScreen->getStatusSfc(), mp_StatusBgrnd, 8));
}
else
{
g_pGfxEngine->pushEffectPtr(new CScrollEffect(mp_StatusScreen->getStatusSfc(), mp_StatusBgrnd, -8));
if(mp_StatusBgrnd)
SDL_FreeSurface(mp_StatusBgrnd);
mp_StatusBgrnd = NULL;
}
}
......
......@@ -17,6 +17,7 @@
#include "CStatusScreenGalaxy.h"
#include "SmartPointer.h"
#include <string>
#include <SDL.h>
class CInventory {
public:
......@@ -40,6 +41,7 @@ public:
CHUD m_HUD;
SmartPointer<CStatusScreenGalaxy> mp_StatusScreen;
SDL_Surface *mp_StatusBgrnd;
const std::string &m_LevelName;
};
......
......@@ -11,6 +11,7 @@
#include "graphics/CGfxEngine.h"
#include "sdl/CVideoDriver.h"
#include "sdl/CInput.h"
#include "sdl/sound/CSound.h"
#include "sdl/music/CMusic.h"
#include "StringUtils.h"
......@@ -84,12 +85,18 @@ void CPlayGameGalaxy::process()
if(m_Inventory.showStatus())
{
if(g_pInput->getPressedAnyCommand())
{
g_pSound->playSound(SOUND_STATUS_SLIDE_OUT);
m_Inventory.toggleStatusScreen();
}
}
else
{
if(g_pInput->getPressedCommand(IC_STATUS))
{
g_pSound->playSound(SOUND_STATUS_SLIDE_IN);
m_Inventory.toggleStatusScreen();
}
}
......@@ -146,8 +153,6 @@ void CPlayGameGalaxy::process()
m_LevelName = m_WorldMap.getLevelName();
m_WorldMap.loadAndPlayMusic();
}
}
void CPlayGameGalaxy::processInput()
......
......@@ -26,6 +26,10 @@ public:
// and start_x and start_y will return the start offset pixel where particular stuff can be drawn
void drawBase(SDL_Rect &EditRect);
// return the pointer to the allocated status screen surface
SDL_Surface *getStatusSfc()
{ return mp_StatusSurface; }
// Draw the status
void draw();
......
/*
* CScrollEffect.cpp
*
* Created on: 13.03.2011
* Author: gerstrong
*/
#include "CScrollEffect.h"
#include "sdl/CVideoDriver.h"
CScrollEffect::CScrollEffect(SDL_Surface *pScrollSurface, SDL_Surface *pBackground, Sint8 speed) :
m_Speed(speed),
m_ScrollPos(0),
mp_OldSurface(NULL),
mp_ScrollSurface(pScrollSurface)
{
mp_OldSurface = SDL_DisplayFormat(pBackground);
if(m_Speed < 0)
m_ScrollPos = mp_ScrollSurface->h;
}
void CScrollEffect::process()
{
SDL_Rect gameres = g_pVideoDriver->getGameResolution();
SDL_Rect dest = gameres;
SDL_Rect src = gameres;
src.y = mp_ScrollSurface->h-m_ScrollPos;
dest.h = m_ScrollPos;
SDL_BlitSurface( mp_OldSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
SDL_BlitSurface( mp_ScrollSurface, &src, g_pVideoDriver->getBlitSurface(), &dest);
if(m_Speed < 0)
{
if(m_ScrollPos + m_Speed < 0) m_ScrollPos = 0;
else m_ScrollPos += m_Speed;
if(m_ScrollPos == 0) m_finished = true;
}
else
{
if(m_ScrollPos + m_Speed > mp_OldSurface->h) m_ScrollPos = mp_ScrollSurface->h;
else m_ScrollPos += m_Speed;
if(m_ScrollPos == mp_ScrollSurface->h) m_finished = true;
}
}
CScrollEffect::~CScrollEffect() {
SDL_Rect gameres = g_pVideoDriver->getGameResolution();
// So the final image is loaded correctly
SDL_BlitSurface( mp_OldSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
if(m_Speed > 0)
SDL_BlitSurface( mp_ScrollSurface, &gameres, g_pVideoDriver->getBlitSurface(), &gameres);
if(mp_OldSurface) SDL_FreeSurface(mp_OldSurface);
}
/*
* CScrollEffect.h
*
* Created on: 13.03.2011
* Author: gerstrong
*/
#ifndef CSCROLLEFFECT_H_
#define CSCROLLEFFECT_H_
#include <SDL.h>
#include "CEffects.h"
class CScrollEffect : public CEffects {
public:
CScrollEffect(SDL_Surface *pScrollSurface, SDL_Surface *pBackground, Sint8 speed);
void process();
virtual ~CScrollEffect();
private:
Sint8 m_Speed;
Sint16 m_ScrollPos;
SDL_Surface *mp_OldSurface;
SDL_Surface *mp_ScrollSurface;
};
#endif /* CSCROLLEFFECT_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment