A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Walk up/down a slope w/o hitTest

  1. #1
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811

    Walk up/down a slope w/o hitTest

    Okay, I am trying to add slopes to my Doodle game (stupid server is down ).

    I haven't taken Trig yet (I'm 14) so I was hoping some of you Math gurus could help.

    I attached a little example I created.

    I THINK I'm close.

    Thanks,
    Frag
    Last edited by Frag; 04-13-2008 at 02:09 PM.

  2. #2
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    u want slopes without hitTest???

    how can u do that? you want the slopes on a platform right? well then u gota have hitTest dont you?

    check the .fla out (i think its tonypa's i dono, he hasnt told me yet )
    Attached Files Attached Files

  3. #3
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    Why not hitTest?

    1) Are stairs possible with hitTest?
    2) I can draw stuff on the map MC and I don't have to worry about Doodle landing on it. For example, at the end of the first level it says Level 2 (written with the paintbrush).
    3) Really thin objects are skipped over!

    Even if you have solutions to all 3 (maybe more I don't know about), I've written 750+ lines based on the system I have now, so converting is too much work at this point.

    No help with the math? ;(

  4. #4
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    here's an old experiment with drawing API in flash, so it's a copy and paste jobby, no hitTest but if you pick it apart you may get some use out of it
    Code:
    wid = 600;
    hei = 300;
    tmp = _root.createEmptyMovieClip("border", 200000);
    sheet = _root.createEmptyMovieClip("bsheet", 100000);
    tmp.lineStyle(0);
    tmp.lineTo(wid, 0);
    tmp.lineTo(wid, hei);
    tmp.lineTo(0, hei);
    tmp.lineTo(0, 0);
    createEmptyMovieClip("land", 0);
    gap = 30;
    yrange = 15;
    xpos = 0;
    depth = 0;
    ypos = hei-yrange*1.5+Math.random()*yrange;
    function createLand() {
    	var clip = _root.createEmptyMovieClip("block"+depth++, depth);
    	var newY = ypos+Math.random()*yrange-yrange/2;
    	if (newY<hei/2) {
    		newY = hei/2+Math.random()*yrange/4;
    	} else if (newY>hei-20) {
    		newY = hei-20-Math.random()*yrange/4;
    	}
    	clip.x1 = xpos;
    	clip.y1 = ypos;
    	clip.x2 = xpos+gap;
    	clip.y2 = newY;
    	clip.m = (clip.y2-clip.y1)/(clip.x2-clip.x1);
    	clip.b = clip.y2-clip.m*clip.x2;
    	with (clip) {
    		lineStyle(2, 0x006600);
    		beginFill(0x009900);
    		moveTo(xpos, ypos);
    		lineTo(xpos+gap, newY);
    		lineStyle(0, 0x000000, 0);
    		lineTo(xpos+gap, hei);
    		lineTo(xpos, hei);
    		endFill();
    	}
    	xpos += gap;
    	ypos = newY;
    }
    for (var i = 0; i<20; i++) {
    	createLand();
    }
    function createMan(w, h, x, y, name) {
    	var clip = _root.createEmptyMovieClip("man"+name, 100+d);
    	with (clip) {
    		_x = x;
    		_y = y;
    		beginFill(0xFF0000);
    		moveTo(-w/2, 0);
    		lineTo(w/2, 0);
    		lineTo(w/2, -h);
    		lineTo(-w/2, -h);
    		lineTo(-w/2, 0);
    		endFill();
    		renderPos();
    	}
    	d++;
    }
    MovieClip.prototype.renderPos = function() {
    	var pos = Math.floor(this._x/gap);
    	var src = _root["block"+pos];
    	var ypos = src.m*this._x+src.b;
    	this._y = ypos;
    };
    createMan(10, 20, 50, 150, "L");
    createMan(10, 20, 120, 150, "R");
    speed = 4;
    line = {};
    manR.yd = -10;
    manL.yd = -10;
    this.onEnterFrame = function() {
    	//	trace(manR.yd)
    	if (Key.isDown(Key.UP)) {
    		if (Key.isDown(Key.RIGHT)) {
    			manR.yd--;
    			if (manR.yd<-20) {
    				manR.yd = -20;
    			}
    		} else if (Key.isDown(Key.LEFT)) {
    			manL.yd--;
    			if (manL.yd<-20) {
    				manL.yd = -20;
    			}
    		}
    	} else if (Key.isDown(Key.DOWN)) {
    		if (Key.isDown(Key.RIGHT)) {
    			manR.yd++;
    			if (manR.yd>-5) {
    				manR.yd = -5;
    			}
    		} else if (Key.isDown(Key.LEFT)) {
    			manL.yd++;
    			if (manL.yd>-5) {
    				manL.yd = -5;
    			}
    		}
    	} else {
    		if (Key.isDown(Key.RIGHT)) {
    			_root.manL._x += speed;
    			_root.manR._x += speed;
    		} else if (Key.isDown(Key.LEFT)) {
    			_root.manL._x -= speed;
    			_root.manR._x -= speed;
    		} else {
    		}
    	}
    	line.x1 = manL._x;
    	line.y1 = manL._y+manL.yd;
    	line.x2 = manR._x;
    	line.y2 = manR._y+manR.yd;
    	line.m = (line.y2-line.y1)/(line.x2-line.x1);
    	line.b = line.y2-line.m*line.x2;
    	sheet.clear();
    	sheet.lineStyle(3);
    	sheet.moveTo(line.x1, line.y1);
    	sheet.lineTo(line.x2, line.y2);
    	manL.renderPos();
    	manR.renderPos();
    };
    c = 0;
    gravity = 0.2;

  5. #5
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    yeh u can make it so:
    - u can run up stairs
    - yup u can do that writing stuff too, just make the hero test against a 'solid' mc inside the map. keep the stuff u dont want him landing on out of the 'solid' mc (make the 'solid' mc invisible and draw the graphics inside the map mc)
    - u dont want him landing on thin objects? well then keep them out of the 'solid' mc too
    - u do want him landing on thin objects, draw the thin things in the map mc, just create thicker ground in the 'solid' mc, ur not gona see it so it will be great

    well thats how i do it

    i know u dont wana change it, but i think if u want slopes... u gota use hitTest



    edit: i was gona say 'no math ' but all u gota do is look above my post

  6. #6
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    YAY!!!

    I did it!

    Thanks token 3, I realized it was easier than I thought after I reviewed your code

    And leight, care to see?

    I know I know it's not curvy and wavy and stuff like the artbased FLA, but it will suit my purpose quite nicely
    Last edited by Frag; 04-13-2008 at 02:09 PM.

  7. #7
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    ah yeh,

    i understand wat u were trying to do now i thort u were trying to do stuff like in art-slopes.fla

    mind explaining how u are going to use that? im guessing to walk up steps and heaps of angles - which is very cool

    nice work!

  8. #8
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    Yes, for tons of stairs and hills, one way slides, etc.

  9. #9
    Run for your life! Phlook's Avatar
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    679
    14 too?
    I learned trig last yr (im a grade ahead in math), so either ur teachers stupid, or ur gonna learn it soon

    [edit]
    300th post
    [/edit]

  10. #10
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    I'm in 8th grade at a jr. high, and every morning I go to the high school for an honors geometry/alg 2 class, but its doesn't matter now that neither geometry/trig/alg 2 was required

  11. #11
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    BTW I learn SohCahToa in geometry but it wasn't working in Flash...

    Sine = opposite/hypotenuse;
    Cosine = adjacent/hypotenuse;
    Tangent = opposite/adjacent;

    Too bad I forgot that for the state tests

  12. #12
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    Care to explain radians?

  13. #13
    Professional Air Guitarist Frag's Avatar
    Join Date
    Dec 2002
    Location
    Brain, Body, Clothes, Computer Chair, Room, House, Neighborhood, City, State, Country, Continent, World, Galaxy, Universe, and on?
    Posts
    811
    That's what I wanted before!

    Oh well...

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