package mikhailkrishtop.twisterSpinner;
import java.util.Random;
import org.cocos2d.actions.instant.CCCallFuncN;
import org.cocos2d.actions.interval.CCMoveTo;
import org.cocos2d.actions.interval.CCScaleTo;
import org.cocos2d.actions.interval.CCSequence;
import org.cocos2d.layers.CCLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.menus.CCMenu;
import org.cocos2d.menus.CCMenuItemSprite;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCLabel;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.sound.SoundEngine;
import org.cocos2d.types.CGPoint;
import org.cocos2d.types.CGSize;
import android.content.Context;
import android.view.MotionEvent;
import org.cocos2d.types.ccColor3B;
public class MainLayer extends CCLayer{
static CGSize winsize = CCDirector.sharedDirector().displaySize();
String[][] res = new String [][]
{{"right foot on the","green"},
{"right foot on the","red"},
{"right foot on the","yellow"},
{"right foot on the","blue"},
{"left foot on the","green"},
{"left foot on the","red"},
{"left foot on the","yellow"},
{"left foot on the","blue"},
{"left hand on the","green"},
{"left hand on the","red"},
{"left hand on the","yellow"},
{"left hand on the","blue"},
{"right hand on the","green"},
{"right hand on the","red"},
{"right hand on the","yellow"},
{"right hand on the","blue"}};
Random rand = new Random();
CCSprite arrow;
CCSprite bar;
Options options;
boolean isLocked = false;
float velocity = 540.0f;
float ang, curr_ang = 0.0f;
Float prev_touch_a = null, curr_touch_a = null;
final CGPoint arrow_center;
public static CCScene scene() {
CCScene scene = CCScene.node();
CCLayer layer = new MainLayer();
scene.addChild(layer);
return scene;
}
public MainLayer() {
MainSingleton.mainLayer = this;
this.setIsTouchEnabled(true);
CCSprite wheel = CCSprite.sprite("wheel.png", true);
wheel.setScale(MainSingleton.scale);
wheel.setPosition(winsize.width * 0.5f, winsize.height - wheel.getHeight() * 0.5f);
this.addChild(wheel);
arrow = CCSprite.sprite("arrow3.png", true);
arrow.setScale(MainSingleton.scale);
arrow_center = CGPoint.make(winsize.width * 0.5f, winsize.height - arrow.getWidth() * 0.5f);
arrow.setPosition(arrow_center);
this.addChild(arrow);
options = new Options();
CCSprite bg = CCSprite.sprite("background2.png", true);
bg.setScale(MainSingleton.scale);
bg.setPosition(winsize.width * 0.5f, bg.getHeight() * 0.5f - options.options.getHeight());
this.addChild(bg,-1);
//bar = CCSprite.sprite("bar.png", true);
//bar.setScale(MainSingleton.scale);
//bar.setPosition(winsize.width * 0.5f, bar.getHeight() * 0.5f);
//this.addChild(bar);
Context context = CCDirector.sharedDirector().getActivity();
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_foot_green);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_foot_red);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_foot_yellow);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_foot_blue);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_foot_green);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_foot_red);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_foot_yellow);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_foot_blue);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_hand_green);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_hand_red);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_hand_yellow);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.left_hand_blue);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_hand_green);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_hand_red);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_hand_yellow);
SoundEngine.sharedEngine().preloadEffect(context, R.raw.right_hand_blue);
}
@Override
public boolean ccTouchesBegan(MotionEvent event) {
return true;
}
@Override
public boolean ccTouchesMoved(MotionEvent event) {
CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY()));
location = CGPoint.make(location.x - arrow_center.x, location.y - arrow_center.y);
float arrow_ang = (curr_ang + 270) % 360.0f;
prev_touch_a = curr_touch_a;
curr_touch_a = (float)Math.toDegrees((Math.atan2(location.x, location.y) + Math.PI));
System.out.println("~~ang_t: "+ curr_touch_a);
System.out.println("~~ang_a: "+ arrow_ang);
if (prev_touch_a != null && !isLocked)
{
double tmp = Math.sqrt(Math.pow(location.x, 2) + Math.pow(location.y, 2));
if (tmp < 0.25f*arrow.getWidth())
{
if (prev_touch_a < ((arrow_ang + 180) % 360.0f) && curr_touch_a > ((arrow_ang + 180) % 360.0f))
{
rotate((rand.nextFloat()*360.0f + 360.0f));
return true;
}
if (prev_touch_a > ((arrow_ang + 180) % 360.0f) && curr_touch_a < ((arrow_ang + 180) % 360.0f))
{
rotate(-(rand.nextFloat()*360.0f + 360.0f));
return true;
}
}
if (tmp < 0.5f*arrow.getWidth())
{
if (prev_touch_a < arrow_ang && curr_touch_a > arrow_ang)
{
rotate((rand.nextFloat()*360.0f + 360.0f));
return true;
}
if (prev_touch_a > arrow_ang && curr_touch_a < arrow_ang)
{
rotate(-(rand.nextFloat()*360.0f + 360.0f));
return true;
}
}
}
return true;
}
@Override
public boolean ccTouchesEnded(MotionEvent event) {
prev_touch_a = null;
curr_touch_a = null;
return true;
}
void rotate(float angle) {
isLocked = true;
ang = angle;
this.schedule("rotateScheduler", 1.0f/60.0f);
if (bar != null)
{
CCScaleTo scaleUp = CCScaleTo.action(0.1f, MainSingleton.scale*1.1f);
CCScaleTo scaleDown = CCScaleTo.action(0.4f, 0.01f);
CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "barIsScaledDown");
CCSequence actions1 = CCSequence.actions(scaleUp, scaleDown, actionMoveDone);
bar.runAction(actions1);
}
}
public void rotateScheduler(float dt) {
if (Math.abs(ang) < 30)
{
ang = 0.0f;
this.unschedule("rotateScheduler");
resultBar(curr_ang);
isLocked = false;
}
else
{
if (ang > 0.0f)
{
rotateClockwise(dt * velocity);
ang -= dt * velocity;
}
else
{
rotateCounterclockwise(dt * velocity);
ang += dt * velocity;
}
}
}
void rotateClockwise(float angle) {
float next_ang = curr_ang + angle;
if (next_ang > 360)
next_ang = next_ang % 360.0f;
arrow.setRotation(next_ang);
curr_ang = next_ang;
}
void rotateCounterclockwise(float angle) {
float next_ang = curr_ang - angle;
if (next_ang < 0)
next_ang += 360.0f;
arrow.setRotation(next_ang);
curr_ang = next_ang;
}
void resultBar(float ang) {
int num = (int)(ang/22.5f);
String text1 = res[num][0];
String text2 = res[num][1];
CCLabel label1 = CCLabel.makeLabel(text1, "Monospace", 36);
CCLabel label2 = CCLabel.makeLabel(text2, "Monospace", 36);
bar = CCSprite.sprite("bar.png", true);
bar.setScale(MainSingleton.scale);
bar.setPosition(winsize.width * 0.5f, bar.getHeight() * 0.5f);
label1.setAnchorPoint(0.5f, 0.5f);
label2.setAnchorPoint(0.5f, 0.5f);
bar.addChild(label1);
bar.addChild(label2);
System.out.println("~pos: " + bar.getPosition().toString());
System.out.println("~anch_point: " + label1.getAnchorPoint().toString());
label1.setPosition(bar.getContentSize().width * 0.5f, (bar.getContentSize().height + label1.getHeight())*0.5f);
label2.setPosition(bar.getContentSize().width * 0.5f, (bar.getContentSize().height - label2.getHeight())*0.5f);
System.out.println("~pos_l1: " + label1.getPosition().toString());
System.out.println("~pos_l2: " + label2.getPosition().toString());
bar.setScale(0.01f);
this.addChild(bar);
没有合适的资源?快使用搜索试试~ 我知道了~
iOS实例开发源码——MKrishtop-TwisterSpinner-b58218a.zip
共728个文件
class:688个
mp3:16个
java:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 53 浏览量
2023-07-02
15:15:25
上传
评论
收藏 13.24MB ZIP 举报
温馨提示
iOS实例开发源码——MKrishtop-TwisterSpinner-b58218a.zip
资源推荐
资源详情
资源评论
收起资源包目录
iOS实例开发源码——MKrishtop-TwisterSpinner-b58218a.zip (728个子文件)
resources.ap_ 3.07MB
proguard.cfg 1KB
GLDebugWrapper$MyGLImplementation.class 30KB
CCSprite.class 24KB
CCNode.class 23KB
Base64.class 22KB
CCDirector.class 19KB
CCParticleSystem.class 18KB
MathLib.class 18KB
CCTexture2D.class 15KB
Matrix4.class 15KB
World.class 14KB
CGAffineTransform.class 14KB
TextBuilder.class 14KB
CCTextureAtlas.class 13KB
CCScheduler.class 13KB
CCTMXLayer.class 12KB
Intersector.class 12KB
Body.class 11KB
CCProgressTimer.class 11KB
CCSpriteSheet.class 11KB
MainLayer.class 10KB
CCMenu.class 10KB
CCTMXMapInfo$CCTMXXMLParser.class 9KB
CCQuadParticleSystem.class 8KB
CCTouchDispatcher.class 8KB
ZwoptexParser.class 8KB
ParticleTest$ParticleDemo.class 8KB
CCActionManager.class 7KB
CCBitmapFontAtlas.class 7KB
CCBitmapFontAtlas$CCBitmapFontConfiguration.class 7KB
CCSpriteFrameCache.class 7KB
Box2dTest$Box2DTestLayer.class 7KB
Vector3.class 7KB
BoundingBox.class 7KB
CCTileMapAtlas.class 7KB
Frustum.class 7KB
CGPoint.class 7KB
CCTMXTiledMap.class 7KB
PlistParser.class 7KB
CCRibbon.class 7KB
CGRect.class 7KB
MenuTest$Layer1.class 7KB
FontTest$Layer1.class 7KB
EffectsTest$TextLayer.class 6KB
CCGridBase.class 6KB
TileMapTest$TMXReadWriteTest.class 6KB
SoundEngine.class 6KB
CCPVRTexture.class 6KB
ActionsTest$ActionDemo.class 6KB
CCDrawingPrimitives.class 6KB
LongHashMap.class 6KB
Options.class 6KB
TransitionsTest$TestLayer.class 6KB
CCLayer.class 6KB
EarCutTriangulator.class 5KB
CCGrid3D.class 5KB
TransitionsTest$TestLayer2.class 5KB
IntMap.class 5KB
EffectsTest.class 5KB
ParticleTest.class 5KB
TransitionsTest.class 5KB
CCTextureCache.class 5KB
CatmullRomSpline.class 5KB
ActionsTest.class 5KB
CCColorLayer.class 5KB
TileMapTest.class 5KB
AtlasTest$Atlas4.class 5KB
FastFloatBuffer.class 5KB
Matrix3.class 5KB
CCPointParticleSystem.class 5KB
Cocos2D.class 5KB
CCShuffleTiles.class 5KB
FontTest$Layer3.class 5KB
MenuTest$Layer3.class 5KB
CCTiledGrid3D.class 5KB
CCLabelAtlas.class 5KB
TileMapTest$TileDemo.class 5KB
EffectsAdvancedTest$TextLayer.class 5KB
CCAnimate.class 5KB
SpritesTest.class 4KB
CCMenuItemLabel.class 4KB
CCAnimation.class 4KB
TGA.class 4KB
CCTMXMapInfo.class 4KB
AtlasTest.class 4KB
EaseActionsTest.class 4KB
CCRenderTexture.class 4KB
ClickAndMoveTest$MainLayer.class 4KB
ConcNodeCachingLinkedQueue.class 4KB
CocosNodeTest.class 4KB
CCAtlasNode.class 4KB
AtlasTest$Atlas3.class 4KB
BufferProvider.class 4KB
ConcurrentArrayHashMap.class 4KB
SchedulerTest.class 4KB
CCMenuItemToggle.class 4KB
CCKeyDispatcher.class 4KB
CCTransitionScene.class 4KB
Fixture.class 4KB
共 728 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
快乐无限出发
- 粉丝: 1155
- 资源: 7299
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功