line endiing fiasco!

This commit is contained in:
James Turk 2003-11-24 22:59:18 +00:00
parent c4faafa8ca
commit 18ecb1905d
6 changed files with 631 additions and 631 deletions

View File

@ -1,86 +1,86 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
ZEngine is Licensed under a BSD-style license. ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions. This example file is in the public domain, it may be used with no restrictions.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZFontTest.cpp,v 1.17 2003/10/21 01:17:35 cozman Exp $*/ /*$Id: ZFontTest.cpp,v 1.18 2003/11/24 22:59:18 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
using namespace std; using namespace std;
using namespace ZE; using namespace ZE;
bool Initialize() bool Initialize()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf"); ZConfigFile cfg("tests.zcf");
int w,h,bpp,rate; int w,h,bpp,rate;
bool fs; bool fs;
string title; string title;
w = cfg.GetInt("ZFontTest","width",800); w = cfg.GetInt("ZFontTest","width",800);
h = cfg.GetInt("ZFontTest","height",600); h = cfg.GetInt("ZFontTest","height",600);
bpp = cfg.GetInt("ZFontTest","bpp",32); bpp = cfg.GetInt("ZFontTest","bpp",32);
fs = cfg.GetBool("ZFontTest","fullscreen",false); fs = cfg.GetBool("ZFontTest","fullscreen",false);
title = cfg.GetString("ZFontTest","title","ZFont Test"); title = cfg.GetString("ZFontTest","title","ZFont Test");
rate = cfg.GetInt("ZFontTest","framerate",60); rate = cfg.GetInt("ZFontTest","framerate",60);
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
//Open and Setup all the Fonts and Create Images// //Open and Setup all the Fonts and Create Images//
ZImage text[6]; ZImage text[6];
ZFont almonte("data/almontew.ttf",48), axaxax("data/axaxax.ttf",32), betsy;//("data/betsy.ttf",64); ZFont almonte("data/almontew.ttf",48), axaxax("data/axaxax.ttf",32), betsy;//("data/betsy.ttf",64);
betsy.OpenFromZip("data/data.zip","betsy.ttf",20); betsy.OpenFromZip("data/data.zip","betsy.ttf",20);
betsy.Resize(64); betsy.Resize(64);
almonte.SetColor(255,0,0,128); almonte.SetColor(255,0,0,128);
almonte.DrawText("This is the font test.",text[0]); almonte.DrawText("This is the font test.",text[0]);
axaxax.SetColor(0,255,255); axaxax.SetColor(0,255,255);
axaxax.SetStyle(true,false,false); axaxax.SetStyle(true,false,false);
axaxax.DrawText("Fonts free from: ",text[1]); axaxax.DrawText("Fonts free from: ",text[1]);
axaxax.SetStyle(false,true,true); axaxax.SetStyle(false,true,true);
axaxax.DrawText("http://larabiefonts.com/",text[2]); axaxax.DrawText("http://larabiefonts.com/",text[2]);
almonte.SetBGColor(0,0,128); almonte.SetBGColor(0,0,128);
almonte.SetColor(0,0,255); almonte.SetColor(0,0,255);
almonte.SetStyle(false,true,false); almonte.SetStyle(false,true,false);
almonte.DrawShadedText("Shaded, italic, bold and underlined tested. ",text[3]); almonte.DrawShadedText("Shaded, italic, bold and underlined tested. ",text[3]);
betsy.SetColor(255,255,255); betsy.SetColor(255,255,255);
betsy.DrawText("Font test successful.",text[4]); betsy.DrawText("Font test successful.",text[4]);
do do
{ {
//In the active loop, check events first// //In the active loop, check events first//
engine->CheckEvents(); engine->CheckEvents();
if(engine->IsActive()) if(engine->IsActive())
{ {
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
betsy.DrawText(FormatStr("FPS: %.2f",engine->GetFramerate()),text[5]); betsy.DrawText(FormatStr("FPS: %.2f",engine->GetFramerate()),text[5]);
engine->Clear(); //clear screen engine->Clear(); //clear screen
//draw the images// //draw the images//
for(int i=0; i <= 5; i++) for(int i=0; i <= 5; i++)
text[i].Draw(10*i,50*i); text[i].Draw(10*i,50*i);
engine->Update(); //update the screen engine->Update(); //update the screen
} }
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(Initialize()) if(Initialize())
Test(); Test();
ZEngine::ReleaseInstance(); ZEngine::ReleaseInstance();
return 0; return 0;
} }

View File

@ -1,143 +1,143 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
ZEngine is Licensed under a BSD-style license. ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions. This example file is in the public domain, it may be used with no restrictions.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZImageTest.cpp,v 1.27 2003/11/14 21:39:51 cozman Exp $*/ /*$Id: ZImageTest.cpp,v 1.28 2003/11/24 22:59:18 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
using namespace std; using namespace std;
using namespace ZE; using namespace ZE;
bool Initialize() bool Initialize()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf"); ZConfigFile cfg("tests.zcf");
int w,h,bpp,rate; int w,h,bpp,rate;
bool fs; bool fs;
std::string title; std::string title;
w = cfg.GetInt("ZImageTest","width",800); w = cfg.GetInt("ZImageTest","width",800);
h = cfg.GetInt("ZImageTest","height",600); h = cfg.GetInt("ZImageTest","height",600);
bpp = cfg.GetInt("ZImageTest","bpp",32); bpp = cfg.GetInt("ZImageTest","bpp",32);
fs = cfg.GetBool("ZImageTest","fullscreen",true); fs = cfg.GetBool("ZImageTest","fullscreen",true);
title = cfg.GetString("ZImageTest","title","ZImage Test"); title = cfg.GetString("ZImageTest","title","ZImage Test");
rate = cfg.GetInt("ZImageTest","framerate",60); rate = cfg.GetInt("ZImageTest","framerate",60);
engine->SetDesiredFramerate(rate); engine->SetDesiredFramerate(rate);
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
float angle=0.0f,movDelta; float angle=0.0f,movDelta;
float alpha=128.0f,alphaDelta=15.0f; float alpha=128.0f,alphaDelta=15.0f;
SDL_Surface *temp; SDL_Surface *temp;
//Open and Setup all the Images// //Open and Setup all the Images//
ZImage image1,image2,image3,image4,textImage; ZImage image1,image2,image3,image4,textImage;
ZFont font("data/almontew.ttf",30); ZFont font("data/almontew.ttf",30);
ZRect clipRect(400,300,30,30); ZRect clipRect(400,300,30,30);
font.SetColor(0,255,0); font.SetColor(0,255,0);
font.SetBGColor(0,0,255); font.SetBGColor(0,0,255);
temp = SDL_LoadBMP("data/rainbow.bmp"); //this is a separate surface temp = SDL_LoadBMP("data/rainbow.bmp"); //this is a separate surface
image1.OpenFromZip("data/data.zip","test02.bmp"); image1.OpenFromZip("data/data.zip","test02.bmp");
image1.SetColorKey(255,0,255); image1.SetColorKey(255,0,255);
image2.Open("data/test01.bmp"); image2.Open("data/test01.bmp");
image2.SetColorKey(255,0,255); image2.SetColorKey(255,0,255);
image3.OpenFromImage(image2.Surface(),5,5,20,20); image3.OpenFromImage(image2.Surface(),5,5,20,20);
image4.Attach(temp); //this attaches the surface into itself image4.Attach(temp); //this attaches the surface into itself
#if (GFX_BACKEND == ZE_OGL) #if (GFX_BACKEND == ZE_OGL)
image4.Resize(400,300); image4.Resize(400,300);
image4.Flip(true,false); image4.Flip(true,false);
#endif #endif
font.DrawShadedText("ZImage Test.",textImage); font.DrawShadedText("ZImage Test.",textImage);
do do
{ {
//In the active loop, check events first// //In the active loop, check events first//
engine->CheckEvents(); engine->CheckEvents();
if(engine->IsActive()) if(engine->IsActive())
{ {
if(engine->ImagesNeedReload()) if(engine->ImagesNeedReload())
{ {
image1.Reload(); image1.Reload();
image2.Reload(); image2.Reload();
image3.Reload(); image3.Reload();
image4.Reload(); image4.Reload();
textImage.Reload(); textImage.Reload();
engine->SetReloadNeed(false); //very important for speed, without this you'd be reloading every frame engine->SetReloadNeed(false); //very important for speed, without this you'd be reloading every frame
} }
//movement// //movement//
movDelta = static_cast<float>(engine->GetFrameTime()*30); movDelta = static_cast<float>(engine->GetFrameTime()*30);
if(engine->KeyIsPressed(SDLK_LEFT)) if(engine->KeyIsPressed(SDLK_LEFT))
clipRect.MoveRel(-movDelta,0); clipRect.MoveRel(-movDelta,0);
if(engine->KeyIsPressed(SDLK_RIGHT)) if(engine->KeyIsPressed(SDLK_RIGHT))
clipRect.MoveRel(movDelta,0); clipRect.MoveRel(movDelta,0);
if(engine->KeyIsPressed(SDLK_UP)) if(engine->KeyIsPressed(SDLK_UP))
clipRect.MoveRel(0,-movDelta); clipRect.MoveRel(0,-movDelta);
if(engine->KeyIsPressed(SDLK_DOWN)) if(engine->KeyIsPressed(SDLK_DOWN))
clipRect.MoveRel(0,movDelta); clipRect.MoveRel(0,movDelta);
if(engine->KeyIsPressed(SDLK_EQUALS)) if(engine->KeyIsPressed(SDLK_EQUALS))
{ {
clipRect.MoveRel(-1,-1); clipRect.MoveRel(-1,-1);
clipRect.ResizeRel(2,2); clipRect.ResizeRel(2,2);
} }
if(engine->KeyIsPressed(SDLK_MINUS)) if(engine->KeyIsPressed(SDLK_MINUS))
{ {
clipRect.MoveRel(1,1); clipRect.MoveRel(1,1);
clipRect.ResizeRel(-2,-2); clipRect.ResizeRel(-2,-2);
} }
if(engine->KeyIsPressed(SDLK_s)) if(engine->KeyIsPressed(SDLK_s))
engine->ToggleFullscreen(); engine->ToggleFullscreen();
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
engine->Clear(); //clear screen engine->Clear(); //clear screen
//draw the images// //draw the images//
alpha += alphaDelta*engine->GetFrameTime(); alpha += alphaDelta*engine->GetFrameTime();
if(alpha >= 255 || alpha <= 0) if(alpha >= 255 || alpha <= 0)
alphaDelta *= -1.0f; alphaDelta *= -1.0f;
image1.SetAlpha(static_cast<Uint8>(alpha)); image1.SetAlpha(static_cast<Uint8>(alpha));
image1.Draw(0,0); image1.Draw(0,0);
#if (GFX_BACKEND == ZE_OGL) #if (GFX_BACKEND == ZE_OGL)
image2.DrawRotated(100,0,angle); image2.DrawRotated(100,0,angle);
angle+=(150*engine->GetFrameTime()); angle+=(150*engine->GetFrameTime());
if(angle > 360) if(angle > 360)
angle = 0.0f; angle = 0.0f;
#elif (GFX_BACKEND == ZE_SDL) #elif (GFX_BACKEND == ZE_SDL)
image2.Draw(100,0); image2.Draw(100,0);
#endif #endif
image3.Draw(200,0); image3.Draw(200,0);
image4.DrawClipped(400,300,clipRect); image4.DrawClipped(400,300,clipRect);
textImage.Draw(0,100); textImage.Draw(0,100);
engine->Update(); //update the screen engine->Update(); //update the screen
} }
else else
engine->Delay(10); engine->Delay(10);
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(Initialize()) if(Initialize())
Test(); Test();
return 0; return 0;
} }

View File

@ -1,96 +1,96 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
ZEngine is Licensed under a BSD-style license. ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions. This example file is in the public domain, it may be used with no restrictions.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZMouseTest.cpp,v 1.19 2003/10/21 01:17:35 cozman Exp $*/ /*$Id: ZMouseTest.cpp,v 1.20 2003/11/24 22:59:18 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
using namespace std; using namespace std;
using namespace ZE; using namespace ZE;
bool Initialize() bool Initialize()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf"); ZConfigFile cfg("tests.zcf");
int w,h,bpp,rate; int w,h,bpp,rate;
bool fs; bool fs;
std::string title; std::string title;
w = cfg.GetInt("ZMouseTest","width",800); w = cfg.GetInt("ZMouseTest","width",800);
h = cfg.GetInt("ZMouseTest","height",600); h = cfg.GetInt("ZMouseTest","height",600);
bpp = cfg.GetInt("ZMouseTest","bpp",32); bpp = cfg.GetInt("ZMouseTest","bpp",32);
fs = cfg.GetBool("ZMouseTest","fullscreen",false); fs = cfg.GetBool("ZMouseTest","fullscreen",false);
title = cfg.GetString("ZMouseTest","title","ZMouse Test"); title = cfg.GetString("ZMouseTest","title","ZMouse Test");
rate = cfg.GetInt("ZMouseTest","framerate",60); rate = cfg.GetInt("ZMouseTest","framerate",60);
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
//Open and Setup all the Images// //Open and Setup all the Images//
ZImage text[3], cursor("data/cursor.bmp"); ZImage text[3], cursor("data/cursor.bmp");
ZFont font("data/almontew.ttf",30); ZFont font("data/almontew.ttf",30);
SDL_Rect textRect; SDL_Rect textRect;
engine->HideCursor(); engine->HideCursor();
cursor.SetColorKey(255,0,255); cursor.SetColorKey(255,0,255);
font.SetColor(0,255,0); font.SetColor(0,255,0);
font.SetBGColor(0,0,255); font.SetBGColor(0,0,255);
font.DrawText("Mouse Test",text[0]); font.DrawText("Mouse Test",text[0]);
font.DrawShadedText("Mouse Test",text[1]); font.DrawShadedText("Mouse Test",text[1]);
textRect.x = textRect.y = 100; textRect.x = textRect.y = 100;
textRect.w = font.StringWidth("Mouse Test"); textRect.w = font.StringWidth("Mouse Test");
textRect.h = font.StringHeight("Mouse Test"); textRect.h = font.StringHeight("Mouse Test");
do do
{ {
//In the active loop, check events first// //In the active loop, check events first//
engine->CheckEvents(); engine->CheckEvents();
if(engine->IsActive()) if(engine->IsActive())
{ {
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
//show where mouse is (clicked or not)// //show where mouse is (clicked or not)//
if(engine->RButtonPressed()) if(engine->RButtonPressed())
font.DrawText(FormatStr("Right button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]); font.DrawText(FormatStr("Right button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
else if(engine->LButtonPressed()) else if(engine->LButtonPressed())
font.DrawText(FormatStr("Left button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]); font.DrawText(FormatStr("Left button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
else if(engine->MButtonPressed()) else if(engine->MButtonPressed())
font.DrawText(FormatStr("Middle button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]); font.DrawText(FormatStr("Middle button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
else else
font.DrawText(FormatStr("Mouse at %d,%d",engine->MouseX(),engine->MouseY()),text[2]); font.DrawText(FormatStr("Mouse at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
engine->Clear(); //clear screen engine->Clear(); //clear screen
//draw the images// //draw the images//
text[engine->MouseInRect(&textRect)].Draw(100,100); text[engine->MouseInRect(&textRect)].Draw(100,100);
text[2].Draw(0,0); text[2].Draw(0,0);
cursor.Draw(engine->MouseX()-8,engine->MouseY()-8); cursor.Draw(engine->MouseX()-8,engine->MouseY()-8);
engine->Update(); //update the screen engine->Update(); //update the screen
} }
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(Initialize()) if(Initialize())
Test(); Test();
ZEngine::ReleaseInstance(); ZEngine::ReleaseInstance();
return 0; return 0;
} }

View File

@ -1,109 +1,109 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
ZEngine is Licensed under a BSD-style license. ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions. This example file is in the public domain, it may be used with no restrictions.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZMusicTest.cpp,v 1.19 2003/10/21 01:17:35 cozman Exp $*/ /*$Id: ZMusicTest.cpp,v 1.20 2003/11/24 22:59:18 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
using namespace std; using namespace std;
using namespace ZE; using namespace ZE;
bool Initialize() bool Initialize()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf"); ZConfigFile cfg("tests.zcf");
int w,h,bpp,rate; int w,h,bpp,rate;
bool fs; bool fs;
std::string title; std::string title;
w = cfg.GetInt("ZMusicTest","width",800); w = cfg.GetInt("ZMusicTest","width",800);
h = cfg.GetInt("ZMusicTest","height",600); h = cfg.GetInt("ZMusicTest","height",600);
bpp = cfg.GetInt("ZMusicTest","bpp",32); bpp = cfg.GetInt("ZMusicTest","bpp",32);
fs = cfg.GetBool("ZMusicTest","fullscreen",false); fs = cfg.GetBool("ZMusicTest","fullscreen",false);
title = cfg.GetString("ZMusicTest","title","ZMusic Test"); title = cfg.GetString("ZMusicTest","title","ZMusic Test");
rate = cfg.GetInt("ZMusicTest","framerate",60); rate = cfg.GetInt("ZMusicTest","framerate",60);
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZMusic song("data/music.ogg"); ZMusic song("data/music.ogg");
ZFont font("data/almontew.ttf",48); ZFont font("data/almontew.ttf",48);
ZImage text[4]; ZImage text[4];
if(!song.IsLoaded()) //this executes if there is no music.ogg file if(!song.IsLoaded()) //this executes if there is no music.ogg file
{ {
engine->Clear(); engine->Clear();
engine->CreateDisplay(800,70,32,false,"ZMusic Test"); engine->CreateDisplay(800,70,32,false,"ZMusic Test");
font.DrawText("Music.ogg does not exist, please read music.txt.",text[0]); font.DrawText("Music.ogg does not exist, please read music.txt.",text[0]);
text[0].Draw(0,0); text[0].Draw(0,0);
engine->Update(); engine->Update();
do do
{ {
engine->CheckEvents(); engine->CheckEvents();
engine->Update(); engine->Update();
} while(!engine->QuitRequested()); } while(!engine->QuitRequested());
} }
else //this is the actual example else //this is the actual example
{ {
font.DrawText("(P)ause\t(U)npause\t(R)ewind",text[0]); font.DrawText("(P)ause\t(U)npause\t(R)ewind",text[0]);
font.DrawText("(F)ade Out\t(H)alt\t",text[1]); font.DrawText("(F)ade Out\t(H)alt\t",text[1]);
font.DrawText("Space - Play\t Up/Down - Control Volume",text[2]); font.DrawText("Space - Play\t Up/Down - Control Volume",text[2]);
song.Play(); song.Play();
do do
{ {
//In the active loop, check events first// //In the active loop, check events first//
engine->CheckEvents(); engine->CheckEvents();
if(engine->IsActive()) if(engine->IsActive())
{ {
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
if(engine->KeyIsPressed(SDLK_r)) if(engine->KeyIsPressed(SDLK_r))
song.Rewind(); song.Rewind();
if(engine->KeyIsPressed(SDLK_p)) if(engine->KeyIsPressed(SDLK_p))
song.Pause(); song.Pause();
if(engine->KeyIsPressed(SDLK_u)) if(engine->KeyIsPressed(SDLK_u))
song.Unpause(); song.Unpause();
if(engine->KeyIsPressed(SDLK_f)) if(engine->KeyIsPressed(SDLK_f))
song.Stop(5000); song.Stop(5000);
if(engine->KeyIsPressed(SDLK_h)) if(engine->KeyIsPressed(SDLK_h))
song.Stop(); song.Stop();
if(engine->KeyIsPressed(SDLK_SPACE)) if(engine->KeyIsPressed(SDLK_SPACE))
song.Play(); song.Play();
if(engine->KeyIsPressed(SDLK_UP)) if(engine->KeyIsPressed(SDLK_UP))
song.SetVolume(song.Volume()+1); song.SetVolume(song.Volume()+1);
if(engine->KeyIsPressed(SDLK_DOWN)) if(engine->KeyIsPressed(SDLK_DOWN))
song.SetVolume(song.Volume()-1); song.SetVolume(song.Volume()-1);
font.DrawText(FormatStr("Volume: %d",song.Volume()),text[3]); font.DrawText(FormatStr("Volume: %d",song.Volume()),text[3]);
engine->Clear(); //clear screen engine->Clear(); //clear screen
for(int i=0; i < 4; i++) for(int i=0; i < 4; i++)
text[i].Draw(0,i*50); text[i].Draw(0,i*50);
engine->Update(); //update the screen engine->Update(); //update the screen
} }
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
} }
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(Initialize()) if(Initialize())
Test(); Test();
ZEngine::ReleaseInstance(); ZEngine::ReleaseInstance();
return 0; return 0;
} }

View File

@ -1,89 +1,89 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
ZEngine is Licensed under a BSD-style license. ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions. This example file is in the public domain, it may be used with no restrictions.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZRectTest.cpp,v 1.20 2003/10/21 01:17:35 cozman Exp $*/ /*$Id: ZRectTest.cpp,v 1.21 2003/11/24 22:59:18 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
using namespace std; using namespace std;
using namespace ZE; using namespace ZE;
bool Initialize() bool Initialize()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf"); ZConfigFile cfg("tests.zcf");
int w,h,bpp,rate; int w,h,bpp,rate;
bool fs; bool fs;
std::string title; std::string title;
w = cfg.GetInt("ZRectTest","Width",800); w = cfg.GetInt("ZRectTest","Width",800);
h = cfg.GetInt("ZRectTest","height",600); h = cfg.GetInt("ZRectTest","height",600);
bpp = cfg.GetInt("ZRectTest","bpp",32); bpp = cfg.GetInt("ZRectTest","bpp",32);
fs = cfg.GetBool("ZRectTest","fullscreen",false); fs = cfg.GetBool("ZRectTest","fullscreen",false);
title = cfg.GetString("ZRectTest","title","ZRect Test"); title = cfg.GetString("ZRectTest","title","ZRect Test");
rate = cfg.GetInt("ZRectTest","framerate",60); rate = cfg.GetInt("ZRectTest","framerate",60);
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZRect moveRect(0,0,25,25),stillRect(100,100,100,100); ZRect moveRect(0,0,25,25),stillRect(100,100,100,100);
float movDelta; float movDelta;
do do
{ {
//In the active loop, check events first// //In the active loop, check events first//
engine->CheckEvents(); engine->CheckEvents();
if(engine->IsActive()) if(engine->IsActive())
{ {
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
//movement// //movement//
movDelta = static_cast<float>(engine->GetFrameTime()*30); movDelta = static_cast<float>(engine->GetFrameTime()*30);
if(engine->KeyIsPressed(SDLK_LEFT)) if(engine->KeyIsPressed(SDLK_LEFT))
moveRect.MoveRel(-movDelta,0); moveRect.MoveRel(-movDelta,0);
if(engine->KeyIsPressed(SDLK_RIGHT)) if(engine->KeyIsPressed(SDLK_RIGHT))
moveRect.MoveRel(movDelta,0); moveRect.MoveRel(movDelta,0);
if(engine->KeyIsPressed(SDLK_UP)) if(engine->KeyIsPressed(SDLK_UP))
moveRect.MoveRel(0,-movDelta); moveRect.MoveRel(0,-movDelta);
if(engine->KeyIsPressed(SDLK_DOWN)) if(engine->KeyIsPressed(SDLK_DOWN))
moveRect.MoveRel(0,movDelta); moveRect.MoveRel(0,movDelta);
if(engine->KeyIsPressed(SDLK_EQUALS)) if(engine->KeyIsPressed(SDLK_EQUALS))
{ {
moveRect.MoveRel(-1,-1); moveRect.MoveRel(-1,-1);
moveRect.ResizeRel(2,2); moveRect.ResizeRel(2,2);
} }
if(engine->KeyIsPressed(SDLK_MINUS)) if(engine->KeyIsPressed(SDLK_MINUS))
{ {
moveRect.MoveRel(1,1); moveRect.MoveRel(1,1);
moveRect.ResizeRel(-2,-2); moveRect.ResizeRel(-2,-2);
} }
engine->Clear(); engine->Clear();
moveRect.Draw(255,0,0,128); moveRect.Draw(255,0,0,128);
stillRect.Draw(0,0,255,128); stillRect.Draw(0,0,255,128);
moveRect.Intersection(stillRect).Draw(0,255,0); moveRect.Intersection(stillRect).Draw(0,255,0);
engine->Update(); engine->Update();
} }
} while(!engine->QuitRequested()); } while(!engine->QuitRequested());
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(Initialize()) if(Initialize())
Test(); Test();
ZEngine::ReleaseInstance(); ZEngine::ReleaseInstance();
return 0; return 0;
} }

View File

@ -1,108 +1,108 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
ZEngine is Licensed under a BSD-style license. ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions. This example file is in the public domain, it may be used with no restrictions.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZSoundTest.cpp,v 1.19 2003/10/21 01:17:35 cozman Exp $*/ /*$Id: ZSoundTest.cpp,v 1.20 2003/11/24 22:59:18 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
using namespace std; using namespace std;
using namespace ZE; using namespace ZE;
bool Initialize() bool Initialize()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf"); ZConfigFile cfg("tests.zcf");
int w,h,bpp,rate; int w,h,bpp,rate;
bool fs; bool fs;
std::string title; std::string title;
w = cfg.GetInt("ZSoundTest","width",800); w = cfg.GetInt("ZSoundTest","width",800);
h = cfg.GetInt("ZSoundTest","height",600); h = cfg.GetInt("ZSoundTest","height",600);
bpp = cfg.GetInt("ZSoundTest","bpp",32); bpp = cfg.GetInt("ZSoundTest","bpp",32);
fs = cfg.GetBool("ZSoundTest","fullscreen",false); fs = cfg.GetBool("ZSoundTest","fullscreen",false);
title = cfg.GetString("ZSoundTest","title","ZSound Test"); title = cfg.GetString("ZSoundTest","title","ZSound Test");
rate = cfg.GetInt("ZSoundTest","framerate",60); rate = cfg.GetInt("ZSoundTest","framerate",60);
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
std::string name[5] = { "monkey", "rooster", "kick", "carcrash", "whip" }; std::string name[5] = { "monkey", "rooster", "kick", "carcrash", "whip" };
ZSound sample[5]; ZSound sample[5];
ZFont font("data/almontew.ttf",48); ZFont font("data/almontew.ttf",48);
ZImage text[6]; ZImage text[6];
int sampleNum = 0; int sampleNum = 0;
for(int i=0; i < 4; i++) for(int i=0; i < 4; i++)
sample[i].OpenFromZip("data/data.zip",FormatStr("%s.wav",name[i].c_str())); sample[i].OpenFromZip("data/data.zip",FormatStr("%s.wav",name[i].c_str()));
sample[4].Open("data/whip.wav"); sample[4].Open("data/whip.wav");
font.DrawText("(P)ause\t(U)npause",text[0]); font.DrawText("(P)ause\t(U)npause",text[0]);
font.DrawText("(F)ade Out\t(H)alt\t",text[1]); font.DrawText("(F)ade Out\t(H)alt\t",text[1]);
font.DrawText("Space - Play\t Up/Down - Control Volume",text[2]); font.DrawText("Space - Play\t Up/Down - Control Volume",text[2]);
font.DrawText("1-5 Change Sample Being Controlled",text[3]); font.DrawText("1-5 Change Sample Being Controlled",text[3]);
do do
{ {
//In the active loop, check events first// //In the active loop, check events first//
engine->CheckEvents(); engine->CheckEvents();
if(engine->IsActive()) if(engine->IsActive())
{ {
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
if(engine->KeyIsPressed(SDLK_1)) if(engine->KeyIsPressed(SDLK_1))
sampleNum = 0; sampleNum = 0;
if(engine->KeyIsPressed(SDLK_2)) if(engine->KeyIsPressed(SDLK_2))
sampleNum = 1; sampleNum = 1;
if(engine->KeyIsPressed(SDLK_3)) if(engine->KeyIsPressed(SDLK_3))
sampleNum = 2; sampleNum = 2;
if(engine->KeyIsPressed(SDLK_4)) if(engine->KeyIsPressed(SDLK_4))
sampleNum = 3; sampleNum = 3;
if(engine->KeyIsPressed(SDLK_5)) if(engine->KeyIsPressed(SDLK_5))
sampleNum = 4; sampleNum = 4;
if(engine->KeyIsPressed(SDLK_p)) if(engine->KeyIsPressed(SDLK_p))
sample[sampleNum].Pause(); sample[sampleNum].Pause();
if(engine->KeyIsPressed(SDLK_u)) if(engine->KeyIsPressed(SDLK_u))
sample[sampleNum].Unpause(); sample[sampleNum].Unpause();
if(engine->KeyIsPressed(SDLK_f)) if(engine->KeyIsPressed(SDLK_f))
sample[sampleNum].Stop(5000); sample[sampleNum].Stop(5000);
if(engine->KeyIsPressed(SDLK_h)) if(engine->KeyIsPressed(SDLK_h))
sample[sampleNum].Stop(); sample[sampleNum].Stop();
if(engine->KeyIsPressed(SDLK_SPACE)) if(engine->KeyIsPressed(SDLK_SPACE))
sample[sampleNum].Play(); sample[sampleNum].Play();
if(engine->KeyIsPressed(SDLK_UP)) if(engine->KeyIsPressed(SDLK_UP))
sample[sampleNum].SetVolume(sample[sampleNum].Volume()+1); sample[sampleNum].SetVolume(sample[sampleNum].Volume()+1);
if(engine->KeyIsPressed(SDLK_DOWN)) if(engine->KeyIsPressed(SDLK_DOWN))
sample[sampleNum].SetVolume(sample[sampleNum].Volume()-1); sample[sampleNum].SetVolume(sample[sampleNum].Volume()-1);
font.DrawText(FormatStr("Volume: %d",sample[sampleNum].Volume()),text[4]); font.DrawText(FormatStr("Volume: %d",sample[sampleNum].Volume()),text[4]);
font.DrawText(FormatStr("Sample: %s",name[sampleNum].c_str()),text[5]); font.DrawText(FormatStr("Sample: %s",name[sampleNum].c_str()),text[5]);
engine->Clear(); //clear screen engine->Clear(); //clear screen
for(int i=0; i < 6; i++) for(int i=0; i < 6; i++)
text[i].Draw(0,i*50); text[i].Draw(0,i*50);
engine->Update(); //update the screen engine->Update(); //update the screen
} }
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(Initialize()) if(Initialize())
Test(); Test();
ZEngine::ReleaseInstance(); ZEngine::ReleaseInstance();
return 0; return 0;
} }