moving out outdated js docs

This commit is contained in:
Peli de Halleux
2016-04-15 14:37:25 -07:00
parent 6515cc0360
commit bb6ae00a49
153 changed files with 0 additions and 81 deletions

View File

@ -0,0 +1,65 @@
# pong activity
Building a game of pong with sprites.
### ~avatar avatar
### @video td/videos/pong-0
Welcome! This tutorial will teach you how to build a simple pong game using sprites.
### ~
The game works as follow: the user moves a paddle on the left of the screen and a ball bounces on the other side. Let's start by creating the 2 sprites.
```
let paddle = game.createSprite(0, 2)
let ball = game.createSprite(4, 2)
```
Let's make the ball start with an angle.
```
ball.setDirection(-45)
```
The user will control the paddle by pressing ``A`` to go up and ``B`` to go down. Let's add ``on button pressed`` event handlers to do that.
```
input.onButtonPressed(Button.A, () => {
paddle.changeYBy(-1)
})
input.onButtonPressed(Button.B, () => {
paddle.changeYBy(1)
})
```
Let's add a ``forever`` loop to start the main game logic.
```
basic.forever(() => {
// Leave the sprite on screen for a little while.
basic.pause(400)
// Let's move the ball in whatever direction it is currently going.
ball.move(1)
// The ball might be on the left side of the screen (``x = 0``), let's test for that.
if (ball.x() == 0) {
// Let's add a little pause to let the user know that the ball is on the side.
basic.pause(400)
// If the paddle is not at the same ``y`` coordinate, it missed the ball and we can trigger a game over. If not, we add a point to the score.
if (paddle.y() != ball.y()) {
game.gameOver()
} else {
game.addScore(1)
basic.pause(500)
}
}
// The ball moved and might be on a side, let's make sure it bounces.
ball.ifOnEdge_Bounce()
// If the ball is on the left side, slide it forward to change slightly the bouncing mechanics.
if (ball.x() == 0) {
ball.changeXBy(1)
}
})
```

View File

@ -0,0 +1,87 @@
# pong quiz answers
create the game Pong.
## Name
## Directions
Use this activity document to guide your work in the [pong tutorial](/lessons/pong/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values.
<br/>
```
ballX = 2
ballY = 1
```
## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values.
<br/>
```
ballXVelocity = 1
ballYVelocity = 1
```
## 3. Write the code that plots the initial position of the paddle and the ball.
<br/>
```
led.plot(0, paddleY)
led.plot(ballX, ballY)
```
## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.)
<br/>
```
input.onButtonPressed(Button.A, () => {
if (paddleNotUp()) {
led.unplot(0, paddleY)
paddleY = paddleY - 1
led.plot(0, paddleY)
}
})
```
## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.)
<br/>
```
input.onButtonPressed(Button.A, () => {
if (paddleNotDown()) {
led.unplot(0, paddleY)
paddleY = paddleY + 1
led.plot(0, paddleY)
}
})
```
## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".)
<br/>
```
if (ballY == 4 || ballY == 0) {
ballYVelocity = (-1) * ballYVelocity
}
```
## 7. Write the code to move the ball. (Hint: look at the function "move ball".)
<br/>
```
led.unplot(ballX, ballY)
ballX = ballX + ballXVelocity
ballY = ballY + ballYVelocity
```

View File

@ -0,0 +1,40 @@
# pong quiz
create the game Pong.
## Name
## Directions
Use this activity document to guide your work in the [pong tutorial](/lessons/pong/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values.
<br/>
## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values.
<br/>
## 3. Write the code that plots the initial position of the paddle and the ball.
<br/>
## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.)
<br/>
## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.)
<br/>
## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".)
<br/>
## 7. Write the code to move the ball. (Hint: look at the function "move ball".)
<br/>