2002-12-01 07:56:17 +00:00
|
|
|
/*******************************************************************************
|
2002-12-29 06:50:19 +00:00
|
|
|
This file is Part of the ZEngine Library for 2D game development.
|
|
|
|
Copyright (C) 2002, 2003 James Turk
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
Licensed under a BSD-style license.
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
|
|
|
and the home of this Library is http://www.zengine.sourceforge.net
|
2002-12-01 07:56:17 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
2003-06-11 05:51:15 +00:00
|
|
|
/*$Id: ZRectTest.cpp,v 1.16 2003/06/11 05:51:47 cozman Exp $*/
|
2003-01-04 05:17:56 +00:00
|
|
|
|
2002-12-01 07:56:17 +00:00
|
|
|
#include <ZEngine.h>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
using namespace ZE;
|
|
|
|
|
2003-01-12 19:00:14 +00:00
|
|
|
bool Initialize()
|
2002-12-01 07:56:17 +00:00
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
|
|
|
ZConfigFile cfg("tests.zcf");
|
2003-01-04 05:16:01 +00:00
|
|
|
int w,h,bpp,rate;
|
2002-12-01 07:56:17 +00:00
|
|
|
bool fs;
|
2003-06-11 05:51:15 +00:00
|
|
|
std::string title;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
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");
|
2003-01-04 05:16:01 +00:00
|
|
|
rate = cfg.GetInt("ZRectTest","framerate",60);
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
engine->SetupDisplay(w,h,bpp,fs);
|
2003-01-04 05:16:01 +00:00
|
|
|
engine->SetDesiredFramerate(rate);
|
2003-01-12 19:00:14 +00:00
|
|
|
return engine->CreateDisplay(title);
|
2002-12-01 07:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test()
|
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
|
|
|
ZRect moveRect(0,0,25,25),stillRect(100,100,100,100);
|
2002-12-21 09:02:23 +00:00
|
|
|
float movDelta;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
//In the active loop, check events first//
|
|
|
|
engine->CheckEvents();
|
2003-01-12 19:00:14 +00:00
|
|
|
|
|
|
|
if(engine->IsActive())
|
2002-12-01 07:56:17 +00:00
|
|
|
{
|
2003-01-12 19:00:14 +00:00
|
|
|
if(engine->KeyIsPressed(SDLK_ESCAPE))
|
|
|
|
engine->RequestQuit();
|
|
|
|
//movement//
|
|
|
|
movDelta = static_cast<float>(engine->GetFrameTime()*30);
|
|
|
|
if(engine->KeyIsPressed(SDLK_LEFT))
|
|
|
|
moveRect.MoveRel(-movDelta,0);
|
|
|
|
if(engine->KeyIsPressed(SDLK_RIGHT))
|
|
|
|
moveRect.MoveRel(movDelta,0);
|
|
|
|
if(engine->KeyIsPressed(SDLK_UP))
|
|
|
|
moveRect.MoveRel(0,-movDelta);
|
|
|
|
if(engine->KeyIsPressed(SDLK_DOWN))
|
|
|
|
moveRect.MoveRel(0,movDelta);
|
|
|
|
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);
|
|
|
|
}
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2003-01-12 19:00:14 +00:00
|
|
|
engine->Clear();
|
|
|
|
moveRect.Draw(255,0,0,128);
|
|
|
|
stillRect.Draw(0,0,255,128);
|
|
|
|
moveRect.Intersection(stillRect).Draw(0,255,0);
|
|
|
|
engine->Update();
|
|
|
|
}
|
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();
|
|
|
|
|
2003-01-12 19:00:14 +00:00
|
|
|
if(Initialize())
|
|
|
|
{
|
|
|
|
//engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
|
|
|
|
Test();
|
|
|
|
}
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
ZEngine::ReleaseInstance(); //release engine instance
|
|
|
|
return 0;
|
|
|
|
}
|