File: fire.cpp

package info (click to toggle)
pinball 0.3.20201218-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 8,452 kB
  • sloc: cpp: 15,230; makefile: 840; sh: 381; xml: 24
file content (80 lines) | stat: -rw-r--r-- 2,659 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***************************************************************************
 Texture coordinate animation test. A flame.
 ***************************************************************************/

#include "Engine.h"
#include "Camera.h"
#include "BillBoard.h"
#include "KeyBehavior.h"
#include "Keyboard.h"
#include "TextureUtil.h"
#include "TexAnimation.h"

/** Main */
int main(int argc, char *argv[]) {
	cerr << "Fire test." << endl;

	if (argc < 2) {
		cerr << "Usage: firee <2x2 fire image-file>" << endl;
		return 0;
	}

	// Create the engine.
	Engine* engine = new Engine(argc, argv);
	engine->setLightning(0.5f, 0.1f);

	// Add a camera. Move a bit.
	Camera* camera = new Camera();
	Group* groupCamera = new Group();
	engine->add(groupCamera);
	groupCamera->setCamera(camera);
	groupCamera->setTranslation(0, 0, 7);
	engine->setEngineCamera(groupCamera);

	// Load a texture
	EmTexture* texture = TextureUtil::loadTexture(argv[1]);

	// Add a BillBoard
	BillBoard* billboard = new BillBoard(texture, 2.0, 3.0);
	billboard->setProperty(EM_BILLBOARD_ALPHATEST);          
	billboard->setProperty(EM_BILLBOARD_TRANS);              
	Group* groupBB = new Group();                            
	engine->add(groupBB);                                 
	groupBB->setBillBoard(billboard);                        

	TexAnimation * anim = new TexAnimation(3, 4, 0);  
	anim->add(0,  0);                                        
	anim->add(0.5,0);                                        
	anim->add(0.5,0.5);                                        
	anim->add(0,  0.5);                                        

	anim->add(0.5,  0);                                        
	anim->add(1,  0);                                        
	anim->add(1,  0.5);                                        
	anim->add(0.5,  0.5);                                        

	anim->add(0,  0.5);                                        
	anim->add(0.5,0.5);                                        
	anim->add(0.5,1);                                        
	anim->add(0,  1);                                        

	anim->add(0.5,0.5);                                        
	anim->add(1  ,0.5);                                        
	anim->add(1  ,1);                                        
	anim->add(0.5,1);                                        

	groupBB->addBehavior(anim);                              

	// Add a behavior to the billboard
	KeyBehavior* keyBeh = new KeyBehavior();
	groupBB->addBehavior(keyBeh);
		
	while (!Keyboard::isKeyDown(SDLK_ESCAPE)) {
		engine->tick();
		engine->render();
		engine->swap();
		SDL_Delay(20);
	}
	delete(engine);
	return 0;
}