/*
* Game4Key.cpp
*
* Created on: 2013-9-11
* Author: song
*/
#include "Game4Key.h"
#include "SimpleAudioEngine.h"
#include "HelloWorldScene.h"
#include <stdlib.h>
USING_NS_CC;
using namespace CocosDenshion;
using namespace cocos2d::extension;
CCScene* Game4Key::scene() {
CCScene *scene = CCScene::create();
Game4Key *layer = Game4Key::create();
scene->addChild(layer);
return scene;
}
bool Game4Key::init() {
if (!CCLayer::init()) {
return false;
}
setTouchEnabled(true);
visibleSize = CCDirector::sharedDirector()->getVisibleSize();
origin = CCDirector::sharedDirector()->getVisibleOrigin();
this->mp3Seconds = 148;
this->currentSeconds = 0;
//音符出生坐标:等边直角三角形的顶点
bornx = origin.x + visibleSize.width / 2;
//高度等于二分之一根号三乘边长
borny = origin.y + sqrtf(3) / 2 * (visibleSize.width);
perKeyW = visibleSize.width / 4;
perNoteBottom_X = perKeyW;
//音符下落的速度
speed = 1;
this->HP = 100;
this->lastHP = 100;
this->score = 0;
key1Rect =
CCRectMake(origin.x,origin.y,origin.x+perKeyW,origin.y+visibleSize.height/2);
key2Rect =
CCRectMake(origin.x+perKeyW,origin.y,origin.x+perKeyW,origin.y+visibleSize.height/2);
key3Rect =
CCRectMake(origin.x+perKeyW*2,origin.y,origin.x+perKeyW,origin.y+visibleSize.height/2);
key4Rect =
CCRectMake(origin.x+perKeyW*3,origin.y,origin.x+perKeyW,origin.y+visibleSize.height/2);
//场景及返回按钮
CCSprite* pSprite = CCSprite::create("song/andy/andy.png");
//节奏大师按键场景
CCSprite* panlGameSprite = CCSprite::createWithSpriteFrameName(
"panl_game.png");
CCSprite* panl4KSprite = CCSprite::createWithSpriteFrameName("panl_4k.png");
CCSprite* top = CCSprite::createWithSpriteFrameName("top.png");
CCSprite* lSide = CCSprite::createWithSpriteFrameName("b_side.png");
CCSprite* rSide = CCSprite::createWithSpriteFrameName("b_side.png");
CCSprite* sider_1 = CCSprite::createWithSpriteFrameName("b_sider.png");
CCSprite* sider_2 = CCSprite::createWithSpriteFrameName("b_sider.png");
CCSprite* sider_3 = CCSprite::createWithSpriteFrameName("b_sider.png");
pSprite->setPosition(
ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(pSprite, 0);
CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png",
"CloseSelected.png", this, menu_selector(Game4Key::menuCallback));
pCloseItem->setPosition(
ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
visibleSize.height - pCloseItem->getContentSize().height/2));
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 10);
top->setAnchorPoint(CCPointZero);
top->setPosition(
ccp(origin.x,origin.y+visibleSize.height-top->getContentSize().height));
panl4KSprite->setAnchorPoint(CCPointMake(0.5,1));
panlGameSprite->setAnchorPoint(CCPointMake(0.5,1));
panlGameSprite->setPosition(
ccp(origin.x+visibleSize.width/2,origin.y+visibleSize.height));
this->addChild(panlGameSprite, 1);
panl4KSprite->setPosition(
ccp(origin.x+visibleSize.width/2,origin.y+visibleSize.height-panlGameSprite->getContentSize().height+1));
this->addChild(panl4KSprite, 2);
this->addChild(top, 5);
//顶点出生音符宽度;
float bornPerx = panlGameSprite->getContentSize().width / 8 / 4;
float tleftx = origin.x + visibleSize.width / 2 - 1.5 * bornPerx;
float trightx = tleftx + 4 * bornPerx;
bornNotePos1 = CCPointMake(tleftx,origin.y+visibleSize.height);
bornNotePos2 = CCPointMake(tleftx+bornPerx,origin.y+visibleSize.height);
bornNotePos3 = CCPointMake(tleftx+2*bornPerx,origin.y+visibleSize.height);
bornNotePos4 = CCPointMake(trightx,origin.y+visibleSize.height);
//内角度数
float ndu = atan(
(panl4KSprite->getContentSize().height / 3
+ panlGameSprite->getContentSize().height)
/ (panl4KSprite->getContentSize().width / 2 - 2 * bornPerx))
* 180 / 3.14;
lSide->setAnchorPoint(CCPointMake(1,0));
lSide->setPosition(
ccp(origin.x,origin.y+panl4KSprite->getContentSize().height/3*2));
lSide->setRotation(90 - ndu);
this->addChild(lSide, 4);
rSide->setAnchorPoint(CCPointMake(0,0));
rSide->setPosition(
ccp(origin.x+visibleSize.width,origin.y+panl4KSprite->getContentSize().height/3*2));
rSide->setRotation(-(90 - ndu));
this->addChild(rSide, 4);
float perns = (panlGameSprite->getContentSize().width
- panl4KSprite->getContentSize().height / 3 * 2) / 4;
float nndu = atan(
(perns - bornPerx) / panlGameSprite->getContentSize().height) * 180
/ 3.14;
sider_1->setAnchorPoint(CCPointMake(0.5,0));
sider_2->setAnchorPoint(CCPointMake(0.5,0));
sider_3->setAnchorPoint(CCPointMake(0.5,0));
sider_2->setPosition(
ccp(origin.x+visibleSize.width/2+1,origin.y+panl4KSprite->getContentSize().height));
sider_1->setPosition(
ccp(sider_2->getPosition().x-perns+1,sider_2->getPosition().y));
sider_3->setPosition(
ccp(sider_2->getPosition().x+perns+1,sider_2->getPosition().y));
sider_1->setRotation(nndu);
sider_3->setRotation(-nndu);
this->addChild(sider_2, 4);
this->addChild(sider_1, 4);
this->addChild(sider_3, 4);
draw1 = CCDrawNode::create();
draw2 = CCDrawNode::create();
draw3 = CCDrawNode::create();
draw4 = CCDrawNode::create();
addChild(draw1, 4);
addChild(draw2, 4);
addChild(draw3, 4);
addChild(draw4, 4);
star1[0] =
ccp(origin.x+visibleSize.width/2-2*bornPerx,origin.y+visibleSize.height);
star1[1] =
ccp(origin.x+visibleSize.width/2-2*perns,origin.y+panl4KSprite->getContentSize().height);
star1[2] =
ccp(origin.x+visibleSize.width/2-perns-1,origin.y+panl4KSprite->getContentSize().height);
star1[3] =
ccp(origin.x+visibleSize.width/2-bornPerx-1,origin.y+visibleSize.height);
star2[0] =
ccp(origin.x+visibleSize.width/2-bornPerx+1,origin.y+visibleSize.height);
star2[1] =
ccp(origin.x+visibleSize.width/2-perns+2,origin.y+panl4KSprite->getContentSize().height);
star2[2] =
ccp(origin.x+visibleSize.width/2-2,origin.y+panl4KSprite->getContentSize().height);
star2[3] = ccp(origin.x+visibleSize.width/2-1,origin.y+visibleSize.height);
star3[0] = ccp(origin.x+visibleSize.width/2+1,origin.y+visibleSize.height);
star3[1] =
ccp(origin.x+visibleSize.width/2+2,origin.y+panl4KSprite->getContentSize().height);
star3[2] =
ccp(origin.x+visibleSize.width/2+perns-2,origin.y+panl4KSprite->getContentSize().height);
star3[3] =
ccp(origin.x+visibleSize.width/2+bornPerx-1,origin.y+visibleSize.height);
star4[0] =
ccp(origin.x+visibleSize.width/2+bornPerx+1,origin.y+visibleSize.height);
star4[1] =
ccp(origin.x+visibleSize.width/2+perns+3,origin.y+panl4KSprite->getContentSize().height);
star4[2] =
ccp(origin.x+visibleSize.width/2+2*perns,origin.y+panl4KSprite->getContentSize().height);
star4[3] =
ccp(origin.x+visibleSize.width/2+2*bornPerx,origin.y+visibleSize.height);
// draw1->clear();
CCBlink* lsideActin = CCBlink::create(10, 10);
CCBlink* rsideActin = CCBlink::create(10, 10);
lSide->runAction(
CCRepeatForever::create(CCSequence::create(lsideActin, NULL)));
rSide->runAction(
CCRepeatForever::create(CCSequence::create(rsideActin, NULL)));
//按键精灵
bottomButton0_1 = CCSprite::createWithSpriteFrameName(
"button_4key_0_1.png");
bottomButton0_2 = CCSprite::createWithSpriteFrameName(
"button_4key_0_2.png");
bottomButton0_3 = CCSprite::createWithSpriteFrameName(
"button_4key_0_3.png");
bottomButton0_4 = CCSprite::createWithSpriteFrameName(
"button_4key_0_4.png");
bottomButton1_1 = CCSprite::createWithSpriteFrameName(
"button_4key_1_1.png");
bottomButton1_2 = CCSprite::createWithSpriteFrameName(
"button_4key_1_2.png");
bottomButton1_3 = CCSprite::createWithSpriteFrameName(
"button_4key_1_3.png");
bottomButton1_4 = CCSprite::createWithSpriteFrameNa