this repo has no description
at main 162 lines 3.2 kB view raw
1package; 2 3import flixel.FlxG; 4import flixel.FlxObject; 5import flixel.FlxSprite; 6import flixel.group.FlxGroup.FlxTypedGroup; 7import flixel.system.FlxAssets.FlxGraphicAsset; 8import flixel.tweens.FlxEase; 9import flixel.tweens.FlxTween; 10import flixel.util.FlxColor; 11 12/** 13 * ... 14 * @author ninjaMuffin 15 */ 16class Player extends FlxSprite 17{ 18 private var bulletArray:FlxTypedGroup<Bullet>; 19 20 public var justShot:Bool = false; 21 22 private var rateOfFire:Int = 6; 23 private var fireCoutner:Int = 0; 24 25 public var xPos:Float = 0; 26 27 private var knockBack:Float = 3; 28 29 private var accel:Float = 3000; 30 31 public var justThought:Bool = false; 32 33 private var thoughtTimer:Float = 4; 34 private var walkTmr:Float = 0.2; 35 private var prevStep:Int = 1; 36 37 public function new(?X:Float = 0, ?Y:Float = 0, playerBulletArray:FlxTypedGroup<Bullet>) 38 { 39 super(X, Y); 40 makeGraphic(64, 64); 41 42 maxVelocity.x = 300; 43 drag.x = 1400; 44 45 bulletArray = playerBulletArray; 46 color = FlxColor.WHITE; 47 } 48 49 override public function update(elapsed:Float):Void 50 { 51 controls(); 52 53 super.update(elapsed); 54 55 if (justThought) 56 { 57 thoughtTimer -= FlxG.elapsed; 58 if (thoughtTimer <= 0) 59 { 60 justThought = false; 61 thoughtTimer = 4; 62 } 63 } 64 } 65 66 private function controls():Void 67 { 68 var _left:Bool = FlxG.keys.anyPressed([A, LEFT]); 69 var _right:Bool = FlxG.keys.anyPressed([D, RIGHT]); 70 var _upP:Bool = FlxG.keys.anyJustPressed([W, UP]); 71 72 var _shift:Bool = FlxG.keys.anyPressed([SHIFT, X]); 73 74 var canJump:Bool = isTouching(FlxObject.FLOOR); 75 76 if (_shift) 77 { 78 maxVelocity.x = 450; 79 } 80 else 81 { 82 maxVelocity.x = 300; 83 } 84 85 if (_left && _right) 86 { 87 _left = _right = false; 88 } 89 90 if (_upP && canJump) 91 { 92 FlxTween.tween(scale, {x: 0.8, y: 1.2}, 0.3, {ease: FlxEase.quadOut}).then(FlxTween.tween(scale, {x: 1, y: 1}, 0.5, {ease: FlxEase.quadInOut})); 93 velocity.y -= 360; 94 } 95 96 acceleration.x = 0; 97 98 if (_left || _right) 99 { 100 walkTmr -= FlxG.elapsed; 101 102 if (walkTmr <= 0 && isTouching(FlxObject.FLOOR) && velocity.x != 0) 103 { 104 walkTmr = FlxG.random.float(0.3, 0.36); 105 prevStep = FlxG.random.int(1, 4, [prevStep]); 106 FlxG.sound.play("assets/sounds/walk" + Std.string(prevStep) + ".ogg"); 107 } 108 109 if (_left) 110 { 111 acceleration.x = -accel; 112 113 facing = FlxObject.LEFT; 114 } 115 if (_right) 116 { 117 acceleration.x = accel; 118 119 facing = FlxObject.RIGHT; 120 } 121 } 122 123 if (color == FlxColor.WHITE) 124 { 125 shooting(); 126 } 127 } 128 129 private function shooting():Void 130 { 131 justShot = false; 132 if (FlxG.keys.pressed.SPACE) 133 { 134 fireCoutner += 1; 135 if (fireCoutner >= rateOfFire) 136 { 137 FlxG.sound.play("assets/sounds/bullet" + FlxG.random.int(1, 3) + ".ogg", FlxG.random.float(0.35, 0.55)); 138 fireCoutner = 0; 139 attack(); 140 justShot = true; 141 } 142 } 143 } 144 145 private function attack():Void 146 { 147 switch (facing) 148 { 149 case FlxObject.RIGHT: 150 xPos = x + 54; 151 x -= knockBack; 152 case FlxObject.LEFT: 153 xPos = x - 22; 154 x += knockBack; 155 default: 156 throw("OOPSIE WOOPSIE!! Uwu We madea fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!"); 157 } 158 159 var newBullet = new Bullet(xPos, y + 32, 1600, facing, 10); 160 bulletArray.add(newBullet); 161 } 162}