INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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[i];
var y = playerY[i];

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[i] = x;
playerY[i] = 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();
};

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close