View Full Version : Teleportation (Where to even start?)
nonprogrammer
April 13th, 2009, 12:18 AM
First, I'm going to say this: I'll be describing exactly what I want to make, but I don't want anyone to go out and just hand it over to me. All I'm looking for is advice on where to START.
The end result should be as follows:
There will be 5 doors and one enemy. The doors will be one the stage, while the enemy will be added to the stage via code. The doors will all have an initial state of being closed. After a small amount of time I will change the state of all those doors to being open. When this state change happens, I want to spawn my single enemy in one of those doors at random. This enemy will then move around the stage (flying) based upon specific paths I set out (multiple paths, one chosen at random) and end their trip by flying back into one of the doors and be removed from the stage, with the doors going back to their closed state.
Rinse and repeat.
So, as I said, the main question is how do I even start? (Oh and done in external AS files).
JapanMan
April 13th, 2009, 02:53 AM
Not really sure about the external files, but the code is the same (I'm a lowly MX-user >.<).
Basically, you want to
1) make the doors (I recommend using just 1 MC, then dragging in multiple copies)
2) label the first frame "closed" or some such thing, and add "stop();" to the AS.
3) make the animation of the door opening and put "stop();" on the last frame (when it's open).
4) right a function with a timer, or change the doors to simply have "x" number of the same frame, and just let them play.
5) when the time is as long as you want, or when the doors are open,
_root.createMovieClip("[name]", "[name]", 100);
Then give it x and y coordinates of the locations or equal to the doors. Use "if" statements with a "random(#)" for which door to create it at. Happy to help with that, too.
cjke.7777
April 13th, 2009, 07:08 AM
hey mate, hows it going?
first are you using as3 or as2?
nonprogrammer
April 18th, 2009, 06:08 PM
JapanMan, thanks for the help. Sorry I didn't respond sooner, but I've been incredibly sick.
Later on someone will be providing an animated door, so for now I don't really have to worry about that myself. For that reason, I've simply made and labeled the door "Closed" on frame one and "Open" on frame two.
Past that point in your help, I've got no idea what to do. Being unexperienced with programming PLUS extremely sick and exhausted, I can't really figure anything out. If I was feeling better and could think straight I might have a chance, but as things are I'm trying and failing.
Any more help would be great.
Thanks.
nonprogrammer
April 20th, 2009, 02:44 AM
Alright, I forced myself to do a bit of work just now as it's the only time I've not felt like utter CRAP (I've got mumps, so think horrible migraines, fever... basically sleeping 16 hours a day) and churned out the following:
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
var doorClosed:Boolean = true
// Create a new Timer object with a delay of 500 ms
var myTimer:Timer = new Timer(20000);
myTimer.addEventListener("timer", timerFunction);
// Start the timer
myTimer.start();
// Function will be called every second
function timerFunction(event:TimerEvent)
{
trace("Timer Fired 20 Seconds x " + myTimer.currentCount);
}
As I stated in the above post, I've made the door as single movie clip with two frames, frame one being Closed (green box) and frame two being Open (blue box).
I added in that boolean so that I can set the door as Closed initially (frame one) and then switch it to open (frame two) and back again. I obviously haven't finished writing that part in, but I feel like crap so I'm going back to sleep.
If anyone wants to help out, please feel free, I'd appreciate it.
Otherwise, I'll finish writing this part up tomorrow when I'm feeling a bit better and come back if (mre likely WHEN) I encounter another problem.
nonprogrammer
April 21st, 2009, 01:28 AM
Alright, here's what I put together today in the small amount of time I've spent awake.
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
var doorClosed:Boolean = true
// Create a new Timer object with a delay of 10 seconds
var myTimer:Timer = new Timer(10000);
myTimer.addEventListener("timer", timerFunction);
// Start the timer
myTimer.start();
trace("Doors are closed");
// Function will be called every 10 seconds
function timerFunction(event:TimerEvent)
{
if (doorClosed = true)
{
Door.gotoAndPlay(1);
doorClosed = false;
trace("Doors are open");
}
else
{
Door.gotoAndPlay(2)
doorClosed = true
trace("Doors are closed");
}
}Now I've got 2 issues with this:
1) Even though all 5 doors were made by dragging out multiple copies of a single movie clip and all of them have the same instance name of "Door", only 1 of them is being affected by the code. What's going on?
2) This one isn't a big deal, but I want to know how to fix it anyway. Watching the file play shows the door changing from green (closed) to blue (open) to green (closed) and so forth just like it is supposed to. The issue is that I don't have the traces properly placed, so it traces "The doors are closed." and then "The doors are open." and then keeps on tracing "The doors are open." every single time, even when they switch to closed.
Any help in making all the code more neat/efficient would be great.
Lastly, I could use help with what japanMan said, as I don't get what he meant:
5) when the time is as long as you want, or when the doors are open, Code:
_root.createMovieClip("[name]", "[name]", 100);
Then give it x and y coordinates of the locations or equal to the doors. Use "if" statements with a "random(#)" for which door to create it at. Happy to help with that, too.
denlranger
April 30th, 2009, 04:30 PM
I am not sure what you are really trying to do...
If you could show me a picture or at least say what type of game you are trying to make, that would be useful...
denlranger
April 30th, 2009, 04:57 PM
I would do this: first put to frames on each door one in which it is closed and one in which it is open. Then I would give each door a instance name such as door1, door2, door3, door4, and door5. Put a stop(); on each of the doors first frame in which they are closed. put this on the first frame of the main time line:
var TIME:number = 100;
var DOOR:number = random(5);
var PATH:number = random(5);
function DoorPick(){
if(_root.DOOR == 1){
_root.monster._x = _root.door1._x;
_root.monster._y = _root.door1._y;
_root.PathPick();
}
if(_root.DOOR == 2){
_root.monster._x = _root.door2._x;
_root.monster._y = _root.door2._y;
_root.PathPick();
}
if(_root.DOOR == 3){
_root.monster._x = _root.door3._x;
_root.monster._y = _root.door3._y;
}
if(_root.DOOR == 4){
_root.monster._x = _root.door4.x;
_root.monster._y = _root.door4._y;
_root.PathPick();
}
if(_root.DOOR == 5){
_root.monster._x = _root.door5._x;
_root.monster._y = _root.door5._y;
_root.PathPick();
}
}
function PathPick(){
if(_root.PATH == 1){
_root.monster.gotoAndPlay(the frame with the path);
}
if(_root.PATH == 2){
_root.monster.gotoAndPlay(the frame with the path);
}
if(_root.PATH == 3){
_root.monster.gotoAndPlay(the frame with the path);
}
if(_root.PATH == 4){
_root.monster.gotoAndPlay(the frame with the path);
}
if(_root.PATH == 5){
_root.monster.gotoAndPlay(the frame with the path);
}
}
_root.TIME--;
if(_root.TIME<=0){
_root.PickDoor();
_root.TIME = 100;
}
---------------------------------------------------------------------
and what you do is you put different animations on the monster making him have different paths and on the end frame of each path put this on the end frame: _root.monster.gotoAndStop(1);
:make sure your monster has a stop(); on his first frame.
in the PickPath function your monster goes to and plays the beginning frame of the path.
nonprogrammer
May 12th, 2009, 06:46 PM
What I have is the following file, how would I incorporate what you've provided into it?
Daganev
May 12th, 2009, 07:47 PM
eeeewwww....
No offense to anybody, but have you ever heard of an array?
public var doorArray:Array
public var pathArray:Array
doorArray = new Array(door1, door2, door3, door4, door5);
pathArray (.. insert your path info objects here).
var rdm = math.random() * 5;
monster.x = doorArray[rdm].x;
monster.y = doorArray[rdm].y;
runMonsterPath(pathArray[rdm]);
nonprogrammer
May 12th, 2009, 08:05 PM
There already is a door array, how did you miss that?
Daganev
May 12th, 2009, 10:18 PM
Sorry, I didn't look at the .fla, I was just going off of what was being said in the thread. didn't notice the dates :(
birdwing
May 13th, 2009, 02:03 AM
Ok i didn't look at the file so I don't know what you have already im just gonna try and explain how I would do it.
1. I would place all the doors on the stage with instance names of door1, door2, door3, door4, door5.
2. The first frame of the door movie clip is the door closed with a stop(); command on that frame. The second frame of the door movie clip is the door open also with a stop(); command on it.
3. I would the place all the door instance names into an array named "doors".
4. I would place a timer on the stage to call a function ever set amount of seconds.
5. The function would randomly select a door using the random function to select a random number from 0 to (total number of doors - 1) and stop the timer.
6. Using that number I would put that into the doors array to get the instance name of the door i want to open.
7. Open the door, and place the monster on the stage based on the x and y positions of the door that was selected. Then i would set a monster_active variable to TRUE.
8. I would have the monster follow a randomly selected path (which is selected the same way the door was)
9. After the monster follows the path and goes back to the door I would set the monster_active variable to FALSE and remove the monster from the stage.
10. If the monster_active variable is FALSE I would close the door and reset the timer.
11. Once the timer again reaches the set time I would start over.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.