OBY30
オビーにいろいろさせる
さ〜てと表情だけじゃなくオビーにいろいろなことができるようにするです。
アクションをフラグで切り替えるってかんじでオビーにアニメーションさせるです。
アクションフラグが「0」ならなにもしなくて、「1」なら移動、「2」なら回転させるとか・・・ってかんじだすな。
■インスタンス変数を追加
● クラス
actionFlagというインスタンス変数を追加しまする。
--------------------------------------------
Morph subclass: #Oby
instanceVariableNames: 'face eye eyes nose lips ears hair hat memoryBank actionFlag '
classVariableNames: ''
poolDictionaries: ''
category: 'ObyMorph'
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
■メソッドを追加します。
まずはactionFlagが1の場合から。
● Obyクラスstepメソッド
actionFlagが1ならnoseの「flashNose」メソッドを実行ってことやね。
4行目の「bouncing」なんてまだないからこれから作るんだけどね。
--------------------------------------------
step
super step.
actionFlag = 1 ifTrue: [
self bouncing].
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
さてさて肝心の「bouncing」メソッドを作るわけですが
そのまえにインスタンス変数を追加しまする。
● ObyNoseクラスにインスタンス変数を追加
インスタンス変数addX,addYを追加します。これ移動量ね。
--------------------------------------------
Morph subclass: #Oby
instanceVariableNames: 'face eye eyes nose lips ears hair hat memoryBank actionFlag addX addY '
classVariableNames: ''
poolDictionaries: ''
category: 'ObyMorph'
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● Obyクラスbouncingメソッド
現在の位置に移動量を追加しています。
3行目の「bouncingWorld」メソッドはこの次に作るです。
--------------------------------------------
bouncing
self position: self position + (addX@addY).
self bouncingWorld.
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● ObyクラスbouncingWorldメソッド
画面の端にぶつかったら跳ね返るようにしてます。
--------------------------------------------
bouncingWorld
self left ActiveWorld left ifTrue: [
addX _ addX negated].
self right > ActiveWorld right ifTrue: [
addX _ addX negated].
self top ActiveWorld top ifTrue: [
addY _ addY negated].
self bottom > ActiveWorld bottom ifTrue: [
addY _ addY negated].
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● ObyクラスaddXメソッド
インスタンス変数をaddXを返すメソッド。
--------------------------------------------
addX
^ addX
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● ObyクラスaddYメソッド
インスタンス変数addYを返すメソッド。
--------------------------------------------
addY
^ addY
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
● Obyクラスinitializeメソッドの修正
addX,addYを初期化する行を追加したでごんす。
--------------------------------------------
initialize
super initialize.
"土台の設定"
self extent: 80@80.
self color: (Color r: 1.0 g: 1.0 b: 1.0 alpha: 0.5).
self borderWidth: 0.
"顔の生成"
face _ ObyFace new.
self addMorph: face.
face align: face center with: self center.
"目の生成"
eyes _ ObyEyes new.
self addMorph: eyes.
eyes align: eyes center with: self center + (0 @ 0).
"口の生成"
lips _ ObyLips new.
self addMorph: lips.
lips align: lips center with: self center + (0 @ 23).
"鼻の生成"
nose _ ObyNose new.
self addMorph: nose.
nose align: nose center with: self center + (0 @ 5).
memoryBank _ Dictionary new.
addX _ 2.
addY _ 2.
--------------------------------------------
アクセプト。
Alt + s ( Cmd + s )
★インスタンスを出してみる
--------------------------------------------
boby _ Oby new openInWorld.
boby actionFlag _ 1.
--------------------------------------------
Alt + d ( Cmd + d )
とめるときはこれね。
--------------------------------------------
boby actionFlag _ 0.
--------------------------------------------
Alt + d ( Cmd + d )
▲PREV ------ ● TOP ● ------ NEXT▼
■ MEMO ■
Links to this Page
- I BOBY last edited on 28 April 2004 at 8:57:55 pm by tk0005-202x210x196x109.ap-TK.usen.ad.jp
- OBY29 last edited on 17 June 2007 at 7:27:29 am by localhost.localdomain
- OBY31 last edited on 18 June 2007 at 5:28:03 am by localhost.localdomain