"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'! Object subclass: #ARRunner instanceVariableNames: 'x lane feet verticalSpeed slideRemaining' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! Object subclass: #ARGenerator instanceVariableNames: 'randomState nextDistance safeLane rows' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-AuroraRelay'! Object subclass: #ARController instanceVariableNames: 'app pressed' 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 := ARRunner new. objects := OrderedCollection new. generator := ARGenerator seed: seed. generator fill: objects distance: distance ! ! !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 isRunning ifFalse: [^ self]. 4 timesRepeat: [self isRunning ifTrue: [self advanceSlice: 0.01]]. ticks := ticks + 1 ! ! !ARRun methodsFor: 'tutorial'! stepOnce state = #over ifTrue: [^ self]. state := #running. self tick. self pause ! ! !ARRun methodsFor: 'tutorial'! statusText state = #over ifTrue: [^ 'RELAY ENDED. R restarts the same seed. Your score is distance + 25 per spark.']. state = #paused ifTrue: [^ 'Paused. No travel, gravity, contacts or score changes. Click scene, then Enter to resume.']. ^ 'Tap lanes, jump hurdles, slide arches. Enter toggles play; Esc pauses; R resets.' ! ! !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. World activeHand newKeyboardFocus: view. ^ 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). World activeHand newKeyboardFocus: view. self synchronizeStepping. ^ self ! ! !ARApp methodsFor: 'tutorial'! okToClose ^ true ! ! !ARApp methodsFor: 'tutorial'! release ^ self ! ! !ARApp methodsFor: 'tutorial'! windowIsClosing self stopStepping. game pause. self controller clear. World hands do: [:hand | hand keyboardFocus == view ifTrue: [hand newKeyboardFocus: nil]. hand mouseFocus == view ifTrue: [hand newMouseFocus: nil]]. window := nil ! ! !ARApp methodsFor: 'tutorial'! wantsStepsIn: aWindow ^ false ! ! !ARApp methodsFor: 'tutorial'! synchronizeStepping (window notNil and: [game isRunning]) ifTrue: [self isStepping ifFalse: [self startStepping]] ifFalse: [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 drawWorldOn: canvas. self drawHUDOn: canvas. app game isRunning ifFalse: [self drawStateOn: 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 ! ! !ARRunner methodsFor: 'tutorial'! initialize super initialize. x := 0.0. lane := 0. feet := 0.0. verticalSpeed := 0.0. slideRemaining := 0.0 ! ! !ARRunner methodsFor: 'tutorial'! x ^ x ! ! !ARRunner methodsFor: 'tutorial'! lane ^ lane ! ! !ARRunner methodsFor: 'tutorial'! feet ^ feet ! ! !ARRunner methodsFor: 'tutorial'! verticalSpeed ^ verticalSpeed ! ! !ARRunner methodsFor: 'tutorial'! slideRemaining ^ slideRemaining ! ! !ARRunner methodsFor: 'tutorial'! changeLane: delta lane := ((lane + delta max: -1) min: 1) ! ! !ARRunner methodsFor: 'tutorial'! height ^ slideRemaining > 0 ifTrue: [0.62] ifFalse: [1.65] ! ! !ARRunner methodsFor: 'tutorial'! advance: dt | difference movement | difference := (lane * 2.5) - x. movement := 18*dt. x := difference abs <= movement ifTrue: [lane * 2.5] ifFalse: [x + (difference sign * movement)]. slideRemaining := (slideRemaining - dt) max: 0. (feet > 0 or: [verticalSpeed > 0]) ifTrue: [ feet := feet + (verticalSpeed * dt) - (10 * dt squared). verticalSpeed := verticalSpeed - (20*dt). feet <= 0 ifTrue: [feet := 0.0. verticalSpeed := 0.0]] ! ! !ARRunner methodsFor: 'tutorial'! center ^ ARVector x: x y: feet + (self height / 2) z: 0 ! ! !ARApp methodsFor: 'tutorial'! tickOnce game stepOnce. self refresh. self synchronizeStepping ! ! !ARView methodsFor: 'tutorial'! drawWorldOn: canvas | visible | visible := self visibleObjects. visible do: [:body | body position z >= 0 ifTrue: [self drawObject: body on: canvas]]. self drawRunnerOn: canvas. visible do: [:body | body position z < 0 ifTrue: [self drawObject: body on: canvas]] ! ! !ARView methodsFor: 'tutorial'! drawRunnerOn: canvas | runner h p shadow | runner := app game player. h := runner height. shadow := camera project: (ARVector x: runner x y: 0.02 z: 0). shadow ifNotNil: [canvas fillOval: (self position + shadow - (26@7) extent: 52@14) color: (Color fromString: '#132637')]. self boxAtX: runner x y: runner feet z: 0 width: 0.65 height: h*0.7 depth: 0.48 on: canvas face: '#58C7BE' side: '#2A7F93'. self boxAtX: runner x y: runner feet+(h*0.7) z: -0.05 width: 0.77 height: h*0.3 depth: 0.57 on: canvas face: '#C4FBDF' side: '#66CBBE'. self lineFrom: (ARVector x: runner x-0.26 y: runner feet+(h*0.86) z: -0.36) to: (ARVector x: runner x+0.26 y: runner feet+(h*0.86) z: -0.36) on: canvas color: '#143D55' width: 4 ! ! !ARRunner methodsFor: 'tutorial'! jump (feet = 0 and: [slideRemaining = 0]) ifTrue: [verticalSpeed := 8.2] ! ! !ARRunner methodsFor: 'tutorial'! slide (feet = 0 and: [verticalSpeed = 0]) ifTrue: [slideRemaining := 0.72] ! ! !ARObstacle methodsFor: 'tutorial'! advanceBy: amount position := position - (ARVector x: 0 y: 0 z: amount) ! ! !ARRun methodsFor: 'tutorial'! speed ^ (11.0 + (distance / 250)) min: self maximumSpeed ! ! !ARObstacle methodsFor: 'tutorial'! center ^ ARVector x: position x y: (self bottom + self top)/2 z: position z ! ! !ARObstacle methodsFor: 'tutorial'! touchesFrom: start to: finish height: height ^ self segmentFrom: start to: finish center: self center half: {self halfWidth + 0.34. (self top-self bottom+height)/2. self halfDepth+0.3} ! ! !ARObstacle methodsFor: 'tutorial'! segmentFrom: start to: finish center: center half: half | enter leave a b c delta lo hi t1 t2 swap | enter := 0.0. leave := 1.0. a := start asArray. b := finish asArray. c := center asArray. 1 to: 3 do: [:axis | delta := (b at: axis)-(a at: axis). lo := (c at: axis)-(half at: axis). hi := (c at: axis)+(half at: axis). delta abs < 0.0000001 ifTrue: [((a at: axis) < lo or: [(a at: axis) > hi]) ifTrue: [^ false]] ifFalse: [t1 := (lo-(a at: axis))/delta. t2 := (hi-(a at: axis))/delta. t1 > t2 ifTrue: [swap := t1. t1 := t2. t2 := swap]. enter := enter max: t1. leave := leave min: t2. enter > leave ifTrue: [^ false]]]. ^ true ! ! !ARArch methodsFor: 'tutorial'! touchesFrom: start to: finish height: height (super touchesFrom: start to: finish height: height) ifTrue: [^ true]. ^ #(-0.86 0.86) anySatisfy: [:dx | self segmentFrom: start to: finish center: (ARVector x: position x+dx y: 0.52 z: position z) half: {0.065+0.34. (1.04+height)/2. 0.3+0.3}] ! ! !ARObstacle methodsFor: 'tutorial'! contactIn: run spent ifTrue: [^ self]. spent := true. self applyTo: run ! ! !ARObstacle methodsFor: 'tutorial'! applyTo: run run crash ! ! !ARSpark methodsFor: 'tutorial'! applyTo: run run collectSpark ! ! !ARRun methodsFor: 'tutorial'! collectSpark coins := coins + 1 ! ! !ARRun methodsFor: 'tutorial'! crash state := #over ! ! !ARRun methodsFor: 'tutorial'! advanceSlice: dt | oldFeet oldX start finish travel height | oldFeet := player feet. oldX := player x. height := player height. player advance: dt. height := height max: player height. start := ARVector x: oldX y: oldFeet+(height/2) z: 0. travel := self speed*dt. finish := ARVector x: player x y: player feet+(height/2) z: travel. objects do: [:body | (state ~= #over and: [body spent not and: [body touchesFrom: start to: finish height: height]]) ifTrue: [body contactIn: self]]. objects do: [:body | body advanceBy: travel]. distance := distance + travel. objects := objects select: [:body | body spent not and: [body position z > -12]]. generator fill: objects distance: distance ! ! !ARGenerator class methodsFor: 'tutorial'! seed: number ^ self new seed: number; yourself ! ! !ARGenerator methodsFor: 'tutorial'! seed: number randomState := (number abs \\ 2147483646) + 1. nextDistance := 30.0. safeLane := 1. rows := 0 ! ! !ARGenerator methodsFor: 'tutorial'! nextDistance ^ nextDistance ! ! !ARGenerator methodsFor: 'tutorial'! safeLane ^ safeLane ! ! !ARGenerator methodsFor: 'tutorial'! rows ^ rows ! ! !ARGenerator methodsFor: 'tutorial'! nextInt: limit randomState := (randomState * 48271) \\ 2147483647. ^ (randomState \\ limit) + 1 ! ! !ARGenerator methodsFor: 'tutorial'! gap ^ 28.0 ! ! !ARGenerator methodsFor: 'tutorial'! fill: objects distance: distance [nextDistance-distance < 155] whileTrue: [ self addRowTo: objects at: nextDistance-distance. nextDistance := nextDistance + self gap] ! ! !ARGenerator methodsFor: 'tutorial'! addRowTo: objects at: z | obstacleClass | rows := rows + 1. rows <= 3 ifTrue: [ safeLane := 1. obstacleClass := {ARHurdle. ARArch. ARWall} at: rows. objects add: (obstacleClass lane: 0 z: z). objects add: (ARWall lane: -1 z: z)] ifFalse: [ safeLane := ((safeLane + (self nextInt: 3) - 2 max: -1) min: 1). -1 to: 1 do: [:lane | lane ~= safeLane ifTrue: [ obstacleClass := {ARWall. ARHurdle. ARArch} at: (self nextInt: 3). objects add: (obstacleClass lane: lane z: z)]]]. objects add: (ARSpark lane: safeLane z: z). objects add: (ARSpark lane: safeLane z: z+3.5) ! ! !ARRun methodsFor: 'tutorial'! maximumSpeed ^ 22.0 ! ! !ARController methodsFor: 'tutorial'! initialize super initialize. pressed := Set new ! ! !ARController methodsFor: 'tutorial'! app: anApp app := anApp. ^ self ! ! !ARController methodsFor: 'tutorial'! pressed ^ pressed ! ! !ARController methodsFor: 'tutorial'! clear pressed removeAll ! ! !ARController methodsFor: 'tutorial'! clearMovement pressed := pressed select: [:key | #(13 27 114 82) includes: key] ! ! !ARController methodsFor: 'tutorial'! keyDown: key (#(13 27 114 82 28 29 30 31 32 97 65 100 68 119 87 115 83) includes: key) ifFalse: [^ false]. (pressed includes: key) ifTrue: [^ true]. pressed add: key. key = 13 ifTrue: [app togglePause. ^ true]. key = 27 ifTrue: [app pauseKeepingKeys. ^ true]. (#(114 82) includes: key) ifTrue: [app restart. ^ true]. app game isRunning ifFalse: [^ true]. (#(28 97 65) includes: key) ifTrue: [app game player changeLane: -1]. (#(29 100 68) includes: key) ifTrue: [app game player changeLane: 1]. (#(30 32 119 87) includes: key) ifTrue: [app game player jump]. (#(31 115 83) includes: key) ifTrue: [app game player slide]. ^ true ! ! !ARController methodsFor: 'tutorial'! keyUp: key pressed remove: key ifAbsent: []. ^ true ! ! !ARRun methodsFor: 'tutorial'! togglePause state = #over ifTrue: [^ self]. state := self isRunning ifTrue: [#paused] ifFalse: [#running] ! ! !ARRun methodsFor: 'tutorial'! pause self isRunning ifTrue: [state := #paused] ! ! !ARApp methodsFor: 'tutorial'! controller ^ controller ifNil: [controller := ARController new app: self] ! ! !ARApp methodsFor: 'tutorial'! hasViewFocus ^ World hands anySatisfy: [:hand | hand keyboardFocus == view] ! ! !ARApp methodsFor: 'tutorial'! togglePause game togglePause. (game isRunning and: [window notNil]) ifTrue: [World activeHand newKeyboardFocus: view]. self refresh. self synchronizeStepping ! ! !ARApp methodsFor: 'tutorial'! pauseKeepingKeys game pause. self refresh. self synchronizeStepping ! ! !ARApp methodsFor: 'tutorial'! pause self controller clear. self pauseKeepingKeys ! ! !ARApp methodsFor: 'tutorial'! restart game restart. self controller clearMovement. window ifNotNil: [World activeHand newKeyboardFocus: view]. self refresh. self synchronizeStepping ! ! !ARView methodsFor: 'tutorial'! handlesMouseDown: event ^ true ! ! !ARView methodsFor: 'tutorial'! mouseDown: event event hand newKeyboardFocus: self ! ! !ARView methodsFor: 'tutorial'! handlesKeyboard: event ^ true ! ! !ARView methodsFor: 'tutorial'! handlesKeyboardOnlyOnFocus ^ true ! ! !ARView methodsFor: 'tutorial'! keyDown: event | key | key := EventSensor virtualKeyTable at: event keyCode ifAbsent: [^ self]. key isCharacter ifTrue: [app controller keyDown: key asciiValue] ! ! !ARView methodsFor: 'tutorial'! keyUp: event | key | key := EventSensor virtualKeyTable at: event keyCode ifAbsent: [^ self]. key isCharacter ifTrue: [app controller keyUp: key asciiValue] ! ! !ARView methodsFor: 'tutorial'! keyStroke: event ^ self ! ! !ARView methodsFor: 'tutorial'! keyboardFocusChange: hasFocus hasFocus ifFalse: [app pause] ! ! !ARApp methodsFor: 'tutorial'! stepTime ^ 40 ! ! !ARApp methodsFor: 'tutorial'! step self hasViewFocus ifFalse: [self pause. ^ self]. game tick. self refresh. self synchronizeStepping ! ! !ARView methodsFor: 'tutorial'! drawHUDOn: canvas | text progress box | text := 'SPEED ' , (app game speed printShowingDecimalPlaces: 1), ' / 22'. self text: text at: 540@17 size: 12 on: canvas color: '#F8DA9F'. self text: ('LANE ', (app game player lane + 2) printString, ' Y ', (app game player feet printShowingDecimalPlaces: 1)) at: 18@43 size: 12 on: canvas color: '#ABC8DA'. box := self position + (18@478) extent: 670@6. canvas fillRectangle: box color: (Color fromString: '#1D2B40'). progress := (app game speed - 11)/11. canvas fillRectangle: (box topLeft extent: ((670*progress) rounded)@6) color: (Color fromString: '#F8C976'). self text: 'PACE BUILDS WITH DISTANCE / one open lane in every row' at: 18@454 size: 11 on: canvas color: '#C2D5E4' ! ! !ARView methodsFor: 'tutorial'! drawStateOn: canvas | box title subtitle | box := self position + (109@165) extent: 488@119. canvas fillRectangle: box color: (Color fromString: '#132D40'). canvas frameRectangle: box width: 2 color: (Color fromString: '#73E5D2'). title := app game state = #over ifTrue: ['RELAY ENDED'] ifFalse: [app game state = #paused ifTrue: ['SKYWAY PAUSED'] ifFalse: ['YOUR NEXT RUN STARTS HERE']]. subtitle := app game state = #over ifTrue: ['R: restart / the same seed, a fresh chance'] ifFalse: ['Enter: run / arrows or WASD / Space: jump']. self text: title at: 132@181 size: 21 on: canvas color: '#F8D28B'. self text: subtitle at: 133@225 size: 14 on: canvas color: '#EEF7FF'. self text: 'Coral: dodge. Orange: jump. Violet: slide. Gold: collect.' at: 133@253 size: 12 on: canvas color: '#B5CBDC' ! ! !ARApp methodsFor: 'tutorial'! stage ^ 10 ! ! !ARApp methodsFor: 'tutorial'! stageTitle ^ 'Finish the playable relay' ! ! !ARCamera methodsFor: 'tutorial'! defaultFocal ^ 360 ! !