-
Notifications
You must be signed in to change notification settings - Fork 0
/
texture.cpp
85 lines (71 loc) · 2.27 KB
/
texture.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
#include "info.hpp"
#include "texture.hpp"
#include "gameWorld.hpp"
using namespace Ginfo::Texture;
static sf::Sprite sprite;
static sf::Texture a_pTextures[TEXTURE_COUNT];
void loadTextures()
{
a_pTextures[BLOCK_TEXTURE].loadFromFile("data/images/blocks.png");
a_pTextures[PLAYER_TEXTURE].loadFromFile("data/images/player.png");
}
sf::Sprite& getSprite(
Ginfo::Entity::Type EntityType,
sf::Vector2f pos,
long typeID,
long DropItemType)
{
sprite.setScale(1.f,1.f);
sprite.setColor(sf::Color(255,255,255));
sprite.setOrigin(0,0);
if (EntityType == Ginfo::Entity::BLOCK)
{
sprite.setTexture(a_pTextures[BLOCK_TEXTURE]);
sprite.setTextureRect(sf::IntRect(
(typeID * BLOCK_SIZE) % (BLOCK_SIZE * 10),
((typeID * BLOCK_SIZE) / (BLOCK_SIZE * 10)) * BLOCK_SIZE,
BLOCK_SIZE,BLOCK_SIZE));
sprite.setPosition(pos);
return sprite;
}
if (EntityType == Ginfo::Entity::SMALL_BLOCK)
{
sprite.setTexture(a_pTextures[BLOCK_TEXTURE]);
sprite.setTextureRect(sf::IntRect(
(typeID * BLOCK_SIZE) % (BLOCK_SIZE * 10),
((typeID * BLOCK_SIZE) / (BLOCK_SIZE * 10)) * BLOCK_SIZE,
BLOCK_SIZE,BLOCK_SIZE));
sprite.setScale(1/9.f,1/9.f);
sprite.setPosition(pos);
return sprite;
}
if (EntityType == Ginfo::Entity::ITEM)
{
}
if (EntityType == Ginfo::Entity::MOB)
{
}
if (EntityType == Ginfo::Entity::PLAYER)
{
sprite.setTexture(a_pTextures[PLAYER_TEXTURE]);
sprite.setTextureRect(sf::IntRect(0,0,PLAYER_SPRITE_SIZE,PLAYER_SPRITE_SIZE));
sprite.setOrigin(sf::Vector2f((float)(PLAYER_SPRITE_SIZE-PLAYER_SIZE)/2,
(float)(PLAYER_SPRITE_SIZE-PLAYER_SIZE)/2));
sprite.setPosition(pos);
return sprite;
}
printf("what did you did ? -__-\n");
}
sf::Sprite& getDropItemSprite(CDropItem* pDropItem)
{
getSprite(pDropItem->m_type, pDropItem->m_pos, pDropItem->m_typeID);
sprite.setScale(
(float)(DROP_ITEM_SIZE+pDropItem->m_count)/BLOCK_SIZE,
(float)(DROP_ITEM_SIZE+pDropItem->m_count)/BLOCK_SIZE);
sprite.setPosition(pDropItem->m_pos);
return sprite;
}
// sf::Sprite& getItemContainerSprite(CItemContainer* pItemCon)
// {
// getSprite(pItemCon->m_type, sf::Vector2f pos)
// }