0% found this document useful (0 votes)
70 views6 pages

Create - Applications From Ideas Written Response Submission Template

The student created a maze game using Code Studio where the player moves a black square through a maze to collect all red dots to win. The student developed the game incrementally, first creating movement and collision detection functions, then adding win and loss conditions. The key functions developed were "detectCollision" to check for collisions, "win" to detect winning, and "movement" to handle key presses and square movement in a timed loop.

Uploaded by

Haidar Alhasnawi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views6 pages

Create - Applications From Ideas Written Response Submission Template

The student created a maze game using Code Studio where the player moves a black square through a maze to collect all red dots to win. The student developed the game incrementally, first creating movement and collision detection functions, then adding win and loss conditions. The key functions developed were "detectCollision" to check for collisions, "win" to detect winning, and "movement" to handle key presses and square movement in a timed loop.

Uploaded by

Haidar Alhasnawi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Create – Applications From Ideas

Written Response Submission Template


Please see Assessment Overview and Performance Task Directions for Student for the task
directions and recommended word counts.

Program Purpose and Development

2a)

The maze game was created using code studio. My game is a maze game and its
purpose is for the black square to collect all the red dots to win. The player will
use the arrow keys to move the black square throughout the game. If the black
square collides into a wall, the game is over. The video illustrates the black
square moving through the maze. It captures the red squares and it collides into
a wall, ending the game.

2b)

I created this program independently and in an incremental manner. I began by


writing the code for moving the black square after designing the maze. After that
part, I coded for a function that would detect collisions, called "detectCollision"
which was developed independently. I had difficulty with simplifying the function
that would detect collisions for all pieces of the maze. Eventually I resolved the
problem by creating a function for detecting collisions with parameters. Next, I
created a function with a timed loop that would constantly keep the pieces of
the maze, laced with collision detecting functions. The second hard task I faced
was getting the game to detect a win when the red squares were all collected. To
solve this issue, I added a bit of code into the loops that would stop the following
timed loop and detect the winning the of the game with the win screen after
collecting all the red dots. After resolving these issues, I decided to add obstacles
in the maze which would disappear after collecting every following red dot to
lead to the next red dot.

AP Computer Science Principles Effective Fall 2017 Page 1 of 6


2c)

function detectCollision(object, Enemy) {


var squareboiX = getXPosition("squareboi");
var squareboiY = getYPosition("squareboi");
var objectX = getXPosition(object);
var objectY = getYPosition(object);
var squareboiWidth = getProperty("squareboi", "width");
var squareboiHeight = getProperty("squareboi", "height");
var objectWidth = getProperty(object, "width");
var objectHeight = getProperty(object, "height");
if (((squareboiX + squareboiWidth >= objectX && squareboiX <= objectX +
objectWidth) && (squareboiY + squareboiHeight >= objectY && squareboiY <=
objectY + objectHeight)) && Enemy == true) {
setScreen("lose");
stopTimedLoop();
}
if (((squareboiX + squareboiWidth >= objectX && squareboiX <= objectX +
objectWidth) && (squareboiY + squareboiHeight >= objectY && squareboiY <=
objectY + objectHeight)) && Enemy == false) {
hideElement(object);
hideElement("button35");
setPosition("button35", 0, 0);
}
var button32X = getXPosition("button32");
var button32Y = getYPosition("button32");

AP Computer Science Principles Effective Fall 2017 Page 2 of 6


var button32Width = getProperty("button32", "width");
var button32Height = getProperty("button32", "height");
var button29X = getXPosition("button29");
var button29Y = getYPosition("button29");
var button29Width = getProperty("button29", "width");
var button29Height = getProperty("button29", "height");
if (((squareboiX + squareboiWidth >= button29X && squareboiX <= button29X +
button29Width) && (squareboiY + squareboiHeight >= button29Y && squareboiY
<= button29Y + button29Height))) {
hideElement("button38");
setPosition("button38", 0, 0);
}
if (((squareboiX + squareboiWidth >= button32X && squareboiX <= button32X +
button32Width) && (squareboiY + squareboiHeight >= button32Y && squareboiY
<= button32Y + button32Height))) {
hideElement("button36");
setPosition("button36", 0, 0);
}
}
function win() {
var squareboiX = getXPosition("squareboi");
var squareboiY = getYPosition("squareboi");
var squareboiWidth = getProperty("squareboi", "width");
var squareboiHeight = getProperty("squareboi", "height");
var button31X = getXPosition("button31");
var button31Y = getYPosition("button31");
var button31Width = getProperty("button31", "width");
var button31Height = getProperty("button31", "height");
if (((squareboiX + squareboiWidth >= button31X && squareboiX <= button31X +
button31Width) && (squareboiY + squareboiHeight >= button31Y && squareboiY
<= button31Y + button31Height))) {
setScreen("win");
WIN = true;
stopTimedLoop();
}
}
function checkWinorLoss() {
onEvent("start", "click", function( ) {
timedLoop(600, function() {
win();
if (WIN == true) {
stopTimedLoop();
}
detectCollision("button1", true);
detectCollision("button2", true);
detectCollision("button3", true);
detectCollision("button4", true);
detectCollision("button5", true);

AP Computer Science Principles Effective Fall 2017 Page 3 of 6


detectCollision("button6", true);
detectCollision("button7", true);
detectCollision("button8", true);
detectCollision("button9", true);
detectCollision("button10", true);
detectCollision("button11", true);
detectCollision("button12", true);
detectCollision("button13", true);
detectCollision("button14", true);
detectCollision("button15", true);
detectCollision("button16", true);
detectCollision("button17", true);
detectCollision("button18", true);
detectCollision("button19", true);
detectCollision("button20", true);
detectCollision("button21", true);
detectCollision("button22", true);
detectCollision("button23", true);
detectCollision("button24", true);
detectCollision("button25", true);
detectCollision("button26", true);
detectCollision("button35", true);
detectCollision("button36", true);
detectCollision("button37", true);
detectCollision("button38", true);
detectCollision("button29", false);
detectCollision("button32", false);
detectCollision("button33", false);
});
});
}

