The 2DIY script archive

A resource containing Actionscript examples for 2Simples 2DIY software.

  • ActionScript
  • Animation Script
  • Collision Script
  • Start Button Script
  • Examples
  • Ideas
  • Help/Videos
  • Discuss

Actionscript Tutorial No.5

Here's the fifth in my series of tutorials aimed at helping 2DIY users to use, and understand, actionscript within their creations.

This tutorial deals with allowing extra players to move around within your activity.

Download 2DIY_tut5

Outline
In several 2DIY activities, you can allow extra players to take part in the activity by specifying keys to move particular elements around the screen.

Code Explanation
2diy_tut3_img1Right click on an element (either a monster or an apple element) and click on the animation options (the second option). Within this option there is an ‘advanced’ (ADV) setting where you can enter ActionScript code, and here we can set a rule to make certain keys cause the element to move.

Tutorial
Create a collecting activity. Add an apple element to the screen, right click on it, and look for the animation settings option (the second option). Choose the advanced (ADV) option and type in the following code;

if(Key.isDown(80)==true) { this._x +=1; }

if(Key.isDown(79)==true) { this._x -=1; }

if(Key.isDown(81)==true) { this._y -=1; }

if(Key.isDown(65)==true) { this._y +=1; }

if  (this tells the computer that there is a condition that will decide whether the code is to be run or not)

((all the code written between these double brackets)) (these are the conditions that need to be met before the code will run)

Key.isDown(80)==true (this means that a key with an identification value of 80 is pressed down)*

Key.isDown(79)==true  (this means that a key with an identification value of 79 is pressed down)*

Key.isDown(81)==true (this means that a key with an identification value of 81 is pressed down)*

Key.isDown(65)==true (this means that a key with an identification value of 65 is pressed down)*

*the identification numbers for all keys is given at the end of this tutorial

{ all the code written between these brackets } (this is the code that will run IF the conditions set out above are met)

this._x +=1; (this means that the horizontal position of the element will increase by 1 pixel - ie move a little to the right of the screen)

this._x -=1; (this means that the horizontal position of the element will decrease by 1 pixel - ie move a little to the left of the screen)

this._y -=1; (this means that the vertical position of the element will decrease by 1 pixel - ie move a little up the screen)

this._y +=1; (this means that the vertical position of the element will decrease by 1 pixel - ie move a little down the screen)

Now press the play button. One person can move the main character using the arrow keys as normal, but a second player can move the apple around the screen using the Q and A keys to move up and down, and the O and P keys to move left and right.

What does this do?
You are telling the computer to check whether a particular key has been pressed, and if it that key has been pressed to respond by making a particular element move in a particular way on screen.

Task
Create a collecting game. Add a character, and then add an apple element and right click on the apple element and choose the animation (the second) option. Select the ‘advanced’ (ADV) option and enter the code above to respond to key presses. Now run your game - can one player avoid being caught by the other player? 

Notes
You can alter the idea of the game and use a monster element instead of an apple element. In this case instead of the main character trying to collect an apple element, the main character will be try to avoid being caught by a monster element.

You do not have to limit it to 2 players either, you can include as many players as are physically able to press keys on the keyboard. 

Why not try with three players - player one could be the main character who is trying to collect an apple element. Player two could be an apple element trying to avoid being caught by player one, whilst player three could be a monster element who is trying to catch player one. 

Or, why not try creating a game with several players moving around a maze?

The identification values for the keys that can be used are as follows;

Alphabet key identification values; A (65)  - Z (90)

Numerical key identification values; 0 (48) - 9 (57)

left arrow(37) / up arrow (38) / right arrow (39) / down arrow (40)

space bar (32) / enter key (13)

You can find out more about this feature in this article

Posted by Xannov in Tutorials | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

More Bowling Park Games

Bowling Park Primary have been busy making more games with 2DIY. Take a look at their latest and greatest creations here.

Bowling Park 2DIY Platform Games with 6SB-1

Posted by Xannov in 2DIY Examples | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

Graphics for Games

Here are some images from Bev Evans that could be really useful when making games;

Right click and "save as" to put onto your computer for use in 2DIY game making.

Black Blue Brown Gold Green Grey Pink Purple Red Seagreen White

 

Posted by Xannov in General | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

Mr. Cobb's Class 2DIY games

Take a look at Mr. Cobb's Class blog to see some of the Christmas 2DIY games they have been making.

Mr Cobbs Class 2DIY Games

Posted by Xannov in 2DIY Examples | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

Bowling Park Primary Games

Bowling Park Primary have been very busy creating 2DIY games recently. Here are some links to the games they've placed onto their school blog;

More of 5NL’s 2DIY snow games

More snow games from 5RW

2DIY Snow Games – 5RW

Making Snow Games with 5RW

5NL – Making snow games with 2DIY

Bowling Park Primary


Posted by Xannov in 2DIY Examples | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

« Previous Articles | More Articles »

Search

Recent Posts

  • 2DIY with Gifted and Talented groups
  • Making characters fly (and other effects)
  • High Lawn Primary Games
  • Creative Learning
  • Gallons of Games
  • Games Pod Creations
  • Kensington Avenue Primary 'Games Pod'
  • Actionscript Tutorial No.8
  • ActionScript Tutorial No.7
  • ActionScript Tutorial No.6

Recent Comments

  • Xannov on Discuss
  • Angela Canas on Discuss
  • Xannov on Discuss
  • Angela Canas on Discuss
  • Xannov on Discuss
  • Ali on Discuss
  • Xannov on Discuss
  • Max Wainewright on Discuss

Archives

  • June 2011
  • May 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010

More...

2Simple Talk

login
Follow @xannov

| The 2DIY script archive |

Design by @xannov