Creating a Vertical Shooter Based on; accessed Tuesday 27 th July, 2010

Similar documents
Space Shooter - Movie Clip and Movement

Notes 3: Actionscript to control symbol locations

Adobe Flash CS3 Reference Flash CS3 Application Window

Instance Name Timeline. Properties Library. Frames, Key Frames, and Frame Rate Symbols movie clips. Events and Event Handlers (functions)

Appendix A ACE exam objectives map

Objectives: To create a Flash motion tween using the timeline and keyframes, and using pivot points to define object movement.

and 150 in the height text box, and then click OK. Flash automatically inserts the px (for pixel) after the number.

COMP : Practical 8 ActionScript II: The If statement and Variables

1. Multimedia authoring is the process of creating a multimedia production:

Introduction to Flash - Creating a Motion Tween

Adobe Flash CS4 Part 4: Interactivity

COMP : Practical 9 ActionScript: Text and Input

The Timeline records the actions in each Frame. It also allows multiple independent images and actions through Layers.

Function Grapher Demystified Step 1

HO-FL1: INTRODUCTION TO FLASH

Notes 13: Are we there yet? Are we there yet? Are we there yet?

Review Questions FL Chapter 3: Working With Symbols and Interactivity

Adobe Flash Professional CS5.5

COMP : Practical 6 Buttons and First Script Instructions

3Using and Writing. Functions. Understanding Functions 41. In this chapter, I ll explain what functions are and how to use them.

Technical Manual Urban Ninja

WORLD FIRST. In our first ever Flash MX 2004 tutorial, we take a look at the new ease-of-use features that can turn anyone into a Flash guru.

The Library is displayed as a window, and its contents are accessed by dragging and dropping onto the Stage.

2 Development of multimedia applications

2 Development of multimedia applications

Function Grapher Demystified Step 2

Loading from external sources

Flash Domain 4: Building Rich Media Elements Using Flash CS5

Valuable points from Lesson 6 Adobe Flash CS5 Professional Classroom in a Book

Making ecards Can Be Fun!

Macromedia Director Tutorial 4

What will you learn: A better understanding of 3 D space How to use keyframes Designing and planning an animation How to render animations

Creating Breakout - Part 2

How to create an animated face

Lesson 1. Importing and Organizing Footage using Premiere Pro CS3- CS5

-Remember to always hit Command + S every time you make a change to your project going forward.

Flash offers a way to simplify your work, using symbols. A symbol can be

IAT 445 Lab 10. Special Topics in Unity. Lanz Singbeil

Chapter 5. Creating Special Effects Delmar, Cengage Learning

Tutorial: Overview. CHAPTER 2 Tutorial

AO3. 1. Load Flash. 2. Under Create New click on Flash document a blank screen should appear:

FLASH ANIMATION TUTORIAL

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical

IT 201: Information Design Techniques. Review Sheet. A few notes from Professor Wagner s IT 286: Foundations of Game Production Course

Dissolving Models with Particle Flow and Animated Opacity Map

Designing and Scoring a Pac-Man Style Maze Game with Flash

Lesson 4: Add ActionScript to Your Movie

Flash basics for mathematics applets

Adobe Flash CS4 Part 2: Working with Symbols

Flash Tutorial. Working With Text, Tween, Layers, Frames & Key Frames

Meet the Cast. The Cosmic Defenders: Gobo, Fabu, and Pele The Cosmic Defenders are transdimensional

Flash CS4 - Lab 3 Introduction to Classes:

FLASH 5 PART II USER MANUAL

Doing a flash animation for animb

Working with Adobe Premiere Pro CS4

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

Valuable points from Lesson 8 Adobe Flash CS5 Professional Classroom in a Book

Dear Candidate, Thank you, Adobe Education

Introduction to Scratch Programming v1.4 (Second Ed) Lesson 6 Calculator

Why use actionscript? Interactive, logic and advance functionality to your flash piece

Adobe Animate Basics

Project 2 Prototype Report Template Creating Instances Dynamically Dynamic Event Handlers Array Methods 2-D Array; multi-d Arrays Game - Match Them

