"실용주의 디자인 패턴"
'보고싶은책' 카테고리의 다른 글
| 유니티 중급 이상 책 (0) | 2013.12.11 |
|---|---|
| 추천 책 (0) | 2013.12.10 |
| 패턴 (0) | 2013.12.10 |
| 만들면서 이해하는 실전! Cocos2d-x 3.x 게임 프로그래밍 (0) | 2013.12.01 |
| cocos2d-x (0) | 2013.11.22 |
| 게임 매니악스 슈팅 게임 알고리즘 (0) | 2013.11.21 |
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace CocosDenshion;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback) );
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
sprite = CCSprite::create("CloseNormal.png");
this->addChild(sprite);
sprite->setPosition(ccp(20, winSize.height/2));
//힘
int Force = 5;
//각도 조절
float x = Force * cos(25);
float y = Force * sin(25);
//벡터값
vector = CCPoint(x, y);
time = 0.0f;
initPos = sprite->getPosition();
CCLog("%f, %f" , x,y);
this->schedule(schedule_selector(HelloWorld::gameLogic));
return true;
}
void HelloWorld::gameLogic(float dt)
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
//CCLog("gameLogic!");
time += dt;
//시간에 따른 포물선 운동 공식
float x = vector.x * time;
float y = vector.y * time - (9.8f/2.0f * time * time);
CCPoint pos = sprite->getPosition();
sprite->setPosition(ccp(pos.x+x,pos.y+y));
if(sprite->getPositionY() < 0)
{
time = 0;
sprite->setPosition(ccp(20, winSize.height/2));
}
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
'잡다한것들전부 > 팁' 카테고리의 다른 글
| 중급 개발자가 되는 방법 5가지 (0) | 2013.12.16 |
|---|---|
| 배경 무한 스크롤링 (0) | 2013.12.11 |
| 포물선 운동 관련 소스 (0) | 2013.12.10 |
| 헥사 게임 알고리즘 (0) | 2013.12.03 |
| 비쥬얼드 로직 (0) | 2013.12.02 |
| 비쥬얼드 3개 블록 맞추는 로직 (0) | 2013.12.02 |
x = S.x + V.x * t;
y = S.y + (V.y * t) - ((1/2) * g * t * t);
z = S.z + V.z * t;
t는 시간
S는 시작위치
g는 중력 가속도이지만 반드시 9.8일 필요는 없고 실제 게임에서 자연스럽게 보이는 값을 지정.
특정시간은 t의 값에 그 시간을 넣고 x,y,z를 최종위치값으로 넣어서 V값을 역산해 결정한 다음
매 프레임마다 t값을 갱신해 가면서 x, y, z를 구하시면 됨
'잡다한것들전부 > 팁' 카테고리의 다른 글
| 유니티 2d 게임 개발 (0) | 2013.12.11 |
|---|---|
| [펌]유니티 구글드라이브 연동 소스 (0) | 2013.12.10 |
| 유니티 포물선 공식 (1) | 2013.12.09 |
| 유니티 대화 예제 (0) | 2013.12.09 |
| 유니티 text 파일로 저장하는 법 (0) | 2013.12.09 |
| [펌] 유니티 런닝게임 관련 질문 (0) | 2013.12.06 |





