Codes:
// Creating Boundries
var Boundry1 = createSprite(200,5,400,10);
Boundry1.shapeColor = 'red';
var Boundry2 = createSprite(395,200,10,400);
Boundry2.shapeColor = 'red';
var Boundry3 = createSprite(200,395,400,10);
Boundry3.shapeColor = 'red';
var Boundry4 = createSprite(5,200,10,400);
Boundry4.shapeColor = 'red';
// Creating Walls
var wall = createSprite(50,50,5,100);
wall.shapeColor = ("red");
var wall2 = createSprite(75,50,50,5);
wall2.shapeColor = ("red");
var wall3 = createSprite(100,125,5,155);
wall3.shapeColor = ("red");
var wall4 = createSprite(75,150,50,5);
wall4.shapeColor = ("red");
var wall5 = createSprite(100,200,100,5);
wall5.shapeColor = ("red");
var wall6 = createSprite(50,225,5,55);
wall6.shapeColor = ("red");
var wall7 = createSprite(25,300,50,5);
wall7.shapeColor = ("red");
var wall8 = createSprite(50,375,5,50);
wall8.shapeColor = ("red");
var wall9 = createSprite(150,225,5,55);
wall9.shapeColor = ("red");
var wall10 = createSprite(100,275,5,55);
wall10.shapeColor = ("red");
var wall11 = createSprite(125,300,55,5);
wall11.shapeColor = ("red");
var wall12 = createSprite(150,325,5,50);
wall12.shapeColor = ("red");
var wall13 = createSprite(125,350,55,5);
wall13.shapeColor = ("red");
var wall14 = createSprite(100,375,5,50);
wall14.shapeColor = ("red");
var wall15 = createSprite(200,350,5,100);
wall15.shapeColor = ("red");
var wall16 = createSprite(225,350,50,5);
wall16.shapeColor = ("red");
var wall17 = createSprite(200,250,100,5);
wall17.shapeColor = ("red");
var wall18 = createSprite(250,275,5,55);
wall18.shapeColor = ("red");
var wall19 = createSprite(275,300,50,5);
wall19.shapeColor = ("red");
var wall20 = createSprite(300,275,5,55);
wall20.shapeColor = ("red");
var wall21 = createSprite(300,375,5,50);
wall21.shapeColor = ("red");
var wall22 = createSprite(350,300,5,200);
wall22.shapeColor = ("red");
var wall23 = createSprite(275,200,155,5);
wall23.shapeColor = ("red");
var wall24 = createSprite(200,125,5,155);
wall24.shapeColor = ("red");
var wall25 = createSprite(125,100,50,5);
wall25.shapeColor = ("red");
var wall26 = createSprite(225,50,50,5);
wall26.shapeColor = ("red");
var wall27 = createSprite(250,75,5,55);
wall27.shapeColor = ("red");
var wall28 = createSprite(300,100,100,5);
wall28.shapeColor = ("red");
var wall29 = createSprite(300,25,5,50);
wall29.shapeColor = ("red");
var wall30 = createSprite(325,50,55,5);
wall30.shapeColor = ("red");
var wall31 = createSprite(325,150,150,5);
wall31.shapeColor = ("red");
// Creating Player
var player = createSprite(75,75,15,15);
player.shapeColor = 'cyan'
// Creating Groups
var BoundryGroup = createGroup();
var WallGroup = createGroup();
// Adding Boundries in Boundry Group
BoundryGroup.add(Boundry1);
BoundryGroup.add(Boundry2);
BoundryGroup.add(Boundry3);
BoundryGroup.add(Boundry4);
// Adding Walls in Wall Group
WallGroup.add(wall)
WallGroup.add(wall2)
WallGroup.add(wall3)
WallGroup.add(wall4)
WallGroup.add(wall5)
WallGroup.add(wall6)
WallGroup.add(wall7)
WallGroup.add(wall8)
WallGroup.add(wall9)
WallGroup.add(wall10)
WallGroup.add(wall11)
WallGroup.add(wall12)
WallGroup.add(wall13)
WallGroup.add(wall14)
WallGroup.add(wall15)
WallGroup.add(wall16)
WallGroup.add(wall17)
WallGroup.add(wall18)
WallGroup.add(wall19)
WallGroup.add(wall20)
WallGroup.add(wall21)
WallGroup.add(wall22)
WallGroup.add(wall23)
WallGroup.add(wall24)
WallGroup.add(wall25)
WallGroup.add(wall26)
WallGroup.add(wall27)
WallGroup.add(wall28)
WallGroup.add(wall29)
WallGroup.add(wall30)
WallGroup.add(wall31)
function draw() {
//Assigning player's velocity
player.velocityX = 0;
player.velocityY = 0;
// Player's movement
if(keyDown('UP_ARROW')){
player.velocityY = -7;
}
if(keyDown('DOWN_ARROW')){
player.velocityY = 7;
}
if(keyDown('LEFT_ARROW')){
player.velocityX = -7;
}
if(keyDown('RIGHT_ARROW')){
player.velocityX = 7;
}
// Reset the player
if(player.isTouching(BoundryGroup)){
player.x = 75;
player.y = 75;
}
if(player.isTouching(WallGroup)){
player.x = 75;
player.y = 75;
}
background("black")
drawSprites();
}
0 Comments: