xxxxxxxxxx
var img, wallsandpills;
var frame = 0;
var numframes = 8;
var layer = 0;
var numlayers = 2;
var mazefile;
var maze;
var pacx = 10;
var pacy = 5;
var yincr = 0;
var xincr = 0;
var isize = 40; // pixel width and height of one square
var moveSpeed = 5; // how often do we move
function preload() {
img = loadImage('face40x8x2.png');
wallsandpills = loadImage('objects40x4.png');
mazefile = loadStrings('maze1.txt');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
maze = [];
for(let i = 0;i<mazefile.length;i++)
{
let m = mazefile[i].split('');
maze.push(m);
}
//console.log(maze);
}
function draw() {
background(255);
var otype = 3;
for(let i = 0;i<maze.length;i++)
{
for(let j = 0;j<maze[i].length;j++)
{
x = j*isize;
y = i*isize;
if(maze[i][j]=='*') otype = 0; // brick
if(maze[i][j]=='-') otype = 1; // space
blend(wallsandpills, otype*40, 0, isize, isize, x, y, isize, isize, BLEND);
}
}
blend(img, frame*isize, layer*isize, isize, isize, pacx*isize, pacy*isize, isize, isize, BLEND);
if(frameCount%3==0) {
frame = (frame+1)%numframes;
}
if(frameCount%moveSpeed==0) {
// teleport:
if(pacx+xincr>maze[0].length-1) pacx=0;
if(pacx+xincr<0) pacx=maze[0].length-1;
if(pacy+yincr>maze.length-1) pacy=0;
if(pacy+yincr<0) pacy=maze.length-1;
if(maze[pacy+yincr][pacx+xincr]=='-')
{
pacx+=xincr;
pacy+=yincr;
}
}
}
function keyPressed() {
if(keyCode==UP_ARROW) {
xincr = 0;
yincr = -1;
}
if(keyCode==DOWN_ARROW) {
xincr = 0;
yincr = 1;
}
if(keyCode==LEFT_ARROW) {
xincr = -1;
yincr = 0;
}
if(keyCode==RIGHT_ARROW) {
xincr = 1;
yincr = 0;
}
}