"Vector / Voyage. Original LearnSqueak software-projected 3D game. File in with Squeak File List." Object subclass: #LS3DVector instanceVariableNames: 'x y z' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Object subclass: #LS3DGame instanceVariableNames: 'player bodies state score rings shields ticks previous' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Morph subclass: #LS3DView instanceVariableNames: 'app camera' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Morph subclass: #LS3DApp instanceVariableNames: 'game view window info status controller' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! SystemWindow subclass: #LS3DWindow instanceVariableNames: 'fixedExtent' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Object subclass: #LS3DCamera instanceVariableNames: 'position focal near far center' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Object subclass: #LS3DBody instanceVariableNames: 'position spent' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! LS3DBody subclass: #LS3DBlock instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! LS3DBody subclass: #LS3DRing instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Object subclass: #LS3DInput instanceVariableNames: 'direction' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Object subclass: #LS3DShip instanceVariableNames: 'position input' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Object subclass: #LS3DCourse instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! LS3DBody subclass: #LS3DGate instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! Object subclass: #LS3DController instanceVariableNames: 'app pressed' classVariableNames: '' poolDictionaries: '' category: 'LearnSqueak-Game3D'! !LS3DVector class methodsFor: 'tutorial'! x: a y: b z: c ^ self new setX: a y: b z: c ! ! !LS3DVector methodsFor: 'tutorial'! setX: a y: b z: c x := a. y := b. z := c. ^ self ! ! !LS3DVector methodsFor: 'tutorial'! x ^ x ! ! !LS3DVector methodsFor: 'tutorial'! y ^ y ! ! !LS3DVector methodsFor: 'tutorial'! z ^ z ! ! !LS3DVector methodsFor: 'tutorial'! + other ^ self class x: x + other x y: y + other y z: z + other z ! ! !LS3DVector methodsFor: 'tutorial'! - other ^ self class x: x - other x y: y - other y z: z - other z ! ! !LS3DVector methodsFor: 'tutorial'! * scalar ^ self class x: x * scalar y: y * scalar z: z * scalar ! ! !LS3DVector methodsFor: 'tutorial'! asArray ^ {x. y. z} ! ! !LS3DGame methodsFor: 'tutorial'! initialize super initialize. self restart ! ! !LS3DGame methodsFor: 'tutorial'! restart player := LS3DShip new. bodies := LS3DCourse bodies. state := #ready. score := 0. rings := 0. shields := 3. ticks := 0 ! ! !LS3DGame methodsFor: 'tutorial'! player ^ player ! ! !LS3DGame methodsFor: 'tutorial'! bodies ^ bodies ! ! !LS3DGame methodsFor: 'tutorial'! state ^ state ! ! !LS3DGame methodsFor: 'tutorial'! score ^ score ! ! !LS3DGame methodsFor: 'tutorial'! rings ^ rings ! ! !LS3DGame methodsFor: 'tutorial'! shields ^ shields ! ! !LS3DGame methodsFor: 'tutorial'! ticks ^ ticks ! ! !LS3DGame methodsFor: 'tutorial'! isRunning ^ state = #running ! ! !LS3DGame methodsFor: 'tutorial'! tick self isRunning ifFalse: [^ self]. previous := player position. player advanceBy: self forwardSpeed. ticks := ticks + 1. self resolveContactsFrom: previous to: player position ! ! !LS3DGame methodsFor: 'tutorial'! stepOnce (#(ready running paused) includes: state) ifFalse: [^ self]. state := #running. self tick. self isRunning ifTrue: [state := #paused] ! ! !LS3DGame methodsFor: 'tutorial'! statusText state = #won ifTrue: [^ 'VOYAGE COMPLETE. The gate is open. Restart to fly again.']. state = #lost ifTrue: [^ shields = 0 ifTrue: ['Shields exhausted. Restart for a new ship and a fresh course.'] ifFalse: ['Gate locked: collect at least 3 rings before reaching Z = 140.']]. state = #paused ifTrue: [^ 'Paused. The ship, contacts and score are frozen.']. ^ 'Collect 3 of 9 gold rings. Avoid coral blocks. Reach the gate with a shield.' ! ! !LS3DGame methodsFor: 'tutorial'! distance ^ player position z ! ! !LS3DGame methodsFor: 'tutorial'! progress ^ self distance / 140.0 ! ! !LS3DApp class methodsFor: 'tutorial'! open ^ self new open ! ! !LS3DApp methodsFor: 'tutorial'! initialize super initialize. self extent: 928@650; color: (Color fromString: '#0B1321'). game := LS3DGame new. view := LS3DView new app: self; position: self position + (22@111). self addMorph: view. self label: 'VECTOR / VOYAGE' at: 22@13 size: 26 color: '#F3F7FB'. self label: 'Smalltalk objects. Three dimensions. One native clock.' at: 23@50 size: 14 color: '#9AACC0'. self label: ('CHECKPOINT ', self stage printString, ' / 10') at: 698@20 size: 14 color: '#76E7CE'. self label: self stageTitle at: 23@80 size: 14 color: '#FFCF78'. info := self label: '' at: 23@607 size: 15 color: '#F3F7FB'. status := self label: '' at: 23@633 size: 12 color: '#9AACC0'. self buildSidebar. self refresh ! ! !LS3DApp methodsFor: 'tutorial'! label: text at: point size: size color: hex | label | label := StringMorph contents: text font: (TextStyle default fontOfSize: size). label position: self position + point; color: (Color fromString: hex). self addMorph: label. ^ label ! ! !LS3DApp methodsFor: 'tutorial'! button: text at: point action: selector | button | button := SimpleButtonMorph new label: text; target: self; actionSelector: selector; color: (Color fromString: '#D5E8EC'); yourself. button position: self position + point. self addMorph: button ! ! !LS3DApp methodsFor: 'tutorial'! buildSidebar self label: 'MODEL / VIEW' at: 708@120 size: 16 color: '#76E7CE'. self label: 'Vector owns x, y, z' at: 708@153 size: 12 color: '#CED8E8'. self label: 'Camera projects points' at: 708@181 size: 12 color: '#CED8E8'. self label: 'Body owns contact rules' at: 708@209 size: 12 color: '#CED8E8'. self label: 'Game owns the session' at: 708@237 size: 12 color: '#CED8E8'. self label: 'View draws the result' at: 708@265 size: 12 color: '#CED8E8'. self label: 'FLIGHT MANUAL' at: 708@313 size: 16 color: '#FFCF78'. self label: 'Arrows / WASD: steer' at: 708@347 size: 12 color: '#CED8E8'. self label: 'Gold: collect rings' at: 708@375 size: 12 color: '#CED8E8'. self label: 'Coral: avoid blocks' at: 708@403 size: 12 color: '#CED8E8'. self label: 'Reach the gate with 3' at: 708@431 size: 12 color: '#CED8E8'. self label: 'rings and a shield left' at: 708@452 size: 12 color: '#CED8E8'. self stage >= 4 ifTrue: [self button: 'Tick once' at: 708@492 action: #tickOnce]. self stage >= 7 ifTrue: [self button: 'Start / Pause' at: 708@527 action: #togglePause. self button: 'Restart' at: 825@527 action: #restart]. self label: (self stage >= 8 ifTrue: ['Enter: start Esc: pause'] ifFalse: ['Inspect first. Then build.']) at: 708@573 size: 11 color: '#9AACC0' ! ! !LS3DApp methodsFor: 'tutorial'! game ^ game ! ! !LS3DApp methodsFor: 'tutorial'! view ^ view ! ! !LS3DApp methodsFor: 'tutorial'! window ^ window ! ! !LS3DApp methodsFor: 'tutorial'! refresh info contents: ('SCORE ', game score printString, ' RINGS ', game rings printString, ' / 9 SHIELDS ', game shields printString, ' ', game state asString asUppercase). status contents: game statusText. view changed ! ! !LS3DApp methodsFor: 'tutorial'! open window ifNotNil: [window comeToFront. World activeHand newKeyboardFocus: view. ^ self]. window := LS3DWindow new model: self; setLabel: 'Vector / Voyage - native Smalltalk 3D'. window addMorph: self fullFrame: (LayoutFrame fractions: (0@0 corner: 1@1)). window fixedExtent: 938@683. window openInWorld. World activeHand newKeyboardFocus: view. self synchronizeStepping. ^ self ! ! !LS3DApp methodsFor: 'tutorial'! okToClose ^ true ! ! !LS3DApp methodsFor: 'tutorial'! release ^ self ! ! !LS3DApp 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 ! ! !LS3DApp methodsFor: 'tutorial'! wantsStepsIn: aWindow ^ false ! ! !LS3DApp methodsFor: 'tutorial'! synchronizeStepping (window notNil and: [game isRunning]) ifTrue: [self isStepping ifFalse: [self startStepping]] ifFalse: [self stopStepping] ! ! !LS3DWindow methodsFor: 'tutorial'! fixedExtent: point fixedExtent := point. super extent: point ! ! !LS3DWindow methodsFor: 'tutorial'! extent: point super extent: (fixedExtent ifNil: [point]) ! ! !LS3DWindow methodsFor: 'tutorial'! lookFocused super lookFocused. label ifNotNil: [label color: Color white] ! ! !LS3DWindow methodsFor: 'tutorial'! lookUnfocused super lookUnfocused. label ifNotNil: [label color: (Color gray: 0.8)] ! ! !LS3DView methodsFor: 'tutorial'! app: anApp app := anApp. self extent: 662@480. camera := LS3DCamera new ! ! !LS3DView methodsFor: 'tutorial'! drawOn: canvas canvas clipBy: self bounds during: [:clipped | clipped fillRectangle: self bounds color: (Color fromString: '#080F1B'). self updateCamera. self drawTunnelOn: clipped. self drawSceneOn: clipped]. canvas frameRectangle: self bounds width: 1 color: (Color fromString: '#304356') ! ! !LS3DView 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) ! ! !LS3DCamera methodsFor: 'tutorial'! initialize super initialize. position := LS3DVector x: 0 y: 0 z: -8. focal := self defaultFocal. near := 0.5. far := 110. center := 331@228 ! ! !LS3DCamera methodsFor: 'tutorial'! defaultFocal ^ 290 ! ! !LS3DCamera methodsFor: 'tutorial'! position ^ position ! ! !LS3DCamera methodsFor: 'tutorial'! focal ^ focal ! ! !LS3DCamera methodsFor: 'tutorial'! near ^ near ! ! !LS3DCamera methodsFor: 'tutorial'! far ^ far ! ! !LS3DCamera methodsFor: 'tutorial'! center ^ center ! ! !LS3DCamera methodsFor: 'tutorial'! position: point position := point ! ! !LS3DCamera methodsFor: 'tutorial'! depthOf: point ^ point z - position z ! ! !LS3DCamera 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)) ! ! !LS3DView methodsFor: 'tutorial'! camera ^ camera ! ! !LS3DView methodsFor: 'tutorial'! updateCamera camera position: (LS3DVector x: 0 y: 0 z: app game distance - 8) ! ! !LS3DView methodsFor: 'tutorial'! drawSceneOn: canvas self drawWorldOn: canvas. self drawHUDOn: canvas. app game isRunning ifFalse: [self drawStateOn: canvas] ! ! !LS3DView 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)] ! ! !LS3DView methodsFor: 'tutorial'! drawTunnelOn: canvas | z start corners next | start := ((camera position z / 8) floor + 1) * 8. 0 to: 11 do: [:index | z := start + (index * 8). corners := {LS3DVector x: -5 y: -3 z: z. LS3DVector x: 5 y: -3 z: z. LS3DVector x: 5 y: 3 z: z. LS3DVector x: -5 y: 3 z: z}. 1 to: 4 do: [:i | next := i \\ 4 + 1. self lineFrom: (corners at: i) to: (corners at: next) on: canvas color: (index even ifTrue: ['#285364'] ifFalse: ['#1B3445']) width: 1]. index < 11 ifTrue: [corners do: [:corner | self lineFrom: corner to: corner + (LS3DVector x: 0 y: 0 z: 8) on: canvas color: '#234754' width: 1]]]. #((-5 -3) (5 -3) (5 3) (-5 3)) do: [:pair | self lineFrom: (LS3DVector x: pair first y: pair second z: camera position z + 0.6) to: (LS3DVector x: pair first y: pair second z: start + 88) on: canvas color: '#39707C' width: 1]. self lineFrom: (LS3DVector x: 0 y: -3 z: start) to: (LS3DVector x: 0 y: -3 z: start + 88) on: canvas color: '#397E85' width: 2 ! ! !LS3DBody class methodsFor: 'tutorial'! at: point ^ self new position: point; yourself ! ! !LS3DBody methodsFor: 'tutorial'! initialize super initialize. spent := false. position := LS3DVector x: 0 y: 0 z: 0 ! ! !LS3DBody methodsFor: 'tutorial'! position ^ position ! ! !LS3DBody methodsFor: 'tutorial'! spent ^ spent ! ! !LS3DBody methodsFor: 'tutorial'! position: point position := point ! ! !LS3DBody methodsFor: 'tutorial'! renderKind ^ #block ! ! !LS3DRing methodsFor: 'tutorial'! renderKind ^ #ring ! ! !LS3DBody methodsFor: 'tutorial'! halfSize ^ 0.7 ! ! !LS3DRing methodsFor: 'tutorial'! halfSize ^ 0.9 ! ! !LS3DView methodsFor: 'tutorial'! visibleBodies ^ (app game bodies select: [:body | body spent not and: [ (camera depthOf: body position) - body halfSize >= camera near and: [ (camera depthOf: body position) + body halfSize <= camera far]]]) sorted: [:a :b | a position z > b position z] ! ! !LS3DView methodsFor: 'tutorial'! drawBody: body on: canvas body renderKind = #ring ifTrue: [^ self drawRing: body on: canvas]. body renderKind = #gate ifTrue: [^ self drawGate: body on: canvas]. self drawBlock: body on: canvas ! ! !LS3DView 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) ! ! !LS3DView methodsFor: 'tutorial'! drawBlock: body on: canvas | p h front back | p := body position. h := body halfSize. front := {p + (LS3DVector x: h negated y: h negated z: h negated). p + (LS3DVector x: h y: h negated z: h negated). p + (LS3DVector x: h y: h z: h negated). p + (LS3DVector x: h negated y: h z: h negated)}. back := front collect: [:point | point + (LS3DVector x: 0 y: 0 z: h*2)]. 1 to: 4 do: [:i | | next | next := i \\ 4 + 1. self polygon: {front at: i. back at: i. back at: next. front at: next} on: canvas color: '#783F53' border: '#F77B86']. self polygon: front on: canvas color: '#C95D71' border: '#FFAEAF'. self lineFrom: front first to: (front at: 3) on: canvas color: '#ED91A0' width: 1. self lineFrom: front second to: front fourth on: canvas color: '#ED91A0' width: 1 ! ! !LS3DView methodsFor: 'tutorial'! drawRing: body on: canvas | p h points | p := body position. h := body halfSize. points := {p + (LS3DVector x: h negated y: 0 z: 0). p + (LS3DVector x: 0 y: h z: 0). p + (LS3DVector x: h y: 0 z: 0). p + (LS3DVector x: 0 y: h negated z: 0)}. 1 to: 4 do: [:i | self lineFrom: (points at: i) to: (points at: i \\ 4 + 1) on: canvas color: '#FFD279' width: 4]. self lineFrom: (p + (LS3DVector x: -0.2 y: 0 z: 0)) to: (p + (LS3DVector x: 0.2 y: 0 z: 0)) on: canvas color: '#FFF0B0' width: 2 ! ! !LS3DInput methodsFor: 'tutorial'! initialize super initialize. self clear ! ! !LS3DInput methodsFor: 'tutorial'! clear direction := 0@0 ! ! !LS3DInput methodsFor: 'tutorial'! direction ^ direction ! ! !LS3DInput methodsFor: 'tutorial'! direction: point direction := ((point x max: -1) min: 1) @ ((point y max: -1) min: 1) ! ! !LS3DShip methodsFor: 'tutorial'! initialize super initialize. position := LS3DVector x: 0 y: 0 z: 0. input := LS3DInput new ! ! !LS3DShip methodsFor: 'tutorial'! position ^ position ! ! !LS3DShip methodsFor: 'tutorial'! input ^ input ! ! !LS3DShip methodsFor: 'tutorial'! position: point position := point ! ! !LS3DShip methodsFor: 'tutorial'! speed ^ 0.25 ! ! !LS3DShip methodsFor: 'tutorial'! advanceBy: forward | delta length dx dy | delta := input direction. length := (delta x squared + delta y squared) sqrt max: 1. dx := delta x / length * self speed. dy := delta y / length * self speed. position := LS3DVector x: ((position x + dx max: -4.5) min: 4.5) y: ((position y + dy max: -2.5) min: 2.5) z: position z + forward ! ! !LS3DApp methodsFor: 'tutorial'! tickOnce game stepOnce. self refresh. self synchronizeStepping ! ! !LS3DView methodsFor: 'tutorial'! drawWorldOn: canvas | bodies shipZ | bodies := self visibleBodies. shipZ := app game distance. bodies do: [:body | body position z > shipZ ifTrue: [self drawBody: body on: canvas]]. self drawShipOn: canvas. bodies do: [:body | body position z <= shipZ ifTrue: [self drawBody: body on: canvas]] ! ! !LS3DView methodsFor: 'tutorial'! drawShipOn: canvas | p | p := app game player position. self polygon: {p + (LS3DVector x: 0 y: 0.25 z: 0.6). p + (LS3DVector x: -0.38 y: -0.22 z: -0.4). p + (LS3DVector x: 0 y: -0.08 z: -0.15). p + (LS3DVector x: 0.38 y: -0.22 z: -0.4)} on: canvas color: '#76E7CE' border: '#DBFFF3'. self lineFrom: (p + (LS3DVector x: 0 y: -0.12 z: -0.25)) to: (p + (LS3DVector x: 0 y: -0.4 z: -1)) on: canvas color: '#70A5EF' width: 3 ! ! !LS3DCourse class methodsFor: 'tutorial'! ringCoordinates ^ #((-2 1 16) (2 -1 30) (0 1 44) (-2 -1 58) (2 1 72) (0 -1 86) (-2 1 100) (2 -1 114) (0 1 128)) ! ! !LS3DCourse class methodsFor: 'tutorial'! bodies | result | result := OrderedCollection new. self ringCoordinates do: [:row | | p | p := LS3DVector x: row first y: row second z: row third. result add: (LS3DRing at: p). result add: (LS3DBlock at: (LS3DVector x: p x negated y: p y negated z: p z))]. result add: (LS3DGate at: (LS3DVector x: 0 y: 0 z: 140)). ^ result asArray ! ! !LS3DGame methodsFor: 'tutorial'! forwardSpeed ^ 0.4 ! ! !LS3DBody methodsFor: 'tutorial'! segmentFrom: start to: finish intersectsHalf: half | enter leave a b centerValues size delta low high t1 t2 swap | enter := 0.0. leave := 1.0. a := start asArray. b := finish asArray. centerValues := position asArray. size := half asArray. 1 to: 3 do: [:axis | delta := (b at: axis) - (a at: axis). low := (centerValues at: axis) - (size at: axis). high := (centerValues at: axis) + (size at: axis). delta abs < 0.000001 ifTrue: [ ((a at: axis) < low or: [(a at: axis) > high]) ifTrue: [^ false]] ifFalse: [ t1 := (low - (a at: axis)) / delta. t2 := (high - (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 ! ! !LS3DBlock methodsFor: 'tutorial'! touchesFrom: start to: finish ^ self segmentFrom: start to: finish intersectsHalf: (LS3DVector x: 0.95 y: 0.95 z: 0.95) ! ! !LS3DRing methodsFor: 'tutorial'! touchesFrom: start to: finish ^ self segmentFrom: start to: finish intersectsHalf: (LS3DVector x: 0.9 y: 0.9 z: 0) ! ! !LS3DBody methodsFor: 'tutorial'! contactIn: game spent ifTrue: [^ self]. spent := true. self applyTo: game ! ! !LS3DBlock methodsFor: 'tutorial'! applyTo: game game damage ! ! !LS3DRing methodsFor: 'tutorial'! points ^ 100 ! ! !LS3DRing methodsFor: 'tutorial'! applyTo: game game collectRingWorth: self points ! ! !LS3DGame methodsFor: 'tutorial'! collectRingWorth: points score := score + points. rings := rings + 1 ! ! !LS3DGame methodsFor: 'tutorial'! damage shields := (shields - 1) max: 0. shields = 0 ifTrue: [state := #lost] ! ! !LS3DGame methodsFor: 'tutorial'! resolveContactsFrom: start to: finish bodies do: [:body | state = #lost ifTrue: [^ self]. (body spent not and: [body touchesFrom: start to: finish]) ifTrue: [body contactIn: self]] ! ! !LS3DGate methodsFor: 'tutorial'! renderKind ^ #gate ! ! !LS3DGate methodsFor: 'tutorial'! halfSize ^ 0 ! ! !LS3DGate methodsFor: 'tutorial'! touchesFrom: start to: finish ^ start z < position z and: [finish z >= position z] ! ! !LS3DGate methodsFor: 'tutorial'! applyTo: game game finish ! ! !LS3DGame methodsFor: 'tutorial'! requiredRings ^ 5 ! ! !LS3DGame methodsFor: 'tutorial'! finish state := rings >= self requiredRings ifTrue: [#won] ifFalse: [#lost]. player input clear ! ! !LS3DGame methodsFor: 'tutorial'! togglePause (#(won lost) includes: state) ifTrue: [^ self]. state := state = #running ifTrue: [#paused] ifFalse: [#running] ! ! !LS3DGame methodsFor: 'tutorial'! pause state = #running ifTrue: [state := #paused]. player input clear ! ! !LS3DApp methodsFor: 'tutorial'! togglePause game togglePause. game isRunning ifFalse: [self controller clearMovement]. self refresh. self synchronizeStepping ! ! !LS3DApp methodsFor: 'tutorial'! restart game restart. self controller clearMovement. self refresh. self synchronizeStepping ! ! !LS3DApp methodsFor: 'tutorial'! pause game pause. self controller clear. self refresh. self synchronizeStepping ! ! !LS3DView methodsFor: 'tutorial'! drawGate: body on: canvas | z points | z := body position z. points := {LS3DVector x: -4.7 y: -2.7 z: z. LS3DVector x: 4.7 y: -2.7 z: z. LS3DVector x: 4.7 y: 2.7 z: z. LS3DVector x: -4.7 y: 2.7 z: z}. 1 to: 4 do: [:i | self lineFrom: (points at: i) to: (points at: i \\ 4 + 1) on: canvas color: '#76E7CE' width: 5] ! ! !LS3DController methodsFor: 'tutorial'! initialize super initialize. pressed := Set new ! ! !LS3DController methodsFor: 'tutorial'! app: anApp app := anApp ! ! !LS3DController methodsFor: 'tutorial'! pressed ^ pressed ! ! !LS3DController methodsFor: 'tutorial'! clear pressed removeAll. app game player input clear ! ! !LS3DController methodsFor: 'tutorial'! clearMovement pressed := pressed select: [:key | #(13 27 114 82) includes: key]. app game player input clear ! ! !LS3DController methodsFor: 'tutorial'! updateDirection | left right up down | left := #(28 97 65) anySatisfy: [:key | pressed includes: key]. right := #(29 100 68) anySatisfy: [:key | pressed includes: key]. up := #(30 119 87) anySatisfy: [:key | pressed includes: key]. down := #(31 115 83) anySatisfy: [:key | pressed includes: key]. app game player input direction: ((right ifTrue: [1] ifFalse: [0]) - (left ifTrue: [1] ifFalse: [0])) @ ((up ifTrue: [1] ifFalse: [0]) - (down ifTrue: [1] ifFalse: [0])) ! ! !LS3DController methodsFor: 'tutorial'! keyDown: key (#(13 27 114 82 28 29 30 31 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 pause. ^ true]. (#(114 82) includes: key) ifTrue: [app restart. ^ true]. self updateDirection. ^ true ! ! !LS3DController methodsFor: 'tutorial'! keyUp: key pressed remove: key ifAbsent: []. self updateDirection. ^ true ! ! !LS3DApp methodsFor: 'tutorial'! controller ^ controller ifNil: [controller := LS3DController new app: self] ! ! !LS3DApp methodsFor: 'tutorial'! hasViewFocus ^ World hands anySatisfy: [:hand | hand keyboardFocus == view] ! ! !LS3DView methodsFor: 'tutorial'! handlesMouseDown: event ^ true ! ! !LS3DView methodsFor: 'tutorial'! mouseDown: event event hand newKeyboardFocus: self ! ! !LS3DView methodsFor: 'tutorial'! handlesKeyboard: event ^ true ! ! !LS3DView methodsFor: 'tutorial'! handlesKeyboardOnlyOnFocus ^ true ! ! !LS3DView methodsFor: 'tutorial'! keyDown: event | key | key := EventSensor virtualKeyTable at: event keyCode ifAbsent: [^ self]. key isCharacter ifTrue: [app controller keyDown: key asciiValue] ! ! !LS3DView methodsFor: 'tutorial'! keyUp: event | key | key := EventSensor virtualKeyTable at: event keyCode ifAbsent: [^ self]. key isCharacter ifTrue: [app controller keyUp: key asciiValue] ! ! !LS3DView methodsFor: 'tutorial'! keyStroke: event ^ self ! ! !LS3DView methodsFor: 'tutorial'! keyboardFocusChange: hasFocus hasFocus ifFalse: [app pause] ! ! !LS3DApp methodsFor: 'tutorial'! stepTime ^ 40 ! ! !LS3DApp methodsFor: 'tutorial'! step self hasViewFocus ifFalse: [self pause. ^ self]. game tick. self refresh. self synchronizeStepping ! ! !LS3DView methodsFor: 'tutorial'! drawHUDOn: canvas | x y bar progress next label | x := app game player position x. y := app game player position y. self text: 'SOFTWARE 3D / native Morphic' at: 18@17 size: 12 on: canvas color: '#76E7CE'. self text: ('X ', (x printShowingDecimalPlaces: 1), ' Y ', (y printShowingDecimalPlaces: 1), ' Z ', (app game distance printShowingDecimalPlaces: 1)) at: 18@39 size: 12 on: canvas color: '#9AACC0'. next := app game bodies detect: [:body | body renderKind = #ring and: [body position z > app game distance]] ifNone: [nil]. label := next ifNil: ['NEXT / finish gate'] ifNotNil: ['NEXT RING / X ', next position x printString, ' Y ', next position y printString]. self text: label at: 407@18 size: 12 on: canvas color: '#FFCF78'. bar := (self position + (18@451)) extent: 626@7. canvas fillRectangle: bar color: (Color fromString: '#263A4A'). progress := (app game progress max: 0) min: 1. canvas fillRectangle: (bar topLeft extent: ((626 * progress) rounded)@7) color: (Color fromString: '#76E7CE'). self text: 'LAUNCH' at: 18@429 size: 10 on: canvas color: '#9AACC0'. self text: 'GATE / 140' at: 570@429 size: 10 on: canvas color: '#9AACC0' ! ! !LS3DView methodsFor: 'tutorial'! drawStateOn: canvas | box title subtitle | box := (self position + (126@178)) extent: 410@112. canvas fillRectangle: box color: (Color fromString: '#122437'). canvas frameRectangle: box width: 2 color: (Color fromString: '#76E7CE'). title := app game state = #won ifTrue: ['VOYAGE COMPLETE'] ifFalse: [app game state = #lost ifTrue: ['FLIGHT ENDED'] ifFalse: [app game state = #paused ifTrue: ['FLIGHT PAUSED'] ifFalse: ['READY, PILOT?']]]. subtitle := (#(won lost) includes: app game state) ifTrue: ['R to restart / a fresh course, a new ship'] ifFalse: ['Enter to fly / arrows or WASD to steer']. self text: title at: 149@195 size: 23 on: canvas color: '#FFCF78'. self text: subtitle at: 150@236 size: 13 on: canvas color: '#F3F7FB'. self text: 'Collect 3 rings. Keep a shield. Reach the gate.' at: 150@260 size: 12 on: canvas color: '#9AACC0' ! ! !LS3DApp methodsFor: 'tutorial'! stage ^ 10 ! ! !LS3DApp methodsFor: 'tutorial'! stageTitle ^ 'A complete native flight deck' ! ! !LS3DGame methodsFor: 'tutorial'! requiredRings ^ 3 ! !