Creating a Penalty Shootout Game with Actionscript 3.0
A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: Creating a Penalty Shootout Game with Actionscript 3.0

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    7

    Creating a Penalty Shootout Game with Actionscript 3.0

    I currently have three weeks left ony my degree and the last thing i have to do is build a penalty shootout game with Actionscript 3.0.

    I thought i would be able to do this but im having trouble getting my head round this.

    I understand that i need to have a player, a ball, goalposts, a crowd and i need a scoring system.

    I know all the basics but i have no idea how to actually go about making this a fully functional game, is there any tutorials on making a penalty shootout game? Ive searched all over but cannot find anything?

  2. #2
    Knowledgable n00b BlueGeek's Avatar
    Join Date
    Nov 2006
    Location
    New York City
    Posts
    137
    Woa boy,

    This one might be tricky. How much programing experience do you have?
    "...there were only two good books in the hotel gift shop and I had written both of them."
    -Douglas Adams

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Basically for the last three years been doing Javascript, PHP, ASP and stuff like that to a basic level.

    Im okay with Actionscript 2.0 for creating websites with Flash but Actionscript 3.0 just baffles me and i think im gonna fail my degree if i dont get this game done lol.

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Got basic experience in Javascript, asp, php over the past couple of years but Actionscript 3.0 totally baffles me lol.

    Heres the code i have for the game so far.................any help would be appreciated!

    /* this creates the instances of the ball and player and
    puts them on the stage*/

    var myBall:Ball = new Ball();
    var myPlayer:Player = new Player();
    var myPosts:Posts = new Posts ();

    var dx:Number = 30;
    var dy:Number = 30;

    stage.addChild(myBall);
    stage.addChild(myPlayer);
    stage.addChild(myPosts);


    /* this sets the position of the ball, player, goalposts etc*/
    myBall.x = 250
    myBall.y = 250
    myPlayer.x = 500
    myPlayer.y = 300
    myPosts.x = 250
    myPosts.y = 100

    var started:Boolean = false;
    stage.addEventListener(MouseEvent.CLICK, clickhandler);

    function clickhandler(evt:Event):void {
    if(started == false) {
    startGame();
    }
    }

    function startGame(){
    started = true;
    myBall = new Ball();
    addChild(myPlayer);
    myPlayer = new Player();
    addChild(myPlayer);
    addEventListener(Event.ENTER_FRAME, runGame);
    }

    function runGame(event:Event) {
    if(started == true) {
    movePlayer();
    moveBall();
    }
    }


    function movePlayer() {
    if(mouseY < 300) {
    myPlayer.y = mouseY;
    }

    {
    if(mouseX < 300) {
    myPlayer.x = mouseX;
    }
    }
    }

    function moveBall() {
    var newX:Number = myBall.x + dx;
    var newY:Number = myBall.y + dy;



    //right goalpost
    if(newX >= 545) {
    newX -= dx;
    dx *= -1;
    }
    //bottom on goaline and top bar
    if(newY <= 5 || newY >= 355) {
    newY -= dy;
    dy *= -1;
    }


    //left goalpost
    if(newX <= 5) {
    newX -= dx;
    dx *= -1;
    }

    myBall.x = newX;
    myBall.y = newY;
    }

  5. #5
    Member
    Join Date
    Nov 2008
    Posts
    49
    Quote Originally Posted by viperlike5258 View Post
    I currently have three weeks left ony my degree and the last thing i have to do is build a penalty shootout game with Actionscript 3.0.

    I thought i would be able to do this but im having trouble getting my head round this.

    I understand that i need to have a player, a ball, goalposts, a crowd and i need a scoring system.

    I know all the basics but i have no idea how to actually go about making this a fully functional game, is there any tutorials on making a penalty shootout game? Ive searched all over but cannot find anything?

    I think the best way to do this is that you just get started with it and anywhere you feel you are confused and can't figure out, share your code here and ask for seniors to suggest.

    I don't think its possible that you can find complete project done. Just start it and you will see it happening.

    Best of luck with it

  6. #6
    Knowledgable n00b BlueGeek's Avatar
    Join Date
    Nov 2006
    Location
    New York City
    Posts
    137
    Just to reiterate my idea with a pinch just_started's input, from your wording it sounds like you may be trying to go about this using JUST Flash's animation engine (ie: without any coding). Although this might be theoretically possible (some combination of basic buttons and a little tweening) it won't give the results you want, and it would be a whole lot of hacking and cleverness to get a mediocre result.

    As started said: give us a little more direction here, and possibly share a little bit about your own experience with computers, programming, and Flash, and we can give a little more back.
    "...there were only two good books in the hotel gift shop and I had written both of them."
    -Douglas Adams

  7. #7
    Knowledgable n00b BlueGeek's Avatar
    Join Date
    Nov 2006
    Location
    New York City
    Posts
    137
    Reposting vipers code for him using AS tags so it's a little easier to read (hint hint). ALSO! added indenting

    Actionscript Code:
    /* this creates the instances of the ball and player and
    puts them on the stage*/


    var myBall:Ball = new Ball();
    var myPlayer:Player = new Player();
    var myPosts:Posts = new Posts ();

    var dx:Number = 30;
    var dy:Number = 30;

    stage.addChild(myBall);
    stage.addChild(myPlayer);
    stage.addChild(myPosts);


    /* this sets the position of the ball, player, goalposts etc*/
    myBall.x = 250
    myBall.y = 250
    myPlayer.x = 500
    myPlayer.y = 300
    myPosts.x = 250
    myPosts.y = 100

    var started:Boolean = false;
    stage.addEventListener(MouseEvent.CLICK, clickhandler);

    function clickhandler(evt:Event):void {
        if(started == false) {
            startGame();
        }
    }

    function startGame(){
        started = true;
        myBall = new Ball();
        addChild(myPlayer);
        myPlayer = new Player();
        addChild(myPlayer);
        addEventListener(Event.ENTER_FRAME, runGame);
    }

    function runGame(event:Event) {
        if(started == true) {
            movePlayer();
            moveBall();
        }
    }


    function movePlayer() {
        if(mouseY < 300) {
            myPlayer.y = mouseY;
        }

        {
            if(mouseX < 300) {
                myPlayer.x = mouseX;
            }
        }
    }

    function moveBall() {
        var newX:Number = myBall.x + dx;
        var newY:Number = myBall.y + dy;



        //right goalpost
        if(newX >= 545) {
            newX -= dx;
            dx *= -1;
        }
        //bottom on goaline and top bar
        if(newY <= 5 || newY >= 355) {
            newY -= dy;
            dy *= -1;
        }


        //left goalpost
        if(newX <= 5) {
            newX -= dx;
            dx *= -1;
        }

        myBall.x = newX;
        myBall.y = newY;
    }
    Last edited by BlueGeek; 03-28-2011 at 09:21 AM. Reason: added indenting
    "...there were only two good books in the hotel gift shop and I had written both of them."
    -Douglas Adams

  8. #8
    Knowledgable n00b BlueGeek's Avatar
    Join Date
    Nov 2006
    Location
    New York City
    Posts
    137
    Alright, so your code in itself isn't bad as AS3, it just has at least one glitche in it syntactically. After you've finished this I suggest you spend a little bit of time making indenting a habit, I caught this error just by throwing in tabs.

    And now the problems I found!

    First of all, I can't run this (I don't have objects for Player, Posts or Ball but I'll assume they're defined in the library as they only use properties native to Sprites and MC's) so fixing this might be a multistep process.

    Check line 55 and 58, you'll find an extra set of {}'s.

    That's all that's really popping out at me from this code, if you post the FLA so I can run it and poke around a bit that might help, too.

    You're not far off though, keep it up!
    "...there were only two good books in the hotel gift shop and I had written both of them."
    -Douglas Adams

  9. #9
    Junior Member
    Join Date
    Mar 2011
    Posts
    7

  10. #10
    Knowledgable n00b BlueGeek's Avatar
    Join Date
    Nov 2006
    Location
    New York City
    Posts
    137
    Alright, this is going to be a 2 parter.

    The first part is going to be going over what you have here and doing a little tidying up.

    Now, as it was, your code actually executes fine, with just one warning. Fonts in Flash are a little bit finicky, since almost all computers have different sets of fonts on them, to use a specific font in an FLA you have to embed it (literally keep a copy of the entire font in your file) which is cumbersome and requires some minor micro management. While you're getting used to Flash, I recommend using the _serif and _sans options. When you specify one of these as your font, the users computer picks what it considers to be the default serif or sans-serif.

    To do this, select your text field.

    Under the font drop down select either _serif, _sans, or _typewriter.



    Another thing regarding the text field. Right now it is set to be TFL, a new format with AS3 that I, personally, am not familiar with. I'm not entirely sure why, but they tend to generate extra files, and odd warnings so I've switched it over to a classic text field; you should do the same so we're on the same page. I'm sure if anyone else ends up seeing this, they'll beat my ear in about why I'm wrong.

    At the top of the properties menu under where you name the instance you'll see a drop down that says "TLF text".

    Click on the drop down and select "Classic Text".



    Next use the drop down under that one and select "Dynamic Text"



    You may have to retype the name of your instance in the appropriate text box.

    Next, your layers. When adding objects programmatically (ie: var myObject:Object = new Object()) everything is added directly to the stage, layers aren't used. Therefore you don't need a separate layer for every object you add. To control which objects appear "on top" change the order in which they are addChild'd to the stage (objects added later appear on top).



    Your layers can be cut down to just this; it's not super important, but it's good to have this grasp on AS3.

    download the new FLA here

    Now that we've tidied up the file, and I see what everything is doing, it's time to start really planning out what you want this to do. Post exactly what you want here. Try to explain it in as much detail as possible, almost as if you were programming it in the english language.

    Hope this helps! Talk soon

    -S
    Last edited by BlueGeek; 03-28-2011 at 07:39 PM. Reason: added ass-covering humor
    "...there were only two good books in the hotel gift shop and I had written both of them."
    -Douglas Adams

  11. #11
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Thanks for clearing that stuff up man. Ill try to explain what im trying to do with the game in plan English............I will quote some stuff for my specification of the game, it is basically a penalty shootout game to advertise a new sports drink......

    Overall Function of Game

    "We are then taken to the penalty shootout with the goalkeeper between the goalposts and the football player waiting to hit the ball which is placed on the penalty spot. The player can either shoot left, right or center and the goalkeeper will either go left, right or stay in the middle in attempt to stop the user from scoring. Advertisement for the sports drink include bottles of the sports drink being placed left and right of the goalposts and also there will be banners near the crowd advertising the drink. Once the shot has been taken the score will be updated on the screen, if the ball went in the net then it will display on the screen but if no goal was scored the points stay at 0. Once the shot has been taken the user gets to take another shot. There will always be an option on the screen to exit the application."

    Movie Clips That Need To Be Created For Application To Work

    mcBall – This is the ball that the football player is aiming to put between the goalposts in order to score points.
    mcPlayer – The player will make contact with the ball either placing it left, right or center to aim to score points.
    mcGoalkeeper – The goalkeeper will either go left, to the right or stay in the middle in order to try and stop the user scoring points.
    mcGoalposts – This is where the ball has to hit in order for the user to score points.

    Events Within The Game

    There will be a ball placed on the penalty spot and the football player controlled by the user can either choose to kick the ball down the center, to the left or to the right to try and score a point. The goalkeeper will choose a random direction to dive whether it be to stay in the center, to dive to the left or to dive to the right. If the ball meets the goalkeeper then that will count as a save and the user will not score a point but if the ball hits the inside of the net then the user will score a point and this will be displayed on the screen to let the user know they have scored a point. It is quite obvious that the collision detection method will have to be used while developing this, this has already been implemented in the labs so it should be possible to do this within the application. My knowledge of collision detection will no doubt be expanded on as i look to implement it into the game.

  12. #12
    Knowledgable n00b BlueGeek's Avatar
    Join Date
    Nov 2006
    Location
    New York City
    Posts
    137
    Alright, so the good news is that this IS actually going to be almost all animation. I'm a bit short on time today so I'll give you a brief outline.

    You're going to want to make 6 animations; 3 of the ball going in each of three directions; 3 of the goal keeper diving in each of three directions. Put each in its own movie clip.

    You're also going to want to use three buttons, one for each direction the ball can be kicked. When one of these buttons is pressed, you tell the appropriate movie clip to play (ball left, ball center, ball right). At the same time pick a random number, 1, 2 or 3. If it's 1, play the animation of the goalie jumping left, if it's 2 center, and 3 right. Use an if statement to see if the goalie and ball went in the same direction.
    "...there were only two good books in the hotel gift shop and I had written both of them."
    -Douglas Adams

  13. #13
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    Could you go into a bit more detail about what i have to do? Im still having trouble getting my head round this (

  14. #14
    Junior Member
    Join Date
    Mar 2011
    Posts
    7
    ????

  15. #15
    Member
    Join Date
    Oct 2003
    Location
    Norwich
    Posts
    87
    Any luck building this back in 2011? I need to build a similar game with 6 areas in the goal to shoot at and a high score system

  16. #16
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    I wish to participate in this project. I am not advanced but I learn fast. Skippers, please list the things you need for your project so i can help you.
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  17. #17
    Member
    Join Date
    Oct 2003
    Location
    Norwich
    Posts
    87
    Thanks Angelhdz.

    I would like to build a football penalty game where the shooter uses the arrow keys to direct the ball into 6 possible areas of the goal. The computer goalkeeper would then dive to a random position to attempt to save. In turn the computer would shoot and the user directs the goalkeeper to save in 1 of 6 directions.

    Player and computer get 5 shots each. You can opt to repeat the process and scores go into a high score chart.

  18. #18
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    Ok. And what panoramic VIEW would you like to use? First person, second person, Top View?


    It will be a little complicated for me, because I don't master the gravity/friction thing, but I like to learn, and build new things and expand my knowledges.
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  19. #19
    Member
    Join Date
    Oct 2003
    Location
    Norwich
    Posts
    87
    I would say a similar angle to this:
    http://www.agame.com/game/penalty-shootout-2012

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com