You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.1 KiB
JavaScript

let defaultFillStyle = '#FF0';
let shapeDebug = true;
let shapeDebugColour = '#FF00FF';
let lineWidth = 1;
// Don't think I'll need/want this too often now
// keeping for UI elements that will draw less regular
// but no longer for entities
function drawRectangle(x,y,w,h,colour = false, strokeColour = false){
if(!colour && colour !== null){ colour = defaultFillStyle; }
ctx.fillStyle = colour;
if(colour !== null){
ctx.fillRect(x,y,w,h);
}
ctx.strokeStyle = strokeColour;
ctx.lineWidth = lineWidth;
ctx.strokeRect(x,y,w,h);
if(shapeDebug && !strokeColour){
ctx.strokeStyle = shapeDebugColour;
ctx.lineWidth = lineWidth;
ctx.strokeRect(x,y,w,h);
}
}
function drawCircle(x,y,w,colour = false, strokeColour = false){
if(!colour){ colour = defaultFillStyle; }
ctx.fillStyle = colour;
ctx.beginPath();
ctx.arc(x,y+(w/2), w/2, 0, 2 * Math.PI); // y+(w/2) to align like rect as circle draws from centre
ctx.fill();
if(shapeDebug){
ctx.strokeStyle = shapeDebugColour;
ctx.lineWidth = lineWidth;
ctx.stroke();
}
ctx.closePath();
}
function drawSemiCircle(x,y,w,colour = false, strokeColour = false){
if(!colour){ colour = defaultFillStyle; }
ctx.fillStyle = colour;
ctx.beginPath();
ctx.arc(x,y+(w/2), w/2, Math.PI, 0);
ctx.fill();
if(shapeDebug){
ctx.strokeStyle = shapeDebugColour;
ctx.lineWidth = lineWidth;
ctx.stroke();
}
ctx.closePath();
}
// Shape references from image canvas to be blitted to
function drawEnemy(entity){
ctx.drawImage(imageCanvas,
// source x,y,w,h
0,0,16,16
// x,y,w,h to be drawn onto the (visibile/game) canvas
,position[entity].x,position[entity].y,size[entity].width,size[entity].height
);
}
function drawAlly(entity){
ctx.drawImage(imageCanvas,
// source x,y,w,h
16,0,16,16
// x,y,w,h to be drawn onto the (visibile/game) canvas
,position[entity].x,position[entity].y,size[entity].width,size[entity].height
);
}
function drawPlayer(entity){
ctx.drawImage(imageCanvas,
// source x,y,w,h
32,0,16,16
// x,y,w,h to be drawn onto the (visibile/game) canvas
,position[entity].x,position[entity].y,size[entity].width,size[entity].height
);
}