Page 1 of 3
A platform game

Posted:
May 12th, 2010, 10:01 am
by Konradix
So I want to make platform game. I've done hero walking, idle and jumping from both sides, but how do I make it walk, and change sprite when I turn (when I'm walking to left then it uses left sprite walking, but when im walking to right its not flipping horizontal, its changing left walking to right.).
Re: A platform game

Posted:
May 13th, 2010, 12:46 am
by Suyo
Drag 'n' Drop or Code?
Konradix wrote:(when I'm walking to left then it uses left sprite walking, but when im walking to right its not flipping horizontal, its changing left walking to right.)
Sounds like you have a problem there. Can you post your code?
Re: A platform game

Posted:
May 13th, 2010, 12:32 pm
by Konradix
Well I had one which actually flipped horizontal when it went to the left. There is it:
CODE IN PLAYER
- Code: Select all
onClipEvent (load) {
gravity = 10;
scale = _xscale;
walkSpeed = 6;
maxjump = 6;
}
onClipEvent (enterFrame) {
if (air == true) {
_y += gravity;
state = 3;
}
if (Key.isDown(Key.LEFT) && !_root.leftbound.hitTest(_x, _y, true)) {
_x -= walkSpeed;
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT) && !_root.rightbound.hitTest(_x, _y, true)) {
_x += walkSpeed;
_xscale = scale;
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (Key.isDown(Key.SPACE) && jump == true) {
_y -= jumpSpeed;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (Key.isDown(Key.SPACE)) {
jumpcount += 1;
}
if (jumpcount > maxjump && jumpSpeed > -2) {
jumpSpeed -= 2;
}
if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe < 4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe < 4) {
state = 1;
}
if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe < 4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe < 4) {
state = 2;
}
if (!Key.isDown(65)) {
gotoAndStop(state);
}
_root.statetxt = state;
}
onClipEvent (keyUp) {
if (Key.getCode() == 83) {
jump = false;
}
}
Re: A platform game

Posted:
May 13th, 2010, 12:36 pm
by Buff_
That looks awfully like coding for flash, are you using flash?
Re: A platform game

Posted:
May 13th, 2010, 1:02 pm
by Konradix
Yes im using flash. It was called Platform Source maybe.
Re: A platform game

Posted:
May 13th, 2010, 1:21 pm
by Buff_
I'll look at the code, and test something out; see if I can do something with it. Also, can I see what you're actually doing? I need to see what the sprites are, I'm only using a square..
EDIT: Should this be moved to Flash Player Showcase?
Re: A platform game

Posted:
May 27th, 2010, 9:50 am
by Buff_
DOUBLE POST!!!!!!! New info on this..
I use this.
- Code: Select all
onClipEvent (load) {
var grav:Number = 0;
var run:Number = 10;
var wlk:Number = 2.5;
var speed:Number = run;
var jumpHeight:Number = 12;
var tjump:Boolean = false;
var slow:Number = .7;
var slowspd:Number = speed/2;
var setspeed:Number = speed;
var scale:Number = _xscale;
var ex:Number = 5;
this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
grav++;
_y += grav;
if (Key.isDown(65)) {
setspeed = wlk;
} else {
setspeed = run;
}
while (_root.ground.hitTest(_x, _y, true)) {
tjump = false;
_y--;
grav = 5;
}
if (_root.water.hitTest(_x, _y, true)) {
grav *= slow*1.25;
speed = slowspd;
} else {
speed = setspeed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
if (djump == false) {
this.gotoAndStop(2);
} else if (tjump == false) {
this.gotoAndStop(4);
} else {
this.gotoAndStop(5);
}
}
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
if (djump == false) {
this.gotoAndStop(2);
} else if (tjump == false) {
this.gotoAndStop(4);
} else {
this.gotoAndStop(5);
}
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(68) && !Key.isDown(83)) {
this.gotoAndStop(3);
}
}
if (Key.isDown(68) && !Key.isDown(Key.UP) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(83) && _root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(8);
}
if (Key.isDown(83) && !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(7);
} else if (Key.isDown(83) && grav>1) {
this.gotoAndStop(6);
}
if (Key.isDown(Key.UP) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
} else if (Key.isDown(Key.UP) && djump == false && grav>0 && tjump == false) {
grav = -dbl;
this.gotoAndStop(4);
} else if (Key.isDown(68) && tjump == false && grav>1) {
grav = -tri;
tjump = true;
this.gotoAndStop(5);
}
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;
}
}
This automatically changes the characters direction. You may need to edit some of the hitTests though.
Re: A platform game

Posted:
May 28th, 2010, 9:32 am
by Konradix
So I just have to make idle guy, jumping guy and walking? Or how, cuz im not sure how you've done that.
Re: A platform game

Posted:
May 28th, 2010, 9:56 am
by Buff_
Walk=Frame 1
Jump=Frame 2
Idle=Frame 3
Moving and in the air=Frame 4
This is all inside the symbol.
Re: A platform game

Posted:
June 3rd, 2010, 5:27 am
by Konradix
Ok guy is turning but what should I put in a platform?