-
Notifications
You must be signed in to change notification settings - Fork 0
/
cAssetManager.cpp
88 lines (77 loc) · 2.34 KB
/
cAssetManager.cpp
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
81
82
83
84
85
86
87
88
// Copyright 2015 Kelvin Chandra, Software Laboratory Center, Binus University. All Rights Reserved.
#pragma warning(disable:4996)
#include "cAssetManager.h"
#include "Globals.h"
cAssetManager::cAssetManager(void) {}
cAssetManager::~cAssetManager(void) {}
int cAssetManager::GetID(int img)
{
return textures[img].GetID();
}
void cAssetManager::GetSize(int img, int *w, int *h)
{
textures[img].GetSize(w, h);
}
bool cAssetManager::LoadImage(int img, char *filename, int type)
{
int res;
res = textures[img].Load(filename, type);
if (!res) return false;
return true;
}
bool cAssetManager::Load()
{
int res;
res = LoadImage(SPRITESHEET_PLAYERS, "Assets/ships.png", GL_RGBA);
if (!res) return false;
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 17; i++) {
float x0, y0, x1, y1;
int tex_w, tex_h;
GetSize(GetID(SPRITESHEET_PLAYERS), &tex_w, &tex_h);
float sprite_width = 32.0f / tex_w;
float sprite_height = 32.0f / tex_h;
x0 = sprite_width*i;
x1 = sprite_width*(i + 1);
y0 = sprite_height*j;
y1 = sprite_height*(j + 1);
player->push_back(new cSprite(GetID(SPRITESHEET_PLAYERS), x0, y0, x1, y1));
puts("ships loaed");
}
}
res = LoadImage(SPRITESHEET_PELOR, "Assets/bullet.png", GL_RGBA);
if (!res) return false;
for (int j = 0; j < 1; j++) {
for (int i = 0; i < 1; i++) {
float x0, y0, x1, y1;
int tex_w, tex_h;
GetSize(GetID(SPRITESHEET_PELOR), &tex_w, &tex_h);
float sprite_width = 100.0f / tex_w;
float sprite_height = 100.0f / tex_h;
x0 = sprite_width*i;
x1 = sprite_width*(i + 1);
y0 = sprite_height*j;
y1 = sprite_height*(j + 1);
pelor->push_back(new cSprite(GetID(SPRITESHEET_PELOR), x0, y0, x1, y1));
puts("bullet loaded");
}
}
res = LoadImage(SPRITESHEET_ENEMY, "Assets/eships.png", GL_RGBA);
if (!res) return false;
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 17; i++) {
float x0, y0, x1, y1;
int tex_w, tex_h;
GetSize(GetID(SPRITESHEET_ENEMY), &tex_w, &tex_h);
float sprite_width = 32.0f / tex_w;
float sprite_height = 32.0f / tex_h;
x0 = sprite_width*i;
x1 = sprite_width*(i + 1);
y0 = sprite_height*j;
y1 = sprite_height*(j + 1);
enemy->push_back(new cSprite(GetID(SPRITESHEET_ENEMY), x0, y0, x1, y1));
puts("ships loaed");
}
}
return true;
}