PDA

View Full Version : my platform engine!


omega10mg
09-27-2003, 08:28 PM
so i'm trying to make my own platformgame engine. :p
it dosent work the way i want.. lets look at the code then i explain what dosent work.

//ON HERO MOVIECLIP
onClipEvent (load) {
yjump = 20;
xwalk = 4;
rightedge = 550;
leftedge = 0;
xspeed = 20;
yspeed = 20;
gravity = 2;
drag = .98;
}

onClipEvent (enterFrame) {

if (Key.isDown(Key.UP)) {
_y -= yjump;
}

if (Key.isDown(Key.RIGHT)) {
_x += xwalk;
}

if (Key.isDown(Key.LEFT)) {
_x -= xwalk;
}
_x = _x+xspeed;
if (_x+_width/2>rightedge) {
_x = rightedge-_width/2;
xspeed = -xspeed;
}
if (_x-_width/2<leftedge) {
_x = leftedge+_width/2;
xspeed = -xspeed;
}
_y = _y+yspeed;
yspeed = yspeed*drag+gravity;
xspeed = xspeed*drag;

}


//ON GROUND MOVIECLIP
onClipEvent (enterFrame) {
if (this.hitTest(_root.hero)) {
tellTarget (_root.hero) {
yspeed = 0;
xspeed = xspeed*0.50;
}
}
}


okey.. often u fall half way down the ground! hum.. any idea on how to fix this?
and i have to hold up to jump elsewise it just falls down real quick.. anyway to make it jump all the way?

and how would i make diffrent animations play when i press left, right and up.
I tryed to to use gotoAndStop(aframe) and on the specific frame i had a movie clip with the correct animation.. but this did not work very well... it was hard to have the guy point at the right direction when he was walking right then jumping etc.

and the last thing.. do u think my idea on this platform engine is anygood?

junahu
09-29-2003, 08:44 AM
I had very similar problems when I started making platformers. I'll be back tomorrow with a nice thick juicy piece of actionscript and explanation. In the meantime try this demo of my latest platformer. The actionscript used is very similar to yours (abet longer). Not exactly sure how it'll help but I never miss a chance to parade my work.


On a side note I think your take on the platformer engine is very good (Mainly because I use it too).

junahu
09-30-2003, 10:22 AM
I promised a large dump of actionscript yesturday. You'll have to do with this from the top of my head.

attach to hero mc

onClipEvent(enterFrame)
{
onground = _root.ground.hitTest(_x,_y,true)
keyup = Key.isDown(Key.UP)
keyleft = Key.isDown(Key.LEFT)
keyright = Key.isDown(Key.RIGHT)
if(Keyup)
{
if(!onground)
{
yspeed = -20
jumped = 1
}
else
{
yspeed += 0.2
}
}
if(!onground)
{
gotoAndStop(3)
yspeed -= 1
if(_root.ground.hitTest(_x,_y + 3,true)
{
_y -= 3
}
}
if(onground)
{
yspeed = 0
if(_root.ground.hitTest(_x,_y - 1,true)
{
_y -= 1
}
}
if(keyleft)
{
xspeed -= 1
}
else if(xspeed < 0)
{
xspeed += 0.1
}
if(keyright)
{
xspeed += 1
}
else if(xspeed > 0)
{
xspeed -= 0.1
}
if(xspeed > 1)
{
if(onground)
{
gotoAndStop(2)
}
_xscale = xscale
}
else if(xspeed < 1)
{
if(onground)
{
gotoAndStop(2)
}
_xscale = -xscale
}
else
{
gotoAndStop(1)
}


have a standing animation on the first frame of your hero movieclip, a running one on the second and a jumping one on the third.
give the ground movieclip an instance name of ground.

This engine can be added to and improved quite a lot. If you want more help, just ask.

omega10mg
09-30-2003, 06:36 PM
thank you for sharing some =)

try out my even newer action platform-engine;

http://notanotherwebsite.mine.nu/omega10mg/nawtk/web/beta.php

Controlls:
W = Jump
A = walk left
D = walk right
SPACE = Reload
Mouse = aim
Mouse leftbutton = fire
1 & 2 = change weapon

i can post the code later when i made some more adjustment, if anyone is interested =)

Xenozip
09-30-2003, 09:12 PM
Bahahaha. Dude, that AK-47 rules. :)
Good job, looks like the final version will rock. :D

junahu
10-01-2003, 05:43 AM
That's a pretty damn cool engine there. Great job man!

obsoleteasian
11-10-2003, 05:51 PM
wow very cool engine. My goal is to create something to this nature. I am working on some ideas, and just playing around with the idea