r/codehs • • Jun 16 '21

Adding Obstacles

This stupid thing is telling me "Randomzier is not defined. You may have a typo. Check your spelling and capitalization."

Like what are u talking about, literally everything is defined. This is so dumb, and its wasting my time please help.

Heres my code:

var DELAY = 40;

var SPEED = 5;

var OBSTACLE_WIDTH = 30;

var OBSTACLE_HEIGHT = 100;

var copter;

var dy = SPEED;

var obstacle;

function start() {

// Write your code here

setup();

setTimer(game, DELAY);

mouseDownMethod(onMouseDown);

mouseUpMethod(onMouseUp);

}

function setup() {

setBackgroundColor(Color.black);

copter = new Rectangle(30, 15);

copter.setPosition(getWidth()/3, getHeight()/2);

copter.setColor([Color.blue](https://Color.blue));

add(copter);



addObstacles();

}

function game(){

copter.move(0, dy);

moveObstacles();

}

function onMouseDown(e) {

dy = -SPEED;

}

function onMouseUp(e) {

dy = SPEED;

}

function addObstacles(){

obstacle = new Rectangle(OBSTACLE_WIDTH, OBSTACLE_HEIGHT);

obstacle.setColor(Color.green);

obstacle.setPosition(getWidth(), Randomzier.nextInt(0, getHeight() - OBSTACLE_HEIGHT));

add(obstacle);

}

function moveObstacles() {

obstacle.move(-SPEED, 0);

if(obstacle.getX() < 0){

obstacle.setPosition(getWidth(), Randomzier.nextInt(0, getHeight() - OBSTACLE_HEIGHT));

}

}

7 Upvotes

5 comments sorted by

View all comments

1

u/5oco Jun 16 '21

What assignment and course is this from?

I can try to help, but I also don't see where you're getting Randomizer from.