<%@LANGUAGE="VBSCRIPT" %> <% Response.CacheControl = "no-cache" %>
Lab 8 (Due 11:00 PM Friday)

Materials to turn in on the server

  • In your Lab08 folder:
    • Lab08part1.php
    • Lab08part1.fla
    • Lab08part1.swf
    • gameMain.as
    • key.as
    • bullet.as
    • badMan.as
    • Lab08part2.php
    • Lab08part2.fla
    • Lab08part2.swf

Expand/Collapse Section ImageLab Description

Students will learn the basics of gaming in flash. Students will simulate gravity, friction, and collision detection.

 

Expand/Collapse Section ImageExercise Specifications - Part 1

  1. Game Setup

    You are provided with all the files correctly setup as needed. Take some time to look at Lab08part1.fla to see how it is setup ( the linkage on the items in the library, the FPS, and the document class ).

    When you are ready to begin, create a new file in the same folder called "gameMain.as". The code that is to go into this file is in gameMain.pdf. Short explanations of some of the key items in the file follow.

    You will also need to create a new file in the same folder called "key.as". The code that goes into that file is in key.pdf.

    The Game Class:

    After creating a package for the class and importing the correct areas to be used in this file, you define the gameMain class. This class is taking over for the root of the flash movieclip, so it has to extend MovieClip.

    Within this class, the first thing you do is define any objects, constants, and other variables that will be used throughout the game. After that, you create a function with the same name as the class ( gameMain ), this is the instantiator function, it is run the instant this class is created, and is your "startup" code. Within this function initialize all your variables for the game, and lastly, start the game loop, in this case we're using "onEnterFrame", which means essentially, all the code in our enterFrame function will be run once every time flash displays a new frame to the user. In this file, that was set to 30fps.

    The Game Loop:

    Within our game loop is the 'meat' of the game code. We update the player's velocity ( a seperate variable from the players X and Y, this allows us to do physics code on it ), get game input, and check its collision with the stage, every frame.

    Point based collision detection:

    Point-based collision detection allows us to check collision based on only the visible parts of a movieclip ( or, the parts of a movieclip with data in it ). In this case, we are taking the x & y coords on the player ( set to the player's feet in the movieclip ), and checking to see if the player has hit the ground. If he has, we run some code to deal with that as needed.

    Gravity:

    Because we have our player's velocity stored outside of his simple x & y, we are able to implement good-enough gravity by simply increasing his downward velocity by our gravity constant every frame. We negate his velocity if he is on the ground.

    Friction:

    For good-enough friction, we multiply the player's velocity by a number less than one every turn to decrease his speed by a set amount.

     

    Content on this page requires a newer version of Adobe Flash Player.

    Get Adobe Flash player

Expand/Collapse Section ImageExercise Specifications - Part 2

  1. Game Part 2

    Download the lab files. You are provided with all the files correctly setup as needed. Take some time to look at Lab08part2.fla to see how it is setup ( the linkage on the items in the library, the FPS, and the document class ).

    Open up gameMain.as to fill in the new code ( you'll have to compare this to what you have already).

    The game class:

    You will be adding new variables for enemies and bullets, and updating those respectively. In addition, you will add scrolling to make this a true sidescroller


    Enemies:

    The enemies code will be created in a seperate folder. You will have to create a file badMan.as in the folder "/src/enemies" for the code to work. In addition, the package will have to be "package src.enemies" to compile correctly. This will help you clean your code up immensely in future actionscripting.

    The enemy has simple ai defined by a switch statement, and some chase code that works by checking the distance between enemy and player.

    Here is the code for enemies

    Bullets:

    Bullets fly straight in this example, but gravity can be applied to it rather simply. Care must be taken not to allow too many bullets on the stage. While flash can handle quite a bit in ActionScript 3.0, each bullet is checking if it is hitting each enemy; with a number of both on the stage, it can get computationally itensive quickly.

    Here is the code for bullet

    Extra Credit (10 pts):

    With the enemies, bullets, and scrolling working, do two things:

    • Make the enemies and player face the direction they are moving in
    • Make the bullets fly in the direction the player is facing
       
    Group work is allowed for this final assignment.

    Content on this page requires a newer version of Adobe Flash Player.

    Get Adobe Flash player

 

Expand/Collapse Section ImageExercise Specifications - Part 3

  1. Liquid GUI
    • create 4 layers: actions, header, body, footer
    • add header elements, convert to symbol, but do NOT export for AS
    • after converting to symbol, be sure to name the instance in the properties panel
    • repeat for footer
    • repeat for body
    • then add this code on frame 1.

Grading

Part 1 10 pts
Part 2 10 pts
Extra Credit 10 pts
Total Possible 30 out of 20 pts