2002-12-01 07:56:17 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
This file is Part of the ZEngine Library for SDL Game Development.
|
|
|
|
Copyright (C) 2002 ConceptOfZero.net
|
|
|
|
|
|
|
|
Licensed under the BSD License, see licensing.txt.
|
|
|
|
|
|
|
|
The maintainer of this library is James Turk (jturk@conceptofzero.net)
|
|
|
|
and the home of this Library is http://www.conceptofzero.net/
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include <ZEngine.h>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
using namespace ZE;
|
|
|
|
|
|
|
|
void Initialize()
|
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
|
|
|
ZConfigFile cfg("tests.zcf");
|
|
|
|
int w,h,bpp;
|
|
|
|
bool fs;
|
|
|
|
string title;
|
|
|
|
|
|
|
|
w = cfg.GetInt("ZRectTest","Width",800);
|
|
|
|
h = cfg.GetInt("ZRectTest","height",600);
|
|
|
|
bpp = cfg.GetInt("ZRectTest","bpp",32);
|
|
|
|
fs = cfg.GetBool("ZRectTest","fullscreen",false);
|
|
|
|
title = cfg.GetString("ZRectTest","title","ZRect Test");
|
|
|
|
|
|
|
|
engine->SetupDisplay(w,h,bpp,fs);
|
|
|
|
engine->CreateDisplay(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test()
|
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
|
|
|
ZRect moveRect(0,0,25,25),stillRect(100,100,100,100);
|
2002-12-04 05:22:39 +00:00
|
|
|
double movDelta;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
//In the active loop, check events first//
|
|
|
|
engine->CheckEvents();
|
|
|
|
if(engine->KeyIsPressed(SDLK_s))
|
|
|
|
{
|
|
|
|
//code to toggle screen//
|
2002-11-28 23:15:52 +00:00
|
|
|
engine->SetupDisplay(engine->Width(),engine->Height(),engine->BPP(),!engine->IsFullscreen());
|
2002-12-01 07:56:17 +00:00
|
|
|
engine->CreateDisplay("ZRect Test");
|
|
|
|
}
|
|
|
|
if(engine->KeyIsPressed(SDLK_ESCAPE))
|
|
|
|
engine->RequestQuit();
|
|
|
|
//movement//
|
2002-12-04 05:22:39 +00:00
|
|
|
movDelta = engine->GetFrameTime()*30;
|
2002-12-03 06:19:43 +00:00
|
|
|
if(engine->KeyPress(SDLK_LEFT))
|
2002-12-04 05:22:39 +00:00
|
|
|
moveRect.MoveRel(-movDelta,0);
|
2002-12-03 06:19:43 +00:00
|
|
|
if(engine->KeyPress(SDLK_RIGHT))
|
2002-12-04 05:22:39 +00:00
|
|
|
moveRect.MoveRel(movDelta,0);
|
2002-12-03 06:19:43 +00:00
|
|
|
if(engine->KeyPress(SDLK_UP))
|
2002-12-04 05:22:39 +00:00
|
|
|
moveRect.MoveRel(0,-movDelta);
|
2002-12-03 06:19:43 +00:00
|
|
|
if(engine->KeyPress(SDLK_DOWN))
|
2002-12-04 05:22:39 +00:00
|
|
|
moveRect.MoveRel(0,movDelta);
|
2002-12-01 07:56:17 +00:00
|
|
|
if(engine->KeyIsPressed(SDLK_EQUALS))
|
|
|
|
{
|
|
|
|
moveRect.MoveRel(-1,-1);
|
|
|
|
moveRect.ResizeRel(2,2);
|
|
|
|
}
|
|
|
|
if(engine->KeyIsPressed(SDLK_MINUS))
|
|
|
|
{
|
|
|
|
moveRect.MoveRel(1,1);
|
|
|
|
moveRect.ResizeRel(-2,-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
engine->Clear();
|
2002-12-01 08:36:39 +00:00
|
|
|
moveRect.Draw(255,0,0,128);
|
|
|
|
stillRect.Draw(0,0,255,128);
|
|
|
|
moveRect.Intersection(stillRect).Draw(0,255,0);
|
2002-12-01 07:56:17 +00:00
|
|
|
engine->UpdateScreen();
|
2002-12-03 06:19:43 +00:00
|
|
|
|
2002-12-01 07:56:17 +00:00
|
|
|
} while(!engine->QuitRequested());
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
|
|
|
|
|
|
|
Initialize();
|
|
|
|
//engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
|
|
|
|
Test();
|
|
|
|
|
|
|
|
ZEngine::ReleaseInstance(); //release engine instance
|
|
|
|
return 0;
|
|
|
|
}
|