-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSceneOOP.hpp
75 lines (65 loc) · 2.78 KB
/
TestSceneOOP.hpp
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
#pragma once
class TestScene {
static constexpr const u32 NUM_ENTITIES = 1500;
static const Rect TEST_AREA;
static Entity enclosure[ 4 ];
static Entity entities[ NUM_ENTITIES ];
public:
static void initialize();
static void update( double deltaT );
static void shutdown();
};
const Rect TestScene::TEST_AREA( Vec2( -420, -240 ), Vec2( 420, 240 ) );
Entity TestScene::enclosure[ 4 ];
Entity TestScene::entities[ NUM_ENTITIES ];
// TODO put randf somewhere appropriate
float randf( float min, float max ) {
static const float F_RAND_MAX = static_cast< float >( RAND_MAX );
return min + ( std::rand() / F_RAND_MAX ) * ( max - min );
}
void TestScene::initialize() {
// create enclosure
const float WALL_THICKNESS = 5.0f;
// top wall
Vec2 position( 0.0f, TEST_AREA.getMax().getY() );
enclosure[ 0 ].setTransform( Transform( position, Vec2::ONE, {} ) );
Rect bounds( Vec2( TEST_AREA.getMin().getX(), 0.0f ),
Vec2( TEST_AREA.getMax().getX(), WALL_THICKNESS ) );
enclosure[ 0 ].setCollider( Collider( bounds ) );
// bottom wall
enclosure[ 1 ].setTransform( Transform( Vec2( position.getX(), TEST_AREA.getMin().getY() - WALL_THICKNESS ), Vec2::ONE, {} ) );
enclosure[ 1 ].setCollider( Collider( bounds ) );
// right wall
position = Vec2( TEST_AREA.getMax().getX(), 0.0f );
enclosure[ 2 ].setTransform( Transform( position, Vec2::ONE, {} ) );
bounds = Rect( Vec2( 0.0f, TEST_AREA.getMin().getY() ),
Vec2( WALL_THICKNESS, TEST_AREA.getMax().getY() ) );
enclosure[ 2 ].setCollider( Collider( bounds ) );
// left wall
enclosure[ 3 ].setTransform( Transform( Vec2( TEST_AREA.getMin().getX() - WALL_THICKNESS, position.getY() ), Vec2::ONE, {} ) );
enclosure[ 3 ].setCollider( Collider( bounds ) );
// create actors
{
PROFILE_BLOCK( "Create Actors" );
AssetIndex textureHandle = AssetManager::loadTexture( "astronaut.png" );
for ( u32 ent = 0; ent < NUM_ENTITIES; ++ent ) {
float r1 = randf( TEST_AREA.getMin().getX(), TEST_AREA.getMax().getX() );
float r2 = randf( TEST_AREA.getMin().getY(), TEST_AREA.getMax().getY() );
Vec2 position( r1, r2 );
float r3 = randf( 0.0f, 2 * PI );
float orientation = r3;
entities[ ent ].setTransform( Transform( position, Vec2::ONE, orientation ) );
entities[ ent ].setSprite( Sprite( textureHandle, Rect( Vec2( 0.0f, 0.0f ), Vec2( 1.0f / 5.0f, 1.0f ) ) ) );
Collider collider( Circle( Vec2::ZERO, 0 ) );
entities[ ent ].setCollider( collider );
entities[ ent ].getCollider().fitCircleToSprite();
float r4 = randf( -1.0f, 1.0f );
float r5 = randf( -1.0f, 1.0f );
Vec2 direction( r4, r5 );
direction = direction.normalized() * 5;
entities[ ent ].setSolidBody( direction );
}
}
}
void TestScene::shutdown() {
}