Thursday, 30 April 2009

Added Features: moving platforms

Moving Platforms


When trying to make moving platforms I ran into a problem the platform would move but the character would not go with it. I fixed this problem by turning the moving platform into a moving springboard that propelled the character a small height giving the player time in the air to move the character along with the moving platform.

Code =

var movspringHeight:Number = 11;
// how high you jump on movingspring

if (_root.movingspring.hitTest(_x, _y+3, true)) {
// Jump
grav = -movspringHeight;
_y -= 4;
this.gotoAndStop(4);
}

Wednesday, 29 April 2009

Added features

Fans





I wanted to make platforms that you could jump through and then land on I managed to make them but when the character was on them he wouldn't walk on them he'd just sort of float above them playing his idle animation so I added a bit of code to make him play the falling animation and changed the art of the platforms into fans. The last paragraph of code makes adds the ability to jump while on a fan.

Code:

var platformHeight:Number=0
//platform resistance

if (_root.platform.hitTest(_x, _y, true)) {
// Jump
grav = -platformHeight;
_y -= 1;
this.gotoAndStop();
}

if (Key.isDown(65) && _root.platform.hitTest(_x, _y, true)) {
// Jump
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
}

Added features

Springboards




Springboards prepare you into the air much higher than normal jumping.



Code used

var springHeight:Number = 30;
// how high you jump on spring

if (_root.spring.hitTest(_x, _y+3, true)) {
// Jump
grav = -springHeight;
_y -= 4;
this.gotoAndStop(3);
_root.spring.gotoAndPlay(2);
}

Player code

The actionscript2 code that is placed on the player character is

onClipEvent (load) {
var slide:Number = 0;
//moving plaform slide
var grav:Number = 0;
// gravity
var speed:Number = 10;
// how fast you walk
var jumpHeight:Number = 15;
// how high you jump
var springHeight:Number = 30;
// how high you jump on spring
var movspringHeight:Number = 11;
// how high you jump on movingspring
var platformHeight:Number=0
//platform resistance
var dangerHeight:Number = 7;
// how high you jump when hit by danger
var slow:Number = .7;
// sets water falling speed
var fast:Number = 7;
var slowspd:Number = speed/2;
// sets water walking speed
var fastspd:Number = speed*1.5;
var setspeed:Number = speed;
var scale:Number = _xscale;
var ex:Number = 10;
// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
this.gotoAndStop(2);

var movingItems = new Array();
}
onClipEvent (enterFrame) {
grav++;
_y += grav;


// If not touching the ground then fall down (gravity)
while (_root.ground.hitTest(_x, _y, true)) {

_y--;
grav = 0;
}

// Test water and slow down
if (_root.water.hitTest(_x, _y, true)) {
if (grav>0) {
grav *= slow;
}
speed = slowspd;
} else {
speed = setspeed;
}

// Test fastbox and speed up
if (_root.fastbox.hitTest(_x, _y, true)) {


speed = fastspd;
}// else {
//speed = setspeed;
//}







if (Key.isDown(key.RIGHT) && !Key.isDown(88)) {
// Moving Right
_x += speed;
_xscale = scale;






if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(4);
}

} else if (Key.isDown(key.LEFT) && !Key.isDown(88)) {
//Moving Left
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(4);
}
} else {
// not moving or falling
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
this.gotoAndStop(3);
}


//fast movement

if (Key.isDown(key.RIGHT) && Key.isDown(88)) {
// Moving Right
_x += fastspd;
_xscale = scale;

if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(4);
}

} else if (Key.isDown(key.LEFT)&& Key.isDown(88)) {
//Moving Left
_x -= fastspd;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(4);
}
} else {
// not moving or falling
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
this.gotoAndStop(3);
}

}


// Check moving blocks
// loop through them all
for(var i =0; i< movingItems.length; i++){

if (movingItems[i].hitTest(_x, _y+3, true)){
var offset = Math.abs(_x - movingItems[i].block._x);
_x = movingItems[i].block._x;

}
}
}

// Animations
if (Key.isDown(79) && !Key.isDown(65) && !Key.isDown(key.LEFT) && !Key.isDown(key.RIGHT) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
if (Key.isDown(73) && !Key.isDown(65) && !Key.isDown(key.LEFT) && !Key.isDown(key.RIGHT) && !Key.isDown(79)) {
this.gotoAndStop(4);
}






//
if (Key.isDown(65) && _root.ground.hitTest(_x, _y+3, true)) {
// Jump
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
}




if (_root.platform.hitTest(_x, _y, true)) {
// Jump
grav = -platformHeight;
_y -= 1;
this.gotoAndStop();
}

if (Key.isDown(65) && _root.platform.hitTest(_x, _y, true)) {
// Jump
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
}



if (_root.spring.hitTest(_x, _y+3, true)) {
// Jump
grav = -springHeight;
_y -= 4;
this.gotoAndStop(3);
_root.spring.gotoAndPlay(2);
}


if (_root.movingspring.hitTest(_x, _y+3, true)) {
// Jump
grav = -movspringHeight;
_y -= 4;
this.gotoAndStop(4);
}



if (_root.danger.hitTest(_x, _y+3, true)) {
// Jump
grav = -dangerHeight;
_y -= 4;
_x -= 0;
this.gotoAndStop(5);
}




//switches
if (Key.isDown(88) && _root.soundbox01.hitTest(_x, _y,true)) {

loadMovie("plechide.swf",_root);
}

if (Key.isDown(88) && _root.soundbox02.hitTest(_x, _y,true)) {

loadMovie("plecnin.swf",_root);
}



// Hiting from Right
if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
_x -= speed;
}

// Hiting from Left
if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
_x += speed;
}

if (_root.ground.hitTest(_x, _y-_height-15, true)) {

grav = 1;
}

_root.gravTxt.text = grav;

}

Visual style


Changed my mind on the visual style, I've opted to use photographs of post it notes to create the levels

http://www.jackuchu.net/plecpost.swf




it doesn't run as fast as i'd like in the browser, I might have to compress the images or dynamical load them in.

Tuesday, 21 April 2009

classy-video-games.




I might use this simplistic artstyle using only one or two colours.

Im running out of time, back to work.