aboutsummaryrefslogtreecommitdiff
path: root/game/coins/CoinSubScene.cpp
blob: d15481931dfa9b56b8101edf86588cd5eba91e35 (plain)
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
#include "CoinSubScene.h"

#include "../Config.h"

#include <crepe/api/Animator.h>
#include <crepe/api/AudioSource.h>
#include <crepe/api/CircleCollider.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Scene.h>

using namespace crepe;
using namespace std;

int CoinSubScene::create(Scene & scn, int coin_counter) {
	vec2 size = {20, 20};

	string unique_name = "coin_" + to_string(coin_counter++);

	GameObject coin = scn.new_object(unique_name.c_str(), "coin", vec2 {650, 0}, 0, 1);
	coin.add_component<Rigidbody>(Rigidbody::Data {
		.body_type = Rigidbody::BodyType::KINEMATIC,
		.kinematic_collision = false,
		.collision_layers = {COLL_LAY_PLAYER},
	});
	coin.add_component<CircleCollider>((size.x / 2) - 3).active = false;
	crepe::OptionalRef<crepe::Sprite> coin_sprite = coin.add_component<Sprite>(
		Asset {"asset/coin/coin1_TVOS.png"},
		Sprite::Data {
			.sorting_in_layer = SORT_IN_LAY_COINS,
			.order_in_layer = 0,
			.size = size,
		}
	);
	coin_sprite->active = false;
	coin.add_component<Animator>(
		coin_sprite, ivec2 {32, 32}, uvec2 {8, 1},
		Animator::Data {
			.fps = 15,
			.looping = true,
		}
	);
	coin.add_component<AudioSource>(Asset {"asset/sfx/coin_pickup_1.ogg"}).volume = 3;

	Sprite & pick_up = coin.add_component<Sprite>(
		Asset {"asset/coin/coinCollect1_TVOS.png"},
		Sprite::Data {
			.sorting_in_layer = SORT_IN_LAY_COINS,
			.order_in_layer = 1,
			.size = size * 2,
		}
	);
	pick_up.active = false;
	coin.add_component<Animator>(
			pick_up, ivec2 {64, 64}, uvec2 {5, 1},
			Animator::Data {
				.fps = 5,
				.looping = false,
			}
	)
		.active
		= false;

	return coin_counter;
}