Archive for February, 2010

Flash Tutorial 8: AI Enemies Type 2

0

If you have already made a moving character (type 2), this Tutorial will be very easy for you.

Set up your new AI enemy exactly as you did your moving character (make sure that everything in the main movie clip is CENTERED). Give it the instance name “AI2″ and use the following script to control it (instead of key down detection):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
onClipEvent(enterFrame){
   var AI_speed = 6; //the higher this number the faster the AI moves
   var reaction_distance = 300; //this higher this number, the farther the AI can "see" your character from.

   var AI_width = this._xscale / 2;
   var AI_hight = this._yscale / 2;

   if(this._y < _parent.character._y){
      var view_direction2 = "down";
      var y_dif = _parent.character._y - this._y;
      this._xscale = 100;
      if(y_dif > x_dif){
         gotoAndStop("down");
      }
   } else {
      var view_direction2 = "up";
      var y_dif = this._y - _parent.character._y;
      this._xscale = 100;
      if(y_dif > x_dif){
         gotoAndStop("up");
      }
   }

   if(this._x < _parent.character._x){
      var view_direction = "right";
      var x_dif = _parent.character._x - this._x;
      this._xscale = 100;
      if(x_dif > y_dif){
         gotoAndStop("right");
      }
   } else {
      var view_direction = "left";
      var x_dif = this._x - _parent.character._x;
      this._xscale = -100;
      if(x_dif > y_dif){
         gotoAndStop("left");
      }
   }

   if(view_direction == "left"){
      if(x_dif > AI_width + 100){
         this._x -= AI_speed;
      } else {
         if(y_dif < AI_hight + 1){
            trace("you've been hit!");
         }
      }
   } else if(view_direction == "right"){
      if(x_dif > AI_width){
         this._x += AI_speed;
      } else {
         if(y_dif < AI_hight){
            trace("you've been hit!");
         }
      }
   }

   if(view_direction2 == "up"){
      if(y_dif > AI_hight){
         this._y -= AI_speed;
      } else {
         if(x_dif < AI_width + 1){
            trace("you've been hit!");
         }
      }
   } else if(view_direction2 == "down"){
      if(y_dif > AI_hight){
         this._y += AI_speed;
      } else {
         if(x_dif < AI_width + 1){
            trace("you've been hit!");
         }
      }
   }
}

Flash Tutorial 7: AI Enemies Type 1

1

This is for action-script 2.0.

Well, if you’ve gone though my moving character tutorials, or if you already know how to make moving characters…you may be wondering “How can I make an AI enemy? A monster if you will.”. As always, I’m here to help!

First things first, make sure your character movie-clip (as I am assuming it is already made) has the instance name “character”.

