Archive for November, 2010

Case 6 – Programming and Animation of enemy

Posted in Cases on November 17, 2010 by alllifeme

In this “case” we were asked to animate and program a new character that should walk towards the main character all the time.

First of, I made a quick frame by frame animation of a normal blobb (look at case 1 for more information). Then I used the main script to add the character on stage and make it follow the ground (not moving yet).

Then I made the script for the new character by copying from someone else in the group and inputting the names and parameters I wanted.he requre

 

What I have yet to do:

I have done all the requirements, but I want add two more things.

 

1. When the main character is near the enemy, I want a life-bar to slowly shrink and maybe make the main characters alpha decrease with the life-bar.

2.  Make the enemy disappear only after the main character have picked up the coin.

Case 5 – Programming 2

Posted in Cases on November 10, 2010 by alllifeme

So in this “case” we were asked to do at least 3 things. We had to put the character animations into a sprite,  make the character follow the ground and pick something up.

I had already put the character animations into a sprite before, so that part was already done.

So I started out with trying to make my character follow the ground. I managed to do this with some help.

Then I made a coin movie clip in the library and placed it (with actionscript) on my stage. With a hit test, I made it so that when my character hit the coin, it was removed (removeChild).

 

Problems:

I forgot (}) alot of times, taking away some of my time. However, I am better at this now.

Other then that, there where minimal amount of trouble.

 

Extra notes:

This blog post might be a little short because I am a little lazy and time was running out. If I remember something  important, I will add it.

 

Case 4 – Programming 1

Posted in Cases on November 3, 2010 by alllifeme

In this “case” we were asked to create the main scene in our game/entertainment production using the graphic and character we made in the 3 first  cases. But this had to be done by placing them through ActionScript 3.0.
We also had to make the character move  left and right and prevent it from walking out of the screen.

What I did:

Our teacher showed us a a script that we could use as a start for our own game. I used that, changing the names I needed to change.

Here is the code: (Bolded parts are my names and things I added myself)

// InteraktivScene1Main.as – ANI121 – DN 271010
package
{
import flash.display.MovieClip;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.display.BitmapData;

public class AS_tryout_1_Main extends MovieClip
{
private var gress1:gress;
private var karakter:gå_høyre;
private var bakgrunn:Bakgrunn;

//  Bounding box
const L:int = 0;                    // Left
const W:int = 550;                    // Width
const T:int = 0;                    // Top
const H:int = 400;                    // Height
const R:int = L+W;                    // Right
const B:int = T+H;                    // Bottom

public function AS_tryout_1_Main()
{
bakgrunn = new Bakgrunn();
addChild(bakgrunn);
bakgrunn.x = 275;
bakgrunn.y = 200;

gress1 = new gress();
addChild(gress1);
gress1.x = 225;
gress1.y = 340;

karakter = new gå_høyre();
addChild(karakter);
karakter.x = 125;
karakter.y = 380;
karakter.gotoAndStop(1);
karakter.width = 100;
karakter.height = 100;

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyReleased);
}
public function onKeyPressed(e:KeyboardEvent) : void
{
if (e.keyCode == Keyboard.LEFT && karakter.x > L)
{
karakter.x = karakter.x – 2;
karakter.scaleX = -0.28;
}
else if (e.keyCode == Keyboard.RIGHT && karakter.x < R) {
karakter.x = karakter.x + 2;
karakter.play();
karakter.scaleX = 0.28;
}

}
public function onKeyReleased(e:KeyboardEvent) : void
{
karakter.gotoAndStop(1);
}
}
}

But it didn’t work to my satisfaction, mainly bacause the movement. With this code, when I pressed end held the mouse button, the character moved first the amount of pixles I said it should, then stopped for a half a second or a second, and moved like it should after that. A classmate, Andreas Hellesvik, solved this with boolean variables. But because his script was quite different from the script I had, he let me copy his script. I changed the names I needed for it to work with my graphic/objects, size of the stage, The pace of my characters movement.

This is my script now:

// AS_tryout_Main_2 – JF 117083

package  {

import flash.display.MovieClip;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;

public class AS_tryout_Main_2 extends MovieClip {

private var forgrunn:gress;
private var himmel:Bakgrunn;
private var tre:animatedgrass;
private var sky:cloud_1;
private var spritemain:spritemain1;
private var leftKey:Boolean = false
private var rightKey:Boolean = false


const L:int = 0;
const W:int = 550;
const T:int = 0;
const H:int = 400;
const R:int = L+W;
const B:int = T+H;

public function AS_tryout_Main_2() {

himmel = new Bakgrunn();
addChild(himmel);
himmel.x = 275;
himmel.y = 200;


forgrunn = new gress();
addChild(forgrunn);
forgrunn.x = 225;
forgrunn.y = 340;


sky = new cloud_1();
addChild(sky);
sky.x = 300;
sky.y = 50;


tre = new animatedgrass();
addChild(tre);
tre.x = 400;
tre.y = 330;


spritemain = new spritemain1();
addChild(spritemain);
spritemain.x = 130;
spritemain.y = 370;
spritemain.height = 100;
spritemain.width = 100;
spritemain.gotoAndStop(1);

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyReleased);
stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);
}

public function onFrameLoop(e:Event) : void
{

sky.x = sky.x – 1;
run();
}

public function onKeyPressed(e:KeyboardEvent) : void
{

if (e.keyCode == Keyboard.LEFT) {

leftKey = true;
}


else if (e.keyCode == Keyboard.RIGHT) {

rightKey = true ;
}
}
public function onKeyReleased(e:KeyboardEvent) : void {

if(e.keyCode == Keyboard.LEFT) {

leftKey = false;
spritemain.gotoAndStop(1)
}

if(e.keyCode == Keyboard.RIGHT) {

rightKey = false;
spritemain.gotoAndStop(1)
}
}

public function run() : void
{

if(leftKey == true) {

spritemain.x-=3;
spritemain.scaleX=-0.28;
spritemain.gotoAndStop(2);
}

if(spritemain.x<15){spritemain.x+=3}
if(rightKey == true) {

spritemain.x+=3;
spritemain.scaleX=0.28;
spritemain.gotoAndStop(2);
}

if(spritemain.x>535)
{
spritemain.x-=3;
}

}

}

}

 

What I have learned:
I have learned that addChild is used to add something to the stage. I have learned about sprites, that it is a great way to add the different movements so that the overall size of the file is smaller. And a great way to easily go to the movements when needed.

I already knew some scripting before I began this, but I still have dificulty understanding everything when put together.