PDA

View Full Version : [AS2] Scrolling screens help


canarybirdfly
12-17-2008, 02:08 AM
Ok I have two pieces of script that are incorrect and I have no idea how to correct them :(

The first:

// I'm not really sure what the first section does tbh

onClipEvent (enterFrame) {
if (_root.keyright == true) {
_root.ball._xscale = 100;
_root.dir = 1;
_root.dx += 1;
}
if (_root.keyleft == true) {
_root.ball._xscale = -100;
_root.dir = -1;
_root.dx -= 1;
}
if (_root.keyleft == false and _root.keyright == false) {
if (_root.dx<0) {
_root.dx += .5;
}
if (_root.dx>0) {
_root.dx -= .5;
}
if (_root.dx == 0 and _root.dy>=0) {
_root.ball.gotoAndPlay(1);
}
}
if (_root.dx>_root.maxspeed) {
_root.dx = _root.maxspeed;
}
if (_root.dx<-_root.maxspeed) {
_root.dx = -_root.maxspeed;
}
if (_root.startrun == true) {
_root.ball.gotoAndPlay(7);
_root.startrun = false;
}
if (_root.downkey == true) {
_root.ball.gotoAndPlay(57);
}
if (_root.dy == 0) {
_root.jumping = false;
}
if ((_root.ground.blocks.hitTest(_root.ball._[ccc]
x , _root.ball._y+_root.dy, true) == true) and [ccc]
!_root.jumping) {
_root.falling = false;
_root.jumping = false;
_root.dy = 0;
} else if (_root.ground.blocks.hitTest[ccc]
(_root.ball._x, _root.ball._y-40+_root.dy, true) ) {
_root.falling = true;
_root.jumping = false;
_root.dy = 2;
} else {
_root.falling = true;
_root.dy++;
}

//The below section checks for collisions with the horizontal wall

if (_root.dx<0) {
if (_root.downkey == false) {
if (_root.ground.blocks.hitTest[ccc]
(_root.ball._x-15, _root.ball._y-10, true) [ccc]
or _root.ground.blocks.hitTest(_root.ball._[ccc]
x-15, _root.ball._y-40, true)) {
_root.dx = 0;
}
} else {
if (_root.ground.blocks.hitTest[ccc]
(_root.ball._x-15, _root.ball._y-10, true)) {
_root.dx = 0;
}
}
} else if (_root.dx>0) {
if (_root.downkey == false) {
if (_root.ground.blocks.hitTest[ccc]
(_root.ball._x+15, _root.ball._y-10, true) [ccc]
or _root.ground.blocks.hitTest(_root.ball._[ccc]
x+15, _root.ball._y-40, true)) {
_root.dx = 0;
}
} else {
if (_root.ground.blocks.hitTest[ccc]
(_root.ball._x+15, _root.ball._y-10, true)) {
_root.dx = 0;
}
}
}
if (_root.dy>_root.maxfall) {
_root.dy = _root.maxfall;
}
_root.y += _root.dy;
_root.x += _root.dx;
_root.ground._x = -_root.offx;
_root.ground._y = -_root.offy;
_root.ball._x = _root.x-_root.offx;
_root.ball._y = _root.y-_root.offy;
}

// The below section contains no errors (Defines area of scrolling screen)

if (_root.scrollon == true) {
if ((_root.x-_root.offx)>330) {
_root.offx += _root.dx;
}
if ((_root.x-_root.offx)<70) {
_root.offx += _root.dx;
}
if ((_root.y-_root.offy)>270) {
_root.offy += _root.dy;
}
if ((_root.y-_root.offy)<70) {
_root.offy += _root.dy;
}
} else {
if ((_root.x-_root.offx)>370) {
_root.offx += 370;
}
if ((_root.x-_root.offx)<30) {
_root.offx -= 370;
}
if ((_root.y-_root.offy)>280) {
_root.offy += 270;
}
if ((_root.y-_root.offy)<30) {
_root.offy -= 270;
}
}
}

The problems:

http://i5.photobucket.com/albums/y186/jelly645/Untitled.jpg


The second:

// This is supposed to help my character move around the stage

onClipEvent (keyDown) {
if (Key.getCode() == Key.RIGHT and [ccc]
root.keyright == false and _root.downkey [ccc] == false)) {
_root.keyright = true;
_root.startrun = true; }
if (Key.getCode() == Key.LEFT and [ccc]
root.keyleft == false and _root.downkey [ccc] == false) {
_root.keyleft = true;
_root.startrun = true;
}
if (Key.getCode() == Key.SHIFT && [ccc]
root.jumping == false && _root.dy == [ccc]
0 and _root.downkey == false) {
_root.falling = true;
_root.jumping = true;
_root.dy = -_root.jumpheight;
}
if (Key.getCode() == Key.DOWN) {
_root.downkey = true;
_root.keyleft = false;
_root.keyright = false;
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.RIGHT) {
_root.keyright = false;
}
if (Key.getCode() == Key.LEFT) {
_root.keyleft = false;
}
if (Key.getCode() == Key.DOWN and [ccc]
root.keyleft == false and _root.keyright [ccc]
== false) {
_root.downkey = false;
}
}

The problems:

http://i5.photobucket.com/albums/y186/jelly645/Untitled2.jpg


I was using a tutorial to try and figure it out which is below:
http://www.adobepress.com/articles/article.asp?p=31456&seqNum=3

I really am stumped basically I have a character in a flash game and I want to use scrolling graphics for a level. Plus I also want the character to be able to jump onto ledges, walk over terrain etc (collision detection & gravity). If anyone has any good tutorials that can help me even more it will be a massive help!

pierre23
12-17-2008, 02:16 AM
There are so many game creation tutorials out there. Google is your best friend here. Usually in most game tutorials they include hittest and gravity.

Try googling:
flash scrolling game tutorial
flash creating a game
flash character hittest

Any of the above will come up with enough info to complete a game, start to finish with gravity, hittest, scores, etc.

Here is one of the links I found:
http://www.emanueleferonato.com/2007/02/09/flash-game-creation-tutorial-part-51/

Scroll down a bit theres a cool "camera follow character; avoid walls" type of game