1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

muzyka i może jakieś drobiazgi

This commit is contained in:
mateuszb 2007-06-19 14:41:03 +00:00
parent e491be6041
commit de95bb0753
5 changed files with 95 additions and 2 deletions

29
CMT.cpp
View File

@ -3,7 +3,9 @@
#include "stdafx.h"
#include "SDL.h"
#include "SDL_TTF.h"
#include "SDL_mixer.h"
#include "CBuildingHandler.h"
#include "SDL_Extensions.h"
#include <cmath>
#include <stdio.h>
#include <string.h>
@ -208,11 +210,36 @@ int _tmain(int argc, _TCHAR* argv[])
SDL_Surface *screen, *temp;
std::vector<SDL_Surface*> Sprites;
float i;
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER/*|SDL_INIT_EVENTTHREAD*/)==0)
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO/*|SDL_INIT_EVENTTHREAD*/)==0)
{
TTF_Init();
atexit(TTF_Quit);
atexit(SDL_Quit);
TNRB = TTF_OpenFont("Fonts\\tnrb.ttf",16);
//initializing audio
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048)==-1)
{
printf("Mix_OpenAudio: %s\n", Mix_GetError());
exit(2);
}
atexit(Mix_CloseAudio);
//audio initialized
Mix_Music *music;
music = Mix_LoadMUS("MP3\\MainMenuWoG.mp3");
if(!music)
{
printf("Mix_LoadMUS(\"MainMenuWoG.mp3\"): %s\n", Mix_GetError());
// this might be a critical error...
}
/*if(Mix_PlayMusic(music, -1)==-1) //uncomment this fragment to have music
{
printf("Mix_PlayMusic: %s\n", Mix_GetError());
// well, there's no music, but most games don't break without music...
}*/
screen = SDL_SetVideoMode(800,600,24,SDL_HWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/);
ekran = screen;
//FILE * zr = fopen("mal.txt","r");

View File

@ -149,3 +149,68 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot)
SDL_FreeSurface(first);
return ret;
}
//converts surface to cursor
SDL_Cursor * CSDL_Ext::SurfaceToCursor(SDL_Surface *image, int hx, int hy)
{
int w, x, y;
Uint8 *data, *mask, *d, *m, r, g, b;
Uint32 color;
SDL_Cursor *cursor;
w = (image->w + 7) / 8;
data = (Uint8 *)alloca(w * image->h * 2);
if (data == NULL)
return NULL;
memset(data, 0, w * image->h * 2);
mask = data + w * image->h;
if (SDL_MUSTLOCK(image))
SDL_LockSurface(image);
for (y = 0; y < image->h; y++)
{
d = data + y * w;
m = mask + y * w;
for (x = 0; x < image->w; x++)
{
color = CSDL_Ext::SDL_GetPixel(image, x, y);
if ((image->flags & SDL_SRCCOLORKEY) == 0 || color != image->format->colorkey)
{
SDL_GetRGB(color, image->format, &r, &g, &b);
color = (r + g + b) / 3;
m[x / 8] |= 128 >> (x & 7);
if (color < 128)
d[x / 8] |= 128 >> (x & 7);
}
}
}
if (SDL_MUSTLOCK(image))
SDL_UnlockSurface(image);
cursor = SDL_CreateCursor(data, mask, w, image->h, hx, hy);
return cursor;
}
Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
default:
return 0; /* shouldn't happen, but avoids warnings */
}
}

View File

@ -10,6 +10,8 @@ public:
static SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip
static SDL_Surface * rotate02(SDL_Surface * toRot);
static SDL_Surface * rotate03(SDL_Surface * toRot);
static SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy);
static Uint32 SDL_GetPixel(SDL_Surface *surface, int x, int y);
};
#endif // SDL_EXTENSIONS_H

BIN
h3m.txt

Binary file not shown.

View File

@ -12,5 +12,4 @@
#include <string>
#include <vector>
#include <fstream>
// TODO: reference additional headers your program requires here