Skip to content

Commit

Permalink
Readd 0301 explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Venzlaff committed Jul 12, 2024
1 parent 7cab381 commit 846be52
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 40 deletions.
26 changes: 13 additions & 13 deletions src/InteractivePongTutorial-Game/IPTBall.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Class {

{
#category : #collision,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> checkCollisionWithPlayer [
"Check collision with Players using 'intersects:' message."
]

{
#category : #collision,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> checkCollisionWithWalls [
(self position x between: self game left and: self game right - self width)
Expand Down Expand Up @@ -50,31 +50,31 @@ IPTBall >> defaultExtent [

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> defaultSpeed [
^ 10.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> game [
^ game.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> game: aGame [
game := aGame.
]

{
#category : #initialization,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> initialize [
super initialize.
Expand All @@ -86,23 +86,23 @@ IPTBall >> initialize [

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> speed [
^ speed.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> speed: aNumber [
speed := aNumber.
]

{
#category : #initialization,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> startOver [
self
Expand All @@ -112,7 +112,7 @@ IPTBall >> startOver [

{
#category : #stepping,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> step [
"Check for collision with a Player."
Expand All @@ -123,23 +123,23 @@ IPTBall >> step [

{
#category : #stepping,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> stepTime [
^ 10.
]

{
#category : #movement,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> turnHorizontal [
self speed: self speed x negated @ self speed y.
]

{
#category : #movement,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTBall >> turnVertical [
self speed: self speed x @ self speed y negated.
Expand Down
26 changes: 13 additions & 13 deletions src/InteractivePongTutorial-Game/IPTGame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ IPTGame class >> open [

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> ball [
^ ball.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> ball: aBall [
ball := aBall.
]

{
#category : #'event handling',
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> handlesKeyboard: anEvent [
^ true.
]

{
#category : #initialization,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> initialize [
super initialize.
Expand All @@ -58,7 +58,7 @@ IPTGame >> initialize [

{
#category : #initialization,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> initializeBall [
self
Expand All @@ -70,7 +70,7 @@ IPTGame >> initializeBall [

{
#category : #initialization,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> initializePlayers [
| offset |
Expand All @@ -88,7 +88,7 @@ IPTGame >> initializePlayers [

{
#category : #'event handling',
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> keyDown: anEvent [
(anEvent keyCharacter asUppercase = $W ) ifTrue: [self playerLeft up].
Expand All @@ -99,7 +99,7 @@ IPTGame >> keyDown: anEvent [

{
#category : #'event handling',
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> keyUp: anEvent [
({$W.$S} anySatisfy: [ :key |
Expand Down Expand Up @@ -129,39 +129,39 @@ IPTGame >> mouseLeave: anEvent [

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> playerBounds [
"Return a colletion of the bounds of all Players. Use 'bounds' message of Morphs."
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> playerLeft [
^ playerLeft.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> playerLeft: aPlayer [
playerLeft := aPlayer.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> playerRight [
^ playerRight.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTGame >> playerRight: aPlayer [
playerRight := aPlayer.
Expand Down
24 changes: 12 additions & 12 deletions src/InteractivePongTutorial-Game/IPTPlayer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,47 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> defaultExtent [
^ (15@100).
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> defaultSpeed [
^ 10.
]

{
#category : #movement,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> down [
self speed: self defaultSpeed.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> game [
^ game.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> game: aGame [
game := aGame.
]

{
#category : #initialization,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> initialize [
super initialize.
Expand All @@ -66,7 +66,7 @@ IPTPlayer >> initialize [

{
#category : #movement,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> move: aNumber [
| dist |
Expand All @@ -77,23 +77,23 @@ IPTPlayer >> move: aNumber [

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> speed [
^ speed.
]

{
#category : #accessing,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> speed: aNumber [
speed := aNumber.
]

{
#category : #stepping,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> step [
self move: self speed.
Expand All @@ -109,15 +109,15 @@ IPTPlayer >> stepTime [

{
#category : #movement,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> stop [
self speed: 0.
]

{
#category : #movement,
#'squeak_changestamp' : 'sv 7/12/2024 19:11'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTPlayer >> up [
self speed: self defaultSpeed negated.
Expand Down
9 changes: 7 additions & 2 deletions src/InteractivePongTutorial-Levels/IPTLevel0301.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ IPTLevel0301 class >> description [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'FH 7/10/2024 19:01'
#'squeak_changestamp' : 'sv 7/12/2024 19:17'
}
IPTLevel0301 class >> explanations [

^ {''.}.
^ {'We want the ball to check if it collides with one of players. For that, the ball needs to know where the players are and how big they are. This information is held by playerBounds.'.
'Then, actually check for a collision in checkCollisionWithPlayer. Luckily, you do not need to implement all the details yourself since Squeak already provides a function that does what we want.'.
'Now, since the ball could start colliding with a player on every new step it takes, we therefore want to check on every step of the ball if there is a collision happening. We do this by calling the function we just wrote.'.
'Hint: playerBounds is a collection, where every entry are the bounds of one player'.
'Hint: checkCollisionWithPlayer checks for collision between ball and every player. So we need to look at every entry of our playerBounds collection.'.
'Hint: To recall: step is called every time we want to move the ball. So we will then need to check for collisions, too.'}.
]

{
Expand Down

0 comments on commit 846be52

Please sign in to comment.