Home » Source Code » cocos2dx+socket » sdDangBan.cpp

sdDangBan.cpp ( File view )

  • By 云飞 2013-10-30
  • View(s):166
  • Download(s):5
  • Point(s): 2
			#include "sdDangBan.h"


sdDangBan::sdDangBan(void)
{


}

sdDangBan::~sdDangBan(void)
{


}

CCRect sdDangBan::rect()
{

	CCSize s = getTexture()->getContentSize();
	return CCRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
	//return CCRectMake(-s.width / 2, s.height, s.width, s.height);

}

sdDangBan* sdDangBan::paddleWithTexture(CCTexture2D* aTexture)
{

	sdDangBan* pPaddle = new sdDangBan();
	pPaddle->initWithTexture( aTexture );
	pPaddle->autorelease();

	return pPaddle;

}

bool sdDangBan::initWithTexture(CCTexture2D* aTexture)
{

	if( CCSprite::initWithTexture(aTexture) ) 
	{

		m_state = kPaddleStateUngrabbed;
	
}
	
	return true;

}

void sdDangBan::onEnter()
{

    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
	CCSprite::onEnter();

}

void sdDangBan::onExit()
{

	CCTouchDispatcher::sharedDispatcher()->removeDelegate(this);
	CCSprite::onExit();

}	

bool sdDangBan::containsTouchLocation(CCTouch* touch)
{

	return CCRect::CCRectContainsPoint(rect(), convertTouchToNodeSpaceAR(touch));

}

bool sdDangBan::ccTouchBegan(CCTouch* touch, CCEvent* event)
{

/*
	ODSocket cSocket;
	cSocket.Init();
	cSocket.Create(AF_INET,SOCK_STREAM,0);
	cSocket.Connect("10.0.0.9",100);
	char recvBuf[64] = "\0";
	while(1)
	{

		cSocket.Send("abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz",strlen("abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz")+1,0);
		cSocket.Recv(recvBuf,64,0);
		//printf("%s was recived from server!\n",recvBuf);
	
}
	cSocket.Close();
	cSocket.Clean();
*/


	if (m_state != kPaddleStateUngrabbed) return false;
	if ( !containsTouchLocation(touch) ) return false;
	
	m_state = kPaddleStateGrabbed;




	return true;

}

void sdDangBan::ccTouchMoved(CCTouch* touch, CCEvent* event)
{

	// If it weren't for the TouchDispatcher, you would need to keep a reference
	// to the touch from touchBegan and check that the current touch is the same
	// as that one.
	// Actually, it would be even more complicated since in the Cocos dispatcher
	// you get CCSets instead of 1 UITouch, so you'd need to loop through the set
	// in each touchXXX method.
	
	CCAssert(m_state == kPaddleStateGrabbed, L"sdDangBan - Unexpected state!");	
	
	CCPoint touchPoint = touch->locationInView( touch->view() );
    touchPoint = CCDirector::sharedDirector()->convertToGL( touchPoint );
	
	setPosition( CCPointMake(touchPoint.x, getPosition().y) );

}

