The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsNevermind @ this thread.
I've already fixed it myself :)
Yes, it's true I copied it from a tutorial, but I did actually read and study all the comments about the coding, so I kinda know what each part does. (The "attack" code actually is mine, I coded that part myself. May be the reason it sucks XD)
Before you even posted, I (may have) found the problem, but I don't really understand WHY that's the problem. You see, if I do this:
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
it works (so it checks if the letter O is pressed). But if I change that to (32) (SPACEBAR), it doesn't work ?
Why would it work with the letter O but not with SPACEBAR?
Thanks :)
sigh, wrong tags, sorry:
onClipEvent (load) {
var grav:Number = 0;
// gravity
var speed:Number = 12;
// how fast you walk
var jumpHeight:Number = 15;
// how high you jump
var slow:Number = .1;
// 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 = 2;
// 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);
}
//attack
if (Key.isDown(32) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.UP) && !Key.isDown(68) && _root.ground.hitTest(_x, _y+3, true) && _currentframe != 6) {
this.gotoAndStop(8);
}
//attack end
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;
}
}
[code]
onClipEvent (load) {
var grav:Number = 0;
// gravity
var speed:Number = 12;
// how fast you walk
var jumpHeight:Number = 15;
// how high you jump
var slow:Number = .1;
// 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 = 2;
// 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);
}
//attack code
if (Key.isDown(32) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.UP) && !Key.isDown(68) && _root.ground.hitTest(_x, _y+3, true) && _currentframe != 6) {
this.gotoAndStop(8);
}
//attack code end
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;
}
}
[/code]
If you mean inside the movieclip:
there's absolutely NO coding inside the attack-animation. I just don't understand why it doesn't work, I did the same for the walk animation etc.
Might it come in handy if I post the .fla here?
Hey guys,
I've got a problem with an animation. I'm making a platformer, my first of course, but now I want to make the player attack.
Now, it does go to the Attack-frame, which contains a movieclip with the animation, just like when making a player walk and jump, etc.
BUT the problem is, the animation doesn't play! It just stays at the first frame of the animation movie-clip, while it DOES work when I coded the walking animation.
if (Key.isDown(32) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.UP) && !Key.isDown(68) && _root.ground.hitTest(_x, _y+3, true) && _currentframe != 6) {
this.gotoAndStop(8);
}
That's my code. What's wrong about it?
Thanks in advance,
Lorenzo
Made a wolf-head, it's also the symbol of Venator Inc.
Please someone help me out ?
doesn't work, I tried it, but it seems the player doesn't even change it's animation to the "fire" one.. What's it I'm clearly doing wrong in the code..?
At 12/14/09 02:07 PM, Yambanshee wrote: maybe its because your saying gotoAndStop("fire") instead of gotoAndPlay("fire") but i just scanned it so im not sure
No, that code makes the frame inside the player movieclip change, and it's only 1 frame with a movieclip in it, which has the fire animation inside it :P
Sounds weird, but that's the same thing as u see in all the tutorials about platform games, with frames "standing, running and jumping". They all contain animated movieclips :P
Hey guys,
I decided to start learning programming games with Flash.
I wanted to make a platform shooter, but I came across a little problem: the shooting.
I can make my player shoot, but he will fire infinite bullets, boom-boom-boom after eachother. I tried giving the player a reload time, so he had to wait till he could shoot again.
The problem is: he doesn't reload, I can never shoot again.
This goes on the player object:
shotnum = 10;
shotmin = 10;
shotmax = 20;
reload = 8;
canshoot = 1;
then comes the shooting action:
if(Key.isDown(Key.SPACE)){
if (canshoot == 1)
{
shotnum ++;
_root.shot.duplicateMovieClip("shot"+sho tnum, shotnum);
_root["shot"+shotnum]._x=this._x+32;
_root["shot"+shotnum]._y=this._y-47;
canshoot = 0;
this.gotoAndStop("fire");
}
}
So I make the player go to his "fire" frame, after the canshoot variable has been set to 0 (disable). That frame contains a firing animation, and the last frame of the animation contains the code:
{
_root.player.canshoot=1;
_root.player.gotoAndStop(3)
}
What am I doing wrong?
Thank you :)
PS: do I have to upload the example of the game too? Or is this clear enough..?
Hey guys,
I decided to start learning programming games with Flash.
I wanted to make a platform shooter, but I came across a little problem: the shooting.
I can make my player shoot, but he will fire infinite bullets, boom-boom-boom after eachother. I tried giving the player a reload time, so he had to wait till he could shoot again.
The problem is: he doesn't reload, I can never shoot again.
This goes on the player object:
shotnum = 10;
shotmin = 10;
shotmax = 20;
reload = 8;
canshoot = 1;
then comes the shooting action:
if(Key.isDown(Key.SPACE)){
if (canshoot == 1)
{
shotnum ++;
_root.shot.duplicateMovieClip("shot"+sho tnum, shotnum);
_root["shot"+shotnum]._x=this._x+32;
_root["shot"+shotnum]._y=this._y-47;
canshoot = 0;
this.gotoAndStop("fire");
}
}
So I make the player go to his "fire" frame, after the canshoot variable has been set to 0 (disable). That frame contains a firing animation, and the last frame of the animation contains the code:
{
_root.player.canshoot=1;
_root.player.gotoAndStop(3)
}
What am I doing wrong?
Thank you :)
PS: do I have to upload the example of the game too? Or is this clear enough..?