Dynamic Animation with Fuse Kit Free!

Fantasy Cartography with Adobe Photoshop: Adapted for Gimp

MOVIE MAKER BUILDING AN ONLINE APPLICATION. by Jason Krogh with original audio and design by Brian Ziffer and James Lloyd of

INSRUCTION SHEET. Flash Lab #1

How to draw and create shapes

Recipes4Success. Animate Plant Growth. Share 4 - Animation

CHAPTER 1. Interface Overview 3 CHAPTER 2. Menus 17 CHAPTER 3. Toolbars and Tools 33 CHAPTER 4. Timelines and Screens 61 CHAPTER 5.

Burning Laser. In this tutorial we are going to use particle flow to create a laser beam that shoots off sparks and leaves a burn mark on a surface!

How to resize content for multiple screens

Adobe Flash CS4 Part 3: Animation

Pong in Unity a basic Intro

In this lesson you will learn how to:

Flash. Session 4: Importing Assets. Shiny Yang special thanks to Alex Miller

Smoother Graphics Taking Control of Painting the Screen

Fig. A. Fig. B. Fig. 1. Fig. 2. Fig. 3 Fig. 4

RENDERING TECHNIQUES

Creating a Text Frame. Create a Table and Type Text. Pointer Tool Text Tool Table Tool Word Art Tool

COM1145 Animation How to Animate with imovie

Sample Hands-On-Training Chapter Review Copy Only Contact Information Notice of Rights Notice of Liability Trademarks

Digital Media. Seasons Assignment. 1. Copy and open the file seasonsbegin.fla from the Read folder.

Flash. Session 2: An introduction to object-oriented design, the display tree and events

After you slave and toil to create a compelling Flash movie, you have

You can also download the complete Demonstration Project from our website. It will be necessary to import it from the main menu of PyroCreator:

Animating Dialogue using the "Mouth Comp" method

The safer, easier way to help you pass any IT exams. Exam : 9A Adobe Flash Lite 2.0 Mobile Developer Exam. Title : Version : DEMO 1 / 7

To add actions to a button:

HO-13: Creating a Simple Racing Car Game in Flash

Working with Symbols and Instances

Intro to Animation. Introduction: Frames and Keyframes. Blender Lesson: Grade Level: Lesson Description: Goals/Objectives: Materials/Tools: 4th and up

Save your project files in a folder called: 3_flash_tweens. Tweens in Flash :: Introduction

Adobe Flash CS5 Revealed Additional ACA Material

ELEC451 Integrated Circuit Engineering Using Cadence's Virtuoso Layout Editing Tool

Working with Time Remap in EDIUS

Chapter 2: ActionScript Programming Introduction

MC Tween: it saves the world.

Add the backgrounds. Add the font.

Lightning Strikes. In this tutorial we are going to take a look at a method of creating some electricity zapper effects using Particle Flow.

Transcription:

Creating a Vertical Shooter Based on; http://www.kirupa.com/developer/actionscript/vertical_shooter.htm accessed Tuesday 27 th July, 2010 So, we will create a game using our super hero Knight to kill dragons that are coming from one side of the screen. I have provided an FLA with all of the graphics you will need. This tutorial is more of an explanation of the code with some design work as opposed to a fully-featured tutorial covering every aspect of a vertical shooter. You have been given the following Movie Clips, sound and picture to use

On the timeline 1. Insert a layer, name it Actions 2. in the first frame of our timeline type the following ActionScript: //---- variables ---- var steps:number = 5; var spritex:number = 265; var spritey:number = 265; //---- functions ---- function checkkeys() { if (Key.isDown(Key.RIGHT)) { spritex += steps; else if (Key.isDown(Key.LEFT)) { spritex -= steps; function updatepawel() { knight._x = spritex; knight._y = spritey; this.onenterframe = function() { checkkeys(); updatepawel(); ; Ok, our hero is moving from side to side on the screen but, he can even move outside of the stage! We can animate the legs and the arms so it will look better and it will add the option of throwing arrows (we don't have arrows yet). If you double click on your knight movie clip, you should be in the timeline for that movie clip. You will see three layers corresponding to the body, arms, and legs:

