harrywatson Posted October 16, 2014 Share Posted October 16, 2014 Hi all, I was having a look at some code for a platformer and decided I didn't like the waythe character locked on to the platform before having finished jumping. So I made my own code, Woo Hoo! In my version I use the createjs class for my bitmap images, other than that, it's just js. I've used 'base' , 'base2', and 'base3' as platforms - same image - just scaled and loadedwith different id's - but do it your way - doesn't matter. Whatever image will work. You can determine the width and height of an image apart from it's actual width and height.So say you have a platform image 10px height but half of that image is a drop shadow.Simply call the the image; myImage.height = 5; then your character won't bang it's headon a drop shadow. X and Y values for platforms are recorded just where you put them. In the below code there is no platform that shares the same same y co-ordinate but that would be easy. if (character.y < platform1.y && character.x > platform1.x + 400 && character.y < Platform2.y){ //plus 400 is width of platform 1platform2 = path} /// DON"T SHOOT ME / HAVEN'T TRIED THIS YET. first make a path...function path(width, height, x, y){ this.width = width; this.height = height; this.x = x; this.y = y;}easy. Then.....if(helpmeghost.y < base.y){ path = base;}elseif(helpmeghost.y > base.y && helpmeghost.y < base2.y){ path = base2;}elseif(helpmeghost.y > base.y && helpmeghost.y > base2.y && helpmeghost.y < base3.y){ path = base3;}Wow! Basic. vy+=gravity; //apply gravity to downward motion if (inAir){ //if not touching platform apply gravity to ghost helpmeghost.y+=vy; } if (vy>15){//limit falling speed vy=15; } if ( helpmeghost.x >= path.x && helpmeghost.x <= path.width && helpmeghost.y >= path.height && helpmeghost.y >= path.y) { helpmeghost.y=path.y; // set pos of ghost to platform/base/path vy=0; // switch gravity off jumping = false; inAir = false; }else{ inAir = true; } if(helpmeghost.x>=550){helpmeghost.x = 550} //keep ghost on stage if(helpmeghost.x<=60){helpmeghost.x =60}You can see all the code (I wouldn't look at it unless I had to) and results here... http://momogames.altervista.org/haunted/ IamThatGuy 1 Quote Link to comment Share on other sites More sharing options...
IamThatGuy Posted October 16, 2014 Share Posted October 16, 2014 -30,000 point's I RULE. =) harrywatson 1 Quote Link to comment Share on other sites More sharing options...
harrywatson Posted October 16, 2014 Author Share Posted October 16, 2014 He he, next job is sorting out my eyeballs. IamThatGuy 1 Quote Link to comment Share on other sites More sharing options...
IamThatGuy Posted October 16, 2014 Share Posted October 16, 2014 Are the eyeballs never suppose to die because I couldn't get rid of them? I clicked them, swipped them, ran into them, jumped on them and they just wouldn't die. I am going to have nightmares about eternal life eyeballs tonight. Quote Link to comment Share on other sites More sharing options...
harrywatson Posted October 16, 2014 Author Share Posted October 16, 2014 Hi no not yet, it's all in progress at the moment. Also the current version is shortened for testing - so not much game play - actually hang on a minute There, lasts for longer now.. The eyeballs will grow on the various platforms and my ghost will have to squash thembefore they explode. If they explode -1000 points. If they get squashed +1000 points.It'll be a couple of days maybe. Happy dreams SEE you later. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.