News:

If you need instructions on how to get through the hotels, check out the enclosed instruction book.

Main Menu

AS2 - platform games

Farted by INoodleClock, March 09, 2009, 10:28:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

INoodleClock

I'm currently working on a small platform game, character design and level background/textures are still in the works so no screenies yet. The code being worked on was started from this:

http://www.newgrounds.com/portal/view/426598

Although it runs ok in the tutorial, more complex designs make it really buggy - it seems to have issues with hitTests, no mater what settings are used. Does anyone know how to improve on this, or even a different way to do it altogether?

The game's going to be based on the shrimp that CubeMelon posted a photo on. :)

SpongeClock SquarePants

read some stuff on optimizing your code, too much enterframes and stuff makes things lag.

AstronautClock

the guy only has a key for the guy to stand walk and jump. no attack? no die?
no objects that can harm you? THIS IS MADNESS

INoodleClock

Yeah obviously adding that sorta thing in.

Here's the code to save having to follow the link. The problem isn't lag, the character just doesn't like getting close to objects, or falling through the sides of platforms. Changing the var ex:Number didn't seem to help, just make it really glitchy after about 100 and he falls through everything under 2 - there doesn't seem to be a happy inbetween however.

onClipEvent (load) {
var grav:Number = 0;
// gravity
var speed:Number = 10;
// how fast you walk
var jumpHeight:Number = 15;
// how high you jump
var slow:Number = .3;
// sets water falling speed
var slowspd:Number = speed/1.5;
// sets water walking speed
var setspeed:Number = speed;
var scale:Number = _xscale;
var ex:Number = 5;
// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}
if (_root.water.hitTest(_x, _y, true)) {
if (grav>0) {
grav *= slow;
}
speed = slowspd;
} else {
speed = setspeed;
}
if (Key.isDown(68)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(65)) {
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
this.gotoAndStop(3);
}
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
if (Key.isDown(73) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
this.gotoAndStop(4);
}
if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
}
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-(_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;
}
}