Commit 8f6ec9c0 authored by Gerhard Stein's avatar Gerhard Stein

Now bad TGA Code has been removed

parent 9b23527d
......@@ -614,6 +614,8 @@ void CObject::draw()
if( sprite == BLANKSPRITE || dontdraw )
return;
CSprite &Sprite = g_pGfxEngine->getSprite(sprite);
scrx = (m_Pos.x>>STC)-mp_Map->m_scrollx;
......
......@@ -190,7 +190,7 @@ private:
// defined under CPlayerItems.cpp
bool getGoodie(int px, int py);
void procGoodie(int tile, int mpx, int mpy);
void riseBonus(int spr, int x, int y);
void riseBonus(const int points, const int x, const int y);
void getBonuspoints(int numpts, int mpx, int mpy);
void incScore(int numpts);
void openDoor(int doortile, int doorsprite, int mpx, int mpy);
......
......@@ -322,22 +322,19 @@ void CPlayer::getBonuspoints(int numpts, int mpx, int mpy)
{
playSound(SOUND_GET_BONUS);
incScore(numpts);
if(mp_option[OPT_RISEBONUS].value)
int spr;
switch(numpts)
{
int spr;
switch(numpts)
{
case 100: spr = PT100_SPRITE; break;
case 200: spr = PT200_SPRITE; break;
case 500: spr = PT500_SPRITE; break;
case 1000: spr = PT1000_SPRITE; break;
case 5000: spr = PT5000_SPRITE; break;
default: spr = 0; break;
}
if (spr) riseBonus(spr, mpx, mpy);
}
if (spr) riseBonus(spr, mpx, mpy);
}
......
......@@ -91,9 +91,7 @@
#define SHOTUP_SPRITE (MAX_SPRITES-16) // rising single shot (ep3)
#define ANKHUP_SPRITE (MAX_SPRITES-17) // rising single shot (ep3)
#define GUNUP_SPRITE (MAX_SPRITES-18) // rising ray gun
#define SHOTS_SPRITE (MAX_SPRITES-19) // invincibility force field, used in editor and in "yorps have forcefields" mode
#define VERSION_SPRITE (MAX_SPRITES-20) // version text shown in lower-right corner at startup
#define LIVES_SPRITE (MAX_SPRITES-21) // says "Demo"
#define OSD_LIVES_SPRITE (MAX_SPRITES-22)
#define OSD_AMMO_SPRITE (MAX_SPRITES-23)
#define OSD_YORPS_SPRITE (MAX_SPRITES-24)
......
......@@ -144,7 +144,7 @@ bool CEGALatch::loadData( std::string &path, short episode, int version, unsigne
// extra icons. For example sliders are in that map
g_pGfxEngine->freeFonts();
g_pGfxEngine->createEmptyFontmaps(2);
g_pGfxEngine->createEmptyFontmaps(3);
g_pGfxEngine->getFont(0).loadinternalFont();
......@@ -153,6 +153,9 @@ bool CEGALatch::loadData( std::string &path, short episode, int version, unsigne
Font.CreateSurface( g_pGfxEngine->Palette.m_Palette, SDL_SWSURFACE );
sfc = Font.getSDLSurface();
g_pGfxEngine->getFont(2).loadAlternateFont();
if(SDL_MUSTLOCK(sfc)) SDL_LockSurface(sfc);
Uint8 *pixel = (Uint8*) sfc->pixels;
......
......@@ -20,6 +20,7 @@
#include "common/CObject.h"
#include "common/tga.h"
#include "CResourceLoader.h"
#include "graphics/CGfxEngine.h"
#include <SDL.h>
#include <stdio.h>
#include <string.h>
......@@ -205,7 +206,7 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
if(RawData){ delete[] RawData; RawData = NULL;}
// Now load the special TGA Sprites if some are available
LoadSpecialSprites( g_pGfxEngine->getSpriteVec() );
//LoadSpecialSprites( g_pGfxEngine->getSpriteVec() );
for(Uint16 s=0 ; s<g_pGfxEngine->getSpriteVec().size() ; s++)
{
......@@ -253,6 +254,8 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
g_pResourceLoader->setPermilage(500+percent);
}
LoadSpecialSprites( g_pGfxEngine->getSpriteVec() );
g_pResourceLoader->setPermilage(750);
// Apply the sprites for player 2,3 and 4
DerivePlayerSprites( g_pGfxEngine->getSpriteVec() );
......@@ -272,83 +275,15 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
return true;
}
// load a 32-bit RGBA TGA file into sprite 's', and add colors to the palette
// as needed so that it can be shown exactly as found in the file.
// returns nonzero on failure.
char CEGASprit::LoadTGASprite( const std::string &filename, CSprite &sprite )
{
byte *image, *base;
int x,y;
Uint16 w,h;
unsigned char r,g,b,a;
int c;
Uint8 *pixel, *maskpx;
// Look in local location than in global, if tga was not found!
if (!LoadTGA(filename, &image, w, h))
return 1;
base = image;
sprite.setSize(w, h);
sprite.createSurface( g_pVideoDriver->mp_VideoEngine->getBlitSurface()->flags, g_pGfxEngine->Palette.m_Palette );
SDL_Surface *sfc = sprite.getSDLSurface();
SDL_Surface *msksfc = sprite.getSDLMaskSurface();
if(SDL_MUSTLOCK(sfc)) SDL_LockSurface(sfc);
if(SDL_MUSTLOCK(msksfc)) SDL_LockSurface(msksfc);
pixel = (Uint8*) sfc->pixels;
maskpx = (Uint8*) msksfc->pixels;
for(y=h-1;y>=0;y--)
{
for(x=0;x<w;x++)
{
b = *image++; g = *image++; r = *image++; a = *image++;
if (a & 128)
{
c = g_pGfxEngine->Palette.getcolor(r, g, b);
if (c==-1) c = g_pGfxEngine->Palette.addcolor(r, g, b);
if (c==-1) return 1;
pixel[y*w + x] = c;
maskpx[y*w + x] = 15;
}
else
maskpx[y*w + x] = 0;
}
}
if(SDL_MUSTLOCK(msksfc)) SDL_UnlockSurface(msksfc);
if(SDL_MUSTLOCK(sfc)) SDL_UnlockSurface(sfc);
sprite.m_bboxX1=0;
sprite.m_bboxY1=0;
sprite.m_bboxX2=sprite.getWidth();
sprite.m_bboxY2=sprite.getHeight();
delete [] base;
return 0;
}
// load special clonekeen-specific sprites from the .raw files
// Code by Caitlin Shaw
void CEGASprit::LoadSpecialSprites( std::vector<CSprite> &sprite )
{
LoadTGASprite(getResourceFilename("gfx/100.tga", m_gamepath, false, true), sprite[PT100_SPRITE] );
LoadTGASprite(getResourceFilename("gfx/200.tga", m_gamepath, false, true), sprite[PT200_SPRITE] );
LoadTGASprite(getResourceFilename("gfx/500.tga", m_gamepath, false, true), sprite[PT500_SPRITE] );
LoadTGASprite(getResourceFilename("gfx/1000.tga", m_gamepath, false, true), sprite[PT1000_SPRITE] );
LoadTGASprite(getResourceFilename("gfx/5000.tga", m_gamepath, false, true), sprite[PT5000_SPRITE] );
LoadTGASprite(getResourceFilename("gfx/lives.tga", m_gamepath, false, true), sprite[LIVES_SPRITE] );
LoadTGASprite(getResourceFilename("gfx/shots.tga", m_gamepath, false, true), sprite[SHOTS_SPRITE] );
//LoadTGASprite("arrowud.tga", sprite[ARROWUD_SPRITE] );
//LoadTGASprite("arrowul.tga", sprite[ARROWUL_SPRITE] );
//LoadTGASprite("arrowur.tga", sprite[ARROWUR_SPRITE] );
//LoadTGASprite("arrowu.tga", sprite[ARROWU_SPRITE] );
//LoadTGASprite("arrowd.tga", sprite[ARROWD_SPRITE] );
sprite[PT100_SPRITE].generateSprite( 100 );
sprite[PT200_SPRITE].generateSprite( 200 );
sprite[PT500_SPRITE].generateSprite( 500 );
sprite[PT1000_SPRITE].generateSprite( 1000 );
sprite[PT5000_SPRITE].generateSprite( 5000 );
}
void CEGASprit::DerivePlayerSprites( std::vector<CSprite> &sprites )
......
......@@ -55,7 +55,7 @@ private:
// in DOS but are ignored here.
}*EGASpriteModell;
char LoadTGASprite( const std::string &filename, CSprite &sprite );
void generateSprite( const int points, CSprite &sprite );
void LoadSpecialSprites( std::vector<CSprite> &sprite );
void DerivePlayerSprites( std::vector<CSprite> &sprites );
void DeriveSpecialSprites( CTilemap &tilemap, std::vector<CSprite> &sprites );
......
......@@ -5,6 +5,7 @@
* Author: gerstrong
*/
#include "CRisingPoints.h"
#include "graphics/CGfxEngine.h"
// GotPoints object (rising numbers when you get a bonus item)
// (this wasn't in original Keen)
......@@ -22,6 +23,7 @@ CObject(p_map, x, y, OBJ_GOTPOINTS)
needinit = 0;
}
void CRisingPoints::process()
{
moveUp(GOTPOINTS_SPEED);
......
......@@ -7,9 +7,10 @@
#include "CFont.h"
#include "CPalette.h"
#include "../FindFile.h"
#include "../sdl/CVideoDriver.h"
#include "FindFile.h"
#include "sdl/CVideoDriver.h"
#include "CGFont.xpm"
#include "alternatefont.xpm"
#include "StringUtils.h"
#include "sdl/extensions.h"
#include <string.h>
......@@ -109,6 +110,17 @@ SDL_Surface *loadfromXPMData(const char **data, const SDL_PixelFormat *format, c
bool CFont::loadAlternateFont()
{
// Has the Surface to the entire font been loaded?
if(mFontSurface)
SDL_FreeSurface(mFontSurface);
SDL_Surface *blit = g_pVideoDriver->getBlitSurface();
mFontSurface = loadfromXPMData( alternatefont_xpm, blit->format, blit->flags );
return true;
}
bool CFont::loadinternalFont()
......
......@@ -27,6 +27,8 @@ public:
bool CreateSurface(SDL_Color *Palette, Uint32 Flags, Uint8 bpp=8, Uint16 width = 128, Uint16 height = 128);
SDL_Surface *getSDLSurface() { return mFontSurface; }
bool loadAlternateFont();
bool loadinternalFont();
void setWidthToCharacter(Uint8 width, Uint16 letter);
......
......@@ -7,9 +7,11 @@
#include "CSprite.h"
#include "CPalette.h"
#include "../FindFile.h"
#include "FindFile.h"
#include <string.h>
#include "../sdl/CVideoDriver.h"
#include "sdl/CVideoDriver.h"
#include "sdl/extensions.h"
#include "graphics/CGfxEngine.h"
#define SAFE_DELETE(x) { if(x) SDL_FreeSurface(x); x = NULL; }
......@@ -56,6 +58,79 @@ bool CSprite::optimizeSurface()
return false;
}
void CSprite::generateSprite( const int points )
{
Uint32 color = 0;
Uint8 r,g,b,a;
std::string pointStr = itoa(points);
setSize( pointStr.size()*8, 8);
createSurface( g_pVideoDriver->mp_VideoEngine->getBlitSurface()->flags, g_pGfxEngine->Palette.m_Palette );
optimizeSurface();
SDL_FillRect(m_surface, NULL, 0xFFFFFFFF);
CFont &smallFont = g_pGfxEngine->getFont(2);
// Create Text Borders TODO: Make this code to draw better looking fonts
smallFont.drawFont( m_surface, pointStr, -1, 0 );
smallFont.drawFont( m_surface, pointStr, 0, -1 );
smallFont.drawFont( m_surface, pointStr, 1, 0 );
smallFont.drawFont( m_surface, pointStr, 0, 1 );
// Now draw the alternate font. It just has another color.
smallFont.drawFont( m_surface, pointStr, 0, 0, true );
if(SDL_MUSTLOCK(m_surface)) SDL_LockSurface(m_surface);
// This makes the white pixel transparent TODO: This and other must get more elegant
Uint8 *pixel = (Uint8*)m_surface->pixels;
for( Uint8 y=0 ; y<m_surface->h ; y++ )
{
for( Uint8 x=0 ; x<m_surface->w ; x++ )
{
memcpy( &color, pixel, m_surface->format->BytesPerPixel );
SDL_GetRGBA( color, m_surface->format, &r, &g, &b, &a );
if( color == 0xFFFFFFFF ) // White
a = 0;
color = SDL_MapRGBA( m_surface->format, r, g, b, a );
memcpy( pixel, &color, m_surface->format->BytesPerPixel );
pixel += m_surface->format->BytesPerPixel;
}
}
if(SDL_MUSTLOCK(m_surface)) SDL_LockSurface(m_surface);
//SDL_BlitSurface(tilemap.getSDLSurface(), &tile_rect, src_sfc, NULL);
/*sprite.setSize( pointStr.size()*8, 8);
sprite.createSurface( g_pVideoDriver->mp_VideoEngine->getBlitSurface()->flags, g_pGfxEngine->Palette.m_Palette );
sprite.optimizeSurface();
SDL_Surface *sfc = sprite.getSDLSurface();
//SDL_Surface *msksfc = sprite.getSDLMaskSurface();
CFont &smallFont = g_pGfxEngine->getFont(2);
//smallFont.drawFont( sfc, pointStr, 0, 0 );
SDL_FillRect(sfc, NULL, 0x8800FF88);*/
m_bboxX1=0;
m_bboxY1=0;
m_bboxX2=getWidth();
m_bboxY2=getHeight();
}
bool CSprite::loadHQSprite( const std::string& filename )
{
if(m_surface)
......@@ -106,7 +181,6 @@ void CSprite::readMask(SDL_Surface *displaysurface)
Uint32 mask32 = (r+g+b)/(3*16);
mask = 15-mask32;
//mask = 15;
memcpy( maskpx, &mask, 1 );
......@@ -134,9 +208,11 @@ void CSprite::applyTransparency()
Uint32 colour, mask;
Uint8 r,g,b,a;
if(!m_masksurface) return;
if(!m_surface) return;
if(m_surface->format->BitsPerPixel == 8) // In case we did not call SDL_Displayformat
if(m_surface->format->BitsPerPixel == 8) // In case we did not call SDL_Displayformat before ???
{
SDL_BlitSurface(m_masksurface, NULL, m_surface, NULL);
return;
......
......@@ -25,6 +25,7 @@ public:
void copy( CSprite &Destination, SDL_Color *Palette );
void replaceSpriteColor( Uint16 find, Uint16 replace, Uint16 miny );
void generateSprite( const int points );
bool loadHQSprite( const std::string& filename );
void setSize(Uint8 w, Uint8 h) { m_xsize = w; m_ysize = h; }
......
This diff is collapsed.
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