| Логика и программирование 09 октября 2011 в 14:34:28
Здравствуйте! Вы не могли бы подсказать код на отскакиваниек от стен, как в princes ololo? Вот код который я использую: stop(); //BASED VARS var gameStart:Boolean = false; var jumping:Boolean = false; var falling:Boolean = false; var jumpPower:Number = 15; var playerSpeed:Number = 5; var playerMove:Boolean = false; var G:Number = 0.2; var GPOW:Number = 0; var JPOW:Number = 0; function INIT():Void { gameStart = true; jumping = false; falling = true; playerMove = false; jumpPower = 15; playerSpeed = 10; pHealth = 100; score = 0; this.onEnterFrame = RENDER; } function TRACKING_CAMERA(obj:Object, smooth:Number):Void { if (smooth<=0) { smooth = 0; } camera._x += (obj._x-camera._x)/smooth; camera._y += (obj._y-camera._y)/smooth; statusBar._x = _root["sky"]._x; statusBar._y = _root["sky"]._y; } function KEY_LISTEN(EV:String):Void { switch (EV) { case "playerMove" : if (Key.isDown(65) || Key.isDown(68)) { playerMove = true; } else { playerMove = false; } if (Key.isDown(65)) { hero._x -= playerSpeed; hero._xscale = -50; } if (Key.isDown(68)) { hero._x += playerSpeed; hero._xscale = 50; } if (Key.isDown(87)) { if (!jumping && !falling) { jumping = true; JPOW = jumpPower; pJumpSound= new Sound(); pJumpSound.attachSound("swing3"); pJumpSound.start(); } } if (Key.isDown(83)) { } break; default : break; } } function ADVANCED_COLLISION():Void { while (platform.hitTest(hero._x, hero._y+1, true)) { hero._y -= 0.1; } while (ceiling.hitTest(hero._x, hero._y-0, true)) { hero._y += 0.1; } while (wall.hitTest(hero._x+25, hero._y+1, true) || wall.hitTest(hero._x+25, hero._y-95, true)) { hero._x -= 0.1; } while (wall.hitTest(hero._x-25, hero._y+1, true) || wall.hitTest(hero._x-25, hero._y-95, true)) { hero._x += 0.1; } } function RENDER():Void { KEY_LISTEN("playerMove"); TRACKING_CAMERA(hero, 8); if (!platform.hitTest(hero._x, hero._y+1, true) && !jumping) { GPOW += G; hero._y += GPOW*5; falling = true; } if (platform.hitTest(hero._x, hero._y+1, true) && !jumping && falling) { GPOW = 0; falling = false; } if (ceiling.hitTest(hero._x, hero._y-80, true) && jumping) { jumping = false; falling = true; } if (jumping) { hero.gotoAndStop(3); } if (playerMove && !jumping && !falling) { hero.gotoAndStop(2); } if (!playerMove && !jumping && !falling) { hero.gotoAndStop(1); } if (jumping) { JPOW -= G*4; if (JPOW<=0) { JPOW = 0; jumping = false; falling = true; } hero._y -= JPOW; } ADVANCED_COLLISION(); } |