Now, lets make the movie-clip for the AI (give it the instance name “AI1″ (It is set up very similarly to your character movie-clip). In fact, set it up EXACTLY as you did your character, except use this script in the “AI1″ movie-clip. And you MUST have everything in the AI1 movie-clip placed at 0,0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
onClipEvent(enterFrame){

   var AI_speed = 1.5; //the higher this number the faster the AI moves
   var reaction_distance = 500; //this higher this number, the farther the AI can "see" your character from.

   var AI_width = this._xscale;
   var AI_highth = this._yscale;

   if(this._x < _parent.character._x){
      var view_direction = "right";
      var x_dif = _parent.character._x - this._x;
      var y_dif = _parent.character._y - this._y;
   } else {
      var view_direction = "left";
      var x_dif = this._x - _parent.character._x;
      var y_dif = this._y - _parent.character._y;
   }

   if(y_dif <= reaction_distance){
      if(view_direction == "left"){
         gotoAndStop("jumping");
      } else {
         gotoAndStop("crouching");
      }
   }

   if(x_dif <= reaction_distance){
      if(view_direction == "left"){
         this._xscale = -100;
         this._x -= 2;
         if(_global.jumping != "yes"){
            gotoAndStop("walking");
         }
      } else {
         this._xscale = 100;
         this._x += 2;
         if(_global.jumping != "yes"){
            gotoAndStop("walking");
         }
      }
   }
}//end on Clip Event

Basics of CSS Part – #9

0

Today we’re going to talk about list styles. Lists are a vital commodity to web site creation. Most side-navigation menus and inline menus are actually lists that are simply listing the things we want them to. From there, we can add styles to these lists and manipulate them however we please.

Lists

In HTML there are two types of lists:

  • Ordered Lists <ol>
  • Unordered Lists

    Ordered Lists are usually marked with numbers or letters whereas Unordered Lists are usually marked with bullets or squares.

    List Type

    We can change how a list looks by using the list-style-type property. Consider the following code:

    1
    2
    3
    
    ul {list-style-type:circle;}
    ol {list-style-type:upper-roman;}

    The CSS code above will make all ul elements have a list style type of a circle and all ol elements have a list style type of upper roman numerals. The output will look like the following:

    • Item 1
    • Item 2
    1. Item 1
    2. Item 2

    Properties

    We can have a few properties for list types and those properties operate the same way as the background properties

    Property Description Values
    list-style This is the all-inclusive property where you can define all of the values list-style-type
    list-style-image
    list-style-position
    list-style-type This property will define type of list style you wish to have in the <li> element. none
    disc
    circle
    square
    decimal
    decimal-leading-zero
    armenian
    georgian
    lower-alpha
    upper-alpha
    lower-greek
    lower-latin
    upper-latin
    lower-roman
    upper-roman
    hebrew
    cjk-ideographic
    hiragana
    hiragana-iroha
    katakana
    katakana-iroha
    list-style-image This property will allow you to define an image as the list marker. url(image url)
    none
    list-style-position This property will allow you to specify whether you want the list to be inside or outside the content flow. inside
    outside

    We can also narrow down the list-style and list-style-type properties for each list element.

    Unordered Lists

    For unordered lists we can use the following values:

    • circle
    • disc
    • square
    • none

    Technically we can use any of the values listed in the table above, however, the purpose of the unordered list would cease to exist.

    Ordered Lists

    We can have many options for the ordered list. Out of the 23 values we posted for list-style-type, only three were solely for unordered lists. We can use the following values:

    1. decimal
    2. decimal-leading-zero
    3. armenian
    4. georgian
    5. lower-aplha
    6. upper-alpha
    7. lower-greek
    8. upper-greek
    9. lower-latin
    1. upper-latin
    2. lower-roman
    3. upper-roman
    4. hebrew
    5. cjk-ideographic
    6. hiragana
    7. hiragana-iroha
    8. katakana
    9. katakanap-iroha

    Using images with lists

    Using images can spice up just a standard web page by a lot. It is very easy to create your own bullet, circle, square, or a small arrow pointing toward the item you are showing in the list. We can use the all-inclusive,

    1
    2
    3
    4
    5
    
    list-style:url ("image/bullet.png");
    /*OR*/
    list-style-image:url ("image/bullet.png");

    This will replace the default bullet in the unordered list with an image of our choice.

    To see these properties in action feel free to click on the download button below!

    lists.zip
    lists.zip
    Size: 9.76 KB

Flash Tutorial 6: A Moving Character Type 2

0

This is for action-script 2.0

There are two types of moving character. As I like to classify them, full 2D and semi 2D. This tutorial is for the semi 2D type.
(A popular example being the original Zelda game.

To make it you need the following:

animations:
-top view facing forwards (1 frame animation)
-top view facing backwards (1 frame animation)
-top view facing right (we can make it face left with action-script) (1 frame animation)
-top view walking facing forwards (standard 2-3 frames)
-top view walking facing backwards (standard 2-3 frames)
-top view walking facing left (we can make it face right with action-script) (standard 2-3 frames)

Detection Scripts:
-Detect the pressing of the UP key
-Detect the pressing of the Down key
-Detect the pressing of the Left key
-Detect the pressing of the Right key

Action Scripts:
-Flip the character
-Make the character move left/right/up/down

so, how do we set this up you ask?

First, lets put the animations in order and set up their action-script. In all of your “view facing” animations (use the facing right animation for facing left, so you have the same animations for left and right) (they should only be one frame), put the following script in the first frame:

for facing right:

1
2
3
4
5
stop();
if(Key.isDown(Key.RIGHT)){
   this._x+=_global.walking_speed;
   gotoAndPlay(2);
}

for facing left:

1
2
3
4
5
stop();
if(Key.isDown(Key.LEFT)){
   this._x-=_global.walking_speed;
   gotoAndPlay(2);
}

for facing forward (back of character to you):

1
2
3
4
5
stop();
if(Key.isDown(Key.UP)){
   this._y-=_global.walking_speed;
   gotoAndPlay(2);
}

for facing backwards (front of character facing you):

1
2
3
4
5
stop();
if(Key.isDown(Key.DOWN)){
   this._y+=_global.walking_speed;
   gotoAndPlay(2);
}

Now, you know those 2-3 frames of walking animation you have? places them after the first frame of their corresponding facing directions. For example, the walking right three frames of animation I have would be pasted into the three frames after the first frame of my view facing right frame. Making a total of 4 frames. (Again, make sure facing left and facing right / walking left and walking right animations are the same in everything except the script on the first frame).

At this point you should now really only have 4 animations (yes, two are the same [left and right]. Make a movie-clip called “character” and make 4 blank frames in it. label the frames “right”, “left”, “up”, “down”. Now put the 4 animations you have in their corresponding frames. (switching left and right doesn’t matter). the animation with your character’s back shown goes in “up”. The animation where their front is shown goes in the “down”.

now, put this script in the “character” movie-clip itself:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
onClipEvent(enterFrame){
   _global.walking_speed = 2; //you can change this number to change the walking speed.
   
   if(Key.isDown(Key.RIGHT)){
      this._xscale = 100;
      gotoAndStop("right");
   }//end Key down RIGHT

   if(Key.isDown(Key.LEFT)){
      this._xscale = -100;
      gotoAndStop("left");
   }//end key down LEFT

   if(Key.isDown(Key.UP)){
      gotoAndStop("up");
   }//end Key down UP

   if(Key.isDown(Key.DOWN)){
      gotoAndStop("down");
   }//end key down DOWN

}//end on Clip Event

and you’re done!

Flash Tutorial 5: A Moving Character Type 1

0

This is for action-script 2.0

There are two types of moving character. As I like to classify them, full 2D and semi 2D. This tutorial is for the full 2D type.
(A popular example being the original Mario game.

To make it you need the following:

animations:
-right view standing (1 frame)
-right view walking (standard of 3-4 frames)
-right view jumping (standard of 12 frames (tween up and down))
-right view crouching (1 frame)
(there are no left view because action-script can change it’s direction dynamically).

Detection Scripts:
-Detect the pressing of the UP key
-Detect the pressing of the Down key
-Detect the pressing of the Left key
-Detect the pressing of the Right key

Action Scripts:
-Flip the character
-Make the character jump
-Make the character move left/right

so, how do we set this up you ask?

First, make a movie clip for each of the animations (all 4).
Then, Make a new movie clip called “character” and give it the instance name “character”. Make 4 blank frames in the “character” movie-clip and put one of the animation movie-clips in each of them. Then put the Stop(); command on all of the 4 frames. Now, label each frame as appropriate to its animation “walking” “standing” “jumping” “crouching”.

now It’s time for the action-script! (To be placed in the “character” movie-clip).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
onClipEvent(enterFrame){

   if(Key.isDown(Key.RIGHT)){
      this._xscale = 100;
      this._x += 2;
      if(_global.jumping != "yes"){
         gotoAndStop("walking");
      }
   }//end Key down RIGHT

   if(Key.isDown(Key.LEFT)){
      this._xscale = -100;
      this._x -= 2;
      if(_global.jumping != "yes"){
         gotoAndStop("walking");
      }
   }//end key down LEFT

   if(Key.isDown(Key.UP)){
      gotoAndStop("jumping");
   }//end Key down UP

   if(Key.isDown(Key.DOWN)){
      gotoAndStop("crouching");
   }//end key down DOWN

}//end on Clip Event

Now for the last bit of scripting.

Make sure you put the stop command in the last frame of every animation except “walking”;

Now put:

_global.jumping = "yes";

at the first frame of your jumping animation.

and:
Code:

_global.jumping = "no"

at the end of your jumping animation.

and you’re done!

Go to Top