User blog:Protanly/Started to create an RPG turn based strategy game.

The code is quite lengthy despite it being early but that's because I set most of it up for later. Here's what I have so far. It's in javascript by the way.

$(document).ready(function{

document.body.onmousedown = function { return false; } //so page is unselectable

//Canvas stuff

var canvas = $("#canvas")[0];

var ctx = canvas.getContext("2d");

var w = $("#canvas").width;

var h = $("#canvas").height;

var mx, my;

var IVDefence;

var IVSpeed;

var IVAttack;

var IVHP;

var StatPoints;

var PVAttack;

var PVDefence;

var PVSpeed;

var PVHP;

var b1x = 100

var b1y = 300;

var b2x = 100;

var b2y = 200;

/////////////////////////////////

////////////////////////////////

//////// GAME INIT

/////// Runs this code right away, as soon as the page loads.

////// Use this code to get everything in order before your game starts

//////////////////////////////

/////////////////////////////

function init

{

//////////

///STATE VARIABLES

// Random Number Generators

//Set up initial values for enemy stats

IVAttack = Math.floor((Math.random * 10) + 1);

IVDefence = Math.floor((Math.random * 10) + 1);

IVSpeed = Math.floor((Math.random * 10) + 1);

while (IVAttack + IVDefence + IVSpeed > 20 || IVAttack + IVDefence + IVSpeed < 9)

{

IVAttack = Math.floor((Math.random * 10) + 1);

IVDefence = Math.floor((Math.random * 10) + 1);

IVSpeed = Math.floor((Math.random * 10) + 1);

}

var IVHP = Math.floor((IVAttack + IVDefence + IVSpeed) / 2) + Math.floor((Math.random * 10) + 15);

alert (" Enemy Stats ");

alert ("Attack, Defence, Speed, Hit Points");

alert (IVAttack + " " + IVDefence + " " + IVSpeed + " " + IVHP);

//Set up initial values for player stats

StatPoints = 36;

PVAttack = 1;

PVDefence = 1;

PVSpeed = 1;

PVHP = 1;

//////////////////////

///GAME ENGINE START

// This starts your game/program

// "paint is the piece of code that runs over and over again, so put all the stuff you want to draw in here

// "60" sets how fast things should go

// Once you choose a good speed for your program, you will never need to update this file ever again.

if(typeof game_loop != "undefined") clearInterval(game_loop);

game_loop = setInterval(paint, 60);

}

init;

///////////////////////////////////////////////////////

//////////////////////////////////////////////////////

//////// Main Game Engine

////////////////////////////////////////////////////

///////////////////////////////////////////////////

function paint

{

ctx.fillStyle = 'red';

ctx.fillRect(0,0, 640,480);

ctx.fillStyle = 'yellow';

ctx.fillRect(b1x,b1y, 50,50);

ctx.fillStyle = 'yellow';

ctx.fillRect(b2x,b2y, 50,50);

ctx.fillStyle = 'black';

ctx.font = "40px Times New Roman";

ctx.fillText("-1", b2x, b2y + 35);

ctx.fillStyle = 'yellow';

ctx.fillRect(100,50, 50,50);

ctx.fillStyle = 'black';

ctx.font = "40px Times New Roman";

ctx.fillText(PVHP, b1x + 5, b1y - 215);

ctx.fillStyle = 'black';

ctx.font = "40px Times New Roman";

ctx.fillText("HP", b1x, b1y - 265);

ctx.fillStyle = 'black';

ctx.font = "40px Times New Roman";

ctx.fillText("+1", b1x, b1y + 35);

ctx.fillStyle = 'black';

ctx.font = "20px Times New Roman";

ctx.fillText("Unallocated stat points:", 100,400);

ctx.fillStyle = 'black';

ctx.font = "20px Times New Roman";

ctx.fillText(StatPoints, 300,400);

}////////////////////////////////////////////////////////////////////////////////END PAINT/ GAME ENGINE

////////////////////////////////////////////////////////

///////////////////////////////////////////////////////

///// MOUSE LISTENER

//////////////////////////////////////////////////////

/////////////////////////////////////////////////////

/////////////////

// Mouse Click

///////////////

canvas.addEventListener('click', function (evt){

if(mx > b1x && mx < b1x + 50 && my > b1y && my < b1y + 50 && StatPoints > 0){

PVHP = PVHP + 1;

StatPoints = StatPoints - 1;

}

else if(mx > b2x && mx < b2x + 50 && my > b2y && my < b2y + 50 && StatPoints < 36){

PVHP = PVHP - 1;

StatPoints = StatPoints + 1;

}

}, false);

canvas.addEventListener ('mouseout', function{pause = true;}, false);

canvas.addEventListener ('mouseover', function{pause = false;}, false);

canvas.addEventListener('mousemove', function(evt) {

var mousePos = getMousePos(canvas, evt);

mx = mousePos.x;

my = mousePos.y;

}, false);

function getMousePos(canvas, evt)

{

var rect = canvas.getBoundingClientRect;

return {

x: evt.clientX - rect.left,

y: evt.clientY - rect.top

};

}

///////////////////////////////////

//////////////////////////////////

//////// KEY BOARD INPUT

////////////////////////////////

window.addEventListener('keydown', function(evt){

var key = evt.keyCode;

//p 80

//r 82

//1 49

//2 50

//3 51

}, false);

})