Skip to content

Commit

Permalink
IPTTests now use the MockChapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Bigly4 committed Jul 11, 2024
1 parent e69666e commit cbaeff0
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 143 deletions.
58 changes: 23 additions & 35 deletions src/InteractivePongTutorial-Game/IPTBall.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ Class {

{
#category : #collision,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> checkCollisionWithPlayer [
(self game playerBounds anySatisfy: [:bounds | bounds intersects: self bounds])
ifTrue: [self turnHorizontal].

]

{
#category : #collision,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> checkCollisionWithWalls [
(self position x between: self game left and: self game right - self width)
ifFalse: [self startOver].
(self position y between: self game top and: self game bottom - self height)
ifFalse: [self turnVertical].

]

{
Expand Down Expand Up @@ -56,88 +52,80 @@ IPTBall >> defaultSpeed [

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> game [
^ game.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> game: aGame [
game := aGame.

]

{
#category : #initialization,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> initialize [
super initialize.
self
color: Color white;
extent: self defaultExtent;
speed: self defaultSpeed @ self defaultSpeed.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> speed [
^ speed.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> speed: aNumber [
speed := aNumber.

]

{
#category : #initialization,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> startOver [
self
center: self game center;
speed: (self defaultSpeed * {1 .-1} atRandom) @ (self defaultSpeed * {1 .-1} atRandom).

]

{
#category : #stepping,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> step [
self position: self position + self speed.
self checkCollisionWithWalls;
checkCollisionWithPlayer.

]

{
#category : #stepping,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> stepTime [
^ 10.
]

{
#category : #movement,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> turnHorizontal [
self speed: self speed x negated @ self speed y.

]

{
#category : #movement,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTBall >> turnVertical [
self speed: self speed x @ self speed y negated.

]
73 changes: 27 additions & 46 deletions src/InteractivePongTutorial-Game/IPTGame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,89 +19,70 @@ IPTGame class >> open [

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> ball [
^ ball.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> ball: aBall [
ball := aBall.

]

{
#category : #'event handling',
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> handlesKeyboard: anEvent [
^ true.

]

{
#category : #initialization,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> initialize [
"Please change the color to black."
super initialize.
self
color: Color black;
color: Color blue;
beSticky.
]

{
#category : #initialization,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> initializeBall [
self
ball: (IPTBall new game: self);
addMorph: self ball.
self ball startOver.

]

{
#category : #initialization,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> initializePlayers [
| offset |
offset := (self extent x / 2 - 30 @ 0).
self
playerLeft: (IPTPlayer new
center: self center - offset;
game: self);
playerRight: (IPTPlayer new
center: self center + offset;
game: self);
addMorph: self playerLeft;
addMorph: self playerRight.

]

{
#category : #'event handling',
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> keyDown: anEvent [
(anEvent keyCharacter asUppercase = $W ) ifTrue: [self playerLeft up].
(anEvent keyCharacter asUppercase = $S ) ifTrue: [self playerLeft down].
(anEvent keyCharacter = Character arrowUp) ifTrue: [self playerRight up].
(anEvent keyCharacter = Character arrowDown) ifTrue: [self playerRight down].

]

{
#category : #'event handling',
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> keyUp: anEvent [
({$W.$S} anySatisfy: [ :key |
anEvent keyCharacter asUppercase = key])
ifTrue: [self playerLeft stop].
((anEvent keyCharacter = Character arrowUp)
or: (anEvent keyCharacter = Character arrowDown)) ifTrue: [self playerRight stop].

]

{
Expand All @@ -124,42 +105,42 @@ IPTGame >> mouseLeave: anEvent [

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:41'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> playerBounds [
^ {self playerLeft bounds . self playerRight bounds}.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> playerLeft [
^ playerLeft.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> playerLeft: aPlayer [
playerLeft := aPlayer.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> playerRight [
^ playerRight.

]

{
#category : #accessing,
#'squeak_changestamp' : 'FH 7/10/2024 19:40'
#'squeak_changestamp' : 'Josua Zehner 7/11/2024 09:14'
}
IPTGame >> playerRight: aPlayer [
playerRight := aPlayer.

]

{
Expand Down
Loading

0 comments on commit cbaeff0

Please sign in to comment.