I'm writing a little platform game in javascript. Not using the canvas tag. I don't want to use the canvas tag right now, so please don't suggest it. I don't mean to sound rude either, but please don't knock my code, I know it's not perfect but I'm trying to figure things out for myself.
I've been stuck on the collision detection. I can get the collision to detect horizontally, but if i use space to jump over the guy, it still detects it. How can I get it to not detect the collision as I jump over the enemy?
One more thing, How can I set an interval inside of javascript itself? for example, if i want to refine the animation of the character jumping, how can I setInterval inside the code itself.
var tree1;
var tree2;
var tree3;
var treeLeft1=365;
var treeLeft2=600;
var treeLeft3=1000;
var cave;
var caveLeft=0;
var ground;
var groundLeft=0;
var groundRight;
var wall;
var wallLeft;
var wallRight;
var bullet;
var bulletLeft=25;
var enemy;
var enemyLeft=300;
var enemyTop=252;
var castle;
var castleLeft = 250;
var bush1;
var bushLeft1=50;
I have two more quick questions if you don't mind. I am trying to make the animation of my character smoother for jumping. I want to actually see him go up when i push space bar.
also, On collision, how can i remove the image from the game becaues the character died?
To mimick a jump, the course is more parabolic not linear so,,
HTML Code:
else if(e.keyCode===32){ pinx=0; moves('jump',true); }
var p=[16,14,12,10,8,6,4,2,0]; var pinx=0
function moves(d,w){
if(d=='jump'){ t=parseInt(guy.style.top);
if(w){ if( pinx<p.length-1){guy.style.top=(t-p[pinx])+'px'; pinx++; setTimeout("moves('jump',"+w+")",20); return}
else{setTimeout("moves('jump')",20); return}
}
else{ if(pinx>=0){guy.style.top=(t+p[pinx])+'px';pinx--; setTimeout("moves('jump')",20); return}}
}
}
A DOM element method is called for to remove characters from the scene-
<script type="text/javascript">
var childnode=document.getElementById("child")
var removednode=document.getElementById("father").removeChild(childnode)
</script>
Bookmarks