"Aurora / Relay. Original LearnSqueak endless runner; native Squeak 6.1. File in, then Do It: ARApp open." Object subclass: #ARVector instanceVariableNames: 'x y z' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! Object subclass: #ARRun instanceVariableNames: 'player objects generator state distance coins ticks seed' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! Morph subclass: #ARView instanceVariableNames: 'app camera' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! Morph subclass: #ARApp instanceVariableNames: 'game view window info status controller' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! SystemWindow subclass: #ARWindow instanceVariableNames: 'fixedExtent' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! Object subclass: #ARCamera instanceVariableNames: 'position focal center near far' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! Object subclass: #ARObstacle instanceVariableNames: 'position spent' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! ARObstacle subclass: #ARWall instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! ARObstacle subclass: #ARHurdle instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! ARObstacle subclass: #ARArch instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! ARObstacle subclass: #ARSpark instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! !ARVector class methodsFor: 'tutorial'! x: a y: b z: c ^ self new setX: a y: b z: c ! ! !ARVector methodsFor: 'tutorial'! setX: a y: b z: c x := a. y := b. z := c. ^ self ! ! !ARVector methodsFor: 'tutorial'! x ^ x ! ! !ARVector methodsFor: 'tutorial'! y ^ y ! ! !ARVector methodsFor: 'tutorial'! z ^ z ! ! !ARVector methodsFor: 'tutorial'! + other ^ self class x: x + other x y: y + other y z: z + other z ! ! !ARVector methodsFor: 'tutorial'! - other ^ self class x: x - other x y: y - other y z: z - other z ! ! !ARVector methodsFor: 'tutorial'! * number ^ self class x: x * number y: y * number z: z * number ! ! !ARVector methodsFor: 'tutorial'! asArray ^ {x. y. z} ! ! !ARRun methodsFor: 'tutorial'! initialize super initialize. seed := 314159. self restart ! ! !ARRun methodsFor: 'tutorial'! restart state := #ready. distance := 0.0. coins := 0. ticks := 0. player := ARVector x: 0 y: 0 z: 0. objects := {ARWall lane: -1 z: 16. ARHurdle lane: 0 z: 10. ARArch lane: 1 z: 20. ARSpark lane: 1 z: 9} asOrderedCollection ! ! !ARRun methodsFor: 'tutorial'! player ^ player ! ! !ARRun methodsFor: 'tutorial'! objects ^ objects ! ! !ARRun methodsFor: 'tutorial'! generator ^ generator ! ! !ARRun methodsFor: 'tutorial'! state ^ state ! ! !ARRun methodsFor: 'tutorial'! distance ^ distance ! ! !ARRun methodsFor: 'tutorial'! coins ^ coins ! ! !ARRun methodsFor: 'tutorial'! ticks ^ ticks ! ! !ARRun methodsFor: 'tutorial'! seed ^ seed ! ! !ARRun methodsFor: 'tutorial'! seed: number seed := number. self restart ! ! !ARRun methodsFor: 'tutorial'! score ^ distance floor + (coins * self coinValue) ! ! !ARRun methodsFor: 'tutorial'! coinValue ^ 25 ! ! !ARRun methodsFor: 'tutorial'! isRunning ^ state = #running ! ! !ARRun methodsFor: 'tutorial'! tick ^ self ! ! !ARRun methodsFor: 'tutorial'! stepOnce self tick ! ! !ARRun methodsFor: 'tutorial'! statusText ^ 'Wall, Hurdle, Arch and Spark answer their own dimensions and appearance.' ! ! !ARApp class methodsFor: 'tutorial'! open ^ self new open ! ! !ARApp methodsFor: 'tutorial'! initialize super initialize. self extent: 968@678; color: (Color fromString: '#111B2B'). game := ARRun new. view := ARView new app: self; position: self position + (20@103). self addMorph: view. self label: 'AURORA / RELAY' at: 22@12 size: 27 color: '#F2F5FF'. self label: 'Run the skyway. Read the objects. Build the whole game.' at: 23@50 size: 14 color: '#B8C5DA'. self label: ('CHECKPOINT ', self stage printString, ' / 10') at: 740@20 size: 14 color: '#73E5D2'. self label: self stageTitle at: 23@78 size: 14 color: '#F8C976'. info := self label: '' at: 22@624 size: 15 color: '#EFF6FE'. status := self label: '' at: 22@655 size: 12 color: '#ACBDD5'. self buildSidebar. self refresh ! ! !ARApp methodsFor: 'tutorial'! label: string at: point size: size color: hex | label | label := StringMorph contents: string font: (TextStyle default fontOfSize: size). label position: self position + point; color: (Color fromString: hex). self addMorph: label. ^ label ! ! !ARApp methodsFor: 'tutorial'! button: string at: point action: selector | button | button := SimpleButtonMorph new label: string; target: self; actionSelector: selector; color: (Color fromString: '#D4E6ED'); yourself. button position: self position + point. self addMorph: button ! ! !ARApp methodsFor: 'tutorial'! buildSidebar self label: 'THREE LANES' at: 747@111 size: 16 color: '#73E5D2'. self label: 'A / D or Left / Right' at: 747@145 size: 12 color: '#DCE6F5'. self label: 'Tap to change lanes' at: 747@167 size: 12 color: '#9DB1CF'. self label: 'W / Up / Space: jump' at: 747@199 size: 12 color: '#DCE6F5'. self label: 'S / Down: slide' at: 747@227 size: 12 color: '#DCE6F5'. self label: 'READ THE ROAD' at: 747@278 size: 16 color: '#F8C976'. self label: 'Coral wall: change lane' at: 747@312 size: 12 color: '#EAA4AB'. self label: 'Orange hurdle: jump' at: 747@340 size: 12 color: '#F4C18A'. self label: 'Violet arch: slide' at: 747@368 size: 12 color: '#C6ADF8'. self label: 'Gold sparks: +25 points' at: 747@396 size: 12 color: '#F8D789'. self stage >= 4 ifTrue: [self button: 'Tick once' at: 747@446 action: #tickOnce]. self stage >= 8 ifTrue: [self button: 'Start / Pause' at: 747@483 action: #togglePause. self button: 'Restart' at: 855@483 action: #restart]. self label: 'Enter: start / pause' at: 747@539 size: 12 color: '#9DB1CF'. self label: 'Esc: pause R: restart' at: 747@565 size: 12 color: '#9DB1CF'. self label: 'Click scene for focus' at: 747@591 size: 11 color: '#73E5D2' ! ! !ARApp methodsFor: 'tutorial'! game ^ game ! ! !ARApp methodsFor: 'tutorial'! view ^ view ! ! !ARApp methodsFor: 'tutorial'! window ^ window ! ! !ARApp methodsFor: 'tutorial'! refresh info contents: ('SCORE ', game score printString, ' SPARKS ', game coins printString, ' METERS ', game distance floor printString, ' ', game state asString asUppercase). status contents: game statusText. view changed ! ! !ARApp methodsFor: 'tutorial'! open window ifNotNil: [window comeToFront. ^ self]. window := ARWindow new model: self; setLabel: 'Aurora / Relay - native Squeak endless runner'. window addMorph: self fullFrame: (LayoutFrame fractions: (0@0 corner: 1@1)). window fixedExtent: 978@711. window openInWorld. window position: World position + (10@10). ^ self ! ! !ARApp methodsFor: 'tutorial'! okToClose ^ true ! ! !ARApp methodsFor: 'tutorial'! release ^ self ! ! !ARApp methodsFor: 'tutorial'! windowIsClosing self stopStepping. window := nil ! ! !ARApp methodsFor: 'tutorial'! wantsStepsIn: aWindow ^ false ! ! !ARApp methodsFor: 'tutorial'! synchronizeStepping self stopStepping ! ! !ARWindow methodsFor: 'tutorial'! fixedExtent: point fixedExtent := point. super extent: point ! ! !ARWindow methodsFor: 'tutorial'! extent: point super extent: (fixedExtent ifNil: [point]) ! ! !ARWindow methodsFor: 'tutorial'! lookFocused super lookFocused. label ifNotNil: [label color: Color white] ! ! !ARWindow methodsFor: 'tutorial'! lookUnfocused super lookUnfocused. label ifNotNil: [label color: (Color gray: 0.8)] ! ! !ARView methodsFor: 'tutorial'! app: anApp app := anApp. self extent: 706@500. camera := ARCamera new ! ! !ARView methodsFor: 'tutorial'! text: string at: point size: size on: canvas color: hex canvas drawString: string at: self position + point font: (TextStyle default fontOfSize: size) color: (Color fromString: hex) ! ! !ARView methodsFor: 'tutorial'! drawOn: canvas canvas clipBy: self bounds during: [:clipped | self drawSkyOn: clipped. self drawRoadOn: clipped. self drawSceneOn: clipped]. canvas frameRectangle: self bounds width: 1 color: (Color fromString: '#415470') ! ! !ARCamera methodsFor: 'tutorial'! initialize super initialize. position := ARVector x: 0 y: 4 z: -7. focal := self defaultFocal. center := 353@154. near := 0.5. far := 175 ! ! !ARCamera methodsFor: 'tutorial'! defaultFocal ^ 410 ! ! !ARCamera methodsFor: 'tutorial'! position ^ position ! ! !ARCamera methodsFor: 'tutorial'! focal ^ focal ! ! !ARCamera methodsFor: 'tutorial'! center ^ center ! ! !ARCamera methodsFor: 'tutorial'! near ^ near ! ! !ARCamera methodsFor: 'tutorial'! far ^ far ! ! !ARCamera methodsFor: 'tutorial'! depthOf: point ^ point z - position z ! ! !ARCamera methodsFor: 'tutorial'! project: point | relative | relative := point - position. (relative z < near or: [relative z > far]) ifTrue: [^ nil]. ^ center + (((relative x * focal / relative z) rounded) @ ((relative y negated * focal / relative z) rounded)) ! ! !ARView methodsFor: 'tutorial'! camera ^ camera ! ! !ARView methodsFor: 'tutorial'! drawSkyOn: canvas | p h | canvas fillRectangle: self bounds color: (Color fromString: '#171D39'). canvas fillRectangle: (self position + (0@100) extent: 706@92) color: (Color fromString: '#353054'). canvas fillOval: (self position + (470@32) extent: 79@79) color: (Color fromString: '#C68882'). 0 to: 18 do: [:i | h := 24 + (i*37 \\ 73). p := self position + ((i*40)@(190-h)). canvas fillRectangle: (p extent: 29@h) color: (Color fromString: '#202D46'). canvas line: p + (6@8) to: p + (6@(h-8)) width: 2 color: (Color fromString: '#486D7E')]. canvas fillRectangle: (self position + (0@190) extent: 706@310) color: (Color fromString: '#10182D') ! ! !ARView methodsFor: 'tutorial'! polygon: vertices on: canvas color: hex border: border | points | points := vertices collect: [:point | camera project: point]. (points anySatisfy: [:point | point isNil]) ifTrue: [^ self]. canvas drawPolygon: (points collect: [:point | self position + point]) color: (Color fromString: hex) borderWidth: 1 borderColor: (Color fromString: border) ! ! !ARView methodsFor: 'tutorial'! lineFrom: a to: b on: canvas color: hex width: width | p q | p := camera project: a. q := camera project: b. (p notNil and: [q notNil]) ifTrue: [canvas line: self position + p to: self position + q width: width color: (Color fromString: hex)] ! ! !ARView methodsFor: 'tutorial'! drawRoadOn: canvas | z offset | self polygon: {ARVector x: -4.3 y: 0 z: -3. ARVector x: 4.3 y: 0 z: -3. ARVector x: 4.3 y: 0 z: 160. ARVector x: -4.3 y: 0 z: 160} on: canvas color: '#243551' border: '#548191'. #(-4.1 -1.25 1.25 4.1) do: [:x | self lineFrom: (ARVector x: x y: 0.015 z: -3) to: (ARVector x: x y: 0.015 z: 150) on: canvas color: (x abs > 4 ifTrue: ['#73E5D2'] ifFalse: ['#52617E']) width: 2]. offset := app game distance \\ 6. 0 to: 26 do: [:i | z := i*6 - offset. z > -3 ifTrue: [self lineFrom: (ARVector x: -4.1 y: 0.02 z: z) to: (ARVector x: 4.1 y: 0.02 z: z) on: canvas color: '#3B4C69' width: 1]]. self text: 'THE SKYWAY / software-projected XYZ' at: 18@17 size: 12 on: canvas color: '#C1F4E8' ! ! !ARView methodsFor: 'tutorial'! drawSceneOn: canvas self visibleObjects do: [:body | self drawObject: body on: canvas] ! ! !ARObstacle class methodsFor: 'tutorial'! lane: lane z: depth ^ self new position: (ARVector x: lane * 2.5 y: 0 z: depth); yourself ! ! !ARObstacle methodsFor: 'tutorial'! initialize super initialize. spent := false ! ! !ARObstacle methodsFor: 'tutorial'! position ^ position ! ! !ARObstacle methodsFor: 'tutorial'! spent ^ spent ! ! !ARObstacle methodsFor: 'tutorial'! position: point position := point ! ! !ARObstacle methodsFor: 'tutorial'! kind ^ #wall ! ! !ARObstacle methodsFor: 'tutorial'! bottom ^ 0 ! ! !ARObstacle methodsFor: 'tutorial'! top ^ 2.6 ! ! !ARObstacle methodsFor: 'tutorial'! halfWidth ^ 0.84 ! ! !ARObstacle methodsFor: 'tutorial'! halfDepth ^ 0.5 ! ! !ARObstacle methodsFor: 'tutorial'! colorHex ^ '#D76C83' ! ! !ARObstacle methodsFor: 'tutorial'! sideHex ^ '#814861' ! ! !ARHurdle methodsFor: 'tutorial'! kind ^ #hurdle ! ! !ARHurdle methodsFor: 'tutorial'! top ^ 0.72 ! ! !ARHurdle methodsFor: 'tutorial'! colorHex ^ '#EEAA62' ! ! !ARHurdle methodsFor: 'tutorial'! sideHex ^ '#9A6442' ! ! !ARArch methodsFor: 'tutorial'! kind ^ #arch ! ! !ARArch methodsFor: 'tutorial'! bottom ^ 1.04 ! ! !ARArch methodsFor: 'tutorial'! colorHex ^ '#AA89E5' ! ! !ARArch methodsFor: 'tutorial'! sideHex ^ '#624B96' ! ! !ARSpark methodsFor: 'tutorial'! kind ^ #spark ! ! !ARSpark methodsFor: 'tutorial'! bottom ^ 0.6 ! ! !ARSpark methodsFor: 'tutorial'! top ^ 1.4 ! ! !ARSpark methodsFor: 'tutorial'! halfWidth ^ 0.35 ! ! !ARSpark methodsFor: 'tutorial'! halfDepth ^ 0.1 ! ! !ARView methodsFor: 'tutorial'! visibleObjects ^ (app game objects select: [:body | body spent not and: [(camera depthOf: body position) - body halfDepth >= camera near and: [(camera depthOf: body position) + body halfDepth <= camera far]]]) sorted: [:a :b | a position z > b position z] ! ! !ARView methodsFor: 'tutorial'! drawObject: body on: canvas body kind = #spark ifTrue: [^ self drawSpark: body on: canvas]. self boxAtX: body position x y: body bottom z: body position z width: body halfWidth*2 height: body top-body bottom depth: body halfDepth*2 on: canvas face: body colorHex side: body sideHex. body kind = #arch ifTrue: [#(-0.86 0.86) do: [:dx | self boxAtX: body position x + dx y: 0 z: body position z width: 0.13 height: 1.04 depth: 0.6 on: canvas face: '#766496' side: '#473A69']] ! ! !ARView methodsFor: 'tutorial'! boxAtX: x y: y z: z width: w height: h depth: d on: canvas face: face side: side | front back | front := {ARVector x: x-(w/2) y: y z: z-(d/2). ARVector x: x+(w/2) y: y z: z-(d/2). ARVector x: x+(w/2) y: y+h z: z-(d/2). ARVector x: x-(w/2) y: y+h z: z-(d/2)}. back := front collect: [:p | p + (ARVector x: 0 y: 0 z: d)]. self polygon: {front first. back first. back fourth. front fourth} on: canvas color: side border: side. self polygon: {front second. back second. back third. front third} on: canvas color: side border: side. self polygon: {front third. back third. back fourth. front fourth} on: canvas color: face border: '#E3D6DE'. self polygon: front on: canvas color: face border: '#E3D6DE' ! ! !ARView methodsFor: 'tutorial'! drawSpark: body on: canvas | p | p := body position + (ARVector x: 0 y: 1 z: 0). self polygon: {p + (ARVector x: -0.38 y: 0 z: 0). p + (ARVector x: 0 y: 0.5 z: 0). p + (ARVector x: 0.38 y: 0 z: 0). p + (ARVector x: 0 y: -0.5 z: 0)} on: canvas color: '#F5CB76' border: '#FFEBB2'. self lineFrom: p - (ARVector x: 0 y: 0.2 z: 0) to: p + (ARVector x: 0 y: 0.2 z: 0) on: canvas color: '#FFF6D2' width: 2 ! ! !ARApp methodsFor: 'tutorial'! stage ^ 3 ! ! !ARApp methodsFor: 'tutorial'! stageTitle ^ 'Give obstacles their own behavior' ! !