void sdDangBan::ccTouchEnded(CCTouch* touch, CCEvent* event)
{

	CCAssert(m_state == kPaddleStateGrabbed, L"sdDangBan - Unexpected state!");	
	
	m_state = kPaddleStateUngrabbed;


} 			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
ChatClient.cpp513.00 B14-01-12 18:00
ChatClient.vcproj4.58 kB12-01-12 15:43
ChatClient.vcproj.PCoS-20111206OT.Administrator.user1.39 kB14-01-12 18:40
ODSocket.cpp3.69 kB12-01-12 16:37
ODSocket.h1.61 kB12-01-12 13:43
ReadMe.txt1.29 kB10-01-12 16:26
stdafx.cpp297.00 B10-01-12 16:26
stdafx.h320.00 B10-01-12 16:26
targetver.h765.00 B10-01-12 16:26
ChatClient.sln896.00 B10-01-12 16:26
ChatClient.suo14.00 kB14-01-12 18:40
Android.mk880.00 B12-01-12 17:39
readme.doc170.00 kB14-01-12 18:40
HelloWorld.mkb291.00 B01-12-11 18:36
Main.cpp250.00 B01-12-11 18:36
Main.h42.00 B01-12-11 18:36
AndroidManifest.xml1.13 kB01-12-11 18:36
build_native.sh605.00 B01-12-11 18:36
default.properties364.00 B01-12-11 18:36
R.java867.00 B01-12-11 18:36
Android.mk303.00 B01-12-11 18:36
Application.mk148.00 B01-12-11 18:36
Android.mk534.00 B01-12-11 18:36
main.cpp993.00 B01-12-11 18:36
list.sh362.00 B01-12-11 18:36
icon.png7.17 kB01-12-11 18:36
icon.png2.24 kB01-12-11 18:36
icon.png4.00 kB01-12-11 18:36
game_demo.xml578.00 B01-12-11 18:36
helloworld_demo.xml595.00 B01-12-11 18:36
strings.xml112.00 B01-12-11 18:36
ApplicationDemo.java2.37 kB01-12-11 18:36
Cocos2dxAccelerometer.java3.17 kB01-12-11 18:36
Cocos2dxActivity.java7.47 kB01-12-11 18:36
Cocos2dxBitmap.java11.16 kB01-12-11 18:36
Cocos2dxGLSurfaceView.java13.50 kB01-12-11 18:36
Cocos2dxMusic.java6.06 kB01-12-11 18:36
Cocos2dxRenderer.java4.70 kB01-12-11 18:36
Cocos2dxSound.java7.63 kB01-12-11 18:36
Cocos2dxTypefaces.java1.71 kB01-12-11 18:36
.badaprj171.00 B01-12-11 18:36
.cproject77.53 kB01-12-11 18:36
.project2.91 kB01-12-11 18:36
application.xml622.00 B01-12-11 18:36
MainMenu.png15.87 kB01-12-11 18:36
Splash.png84.47 kB01-12-11 18:36
manifest.xml871.00 B01-12-11 18:36
.badaprj260.00 B01-12-11 18:36
.cproject75.58 kB01-12-11 18:36
.project3.06 kB01-12-11 18:36
application.xml866.00 B01-12-11 18:36
Splash_type2.png29.58 kB01-12-11 18:36
Splash_type3.png34.29 kB01-12-11 18:36
Splash_type4.png84.47 kB01-12-11 18:36
test_type2.png8.00 kB01-12-11 18:36
test_type3.png8.00 kB01-12-11 18:36
test_type4.png12.04 kB01-12-11 18:36
manifest.xml779.00 B01-12-11 18:36
HelloWorldEntry.cpp1.23 kB01-12-11 18:36
Android.mk760.00 B01-12-11 18:36
AppDelegate.cpp4.05 kB23-12-11 11:12
AppDelegate.h1.09 kB01-12-11 18:36
HelloWorldScene.cpp4.26 kB14-01-12 18:18
HelloWorldScene.h899.00 B07-01-12 18:56
ODSocket.cpp3.69 kB12-01-12 17:11
ODSocket.h1.63 kB12-01-12 18:58
sdBall.cpp2.14 kB10-01-12 18:09
sdBall.h571.00 B22-12-11 19:54
sdDangBan.cpp2.51 kB14-01-12 18:05
sdDangBan.h725.00 B22-12-11 19:54
AppController.h1.45 kB01-12-11 18:36
AppController.mm4.93 kB01-12-11 18:36
HelloWorld-Info.plist963.00 B01-12-11 18:36
project.pbxproj132.52 kB01-12-11 18:36
HelloWorld_Prefix.pch189.00 B01-12-11 18:36
main.m368.00 B01-12-11 18:36
RootViewController.h1.36 kB01-12-11 18:36
RootViewController.mm2.61 kB01-12-11 18:36
project.pbxproj137.45 kB01-12-11 18:36
.cproject141.13 kB01-12-11 18:36
.project2.77 kB01-12-11 18:36
main.cpp213.00 B01-12-11 18:36
main.h114.00 B01-12-11 18:36
Makefile977.00 B01-12-11 18:36
postCompiled.sh804.00 B01-12-11 18:36
app.config.txt90.00 B01-12-11 18:36
app.icf139.00 B01-12-11 18:36
background.png477.73 kB22-12-11 19:30
Ball.png3.35 kB21-12-11 14:14
CloseNormal.png5.12 kB01-12-11 18:36
CloseSelected.png6.02 kB01-12-11 18:36
DangBan.png9.23 kB21-12-11 15:15
HelloWorld.png27.88 kB21-12-11 16:38
Icon.png9.11 kB01-12-11 18:36
HelloWorld.win32.vcproj5.21 kB12-01-12 17:16
HelloWorld.win32.vcproj.PCoS-20111206OT.Administrator.user1.44 kB14-01-12 18:17
HelloWorld.win32.vcproj.user487.00 B01-12-11 18:36
HelloWorld.win32.vcxproj7.01 kB01-12-11 18:36
HelloWorld.win32.vcxproj.filters1.18 kB01-12-11 18:36
HelloWorld.win32.vcxproj.user764.00 B01-12-11 18:36
main.cpp408.00 B01-12-11 18:36
main.h277.00 B01-12-11 18:36
HelloWorld.TMK33.03 kB01-12-11 18:36
HelloWorld.wophone.vcproj6.34 kB01-12-11 18:36
HelloWorld.wophone.vcproj.user1.40 kB01-12-11 18:36
HelloWorldUnicodeScript.h250.00 B01-12-11 18:36
HelloWorldUnicodeScript_str.h604.00 B01-12-11 18:36
main.cpp389.00 B01-12-11 18:36
Makefile.ARM2.07 kB01-12-11 18:36
NewDeleteOp.cpp2.05 kB01-12-11 18:36
HelloWorld.upiproj40.80 kB01-12-11 18:36
install.xml380.00 B01-12-11 18:36
TG3AppDllEntry.cpp5.27 kB01-12-11 18:36
TG3AppDllEntry.h1.39 kB01-12-11 18:36
ODSocket.cpp3.69 kB12-01-12 16:37
ODSocket.h1.61 kB12-01-12 13:43
ReadMe.txt1.27 kB10-01-12 16:34
Server.cpp701.00 B14-01-12 18:00
Server.vcproj4.53 kB12-01-12 16:24
Server.vcproj.PCoS-20111206OT.Administrator.user1.39 kB14-01-12 18:40
stdafx.cpp293.00 B10-01-12 16:34
stdafx.h320.00 B10-01-12 16:34
targetver.h765.00 B10-01-12 16:34
Server.sln884.00 B10-01-12 16:35
Server.suo18.00 kB14-01-12 18:40
<application>0.00 B14-01-12 18:39
<application>0.00 B14-01-12 18:39
<lib>0.00 B14-01-12 18:39
<cocos2dx>0.00 B14-01-12 18:39
<cocos2dx>0.00 B14-01-12 18:39
<org>0.00 B14-01-12 18:39
<helloworld>0.00 B14-01-12 18:39
<drawable-hdpi>0.00 B14-01-12 18:39
<drawable-ldpi>0.00 B14-01-12 18:39
<drawable-mdpi>0.00 B14-01-12 18:39
<layout>0.00 B14-01-12 18:39
<values>0.00 B14-01-12 18:39
<org>0.00 B14-01-12 18:39
<Icons>0.00 B14-01-12 18:39
<Icons>0.00 B14-01-12 18:39
<gen>0.00 B14-01-12 18:39
<jni>0.00 B14-01-12 18:39
<res>0.00 B14-01-12 18:39
<src>0.00 B14-01-12 18:39
<sdk1.0>0.00 B14-01-12 18:39
<sdk2.0>0.00 B14-01-12 18:39
<src>0.00 B14-01-12 18:39
<HelloWorld.xcodeproj>0.00 B14-01-12 18:39
<HelloWorld.xcodeproj>0.00 B14-01-12 18:39
<pak>0.00 B14-01-12 18:39
<ChatClient>0.00 B14-01-12 18:41
<airplay>0.00 B14-01-12 18:39
<android>0.00 B14-01-12 18:39
<bada>0.00 B14-01-12 18:39
<Classes>0.00 B14-01-12 18:39
<ios>0.00 B14-01-12 18:39
<iphone>0.00 B14-01-12 18:39
<Linux>0.00 B14-01-12 18:39
<Resource>0.00 B14-01-12 18:39
<win32>0.00 B14-01-12 18:42
<wophone>0.00 B14-01-12 18:39
<Server>0.00 B14-01-12 18:41
<PCClient>0.00 B14-01-12 18:41
<HelloWorld>0.00 B14-01-12 18:39
<PCServer>0.00 B14-01-12 18:41
...
Sponsored links

sdDangBan.cpp (1.05 MB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D