The parent function, "checkWinorLoss" includes an algorithm in the form of an If-


statement. The purpose of the function was to detect a win or loss based on
whether or not the black square collides with the maze or checks if all red
squares were collected to detect a win. "checkWinorLoss" includes the two sub-
functions called, "detectCollision" and "win". "detectCollision" includes "if
statements" that contain logical statements that work independently to select an
entire part of the maze to check if it's colliding with another object, presumable,
the black square using getXPosition and getYPosition. The "win" function
includes algorithms in the form of an if-statement that utlilizes logic to check if
all the red squares have been collected, and if they are, a win is detected, giving
the user a win screen.

AP Computer Science Principles Effective Fall 2017 Page 4 of 6


2d)

function movement() {
onEvent("start", "click", function() {
setScreen("screen1");
hideElement("start");
timedLoop(17, function() {
xVel = 0;
yVel = 0;
if (keys[0]) {
xVel += -2;
}
if (keys[1]) {
xVel += 2;
}
if (keys[2]) {
yVel += -2;
}
if (keys[3]) {
yVel += 2;
}
setPosition("squareboi", getXPosition("squareboi")+xVel,
getYPosition("squareboi")+yVel);
});
});
onEvent("screen1", "keydown", function(event) {

AP Computer Science Principles Effective Fall 2017 Page 5 of 6


if (event.key == "Up") {
keys[2] = true;
} else if ((event.key == "Down")) {
keys[3] = true;
} else if ((event.key == "Left")) {
keys[0] = true;
} else if ((event.key == "Right")) {
keys[1] = true;
}
});
onEvent("screen1", "keyup", function(event) {
if (event.key == "Up") {
keys[2] = false;
} else if ((event.key == "Down")) {
keys[3] = false;
} else if ((event.key == "Left")) {
keys[0] = false;
} else if ((event.key == "Right")) {
keys[1] = false;
}
});
}

The abstraction "movement" was developed independently with logical if-else-if


statements that would determine the movement of the black square. In doing
so, the function "movement" manages the complexity of the program by
abstracting the amount of times that I would have needed to rewrite the same
code over and over again. The logical statements allow the black square to move
up, down, left, and right using simplified code that applies to the whole program.
Because of that, the program is able to function efficiently with the simplified
code.

AP Computer Science Principles Effective Fall 2017 Page 6 of 6

You might also like