Friday, 15 July 2011

A little bit of Code

So I've finally stopped being distracted by reading manga and playing games and actually done some programming. As I'm sure everyone knows here, Jade made a game last year. The game was made in flash using action script 2. While action script 2 is good and quite user friendly, action script 3 is more flexible and will (hopefully) provide us with more options. So I've decided to try and update the code to that previous project. Overall its was fairly easy and only took my a few hours to update the very basics, this was more of an experiment to find how easily I could figure it out and it was easier then I thought it would be.

Another bonus to as3 is that you cant attach code to objects. This might seem like a bad thing at first but personally I quite like it as it means the code can all be one place rather then spread out amongst several. At the moment all this code is attached to frames. So I have one frame per scene, then you can put all the movie clips in the frame and you can easily reference them.


stop();

window.buttonMode = true;
window.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void
{
        gotoAndStop(2);
}


So this is the first frame of the film which displays the door. I created a movie clip with the alpha turned down to zero to select the windows, this would then transfer you to the window scene.


hair.buttonMode = true;
hair.addEventListener(MouseEvent.CLICK, onClick2);

function onClick2(event:MouseEvent):void
{
      removeChild(hair);
      hair2.visible=true;
     
}

Same deal pretty much, the hair is a movie clip, once clicked on its removed from the scene and the hair in the inventory is visible.

I was thinking and I reckon it is possible, although bit it with quite a bit of effort to have it so that when an item is added to the inventory its added to the next available slot rather then how it is at the moment where all the items are already in the inventory just invisible. It's a minor thing so it's not something I'll threat over but I'll try my hand at trying to do that.

text1.visible =false;
text2.visible =false;

inv_hairkite2.visible=false;

hair3.buttonMode = true;
hair3.addEventListener(MouseEvent.CLICK,displaytext);

function displaytext(event:MouseEvent):void
{
        text1.visible=true;
       
}

inv_kite2.buttonMode = true;
inv_kite2.addEventListener(MouseEvent.CLICK,displaytext2);

function displaytext2(event:MouseEvent):void
{
        text1.visible=true;
}

hair3.addEventListener(MouseEvent.CLICK, initDragger);

function initDragger(mc:MovieClip):void
{
    mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    mc.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}

function mouseDownHandler(e:MouseEvent):void
{
    e.currentTarget.startDrag();
}
function mouseUpHandler(e:MouseEvent):void
{
    e.currentTarget.stopDrag();
    hair3.x=170;
    hair3.y=48;
}


initDragger(hair3);


inv_kite2.addEventListener(MouseEvent.CLICK, initDragger2);

function initDragger2(mc:MovieClip):void
{
    mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
    mc.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler2);
}

function mouseDownHandler2(e:MouseEvent):void
{
    e.currentTarget.startDrag();
}
function mouseUpHandler2(e:MouseEvent):void
{
    e.currentTarget.stopDrag();
    inv_kite2.x=130;
    inv_kite2.y=48;
   
   
}


initDragger2(inv_kite2);

hair3.addEventListener(Event.ENTER_FRAME, circleHit);

function circleHit(event:Event):void {
if (hair3.hitTestObject(inv_kite2)) {
removeChild(hair3);
removeChild(inv_kite2);
inv_hairkite2.visible=true;
}
}

The text at the top are movie clips of the descriptions for each item which are simply made visible by clicking on them. You might notice theres no way for the text to be removed, this is simply because I haven't added it yet but it would be easy enough to do.
The rest of the code is for dragging the items and then making them combine into a new item when they overlap. Again all this does is when they overlap they are removed from the scene and the new item is made visible. This seems like an awful lot of code especially just to move items around so I'm going to see if theres a more streamlined way of doing this as I'm sure there is.

That's the endeavors of all my coding for today, I hope you have enjoyed. I've pretty much figured out how to convert everything into action script 3 so now I'm gonna mess around with packages and see if I can find a simpler way of doing things, I was hoping to post the progress of that up today but its been harder then I thought.
At the very least today I know that converting actions script 2 to action script 3 is very easy, so we know at the very least we can achieve what was done in TKON

BTW if anyone finds a flash file that they look hows it done and want to find out how it was created use this website - http://www.showmycode.com/ - it will display all the code used for the project and is rather helpful when you know what you're looking fo

3 comments:

  1. Wow Mike, that's incredibly helpful...a big THANK YOU man!

    By doing that we're pretty much got a good pace doing this and perhaps now we can figure out how to do a save/load function like in Ren'Py. If you're bored, maybe you can muck about with it? Don't worry if you don't have time because I'll get round to doing it sooner or later. I'll post up a schedule soon just so that we can have an idea of some sort of deadline.

    Seriously thank you so much for doing this! Once I have the script written out I can discuss what kind of cool game mechanics we can emulate certain bits of the script by.

    Also cheers for the link, I shall see whether I can find out how John Su does his ripple effect....fufu.

    ReplyDelete
  2. All in a days work! I'm sure save load function is possible. The good thing about the internet is if you want to learn how to do something theres probably a bunch of tutorials on how to do it. Plus I know the latest version of flixel it has a save function built it so i could always rip the code from that. I'll much around with Renpy tommorow and as3 a bit more, anything that we want to do probably can be done, it just takes finding the right info. I'll try and post up a real simple game in as3 in a few days or something

    ReplyDelete

Note: only a member of this blog may post a comment.