More importantly, notice that the arms and legs are movie clips with the instance names...arms and legs! If you look inside the arms and legs movie clips, you will find that they have some keyframes that provide some extra animation for movement. Let's modify our code to take advantage of the new movement in the legs and arms: //---- functions ---- function checkkeys() { if (Key.isDown(Key.RIGHT) && spritex<510) { spritex -= steps; else if (Key.isDown(Key.LEFT) && spritex>40) { spritex -= steps; if (Key.isDown(Key.UP)) { knight.arms.play(); Explanation Let's go through the code you have used: -------------------------------------------------------------------------------- //---- variables ---- var steps:number = 5; var spritex:number = 265; var spritey:number = 265; First we declare the variables, steps are the number of pixels our hero will move, spritex and spritey will help us to give value to the X and Y position of our hero.

-------------------------------------------------------------------------------- The first function checks if we are pressing the keys that are making our hero to do things: if (Key.isDown(Key.RIGHT) && spritex<510) { spritex += steps; The above code essentially says that only if we press the Right arrowkey and our hero is not outside of the stage, our hero will move to the right (remember, steps = 5 pixels) and play the legs animation. else if (Key.isDown(Key.LEFT) && spritex>40) { spritex -= steps; This code is the same as above, except I now check for the Left arrow key and ensure that our hero is not outside the left edge of our stage. If we press the Up arrowkey on our keyboard, the animation in our arms movieclip will play. function updatepawel() { knight._x = spritex; knight._y = spritey; This function tells Flash that our hero will take the X and Y values of the variables spritex and spritey. this.onenterframe = function() { checkkeys(); updatepawel(); ; This onenterframe event checks to see if we are pressing keys on the keyboard or if our hero is moving.

Adding a Background Now we are able to move our sprite, but our sprite is "in the air." We will fix that by adding a background. To add a background is easy as you already know. Just add another layer in the main timeline and draw your background : You can use any drawing program and paste it into Flash CS-4 or just draw a green rectangle for the grass and a blue for the sky.

Drawing the Arrow The arrow can be drawn in Flash as well (I used Photoshop to draw mine). If you take a look at my FLA, you will see the arrow movie clip and image in the Library. Whether you create your own arrow, or use my arrow, just ensure that your arrow is inside a movie clip. The arrow should be a movieclip and we should leave it in the library, not on the stage. Open the Library (Ctrl + L) and right click the arrow movieclip so you can open the Linkage Properties box. From the Linkage Properties dialog box, if you tick in linkage options Export for Actionscript by default the identifier will be arrow, so leave it like that. Getting back to the Code Let's modify the code we added in the previous page. Let's add to the script a couple of variables: one to declare the speed of our arrow and another to allow us to shoot one arrow at a time. Now, we also need a function to update our arrow. Now the script looks like: //---- variables ---- var steps:number = 5; var spritex:number = 265; var spritey:number = 265; var speed:number = 25; var arrowactive:boolean = false; //---- functions ---- function checkkeys() { if (Key.isDown(Key.RIGHT) && spritex<510)>40) { spritex -= steps; if (Key.isDown(Key.UP) && arrowactive == false) { knight.arms.play(); attachmovie("arrow", "arrows", 8); arrows._x = spritex; arrows._y = spritey+50; arrowactive = true function updatepawel() { knight._x = spritex; knight._y = spritey; function updatearrow() { if (arrowactive == true) {

arrows._y -= speed; if (arrows._y<-10) { arrowactive = false; removemovieclip(arrows); this.onenterframe = function() { ; checkkeys(); updatepawel(); updatearrow(); Adding the Dragon! Pawel shoots arrows, moves and there is a beautiful background (hopefully), but Pawel is shooting into an empty sky! We need the dragons. Here is how my dragon looks like: For the sake of this tutorial, let's leave it as an image. You can make an animation of the wings/tail/etc. if you really really want to. We don't need instances of our dragon on the stage but we need it in the Library as a movieclip. Like we did with the arrow, let's change it's Linkage Properties. Open the Library and right click on the dragons movieclip to open the Linkage Properties window, tick Export for Actionscript, and leave the identifier as default (dragon). Back to the ActionScript We now need to add some more variables: var dragons:number = 3; var i:number = 0; var score:number = 0;

dragons is the number of dragons we will have on the stage. The variable i is a bit difficult to explain right now, for it does several things. Hopefully with the rest of the code, you will see what i does. score is to store our score, we can add a dynamic text box on the stage with variable name score so we know how good we are killing dragons. We need to add two new functions, one to initialize the dragons and another one to update them. Add the following code to the end of your existing code: function initdragons() { for (i; i<dragons; i++) { attachmovie("dragon", "dragon"+i, i); dragon = _root["dragon"+i]; updatedragons(dragon); ; dragon.onenterframe = function() { initdragons(); if (this.hittest(arrows)) { score += 5; trace(score); arrowactive = false; removemovieclip(arrows); updatedragons(this); if (this._x>0) { this._x -= this.velo; else { updatedragons(this); function updatedragons(which) { which.gotoandstop(random(4)); which._x = random(100)+530; which._y = random(80)+20; which.velo = random(10)+2;

In the function initdragons(), we start with the loop for (i; i<dragons; i++), usually this sort of loops look the same, with a variable to initialize the loop, the condition to loop and then increment the variable value after each loop iteration. When the value of i is less than the number of dragons, we will attach an instance of our movieclip dragon with this script: attachmovie("dragon", "dragon"+i, i) The new name of this instance is "dragon"+i, the value of i is incrementing, so the first one will be called dragon0, the second dragon1 and because we set dragons number as 3, the last instance will be dragon2 finishing the loop. To make our life easier, we will set a variable to store the name of each dragon, dragon = _root["dragon"+i]; To update the dragons that have been just created, we need to call the function updatedragons(dragon). if (this.hittest(arrows)): this line checks if the arrows hit them, and if it happens, we increment the score by 5: score += 5; arrowactive = false: sets the arrow's status to be inactive removemovieclip(arrows): because the arrow has already hit something, we can safely remove it. This line does that. updatedragons(this): we will update the dragons using the soon to be explained updatedragons function. if (this._x>0) { this._x -= this.velo; else { updatedragons(this); if the dragon is on the stage, then its x position is bigger than zero. We will set it to move horizontally (x axis), but if the x position is not greater then zero, then we send that dragon to our updatedragons function. The update Dragons function is pretty straightforward. It is run whenever a dragon has been hit with an arrow or if it moves outside of the stage. We simply try to simulate a new dragon by specifying a new vertical position, horizontal position, and speed.

Your final code should look like the following: //---- variables ---- var steps:number = 5; var spritex:number = 265; var spritey:number = 265; var speed:number = 25; var arrowactive:boolean = false; var dragons:number = 3; var i:number = 0; var score:number = 0; //---- properties ---- knight.swapdepths(10); //---- functions ---- function checkkeys() { if (Key.isDown(Key.RIGHT) && spritex<510) { spritex += steps; else if (Key.isDown(Key.LEFT) && spritex>40) { spritex -= steps; if (Key.isDown(Key.UP) && arrowactive == false) { knight.arms.play(); attachmovie("arrow", "arrows", 8); arrows._x = spritex; arrows._y = spritey+50; //arrowactive = true function updatepawel() { knight._x = spritex; knight._y = spritey; function updatearrow() { if (arrowactive == true) { arrows._y -= speed;

if (arrows._y<-10) { arrowactive = false; removemovieclip(arrows); function initdragons() { for (i; i<dragons; i++) { attachmovie("dragon", "dragon"+i, i); dragon = _root["dragon"+i]; updatedragons(dragon); ; dragon.onenterframe = function() { initdragons(); if (this.hittest(arrows)) { score += 5; trace(score); arrowactive = false; removemovieclip(arrows); updatedragons(this); if (this._x>0) { this._x -= this.velo; else { updatedragons(this); function updatedragons(which) { which._x = random(100)+530; which._y = random(80)+20; which.velo = random(10)+2; this.onenterframe = function() { checkkeys();

; updatepawel(); updatearrow();