PDA

View Full Version : Need an actionscript/help on one


Ballswick
12-12-2005, 09:11 AM
I've been In search for a very long time for someone to help me on a game I've been working on very amatuer but I still need help and I haven't gotten any so I hope someone can help on this site this is what I got so far
on (keyPress "a") {
currentX = this._x;
this._x = currentX-2;
_root.bug._rotation = -90;
}
on (keyPress "d") {
currentX = this._x;
this._x = currentX+2;
_root.bug._rotation = 90;
}
onClipEvent (load) {
grav_y = 0;
jumping = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE) && !jumping) {
grav_y = 20;
jumping = true;
}
if (jumping == true) {
grav_y -= 1;
if (grav_y<=-10) {
grav_y = -10;
}
this._y -= grav_y;
}
if (_root.ground.hitTest(this._x, this._y+45, true)) {
grav_y = 0;
jumping = false;
}
}


It doesn't really work the movment does but the jumping it just falls through the ground If you would like to help me and want to know more of what I'm doing please let me know.

Thanks

Ilikepandas
12-13-2005, 03:19 AM
That's sucky code for moving left and right

However, being the true geek that I am I managed to make it work quite quickly (I think this works best on flash 8)

onClipEvent (load) {
grav_y = 0;
jumping = false;
speed = 5
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this._x -= speed
_rotation = 90
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed
_rotation = -90
}
if (Key.isDown(Key.SPACE) && !jumping) {
grav_y = 20;
jumping = true;
}
if (jumping <> false) {
grav_y -= 1;
if (grav_y<=-10) {
grav_y = -10;
}
this._y -= grav_y;
}
if (_root.ground.hitTest(this._x, this._y+45, true)) {
grav_y = 0;
jumping = false;
}
}


Don't forget to label the character bug and a block called ground for it to work.
I used the arrow keys to move instead

Ballswick
12-13-2005, 07:19 PM
Thanks a lot but that's not what I was quite looking for I have multiple platforms and when I jump under one I 'd like it to hit the the paltform and fall down and when I jump I would like my "bug" to to start falling down unless it lands on a platform so if that's not to much trouble could you help me with that

Ilikepandas
12-14-2005, 08:29 PM
Aaaah yep-
I'll have to change the code entirely now...

DONE IT!!

okay for the bug add this code:

onClipEvent (load) {
_root.gravity = 10;
_root.jumping = false;
speed = 5
power = 20
}
onClipEvent (enterFrame) {
this._y += _root.gravity
if (Key.isDown(Key.LEFT)) {
this._x -= speed
_rotation = 90
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed
_rotation = -90
}
if (Key.isDown(Key.SPACE)) {
if(_root.jumping <> true){
_root.jumping = true;
}
}
if(_root.jumping <> false){
this._y -= power
if(power > 0){
power -= 1
}
}
}

And for the platforms or blocks add this. (Don't give these an instance name, leave them unnamed)

onClipEvent (enterFrame) {
if (this.hitTest(_root.bug)) {
if (_root.bug._y>this._y) {
_root.bug._y += _root.gravity;
_root.jumping = true;
_root.bug.power = 0
} else if (_root.bug._y<this._y) {
_root.bug._y -= _root.gravity;
if((Key.isDown(Key.SPACE)) <> true){
_root.jumping = false;
_root.bug.power = 20
}
}
}
}

Does this help?

Ballswick
12-14-2005, 10:34 PM
Oh yes it does Thank you so much but there is one problem with it everytime my "bug" mc hits my "floor" it just goes through have any ideas and this is my final question how would you do a rollover effect with a movieclip like if I were to move it into a gun for example how would I make it to where if you pick it up you can shoot it I mainly need to know how to pick it up and shoot it

Thanks again

Ilikepandas
12-19-2005, 04:00 PM
Oh yes it does Thank you so much but there is one problem with it everytime my "bug" mc hits my "floor" it just goes through have any ideas and this is my final question how would you do a rollover effect with a movieclip like if I were to move it into a gun for example how would I make it to where if you pick it up you can shoot it I mainly need to know how to pick it up and shoot it

Thanks again
Aaah- did you call the floor "floor"?, you must make sure that the ground has no instance but the bug does. I'm not sure if that's the problem though. Now for shooting, there's lots of methods but first I'll show you what to do to make something pickupable:

in a movieclip, draw the gun first frame and add the stop() action to the frame. Then press F7 to make a blank frame next to it. Leave this frame blank
Now, add this code to the movieclip:
onClipEvent (enterFrame) {
if (this.hitTest(_root.bug)) {
nextFrame()
}
}

Ballswick
12-19-2005, 11:30 PM
Was that the script so I can pick things up because it didn't work
Thanks though