Space Shooter - Movie Clip and Movement

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

Notes 3: Actionscript to control symbol locations

Clickteam Fusion 2.5 Creating a Debug System - Guide

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

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

Technical Manual Urban Ninja

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

Fruit Snake SECTION 1

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

for more please visit :

Basic Computer Programming (Processing)

Start Visual Studio, create a new project called Helicopter Game and press OK

Flash CS4 - Lab 3 Introduction to Classes:

Creating Breakout - Part 2

This is the empty form we will be working with in this game. Look under the properties window and find the following and change them.

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

A Rapid Development Toolkit for Instructional Designers

Introduction to Flash - Creating a Motion Tween

Chapter 1- The Blender Interface

Function Grapher Demystified Step 1

imovie with Still Pictures

Function Grapher Demystified Step 2

COMP : Practical 6 Buttons and First Script Instructions

Pacman. you want to see how the maze was created, open the file named unity_pacman_create_maze.

imovie HD imovie HD is an application that is used to create movies using digital video, photos, and audio. Use this planning guide to get started.

MoleMash for App Inventor 2. Getting Started. Introduction. Workshop, S.1

What You're Building 2. Getting Started 3 Introduction 4 Iteration or how we will get to Finished App. 4

Layout of Movie Maker. Elements of Movie Maker. Step by step instructions on how to use Movie Maker. Web resources for Movie Maker

Movavi Split Movie for Mac User manual

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

Make A New Cell Palette In Clicker 5

2. This tutorial will teach you the basics of PowerPoint and how to hyperlink and embed (insert) videos into your PowerPoint.

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

PowerPoint 2010 Project Four Assignment Sheet

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

Add the backgrounds. Add the font.

Making ecards Can Be Fun!

--APOPHYSIS INSTALLATION AND BASIC USE TUTORIAL--

Phillip Kerman. Smart Clips Made Easy. Clips that are smart and Smart Clips

PATTERN SEQUENCER GUIDE

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.

ACTIONSCRIPT ESSENTIALS

Working with Symbols and Instances

Flash basics for mathematics applets Tutorial 2. Reading input text boxes and writing to dynamic text boxes

FLASH ANIMATION TUTORIAL

Working with Adobe Premiere Pro CS4

COMP : Practical 11 Video

How to resize content for multiple screens

Audacity tutorial. 1. Look for the Audacity icon on your computer desktop. 2. Open the program. You get the basic screen.

Adobe Flash CS4 Part 2: Working with Symbols

Windows Movie Maker lets you edit videos from video and photo files. It is free from Microsoft.

COMP : Practical 9 ActionScript: Text and Input

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

Flash Domain 4: Building Rich Media Elements Using Flash CS5

HO-FL1: INTRODUCTION TO FLASH

All Blocks of Scratch

Sonne Flash Decompiler

2 Development of multimedia applications

2 Development of multimedia applications

ADOBE 9A Certified Macromedia Flash MX 2004 Designer.

Popcorn's ini Tutorial

Adobe Flash Professional CS5.5

In this lesson you will learn how to:

GET FAMILIAR WITH WINDOWS MOVIE MAKER

Exit: These control how the object exits the slide. For example, with the Fade animation the object will simply fade away.

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

Handout Objectives: a. b. c. d. 3. a. b. c. d. e a. b. 6. a. b. c. d. Overview:

Lesson 1 New Presentation

S3 Scratch Programming

CS12020 for CGVG. Practical 2. Jim Finnis

Flash Decompile Master

Deconstructing bonsai2.swf

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

Digital Video Projects (Creating)

INTRODUCTION TO FLASH MX

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

SWF Decompiler Premium

Asteroid Destroyer How it Works

How to create interactive documents

Scratch Programming In Easy Steps Covers Versions 2 0 And 1 4

Click on the empty form and apply the following options to the properties Windows.

Sequence settings for this project. Sequence settings for this project. source monitor. The Program Window: The Bin. The Sequence Window: The Timeline

Hazel a tool for automating your Mac Introduction Basic setup The Folders tab The Trash tab The Info tab...

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

