Friday, 28 August 2015

Week 5 - Prac B

Week 5 - Prac B

This week practical we have a discussion about how to use action-script 3.0 to create game in flash, tutor gave us a a website called Lynda  which is quite helpful for coding stuff in action-script 3.0. 

I also found a snake game code through google and I know how to code the snake up/down/left/right direction:


private function directionChanged(e:KeyboardEvent):void
        {
            var m:Object = new Object(); //MARKER OBJECT
            if (e.keyCode == Keyboard.LEFT && last_button_down != e.keyCode && last_button_down != Keyboard.RIGHT)
            {
                snake_vector[0].direction = "L";
                m = {x:snake_vector[0].x, y:snake_vector[0].y, type:"L"};
                last_button_down = Keyboard.LEFT;
            }
            else if (e.keyCode == Keyboard.RIGHT && last_button_down != e.keyCode && last_button_down != Keyboard.LEFT)
            {
                snake_vector[0].direction = "R";
                m = {x:snake_vector[0].x, y:snake_vector[0].y, type:"R"};
                last_button_down = Keyboard.RIGHT;
            }
            else if (e.keyCode == Keyboard.UP && last_button_down != e.keyCode && last_button_down != Keyboard.DOWN)
            {
                snake_vector[0].direction = "U";
                m = {x:snake_vector[0].x, y:snake_vector[0].y, type:"U"};
                last_button_down = Keyboard.UP;
            }
            else if (e.keyCode == Keyboard.DOWN && last_button_down != e.keyCode && last_button_down != Keyboard.UP)
            {
                snake_vector[0].direction = "D";
                m = {x:snake_vector[0].x, y:snake_vector[0].y, type:"D"};
                last_button_down = Keyboard.DOWN;
            }
            markers_vector.push(m);
        }

No comments:

Post a Comment