简单横版游戏
作业要求
- 左边wasd4个虚拟按键能控制角色移动
- 右边2个虚拟按键x,y能控制角色播放不同的帧动画
- 界面所有字体要求:使用fonts目录下的arial.ttf,字体大小为36
- 角色不会移动到可视窗口外
- 添加倒计时
- 添加人物血条
- X、Y播放的动画不能同时播放
- 点击虚拟按键x播放帧动画并让血条减少,点击y播放帧动画并让血条增加(加分项)
实现效果
具体实现
HelloWorldScene.cpp
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace std;
#pragma execution_character_set("utf-8")
USING_NS_CC;
Scene* HelloWorld::createScene()
{
return HelloWorld::create();
}
static void problemLoading(const char* filename)
{
printf("Error while loading: %s\n", filename);
printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}
bool HelloWorld::init()
{
if ( !Scene::init() )
{
return false;
}
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
auto texture = Director::getInstance()->getTextureCache()->addImage("$lucia_2.png");
auto frame0 = SpriteFrame::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(0, 0, 113, 113)));
player = Sprite::createWithSpriteFrame(frame0);
player->setPosition(Vec2(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height / 2));
addChild(player, 3);
Sprite* sp0 = Sprite::create("hp.png", CC_RECT_PIXELS_TO_POINTS(Rect(0, 320, 420, 47)));
Sprite* sp = Sprite::create("hp.png", CC_RECT_PIXELS_TO_POINTS(Rect(610, 362, 4, 16)));
pT = ProgressTimer::create(sp);
pT->setScaleX(90);
pT->setAnchorPoint(Vec2(0, 0));
pT->setType(ProgressTimerType::BAR);
pT->setBarChangeRate(Point(1,