dream-of-sleeping

LD27

Just declaring my rubbish base code

This will be my first Ludum Dare. I have entered three 48 hour game jams recently (the weekly Fight Magic Run competition), and won one of them,  so I’m pretty wamed up. I’ve been using createjs. The only base code that I will use that I wrote myself will probably be my key input class. I wrote it some time ago and it’s  pretty messy but it’s worked pretty well. So I thought I had better declare it. Also my loading bar class which was written last minute and rubbish, but again it does the job.  I don’t have a github, so I’m pasting the code below. You can use it if you like, but I doubt you will want to! haha

njc.KeyInput = function() {
this.keyActions = [];
this.keyEvents = [];
this.loggingInput = false;

 

njc.KeyInput.prototype.register = function(elementId) {
var element = document.getElementById(elementId);
var referenceName = this;
element.addEventListener(“keydown”, function(event) {referenceName.onEvent(event)}, false);
element.addEventListener(“keyup”, function(event) {referenceName.onEvent(event)}, false);
element.addEventListener(“keypress”, function(event) { referenceName.iHateOpera(event)}, false);
};

// opera doesn’t support pevent default on keydown! edit: or it didn’t I have no idea anymore what this is for
njc.KeyInput.prototype.iHateOpera = function(event) {

if (!this.loggingInput) {
return;
}

if (this.getActionByCode(event.keyCode)) {
event.preventDefault();
}
};

njc.KeyInput.prototype.onEvent = function(event) {

if (!this.loggingInput) {
return;

}
var keyAction = this.getActionByCode(event.keyCode);

if (keyAction) {
event.preventDefault();
}
this.keyEvents.push(event);
};

njc.KeyInput.prototype.poll = function() {
this.resetPress();

for (var i = 0; i < this.keyEvents.length; i++) {
this.processEvent(this.keyEvents[i]);
}

this.keyEvents.length = 0;
};

njc.KeyInput.prototype.processEvent = function(e) {
keyAction = this.getActionByCode(e.keyCode);

if (keyAction != undefined) {

if (e.type == “keydown”) {
keyAction.press();
} else if (e.type == “keyup”) {
keyAction.release();
}
};
};

njc.KeyInput.prototype.addKeyAction = function(name, code, rapidFireTime, initialDelay) {
var keyAction = new njc.KeyAction(name, code);

if (rapidFireTime) {
keyAction.rapidFire = true;
keyAction.rapidFireTime = rapidFireTime;
}

if (initialDelay) {
keyAction.initialDelay = initialDelay;

}

this.keyActions.push(keyAction);

return this;
};

njc.KeyInput.prototype.getActionByCode = function(keyCode) {

for (var i = 0; i < this.keyActions.length; i++) {
if (this.keyActions[i].code == keyCode) {
return this.keyActions[i];
}
};
};

njc.KeyInput.prototype.key = function(keyName) {

for (var i = 0; i < this.keyActions.length; i++) {
if (this.keyActions[i].name == keyName) {
return this.keyActions[i];
}
};
return undefined;
};

njc.KeyInput.prototype.resetPress = function() {
for (var i = 0; i < this.keyActions.length; i++) {
var keyAction = this.keyActions[i];
keyAction.pressed = false;
keyAction.released = false;
}
};

njc.KeyInput.prototype.logInput = function(log) {
this.loggingInput = log;
this.keyEvents.length = 0;
// reset all keys when log input is enabled or disabled to make sure
// game has no unwanted actions.
for (var i = 0; i < this.keyActions.length; i++) {
this.keyActions[i].fullReset();
}
};
};

njc.KeyAction = function(name, code) {
this.name = name;
this.code = code;

this.rapidFire = false;
this.rapidFireTime;
this.initialDelay = 0;
this.firstPress = false;
this.timeStamp;

this.isDown = false;
this.pressed = false;
this.released = false;

njc.KeyAction.prototype.fullReset = function() {
this.isDown = false;
this.pressed = false;
this.released = false;
};

njc.KeyAction.prototype.press = function() {

if (!this.isDown) {
this.isDown = true;
this.pressed = true;
this.firstPress = true;

if (this.rapidFire) {
this.timeStamp = new Date().getTime();
}
}
};

njc.KeyAction.prototype.release = function() {
this.isDown = false;
this.released = true;
};

njc.KeyAction.prototype.wasReleased = function() {
return this.released;
};

njc.KeyAction.prototype.wasPressed = function() {

if (this.rapidFire && this.isDown && this.enoughTimePassed()) {
this.timeStamp = new Date().getTime();
this.firstPress = false;
this.pressed = true;
}

return this.pressed;
};

njc.KeyAction.prototype.enoughTimePassed = function() {
var time = this.rapidFireTime;

if (this.firstPress && this.initialDelay != 0) {
time = this.initialDelay;
}

if (new Date().getTime() – this.timeStamp >= time) {
return true;
}

return false;
};
};

 

 

 