Playlist Builder 1.5 Manual

Microsoft Office: PowerPoint 2013

An Introduction to Video Editing Using Windows Movie Maker 2 Duncan Whitehurst - ICT Advisory Teacher Pembrokeshire County Council

INFORMATICS LABORATORY WORK #4

Creating a Game 4. October 13, Copyright 2013 by World Class CAD, LLC. All Rights Reserved.

Visual C# Program: Simple Game 3

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

General Directions for Creating a Program with Flash

FLASH 5 PART II USER MANUAL

Back to the main page Back to the Tutorial Page Digital Audio Rules of Audacity Setup, Audio Import and Playback Recording with Audacity

BEGINNER PHP Table of Contents

Adobe Flash CS4 Part 4: Interactivity

1 To access Movie Maker

Adobe Flash CS3 Reference Flash CS3 Application Window

Chapter 1- The Blender Interface

From time to time Google changes the way it does things, and old tutorials may not apply to some new procedures.

Transcription:

Space Shooter - Movie Clip and Movement Type : TextSource File: space-shooter-movie-clip-and-movement.zip Result : See the result Index Series Next >>> In this tutorial series you will learn how to create a simple space shooter game from scratch in flash. It is a good and - more importantly - fun way to get to grips with using actionscript and flash. If you like gaming try out this great website and you can actually earn money while playing games! Click Here! This tutorial is series of tutorials that will teach you how to create Space Shooter Game. The tutorial is divided in 5 parts. To see the complete tutorials, please see Space Shooter Flash Game This is the first part of a series of Space Shooter tutorials. In this part we are going to learn the basics of Movie Clips and character movement. First create a new document in Flash, click "File" > "New...", select "ActionScript 2.0" and click Ok. Create a Movie Clip by right clicking your library tab and selecting "New Symbol...", make sure "Movie Clip" is selected and choose a name. Flash will create and open the Movie Clip for editing, so just paste an image or draw a space ship with Flash's drawing tools. After drawing your ship, get back to the main timeline by click on "Scene 1":

Now drag your Movie Clip from the library to the Stage, select it and give it an instance name. I am going to name it "Ship". So "Ship" is how I am going to call this Movie Clip instance inside my code. We just made our ship, so let's make it move. Right click the first frame in your timeline and select "Actions". Type this: this.onenterframe = function() { if (Key.isDown(Key.RIGHT)) { Ship._x += 10; } else if (Key.isDown(Key.LEFT)) { Ship._x -= 10; } else if (Key.isDown(Key.UP)) { Ship._y -= 10; } else if (Key.isDown(Key.DOWN)) { Ship._y += 10; } } Press Ctrl + Enter and test it, use the arrow key to move your ship around. Here is how this code works: this.onenterframe = function() {... } This is a very simple event from flash; the code inside it will be executed every time flash enters this frame.

