Be a Supporter!

Code Help

  • 272 Views
  • 4 Replies
New Topic Respond to this Topic
Saif36
Saif36
  • Member since: May. 2, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Code Help 2009-09-07 18:03:01 Reply

Hey there im making this platformer and i need help with this code...The current controls on this code are set to A,W And D and i want it as left arrow key,right arrow key and the up arrow key can somebody change this code quickly...Thanks :)

onClipEvent (load) {
var grav:Number = 0;
// gravity
var speed:Number = 6.5;
// how fast you walk
var jumpHeight:Number = 10;
// how high you jump
var slow:Number = .7;
// 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;
}
}

FalconPuuunch
FalconPuuunch
  • Member since: Apr. 24, 2008
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Code Help 2009-09-07 18:09:06 Reply

Just put "LEFT" and whatever direction you want into where it has numbers.


i like nachos... yea

BBS Signature
Magical-Zorse
Magical-Zorse
  • Member since: May. 10, 2008
  • Offline.
Forum Stats
Member
Level 40
Melancholy
Response to Code Help 2009-09-07 18:09:11 Reply

Here you go, but if you can't figure it out, then you probably won't be able to make this into a game.

onClipEvent (load) {
var grav:Number = 0;
// gravity
var speed:Number = 6.5;
// how fast you walk
var jumpHeight:Number = 10;
// how high you jump
var slow:Number = .7;
// 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(Key.RIGHT)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(Key.LEFT)) {
_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(Key.UP) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
if (Key.isDown(73) && !Key.isDown(Key.UP) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(79)) {
this.gotoAndStop(4);
}
if (Key.isDown(Key.UP) && _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;
}
}

BBS Signature
Kwing
Kwing
  • Member since: Jul. 24, 2007
  • Offline.
Forum Stats
Member
Level 45
Game Developer
Response to Code Help 2009-09-07 18:36:25 Reply

Also, on a side note, you should try learning some script instead of copy/pasting. I'm not asking you to take classes, but when you paste script, take a quick glance at it; that's how I learned.


If I offer to help you in a post, PM me to get it. I often forget to revisit threads.
Want 180+ free PSP games? Try these links! - Flash - Homebrew (OFW)

moonhitler
moonhitler
  • Member since: Jun. 30, 2007
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Code Help 2009-09-07 18:56:25 Reply

I learnt by doing that, then making it up as I went along. Most of the scripting I do is just experimenting.


a garlic a day keeps the vampire away.

My Facebook Music page.