// loading scene
njc.LoadingScene = function(stage, numberToLoad) {
this.barColor = “white”;
this.fontColor = “white”;
this.fontStyle = “30px arial, sans-serif”;
this.barWidth = 400;
this.barHeight = 40;
this.text = “Loading…”;
this.backgroundColor = “rgb(30, 30, 30)”;

this.stage = stage;
this.numberToLoad = numberToLoad;
this.assetsLoaded = 0;

this.background = new createjs.Shape();

this.background.graphics.beginFill(this.backgroundColor).drawRect(0, 0, this.stage.canvas.width, this.stage.canvas.height);

this.barText = new createjs.Text(this.text, this.fontStyle, this.fontColor)
this.barText.x = (this.stage.canvas.width – this.barText.getMeasuredWidth() ) / 2;
this.barText.y = 330;

this.bar = new createjs.Shape();
this.bar.x = (this.stage.canvas.width – this.barWidth) / 2;
this.bar.y = (this.stage.canvas.height – this.barHeight) / 2;

this.barOutLine = new createjs.Shape();
this.barOutLine.x = this.bar.x;
this.barOutLine.y = this.bar.y;
this.barOutLine.graphics.beginStroke(this.barColor).drawRect(0, 0, this.barWidth, this.barHeight);

this.stage.addChild(this.background);
this.stage.addChild(this.bar);
this.stage.addChild(this.barOutLine);
this.stage.addChild(this.barText);
this.stage.update();
};

njc.LoadingScene.prototype.onComplete = function() {
this.stage.removeChild(this.background);
this.stage.removeChild(this.bar);
this.stage.removeChild(this.barOutLine);
this.stage.removeChild(this.barText);
};

njc.LoadingScene.prototype.render = function() {
this.bar.graphics.clear();

var percentageLoaded =  this.assetsLoaded / this.numberToLoad * 100;
var width = (percentageLoaded / 100) * this.barWidth;
this.bar.graphics.beginFill(this.barColor).drawRect(0, 0, width, this.barHeight);
this.stage.update();
};

njc.LoadingScene.prototype.onAssetLoaded = function() {

this.assetsLoaded++;

if (this.assetsLoaded > this.numberToLoad) {
console.log(“Error”);
return;
}

this.render();
};

Comments

JPatrick
21. Aug 2013 · 15:53 UTC
Please use pastebin or gist next time.
Dream Of Sleeping
21. Aug 2013 · 16:22 UTC
Ok sorry, I will do in future.

Ugly Start

I got up this morning at about 5am to start. Where has the time gone???? Well I’ve got the basic gameplay up and running, but my god is it ugly. I’m just using placeholder art so far, but even my rectangles are way uglier than the norm. Kind of like the cast of Thomas Was  Alone if they were all horribly disfigured. I’ll have to try and draw some sprites now. Small and from above like Super Smash TV. I’ll be using inkscape although I wish I had learned how to do pixel art.

What do you do when there is the possibilty of loads of gun shots going off at the similar time, so it get’s all computery sounding and horrid? I could have a few different gun shot effects, but I’m thinking I may check to see how many are playing and if it’s above a certain number not play it. Problem is firefox doesn’t play short sounds so they will all have to be over 1 second long.

I’ll tell you my game idea but don’t tell me if it’s been done loads of times before, or if last years winner did it or something. I don’t want to know, i’ve come to far. Basically every ten seconds you are cloned. And your new clone does just what you did for last ten seconds. If you moved left he moves left, and most importantly if you fired your gun, he fires his gun. You have to shoot as many clones as you can. The more you shoot, the more they shoot  at you.

I have a question about source files

My game uses html5 and javascript so obviously it will be viewable on the page with the game on it. Will that count as uploading source files? If not can someone tell me the easiest way to make my source downloadable. I’ve looked into github but I can barely even see at the moment from working so hard I can’t face learning it.

Comments

alfie275
25. Aug 2013 · 14:40 UTC
Personally I just use DropBox for hosting most stuff, you just put stuff into the folder and it gets uploaded.

Ahh…if only the theme had been 5 seconds

This was my first Ludum Dare, but my fourth 48 hour game jam. in the past couple of months. I think now I’ve more games made in game jams than not! I always work flat out, and push myself, but I think I’m pretty good at knowing my limitations (which there are many). I’ve never not finished.

My game was called Ten Second Clone. Every ten seconds you are cloned, and that clone moves how you moved and shoots when you shot for the 10 seconds before it came into existence. You can play it here.  http://www.ludumdare.com/compo/ludum-dare-27/?action=preview&uid=25172      

It was always going to be a challenge having the enemy just act out your movements without making it easy for you to make it easy on yourself. And for the Ludum Dare version, I failed. You can get about 30 kills just by standing on the spot. It takes too long to get going.  However, I have been working hard on the sequel 5 Second Clone! There are more changes than just the timing. Now you can’t shoot through clones so you can’t just line them up and get them one after the other. After 3 shots the clone disappears for good. Now if the clones reach the bottom of the screen, you turn into a clone of your clone!

If you played Ten Second Clone, and quite liked it but thought, it was a bit slow, you really need to try 5 Second Clone http://www.dreamofsleeping.co.uk/games/fivesecondclone/ Obviously you can’t rate that game as part of the competion, but there it is anyway.  I’m going to be adding more to it. Hopefully better graphics, some sound effects when you die, but I think it’s a fun game now.