-
Notifications
You must be signed in to change notification settings - Fork 11
/
GameMap.cpp
88 lines (79 loc) · 2.73 KB
/
GameMap.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
/*!
* \class GameMap
*
* \ingroup GroupName
*
* \brief
*
* TODO: long description
*
* \note
*
* \author SuooL
*
* \version 1.0
*
* \date 六月 2015
*
* Contact: [email protected]
*
*/
#include "GameMap.h"
#include "GlobalDefine.h"
#include "Hero.h"
#include "cocos2d.h"
USING_NS_CC;
GameMap::GameMap()
{
m_map1 = NULL;
m_map2 = NULL;
m_map3 = NULL;
}
GameMap::~GameMap()
{
}
void GameMap::InitMap(const char *map_name1,const char *map_name2,const char *map_name3)
{
this->m_map1 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(map_name1));
this->m_map2 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(map_name2));
this->m_map3 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(map_name3));
m_map1->setAnchorPoint(Point(0, 0));
m_map1->setTag(11);
m_map2->setAnchorPoint(Point(0, 0));
m_map3->setAnchorPoint(Point(0, 0));
parallax = ParallaxNode::create();
parallax->addChild(m_map1, 1, Point(1.18, 0), Point(0,360));
parallax->addChild(m_map2, 2, Point(1, 0), Point(0,0));
parallax->addChild(m_map3, 3, Point(0.7, 0), Point(0, 0));
this->setAnchorPoint(ccp(0, 0));
this->addChild(parallax);
log("%f%f", parallax->getPositionX(), parallax->getPositionY());
log("%f%f", parallax->getContentSize().width, parallax->getContentSize().height);
log("%f%f", m_map1->getContentSize().width, m_map1->getContentSize().height);
}
void GameMap::MoveMap(Hero *hero)//
{
auto map = (Sprite*)parallax->getChildByTag(11);
if (hero->JudgePosition(WINSIZE) && hero->HeroDirecton == false)//精灵运动到中间,地图才移动
{
if (this->getPositionX() >= -(m_map2->getContentSize().width - WINSIZE.width))//防止地图左边运动后超出边缘
this->setPosition(this->getPositionX() - hero->m_iSpeed, this->getPositionY());
log("map is %f", this->getPositionX());
}
if (hero->JudgePosition(WINSIZE) && hero->HeroDirecton == true)//精灵运动到中间,地图才移动
{
log("Hero Walk Left %f", hero->getPositionX());
log("map is %f", this->getPositionX());
if (this->getPositionX() <= -10) //防止地图左边运动后超出边缘
this->setPosition(this->getPositionX() + hero->m_iSpeed, this->getPositionY());
}
}
bool GameMap::JudgeMap(Hero *hero)
{
if (this->getPositionX() >= -(m_map2->getContentSize().width - WINSIZE.width) && hero->HeroDirecton == false)//防止地图左边运动后超出边缘
return false;
else if (this->getPositionX() <= -10 && hero->HeroDirecton == true) //防止地图左边运动后超出边缘
return false;
else //地图已经移动到达边缘
return true;
}