Im trying to make a fairly simple space invaders clone using html, css, jquery, and javascript. its going pretty good until I got to making collision detections for the bullets and the enemys. I looked into it for a bit, but couldn't find anything that could help me because Im not using canvas. How should I do this?
Here's the Javascript:
function init() {
$("#playerShip").hide();
$("#playerMarLeftCounter").hide();
$("#startButton").click(startGame);
}
function startGame() {
$("#playerShip").show();
$("#title").hide();
$("#startButton").hide();
}
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event)
{keycode = window.event.keyCode;}
else if (e)
{keycode = e.which;}
if(keycode == 37){
playerMoveLeft();
}
else if (keycode == 39){
playerMoveRight();
}
else if (keycode == 32){
shipFireBullet();
}
//alert("keycode: " + keycode);
}
function shipFireBullet(){
$("#shipBullet").css("animation-name", "fireBullet");
setTimeout(function(){ $("#shipBullet").css("animation-name", "nothing"); }, 750);
}
function playerMoveLeft(){
var whatMarLeft = $("#playerMarLeftCounter").html();
whatMarLeft = parseInt(whatMarLeft);
if (whatMarLeft <= -160){
return false;
}
else{
//alert (whatMarLeft);
var x = whatMarLeft - 15;
//alert(x);
$("#playerShip").css("margin-left", x);
$("#playerMarLeftCounter").html(x);
}
}
function playerMoveRight(){
var whatMarLeft = $("#playerMarLeftCounter").html();
whatMarLeft = parseInt(whatMarLeft);
if (whatMarLeft >= 1080){
return false;
}
else {
//alert (whatMarLeft);
var x = whatMarLeft + 15;
//alert(x);
$("#playerShip").css("margin-left", x);
$("#playerMarLeftCounter").html(x);
}
}
I know it might be a bit scuffed because Im newer to programming, but if someone could help me just get the collision detection down, that would be great. Thanks!