if (Key.isDown(Key.RIGHT)) { Ship._x += 10; //_x -= 10 would move the ship to the left. } This check if the right key is pressed, then move the Ship 10 pixels to the right. else if (Key.isDown(Key.Up)) { Ship._y -= 10; // _y += 10 would move the ship down. } If the up arrow key is pressed, the ship will move up. It's the same thing as before, but this time we added "else" before "if" because we don't want the ship to move in two directions at the same time. In case you want the ship to move freely remove the "else" and try to move it. We are done with movement! In the next tutorial we are going to make our ship fire bullets. Index Series Next >>> This tutorial is a series of tutorials that will teach you how to create Space Shooter Game. The tutorial is divided in 5 parts. If you haven't learned the previous tutorials, please see Space Shooter Flash Game This is the second part of the tutorial and we are going to enable the ship to shoot. Previously we made our ship fly; now we are going to make it shoot and set limits to where it can go. First we need to make our bullets, right click the library tab, select "New Symbol the name "Bullet". " and give it Before clicking OK, click Advanced, select "Export for Actionscript" and make sure the identifier is "Bullet".

We do this because we need to export the Bullet Movie Clip during running time to create many bullets and we will use the name determined in identifier to call it later. Draw a small bullet, and position it like this: This is called registration point, in the stage this is the position of the Bullet Movie Clip. Now open the actions window of the first frame of the Movie Clip and paste this code: this.onenterframe = function() { this._x += 12; if (this._x > 550) { this.removemovieclip(); } } "this" is the Movie Clip instance, so if we duplicate 100 bullets each bullet will have the same code. this._x += 12; Every frame, the bullet will move 12 pixels to the right. if (this._x > 550) { this.removemovieclip(); } If the bullet passed the limits of the screen (550px) it's no longer visible, so we remove it by using this method "removemovieclip()" Now go to the main timeline, select the first frame and open the actions windows. You will see the previous codes that we have written. Add this code to the old one so we can fire our bullets: var i = 0; this.onenterframe = function() {... else if (Key.isDown(Key.DOWN)) { Ship._y += 5; } if (Key.isDown(Key.SPACE)) { i++; _root.attachmovie("bullet", "Bullet" + i,

_root.getnexthighestdepth()); _root["bullet" + i]._x = Ship._x + 3; _root["bullet" + i]._y = Ship._y; } } <<< Previous Index Series Next >>> This tutorial is a series of tutorials that will teach you how to create Space Shooter Game. The tutorial is divided in 5 parts. If you haven't learned the previous tutorials, please see Space Shooter Flash Game This is the third tutorial of a series about developing a Space Shooter game, in this tutorial we are going to make enemy ships. Create a new Movie Clip and draw your enemy ship, don't forget to set the identifier to "Enemy" and select "Export to Actionscript". Now drag the enemy Movie Clip to the stage, give it an instance name of "Enemy0", right click it and select "Actions". Paste this: onclipevent(load) { function reset() { var timer = 12; this._y = Math.random() * 300 this._x = 550 myspeed = Math.ceil(Math.random() * 6) + 1; } reset(); } This part of the code creates a function called reset() when the Movie Clip loads for the first time. Inside reset() we set this._y to a random number between 0 and 300, this._x to 550 and the speed of our enemy to a random number between 1 and 6. And paste this: onclipevent(enterframe) { //in every frame the enemy move left in the speed defined in the reset function. this._x -= myspeed; if (this._x < -10) { //if the enemy is not on the screen, we reset it. reset(); } //if our timer is bigger than 12 we get a new if (timer >= 12) { //direction to the Ship. var dir = Math.ceil(Math.random() * 2) //We get a random number, 1 or 2. 1 is up, 2 is down. //Then we set timer to 0, so we only get a new dir when timer is bigger than 12 timer = 0; } if (dir == 1) { //if dir = 1, we move the ship up. this._y -= 3; } else if(dir == 2) { //if dir = 2, we move the ship down. this._y += 3; } //increase timer by 1, so the timer gets equal to 12 and we get a new direction. timer++ } This is a VERY basic AI that will be improved when we let the enemy know when it killed our ship or if it was killed by us. We only have one enemy, so let's make more. Add this code in the main timeline before the rest of the code.

var nrenemies = 3; for (i = 1; i < nrenemies; i++) { _root.enemy.duplicatemovieclip("enemy" + i, _root.getnexthighestdepth()); } The variable nrenemies represents the number of enemies in the screen at the same time. for (i = 1; i < nrenemies; i++) {... } The "for loop" will run the code inside it depending on nrenemies. <<< Previous Index Series Next >>> This tutorial is a series of tutorials that will teach you how to create Space Shooter Game. The tutorial is divided in 5 parts. If you haven't learned the previous tutorials, please see Space Shooter Flash Game This is the forth part of the development of a Space Shooter game. In this tutorial we will add lives, scores and game over to our game. Let's start with score. Open the main timeline code and add this variable: var score = 0; Now open the Bullet's code and add this: this.onenterframe = function() { this._x += 9; if (this._x > 550) { this.removemovieclip(); } for (i = 0; i < _root.nrenemies; i++) { if (this.hittest(_root["enemy" + i])) { _root["enemy" + i].reset(); _root.score += 10; this.removemovieclip(); } } } This is the code we used before to know if a bullet hits an enemy, so we can put the score for killing an enemy there. If you want the player to lose points for getting killed, just add "_root.score -= PointsToLose" to the code that checks if the player was killed. The score is done; we just need to show the player his score. To do that, select the Text Tool and draw it on the stage.

Write "Score:" Now draw another Text box on the stage. Select this new Text box and change these properties: Run the game and see how it works. Now let's make our ship have lives. Add another variable in the main code: var lives = 3; <<< Previous Index Series Next >>>

This tutorial is a series of tutorials that will teach you how to create Space Shooter Game. The tutorial is divided in 5 parts. If you haven't learned the previous tutorials, please see Space Shooter Flash Game This is the last part of our game and we are going to add sound and a pause key. Before we start with sound we need to make some changes. You may have noticed that our ship shoots bullets as much as the player press the space bar, that's not right as it makes the game much easier. To prevent that, we are going to add a timer and the ship will shoot as much as WE want. First add a new variable: var timer = 8; Now make these changes: this.onenterframe = function() { timer++;... if (Key.isDown(Key.SPACE)) { i++; if(timer >= 8) { _root.attachmovie("bullet", "Bullet" + i, _root.getnexthighestdepth()); _root["bullet" + i]._x = Ship._x + 3; _root["bullet" + i]._y = Ship._y; timer = 0; } } } The code runs like this: 1. If timer >= 8 then shoot a bullet and set timer to 0 2. Now that timer = 0, the bullet wont shoot, so the player has to wait all the code to run at least 8 timer to shoot again (timer++ will increase timer by 1 every frame) 3. Timer will be bigger than 8 again and the player can shoot. Before: After:

We can add the sound now. You need to have an mp3 file that's going to be the sound played when you fire. You can download one right here. Or simply download the source file that contains sound file. Now that you have your sound, click File > Import > Import to library... Select your mp3 file and click open, a new file should appear on the library. Right click it and click "Linkage..." Check "Export to Actionscript..." and set the Identifier to "shoot". This is the same thing we did previously with the Bullet Movie Clip, we need the linkage to call this on the code. Add this to the shooting code: if (Key.isDown(Key.SPACE)) { i++; if(timer >= 8) { _root.attachmovie("bullet", "Bullet" + i, _root.getnexthighestdepth()); _root["bullet" + i]._x = Ship._x + 3; _root["bullet" + i]._y = Ship._y; var shoot_sound = new Sound(); shoot_sound.attachsound("shoot"); shoot_sound.start(); timer = 0; } } <<< Previous Index Series

Space Shooter - Game Pause and Sound Type : TextSource File: space-shooter-pause-game-sound.zip Result : See the result <<< Previous Index Series The first thing we do is declare a new Sound(): var shoot_sound = new Sound(); Then we attach the sound we have on our library to this variable: shoot_sound.attachsound("shoot"); And we tell our sound to play using the start() method: shoot_sound.start(); Run the code (Ctrl + Enter) and see the results. Now we are going to add a pause to our game. Add a new variable to know whether we are paused or not: var gpause = false; Then make some changes to ALL codes. Main code: this.onenterframe = function() { if (!gpause) { //this is the rest of the code we did previously. } } Enemy's code: onclipevent(enterframe) { if (!_root.gpause) { this._x -= myspeed; if (this._x < -10) { reset(); } } } Bullet's code: this.onenterframe = function() { if (!_root.gpause) { //rest of the code we did } } It's pretty simple; if gpause is false the code will run normally, but if gpause is true the code will not run. Add another code to the main timeline: this.onenterframe = function() { if (!_root.gpause) { //rest of the code we did } if (Key.isDown(Key.CONTROL)) { if (gpause) { gpause = false; } else if (!gpause) { gpause = true; } } } If the players press "ctrl" we set gpause to true or false depending on the value of gpause. This needs to be outside "if (!_root.gpause)" because we need to check if the user pressed the

pause key even if the game is paused. The game is done! I hope you enjoyed developing it. And see you in the next series! <<< Previous Index Series