Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import flixel.FlxG;
- import flixel.FlxSprite;
- import flixel.math.FlxVelocity;
- import flixel.math.FlxAngle;
- import flixel.FlxObject;
- class Ball extends FlxSprite
- {
- /**
- * The name of the current FlxSprite
- * Use it to differentiate between anonymous masses of Sprites like in FlxGroups!
- */
- public var name:String;
- public var speed = 0;
- public function new(?X:Int = 0, ?Y:Int = 0)
- {
- super(X, Y);
- loadGraphic(AssetPaths.ball__png, false, 15, 15);
- screenCenter();
- elasticity = 1.0;
- set_alpha(Reg.spriteAlpha);
- name = "ball";
- }
- override public function update(elapsed:Float):Void
- {
- updateFacing();
- super.update(elapsed);
- }
- function updateFacing()
- {
- if (velocity.y < 0 && Math.abs(velocity.y) > Math.abs(velocity.x))
- facing = FlxObject.UP;
- if (velocity.y > 0 && velocity.y > Math.abs(velocity.x))
- facing = FlxObject.DOWN;
- if (velocity.x < 0 && Math.abs(velocity.x) > Math.abs(velocity.y))
- facing = FlxObject.LEFT;
- if (velocity.x > 0 && velocity.x > Math.abs(velocity.y))
- facing = FlxObject.RIGHT;
- FlxG.watch.addQuick("Normal X", velocity.x);
- FlxG.watch.addQuick("Normal Y", velocity.y);
- FlxG.watch.addQuick("Math.abs() X", Math.abs(velocity.x));
- FlxG.watch.addQuick("Math.abs() Y", Math.abs(velocity.y));
- FlxG.watch.addQuick("Facing", facing);
- }
- public function resetBall()
- {
- screenCenter();
- if (Reg.lives == 3)
- speed = FlxG.random.int(200, 300);
- var randomAngle = FlxG.random.float(-180, 180);
- var randomDirection = FlxVelocity.velocityFromAngle(randomAngle, speed);
- velocity.set(randomDirection.x, randomDirection.y);
- }
- public function increaseSpeed()
- {
- speed += 15;
- Reg.speed += 15;
- var curAngle = FlxAngle.asDegrees(Math.atan2(velocity.y, velocity.x));
- var newSpeed = FlxVelocity.velocityFromAngle(curAngle, speed);
- //FlxVelocity.velocityFromFacing(this, speed);
- velocity.set(newSpeed.x, newSpeed.y);
- }
- public function updateBallPos(collideObj:FlxNamedSprite)
- {
- /*
- switch (collideObj.name)
- {
- case "paddle":
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement