A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Early balloon/game Engine.

  1. #1
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650

    Early balloon/game Engine.

    Ok, just wanted to show what I'm currently working on. It will become a platform adventure game. You will not have the balloon at the start and will have to earn money first to buy it. I know exactly how I want the game. The only hold back are making the hittest work properly with the stage for both the balloon and the player.

    As you will see, it's jumpy and glitchy and I have done the best I can. I made this engine from scratch and knew I had to use the _y, _x, true hittest type and to check all corners.

    I first had it so that when he fell, gravity were used so he fell faster and faster, it's realistic and looks good... but he sometime fell through the ground and stuff and as I couldn't fixe it I changed the fall speed to constant instead. As he is falling slowly I was thinking of adding a falling animation, like his standing stance holding an umbrella.. but that would look gay so I instead made a short 2 frame animation where he flaps his arms (comic style )... but can't get the animation to play as it loops frame 1. I have tried several ways but can't make Flash stop playing only the first frame.... I have sooo many problems with this engine as it is my very first platform. My Kung Fu game doesn't count as all I did there was hittesting against a ground mc. For other buggy situations I had to restrict the balloon flight area, thus the "no balloon within this area" sign.... lot's of more work to do... just wanted to show it as it's my first.... platform engine.

    I started out with this: (the gravity code from my KFR game)

    MoveY ++;
    Y += MoveY;
    _y= Y;

    I had a hell to get the gravity to work, really . It's complicated for me.... and then when I got the balloon to fall in an accellerated speed, I had to make it so it slowly reverse and go upward with the space... it was hell I tell ya....

    Oh well.... here it is: Balloon/game engine

    edit: Press down when you have landed to exit the balloon, and space to enter it (space will be changed as it's used for jumping aswell). If you use IE, you will probably have 30ish fps... it's just 24ish with firefox.... as with most flash games.... +5fps in IE, -5 in most others
    Last edited by Ironclaw; 03-28-2006 at 01:49 PM.

  2. #2
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    It is a pretty cool concept, but to me seems a bit too "slow".

    To get the platform to land on top of the(or moved up), just set the y of the balloon to(assuming the tops of the movieclips are zero):

    balloon._y=platform._y+balloon._height;

    About the balloon actually going through the platforms, you could just cut the movement into sections(eg if it moves 10 px, move it 2, hittest, 4, hittest, 6 hittest, 8, hittest, 10 hittest).

    Interesting Idea.

  3. #3
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Quote Originally Posted by UnknownGuy
    To get the platform to land on top of the(or moved up), just set the y of the balloon to(assuming the tops of the movieclips are zero):

    balloon._y=platform._y+balloon._height;
    You mean hittesting against the top of the balloon so the balloon part doesn't go through the placed out/hovering platforms?. I know how to do that but havn't decided yet if I want the balloon to go through them or not. So far only the basket is hittesting against the platforms.


    Quote Originally Posted by UnknownGuy
    About the balloon actually going through the platforms, you could just cut the movement into sections(eg if it moves 10 px, move it 2, hittest, 4, hittest, 6 hittest, 8, hittest, 10 hittest).
    Think the above answer is suitable for this one aswell...



    My problems are:

    1. When landed with the balloon on a platform or ground and when walking with the player, the balloon moves around a couple of pixels.

    2. When jumping against a wall and holding the direction key and space, the player sort of climbs the walls (he shouldn't)

    3. I can't get my script to play the fall animation correctly, all it does is playing the first frame. I have tried variables to stop the loop til he reaches the ground.. but doesn't work.

    4. If I make a courner like this:



    The player can jump through them if he jump up-left or up-right.

    5. For some odd reason I can't get the bottom of the basket to hittest its edges against the ground, it only hittests against the middle of the basket, even if I use _y+15 _y-15 as it is about 30 pixels wide.

    etc... but this is enough.


    The player's and balloon's reg points are at the bottom:



    I think you'll have to see my code to be able to help me. It has all started to become confusing. I think most of my problems lies in the _y in all things. I sometimes use +3, 0 and -1 for my _y's.... and changing one of them makes things mess up... I'm just lucky to find the somewhat proper numbers.

    Hope someone really can help me find a solution to my problems. Heck, I could attach my game fla with gfx and all, not stripped down.... if someone just knew he could help me.


    Thankful for any replies.

  4. #4
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    PM me if you want me to look at the FLA

  5. #5
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    PM sent

  6. #6
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Hi again, still need help . UnknownGuy took a look at the fla and could unfortunately fix any of the problems :/... thanks for taking a look though UG.

  7. #7
    Senior Member SlimSlaby's Avatar
    Join Date
    May 2005
    Posts
    158
    I'd like to take a look at it. I had a similar problem recently, can't remember how I fixed it.

    Basically I had a mc that kept floating upwards I fixed it by doing it another way, but I never really figured out why it was happening. It really seemed like a bug with Flash somehow.

  8. #8
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    You better search.. tons of threads and flas about platform detection.... my code is too messy to figure out what keeps the player and the balloon on the ground anyway... and I have checked some of those threads and fla's... they don't work for me... so my fla is to no use for you, sorry.

  9. #9
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Bump

    Still havn't solved this.... ok, would it be easier to do a good collision with lots of mcs instead of shape hittesting?.. I don't use any slopes anyway....

    well... still asking for help with my current problems....

  10. #10
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    hey

    i think that hittesting isn't a great solution for this

    perhaps you should consider a math approach which takes into account geometric shapes. I have never actually made a circle-square collision test algorithm, but i've done line-circle so it shouldn't be 2 different

    tell me if you want a deeper explanation, but also visit metanet's tutorials because they address this issue and more

  11. #11
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    I suck at math and have read some tutorials and they are quite confusing.....

    Anyway........ here's the complete code for the game... dont think anyone can solve anything by looking at it anyway as it's quite complicated.... one wrong number and something stop working..... or bugs out...


    Code:
    limits = false;
    limitsNew = false;
    lifting = false;
    landed = false;
    halt = false;
    goneOff = false;
    lock = true;
    falling = false;
    fallingNew = false;
    //--------------------------------------------------------------
    this.onEnterFrame = function() {
    	balloonX = balloon._x;
    	balloonY = balloon._y;
    	worldX = world._x;
    	worldY = world._y;
    	//--------------------------------------------------------
    	if (Key.isDown(Key.SPACE) and landed == false) {
    		balloon.thrust.gotoAndStop(2);
    	} else {
    		balloon.thrust.gotoAndStop(1);
    	}
    	//--------------------------------------------------------
    	if (balloon._x<=world._x-1105) {
    		xSpeed = -1;
    	}
    	if (balloon._x>=world._x+1290) {
    		xSpeed = +1;
    	}
    	if (Key.isDown(Key.RIGHT) and landed == false and halt == false) {
    		xSpeed -= 0.05;
    	}
    	if (Key.isDown(Key.LEFT) and landed == false and halt == false) {
    		xSpeed += 0.05;
    	}
    	if (Key.isDown(Key.SPACE) and landed == true and halt == false) {
    		_root.world._y = _root.world._y+5;
    		landed = false;
    		lifting = true;
    	}
    	//--------------------------------------------------------------
    	if (landed == false and halt == false and limits == false) {
    		if (balloon._x<=world._x+1310 and balloon._x>=world._x-1125) {
    			world._x += xSpeed;
    			xSpeed += 0.0;
    			world._y -= ySpeed;
    			ySpeed += 0.04;
    			balloon._y = 260;
    			balloon._x = 276;
    		}
    		if (Key.isDown(Key.SPACE) and landed == false and halt == false) {
    			ySpeed -= 0.08;
    			if (!world.platforms.hitTest(_root.balloon._x+15, _root.balloon._y, true) and !world.platforms.hitTest(_root.balloon._x-15, _root.balloon._y, true) and landed == false and halt == false) {
    				lifting = false;
    			}
    		}
    	}
    	//--------------------------------------------------------------
    	if (world.platforms.hitTest(_root.balloon._x+15, _root.balloon._y-1, true) and world.platforms.hitTest(_root.balloon._x-15, _root.balloon._y-1, true) and landed == false and halt == false) {
    		if (ySpeed<=4 and ySpeed>=-4) {
    			y = _root.world._y;
    			x = _root.world._x;
    			groundHitTest = true;
    			if (lifting == false) {
    				landed = true;
    				ySpeed = -0;
    				xSpeed = -0;
    			}
    		} else {
    			groundHitTest = true;
    			balloon.gotoAndStop("Crash");
    			halt = true;
    			landed = true;
    		}
    	}
    	if (world.platforms.hitTest(_root.balloon._x+15, _root.balloon._y-1, true) and world.platforms.hitTest(_root.balloon._x-15, _root.balloon._y-1, true)) {
    		_root.world._y++;
    	}
    	if (world.platforms.hitTest(_root.balloon._x+15, _root.balloon._y-1, true) and world.platforms.hitTest(_root.balloon._x+15, _root.balloon._y-15, true)) {
    		_root.world._x += 4;
    	}
    	if (world.platforms.hitTest(_root.balloon._x-15, _root.balloon._y-1, true) and world.platforms.hitTest(_root.balloon._x-15, _root.balloon._y-15, true)) {
    		_root.world._x -= 4;
    	}
    	//---------------------------------------------------
    	if (Key.isDown(Key.DOWN) and goneOff == false and halt == false and landed == true) {
    		trace("Jumped off");
    		velY = 0;
    		halt = true;
    		goneOff = true;
    		i += 1;
    		balloon.driver.gotoAndStop(2);
    		_root.attachMovie("player", "player"+i, i);
    		_root["player"+i]._x = balloon._x;
    		_root["player"+i]._y = balloon._y;
    		lock = false;
    		jumping = false;
    	}
    	//---------------------------------------------------
    	if (Key.isDown(Key.RIGHT) and goneOff == true and limitsNew == false) {
    		_root.balloon._x = _root.world._x-(x-276);
    		world._x -= 3;
    		_root["player"+i]._xscale = -100;
    		_root["player"+i].guy.gotoAndStop("run");
    		if (world.platforms.hitTest(_root["player"+i]._x+11, _root["player"+i]._y-43, true) or world.platforms.hitTest(_root["player"+i]._x+11, _root["player"+i]._y-1, true) and landed == true) {
    			_root.balloon._x = _root.world._x-(x-280);
    			_root.world._x += 4;
    		}
    	} else {
    		if (Key.isDown(Key.RIGHT) and goneOff == true and limitsNew == true) {
    			_root["player"+i]._xscale = -100;
    			_root["player"+i].guy.gotoAndStop("run");
    			_root["player"+i]._x += 4;
    		}
    	}
    	if (!Key.isDown(Key.RIGHT) and !Key.isDown(Key.LEFT) and fallingNew == false) {
    		_root["player"+i].guy.gotoAndStop("stand");
    	}
    	if (Key.isDown(Key.LEFT) and goneOff == true and limitsNew == false) {
    		_root.balloon._x = _root.world._x-(x-280);
    		world._x += 3;
    		_root["player"+i]._xscale = 100;
    		_root["player"+i].guy.gotoAndStop("run");
    		if (world.platforms.hitTest(_root["player"+i]._x-11, _root["player"+i]._y-43, true) or world.platforms.hitTest(_root["player"+i]._x-11, _root["player"+i]._y-1, true) and landed == true) {
    			_root.balloon._x = _root.world._x-(x-280);
    			_root.world._x -= 4;
    		}
    	} else {
    		if (Key.isDown(Key.LEFT) and goneOff == true and limitsNew == true) {
    			_root["player"+i]._xscale = 100;
    			_root["player"+i].guy.gotoAndStop("run");
    			_root["player"+i]._x -= 4;
    		}
    	}
    	//-------------------------------------------------------
    	if (_root["player"+i]._x<=world._x+1315 and _root["player"+i]._x>=world._x-1125) {
    		_root["player"+i]._x = 275;
    		limitsNew = false;
    	} else {
    		limitsNew = true;
    	}
    	if (Key.isDown(Key.SPACE) and goneOff == true) {
    		if (_root["player"+i].centerHitTest.hitTest(balloon.ladder)) {
    			lock = true;
    			_root["player"+i].removeMovieClip();
    			balloon.driver.gotoAndStop(1);
    			halt = false;
    			goneOff = false;
    		} else if (falling == false) {
    			jumping = true;
    		}
    	}
    	if (jumping == true) {
    		_root["player"+i].guy.gotoAndStop("jump");
    		_root.world._y -= velY;
    		velY += 0.7;
    		_root.balloon._y = _root.world._y-(y-257);
    		if (velY>=0.7) {
    			velY = 4;
    			trace("fall from jumping");
    			_root["player"+i].guy.gotoAndStop("fall");
    			_root.balloon._y = _root.world._y-(y-257);
    		}
    		if (world.platforms.hitTest(_root["player"+i]._x+11, _root["player"+i]._y-43, true) or world.platforms.hitTest(_root["player"+i]._x-11, _root["player"+i]._y-43, true)) {
    			velY = +5;
    		}
    		if (world.platforms.hitTest(_root["player"+i]._x+11, _root["player"+i]._y, true) or world.platforms.hitTest(_root["player"+i]._x-11, _root["player"+i]._y, true)) {
    			velY = -8;
    			velYx = -8;
    			jumping = false;
    		}
    	}
    	if (world.platforms.hitTest(_root["player"+i]._x+11, _root["player"+i]._y-1, true) and world.platforms.hitTest(_root["player"+i]._x-11, _root["player"+i]._y-1, true) and landed == true and goneOff == true) {
    		falling = false;
    		fallingNew = false;
    		_root.balloon._y = _root.world._y-(y-257);
    		_root.balloon._x = _root.world._x-(x-280);
    		_root.world._y++;
    	}
    	if (jumping == false) {
    		if (!world.platforms.hitTest(_root["player"+i]._x+11, _root["player"+i]._y+2, true) and !world.platforms.hitTest(_root["player"+i]._x-11, _root["player"+i]._y+2, true) and lock == false) {
    			fallingNew = true;
    			_root["player"+i].guy.gotoAndStop("fall");
    			velYx -= 0.7;
    			_root.balloon._y = _root.world._y-(y-257);
    			_root.world._y += velYx;
    			if (velYx<=0.7) {
    				trace("fall from edge");
    				velYx = -2;
    				_root.balloon._y = _root.world._y-(y-257);
    				_root.world._y += velYx;
    				fallingNew = false;
    			} else {
    				velY = -8;
    				velYx = -8;
    			}
    		}
    	}
    };

    Quote Originally Posted by Squize
    Also ( Tiny, tiny point ), most people use camel case when coding in Flash, so:

    SpawnSpeed

    would be

    spawnSpeed

    Starting with a captial is used for classes / packages.

    Squize.
    Look, Squize! I use the camel thingy :P!.. I decided to do it the way most people do it after all ^^. I read an article and seems like I was using the UpperCamelCase which in mo is best as it's easier to read, but.... I want to do it like the pro's so ...
    Last edited by Ironclaw; 04-06-2006 at 06:02 AM.

  12. #12
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926


    I'm impressed stubborn boy

    Now if you were to put var infront of all those variable declarations you've got going on at the top of your code I'd dance for you ( All variables should be declared with var, stops memory leaks )

    Squize.

    PS. Sorry, wouldn't even know where to start with your code, I'll try and have a look when I get a minute, but don't wait on me too much

  13. #13
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    I havent read the rest of the posts but I just want to let you know im getting 8 fps on a p4 1.6ghz 256mb ram
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  14. #14
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    IronClaw,

    I'd like to take a look at this project to see if I can help you solve your issues. No promises, but I think I can help and I need the experience.

    As long as it's MX '04 and you have a PC I can give it a try.
    +Q__
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  15. #15
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Hi QH, I use a PC and Flash MX (6) and from what I know, MX '04 users can't save to flash MX .

    But, I will gladly PM you a link to the fla in hope of you fixing something , and if you manage to fix my collision problem, I can download a trial version of MX '04 .

  16. #16
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    Ironclaw, to fix the collision problems you really need to go away from just point vs landscape collision and move into individual movieclips/rectangles.

  17. #17
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Maybe, I don't know and it wouldn't make it easier for me anyway . Would still have similar problems I guess. But you told me to use movieclips in a pm aswell and yeah... maybe I should use lots of mcs instead... but instead of splitting the whole stage up in rectangles, can't I just put empty MC on top of things?

    I will see if QH can do something to my collision problem, if he can't, I'll use lots of MCs.
    Last edited by Ironclaw; 04-08-2006 at 09:53 AM.

  18. #18
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    Well, theoretically if you went all math you wouldn't need mcs, but you would need to create an "object" with the x,y,width and height of each platform.

    But if you split it into mc's, you can just use a normal rectangle vs rectangle hittest, not using points.

  19. #19
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Well, it's easy to add empty MCs ontop of things with the size of all different platforms and stuff.... but when I do and if,,,,, I'll still not know how to do the hittesting.... can only get a little bit on the way making it work like in my current engine...jumpy and sh*t...... will wait a couple of more days on QH.. then make the changes ...

  20. #20
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    IronClaw,

    I just received the file, and I can immediately tell you that it will require alot of work to fix. I can do this, no problem, but give me a couple days to hammer it out.

    Also, I may have to completely change the way your hitTest() works. Hopefully not, but a possibility.

    +Q__
    Qwai•zang \kwî-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center