Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A few javascript questions.... I cant find the causing errors

Status
Not open for further replies.

StacyFace

Programmer
Apr 29, 2014
1
0
0
US
I am currently trying to make a "frogger" like game using Sublime Text 2 and Perlenspiel. So far I have the board somewhat built. I am running into two problems at the moment.

First: When I move the function (DrawPlayer), the glyph trails, but not the color of the bead.... I cannot figure out how to get the glyph to disappear and change back to the original color of the bead, Violet....

Second: I've made functions and if/else if statements to make the "enemies" appear randomly that should technically begin by falling downwards on the grid from top to bottom. Yet I can't seem to get these "skulls" to show up at all. Can someone point out where I've made the mistake? Is it in the timer area or the if/else if statements?

I've copied and pasted all the coding I have for this game thus far. Please please help!!

Thank you in advance for your guidance!!!
________________________________________________________________________________________________

// Put your global variables after this line
var worldWidth = 16;
var worldHeight = 16;
var GAME_SPEED = 30
var playerX = (2, 2);
var playerY = (2, 2);
var ENEMY = "☠"
var enemyColor = PS.COLOR_GREEN
var bGroundColor = PS.COLOR_VIOLET


// Put your function definitions after this line
function DrawPlayer(x, y)
{
PS.glyph(playerX, playerY, "╬");
PS.glyphColor(playerX, playerY, PS.COLOR_BLUE);
PS.color(playerX, playerY, PS.COLOR_BLACK);
}

function PlaceWall(x, y)
{
PS.color(x, y, PS.COLOR_BLACK);
PS.data(x, y, "wall");
}

function EraseTrail(x, y)
{
PS.color(playerX, playerY, PS.COLOR_VIOLET);
PS.glyphColor(bGroundColor);
PS.data(x, y, 0);
}
function MakeEnemy(x, y)
{
playerX.push(x);
playerY.push(y);
DrawEnemy(x, y);
}
function DrawEnemy(x, y)
{
var randomIndex = PS.random(enemyColor.length) - 1
PS.glyphColor(x, y, enemyColor[randomIndex]);
PS.glyph(x, y, ENEMY);
}
function Update()
{
for (var i = 0; i < playerX.length; ++i)
{
var x = playerX;
var y = playerY;

EraseTrail(x, y);

// Skull moves downward
y++

// Random horizontal movement of skull
x+= PS.random(3) -2;

if (x < 0)
x = 0;

if (x >= worldWidth)
x = worldWidth - 1;
}
// Does the skull(s) stay on the grid?
if (y < worldHeight)
{
MakeEnemy(x, y);
playerX = x;
playerY = y;
}
else
{
// Delete the skull from the array
playerX.splice(i, 1);
playerY.splice(i, 1);
// Corrects the for-loop error
i --;
}

}
if(PS.random(3) == 1)
{
MakeEnemy(PS.random(worldWidth) - 1, 0)
}


// PS.init( system, options )


// Initializes the game
PS.init = function (system, options) {
"use strict";



PS.gridSize(worldWidth, worldHeight);
PS.statusText("Level: Lives Left: ");
PS.data(2, 2, "powerup1");
PS.color(2, 2, PS.COLOR_GREEN);
PS.timerStart(GAME_SPEED, Update);


PS.color(PS.ALL, PS.ALL, PS.COLOR_VIOLET);

DrawPlayer();

// Border of level 1

PlaceWall (0 , 0);
PlaceWall (1 , 0);
PlaceWall (2 , 0);
PlaceWall (3 , 0);
PlaceWall (4 , 0);
PlaceWall (5 , 0);
PlaceWall (6 , 0);
PlaceWall (7 , 0);
PlaceWall (8 , 0);
PlaceWall (9 , 0);
PlaceWall (10 , 0);
PlaceWall (11 , 0);
PlaceWall (12 , 0);
PlaceWall (13 , 0);
PlaceWall (14 , 0);
PlaceWall (15 , 0);
PlaceWall (15 , 1);
PlaceWall (15 , 2);
PlaceWall (15 , 3);
PlaceWall (15 , 4);
PlaceWall (15 , 5);
PlaceWall (15 , 6);
PlaceWall (15 , 7);
PlaceWall (15 , 8);
PlaceWall (15 , 9);
PlaceWall (15 , 10);
PlaceWall (15 , 11);
PlaceWall (15 , 12);
PlaceWall (15 , 13);
PlaceWall (15 , 14);
PlaceWall (15 , 15);
PlaceWall (14 , 15);
PlaceWall (13 , 15);
PlaceWall (12 , 15);
PlaceWall (11 , 15);
PlaceWall (10 , 15);
PlaceWall (9 , 15);
PlaceWall (8 , 15);
PlaceWall (7 , 15);
PlaceWall (6 , 15);
PlaceWall (5 , 15);
PlaceWall (4 , 15);
PlaceWall (3 , 15);
PlaceWall (2 , 15);
PlaceWall (1 , 15);
PlaceWall (0 , 15);
PlaceWall (0 , 14);
PlaceWall (0 , 13);
PlaceWall (0 , 12);
PlaceWall (0 , 11);
PlaceWall (0 , 10);
PlaceWall (0 , 9);
PlaceWall (0 , 8);
PlaceWall (0 , 7);
PlaceWall (0 , 6);
PlaceWall (0 , 5);
PlaceWall (0 , 4);
PlaceWall (0 , 3);
PlaceWall (0 , 2);
PlaceWall (0 , 1);
};

// PS.touch ( x, y, data, options )
PS.touch = function (x, y, data, options) {
"use strict";

// PlaceWall(x, y);
// PS.debug("PlaceWall (" + x + " , " + y + ");\n");

MakeEnemy();
};
 
Hi

could you provide some context on the 'why' of this task? I've seen similar tasks be set for as interview technical-tests and for academic homework/test purposes.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top