Trying to do a charged shot for a game

My name is Justin and I know next to nothing about Coding. Yet I was assigned to a coding team for a game we're working on for school. I managed to put together a decent shooting mechanic for our game by watching tutorials but I can't find any sources or tutorials on how to do charged shots. Here's my code. Any help would be much appreciated.
Main timeline:
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftBumping:Boolean = false;
var rightBumping:Boolean = false;
var upBumping:Boolean = false;
var downBumping:Boolean = false;
var leftBumpPoint:Point = new Point(-30, -55);
var rightBumpPoint:Point = new Point(30, -55);
var upBumpPoint:Point = new Point(0, -120);
var downBumpPoint:Point = new Point(0, 0);
var scrollX:Number = 0;
var scrollY:Number = 0;
var xSpeed:Number = 0;
var ySpeed:Number = 0;
var speedConstant:Number = 4;
var frictionConstant:Number = 0.9;
var gravityConstant:Number = 1.8;
var jumpConstant:Number = -35;
var maxSpeedConstant:Number = 18;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.addEventListener(Event.ENTER_FRAME, loop);
var bulletList:Array = new Array();
function loop(e:Event):void{
if(back.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){
leftBumping = true;
} else {
leftBumping = false;
if(back.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){
rightBumping = true;
} else {
rightBumping = false;
if(back.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){
upBumping = true;
} else {
upBumping = false;
if(back.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){
downBumping = true;
} else {
downBumping = false;
if(leftPressed){
xSpeed -= speedConstant;
} else if(rightPressed){
xSpeed += speedConstant;
if(leftBumping){
if(xSpeed < 0){
xSpeed *= -0.5;
if(rightBumping){
if(xSpeed > 0){
xSpeed *= -0.5;
if(upBumping){
if(ySpeed < 0){
ySpeed *= -0.5;
if(downBumping){
if(ySpeed > 0){
ySpeed = 0;
if(upPressed){
ySpeed = jumpConstant;
} else {
ySpeed += gravityConstant;
if(xSpeed > maxSpeedConstant){
xSpeed = maxSpeedConstant;
} else if(xSpeed < (maxSpeedConstant * -1)){
xSpeed = (maxSpeedConstant * -1);
xSpeed *= frictionConstant;
ySpeed *= frictionConstant;
if(Math.abs(xSpeed) < 0.5){
xSpeed = 0;
scrollX -= xSpeed;
scrollY -= ySpeed;
back.x = scrollX;
back.y = scrollY;
function keyDownHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = true;
} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = true;
} else if(e.keyCode == Keyboard.UP){
upPressed = true;
} else if(e.keyCode == Keyboard.DOWN){
downPressed = true;
function keyUpHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftPressed = false;
} else if(e.keyCode == Keyboard.RIGHT){
rightPressed = false;
} else if(e.keyCode == Keyboard.UP){
upPressed = false;
} else if(e.keyCode == Keyboard.DOWN){
downPressed = false;
if(e.keyCode == Keyboard.SPACE){
fireBullet();
function fireBullet():void {
var playerDirection:String;
if(player.scaleX < 0){
playerDirection = "left";
} else if(player.scaleX > 0){
playerDirection = "right";
var bullet:Bullet = new Bullet(player.x - scrollX, player.y - scrollY, playerDirection, xSpeed);
back.addChild(bullet);
bullet.addEventListener(Event.REMOVED, bulletRemoved);
bulletList.push(bullet);
function bulletRemoved(e:Event):void
e.currentTarget.removeEventListener(Event.REMOVED, bulletRemoved); //this just removes the eventListener so we don't get an error
bulletList.splice(bulletList.indexOf(e.currentTarg et), 1); //this removes 1 object from the bulletList, at the index of whatever object caused this function to activate
External AS File(Bullet)
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Stage;
public class Bullet extends MovieClip {
private var speed:int = 30;
private var initialX:int;
public function Bullet(playerX:int, playerY:int, playerDirection:String, playerSpeed:int) {
// constructor code
if(playerDirection == "left") {
speed = -30 + playerSpeed; //speed is faster if player is running
x = playerX - 25;
} else if(playerDirection == "right") {
speed = 30 + playerSpeed;
x = playerX + 25
y = playerY - 75;
initialX = x; //use this to remember the initial spawn point
addEventListener(Event.ENTER_FRAME, loop);
public function loop(e:Event):void
//looping code goes here
x += speed;
if(speed > 0) { //if player is facing right
if(x > initialX + 640) { //and the bullet is more than 640px to the right of where it was spawned
removeSelf(); //remove it
} else { //else if player is facing left
if(x < initialX - 640) { //and bullet is more than 640px to the left of where it was spawned
removeSelf(); //remove it
public function removeSelf():void
trace("remove self");
removeEventListener(Event.ENTER_FRAME, loop); //stop the loop
this.parent.removeChild(this); //tell this object's "parent object" to remove this object
//in our case, the parent is the background because in the main code we said:
//back.addChild(bullet);

import flash.events.KeyboardEvent;
import flash.utils.Timer;
stage.addEventListener(KeyboardEvent.KEY_DOWN, startTimer);
stage.addEventListener(KeyboardEvent.KEY_UP, endTimer);
var _timer:Timer = new Timer(3000,1);
var charged:Boolean = false;
var _keyDown:Boolean = false;
_timer.addEventListener(TimerEvent.TIMER_COMPLETE,completeHandler);
function startTimer(e:KeyboardEvent):void{
    if(!_keyDown){
    _keyDown = true;
    _timer.start();
    charged = false;
function endTimer(e:KeyboardEvent):void{
    trace("KEY UP");
    _keyDown = false;
    if(_timer.running){
        _timer.stop();
    trace(charged);
function completeHandler(e:TimerEvent):void{
    trace("TIMER ENDED");
    charged = true;
    _timer.stop();

Similar Messages

Maybe you are looking for

  • Synchronising contract data in R3 AND CRM

    Hi All , Greetings for the day!! I had appended a new field in contract (VBAP-ZZFIELD) in R3.This contract first get created in CRM and gets copied in R3. Whatever changes i make to new field in R3 must gets copied to same contract in  CRM & vice ver

  • Audio Missing When Exporting to Flash

    When I export this Keynote presentation to Flash, I get an error message that says "Can't export an audio file because of an unknown error." Then it says that "Couldn't export a media file on slide 1" and so on for all 10 slides. It's basically a pre

  • Reservation Creation in Issue Unit of Measure

    Hi, I have a product whose component has Base Unit of Measure as EACH and Issue unit of Measure is  PIECE. ( 5 Piece = 1 Each) .In BOM we maintain as PIECE and in Work Scheduling view of materialMaster issue unit is maintained as PIECE.  Now the issu

  • Wacom Intuous4 in Lightroom configuration/settings

    I bought a Wacom Intous4 about a month ago, and am loving it so far. I'm still in the process of deciding how I want to set up my ExpressKeys, Touch Ring, and Radial Menu, so I thought I'd check in here and see what other folks are doing. How have yo

  • CcBPM: Message outbound status, Message being sent

    Hi I have a message with status flag message being sent at the outbound status PE since 30 days. Because of this message many messages got blocked with scheduled on outbound side status. I tried to delete work items related to the message in SWWL, bu