OSDN Git Service

...。
[ring-lang-081/ring.git] / docs / ja-jp / build / html / _sources / gameengine.txt
1 .. index:: 
2         single: 2D ゲームエンジン; はじめに
3
4 ====================================
5 デモプロジェクト - 2D ゲームエンジン
6 ====================================
7
8 シンプルな 2D ゲームエンジンの作成を通じて、多種多様なプログラミングパラダイムをプロジェクトで併用する方法を学びます。
9
10 これでデスクトップ、またはモバイル用 2D ゲームを作成できます。
11
12 .. index:: 
13         pair: 2D ゲームエンジン; プロジェクトの階層
14
15 プロジェクトの階層
16 ==================
17
18 このような階層をプロジェクトで使用しています。
19
20 * ゲームの階層 (宣言型プログラミング)
21 * ゲームエンジンのクラス (オブジェクト指向プログラミングのパラダイム)
22 * グラフィックスライブラリへのインタフェース (手続き型プログラミング)
23 * グラフィックスライブラリへのバインディング (RingAllegro と RingLibSDL)
24
25 .. index:: 
26         pair: 2D ゲームエンジン; グラフィックスライブラリのバインディング
27
28 グラフィックスライブラリのバインディング
29 ========================================
30
31 Allegro ゲームプログラミング・ライブラリ用の RingAllegro と
32 LibSDL ゲームプログラミング・ライブラリ用の RingLibSDL があります。
33
34 RingAllegro と RingLibSDL は Ring コード生成器の支援により
35 C による拡張機能として作成されています。
36
37 RingAllegro と RingLibSDL はシンプルな設定ファイルを記述した後に生成される
38 10,000 行以上の C コードからなります (コード生成器による処理)。
39
40 RingAllegro と RingLibSDL の設定ファイルで関数名、構造体情報、および定数を決定後、
41 この設定ファイルを生成器で処理して C コードと
42 Ring コードから読み込み可能なライブラリを生成します。
43
44 RingAllegro と RingLibSDL の使用は同一関数を有する C コードから
45 Allegro および LibSDL の使用と非常に類似していますが Ring の機能で構築できます。
46
47 * RingAllegro のソースコード : https://github.com/ring-lang/ring/tree/master/extensions/ringallegro
48 * RingLibSDL のソースコード : https://github.com/ring-lang/ring/tree/master/extensions/ringsdl
49
50 .. index:: 
51         pair: 2D ゲームエンジン; グラフィックスライブラリへのインタフェース
52
53 グラフィックスライブラリへのインタフェース
54 ==========================================
55
56 この階層には gl_allegro.ring および gl_libsdl.ring があります。
57
58 グラフィックスライブラリとの相互作用により、ライブラリ間で同一関数を使えます。
59
60 この階層は RingAllegro と RingLibSDL の詳細と差異を吸収します。
61
62 同一関数で Allegro と LibSDL を何時でも切り替えて使えます。
63
64 なぜですか?
65
66 Allegro は非常に単純明快であり Windows, Linux および macOS 用の 2D ゲームを手軽に作成できます。
67
68 Ring 1.0 から Allegro へ対応しました。
69
70 また LibSDL は非常に強力かつ普及しており、モバイル開発では非常に簡単に使えます。
71
72 Ring 1.1 から LibSDL へ対応しているため、モバイル用のゲームを手軽に作成できます。
73
74 .. note:: このライブラリだけで、デスクトップとモバイル開発ができます。
75
76 * gl_allegro.ring のソースコード : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gl_allegro.ring
77 * gl_libsdl.ring のソースコード : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gl_libsdl.ring
78
79 .. index:: 
80         pair: 2D ゲームエンジン; ゲームエンジンのクラス
81
82 ゲームエンジンのクラス
83 ======================
84
85 このクラスがエンジンにあります。
86
87 * GameBase クラス
88 * Resources クラス
89 * Game クラス
90 * GameObject クラス
91 * Sprite クラス
92 * Text クラス
93 * Animate クラス
94 * Sound クラス
95 * Map クラス
96
97 * ソースコード : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gameengine.ring
98
99 .. index:: 
100         pair: 2D ゲームエンジン; ゲームの階層
101
102 ゲームの階層
103 ============
104
105 この階層では、ゲームエンジンのクラスを使用してゲームを作成します。
106
107 宣言型プログラミングでクラスの設計を行っています。
108
109 このクラスをゲームで使用しています。
110
111 * Game クラス
112 * Sprite クラス
113 * Text クラス
114 * Animate クラス
115 * Sound クラス
116 * Map クラス
117
118 .. note:: エンジンに実装されている上記以外のクラスは、エンジンの内部処理用です。
119
120 三種類のゲームと用例を紹介します:
121
122 * Stars Fighter ゲーム
123 * Flappy Bird 3000 ゲーム
124 * Super Man 2016 ゲーム
125
126 .. index:: 
127         pair: 2D ゲームエンジン; Game クラス
128
129 Game クラス
130 ===========
131
132 この表はクラスの属性です。
133
134 ============    =================================================================================
135 属性                  説明
136 ============    =================================================================================
137 FPS                     数値により毎秒ごとの draw() メソッドの呼び出し回数を決定します。
138 FixedFPS                数値により毎秒ごとの animate() メソッドの呼び出し回数を決定します。
139 Title                   文字列によりゲームのウィンドウタイトルを決定します。
140 aObjects                ゲーム内の全てのオブジェクトを有するリストです。
141 shutdown                True/False 値によりゲームのループを終了します。
142 ============    =================================================================================
143
144 この表はクラスのメソッドです。
145
146 ================        =================================================================================
147 メソッド                    説明
148 ================        =================================================================================
149 refresh()                       オブジェクトを削除します。
150 settitle(cTitle)        文字列による仮引数でウィンドウのタイトルを設定します。
151 shutdown()                      アプリケーションを閉じます。
152 find(cName)             オブジェクト名でオブジェクトを検索します。
153 remove(nID)             オブジェクト ID でオブジェクトを削除します。
154 ================        =================================================================================
155
156 この表はクラスで定義されているキーワードのグループです。
157
158 ================        =================================================================================
159 キーワード                 説明
160 ================        =================================================================================
161 sprite                          新しい Sprite オブジェクトを作成後に Game オブジェクトへ追加します。
162 text                            新しい Text オブジェクトを作成後に Game オブジェクトへ追加します。
163 animate                         新しい Animate オブジェクトを作成後に Game オブジェクトへ追加します。
164 sound                           新しい Sound オブジェクトを作成後に Game オブジェクトへ追加します。
165 map                             新しい Map オブジェクトを作成後に Game オブジェクトへ追加します。
166 ================        =================================================================================
167
168 .. index:: 
169         pair: 2D ゲームエンジン; GameObject クラス
170
171 GameObject クラス
172 =================
173
174 この表はクラスの属性です。
175
176 ============    =====================================================================================
177 属性                  説明
178 ============    =====================================================================================
179 enabled                 True/False によりオブジェクトの状態 (活動または休止) を決定します
180 x                               オブジェクトの x 位置を数値で決定します。
181 y                               オブジェクトの y 位置を数値で決定します。
182 width                   オブジェクトの幅を数値で決定します。
183 height                  オブジェクトの高さを数値で決定します。
184 nIndex                  数値によりオブジェクトの ID を決定します。
185 name                    文字列によりオブジェクト名を決定します。
186 animate                 True/False によりオブジェクトのアニメーションを行うかどうか決定します。
187 move                    True/False によりキーボードでオブジェクトの画像を移動するかどうか決定します。
188 Scaled                  True/False によりオブジェクトの画像の寸法を変更するかどうか決定します。
189 draw                    オブジェクトの描画時に呼び出される関数です。
190 state                   オブジェクトのアニメーションで呼び出される関数です。
191 keypress                キーが押し下げられた時に呼び出される関数です。
192 mouse                   マウスイベント発生時に呼び出される関数です。 
193 ============    =====================================================================================
194
195 この表はクラスのメソッドです。
196
197 ==============================  ================================================================
198 メソッド                                            説明
199 ==============================  ================================================================
200 keyboard(oGame,nkey)                    キーボードイベントを返します。
201 mouse(oGame,nType,aMouseList)   マウスイベントを確認します。
202 rgb(r,g,b)                                              RGB (赤色、緑色、および青色) 値で新しい色を返します。
203 ==============================  ================================================================
204
205 .. index:: 
206         pair: 2D ゲームエンジン; Sprite クラス
207
208 Sprite クラス
209 =============
210
211 親クラス : GameObject クラス
212
213 この表はクラスの属性です。
214
215 ============    =================================================================================
216 属性                  説明
217 ============    =================================================================================
218 image                   画像ファイル名を文字列で決定します。
219 point                   数値によりオブジェクトにおける自動移動の制限を決定します。
220 direction               数値により移動方向を決定します。
221 nstep                   数値により移動中の増分または減分を決定します。
222 type                    数値によりゲームでのオブジェクトの種類を決定します (オプション扱い)。
223 transparent     True/False の値により画像の透過を決定します。
224 ============    =================================================================================
225
226 この表はクラスのメソッドです。
227
228 ================        =================================================================================
229 メソッド                    説明
230 ================        =================================================================================
231 Draw(oGame)             オブジェクトを描画します。
232 ================        =================================================================================
233
234 .. index:: 
235         pair: 2D ゲームエンジン; Text クラス
236
237 Text クラス
238 ===========
239
240 親クラス : Sprite クラス
241
242 この表はクラスの属性です。
243
244 ============    =================================================================================
245 属性                  説明
246 ============    =================================================================================
247 size                    数値によりフォントの寸法を決定します。
248 font                    文字列によりフォントのファイル名を決定します。
249 text                    文字列により表示されるテキストを決定します。
250 color                   数値により色を決定します。
251 ============    =================================================================================
252
253 この表はクラスのメソッドです。
254
255 ================        =================================================================================
256 メソッド                    説明
257 ================        =================================================================================
258 Draw(oGame)                     オブジェクトを描画します。
259 ================        =================================================================================
260
261
262 .. index:: 
263         pair: 2D ゲームエンジン; Animate クラス
264
265 Animate クラス
266 ==============
267
268 親クラス : Sprite クラス
269
270 この表はクラスの属性です。
271
272 ============    =================================================================================
273 属性                  説明
274 ============    =================================================================================
275 frames                  数値によりフレーム数を決定します。
276 frame                   数値により有効なフレームを決定します。
277 framewidth              数値によりフレームの幅を決定します。
278 animate                 True/False によりアニメーションの使用を決定します。
279 scaled                  True/False により画像の尺度変更を決定します。
280 ============    =================================================================================
281
282 この表はクラスのメソッドです。
283
284 ================        =================================================================================
285 メソッド                    説明
286 ================        =================================================================================
287 Draw(oGame)             オブジェクトを描画します。
288 ================        =================================================================================
289
290 .. index:: 
291         pair: 2D ゲームエンジン; Sound クラス
292
293 Sound クラス
294 ============
295
296 親クラス : GameObject クラス
297
298 この表はクラスの属性です。
299
300 ============    =================================================================================
301 属性                  説明
302 ============    =================================================================================
303 file                    音声ファイル名を文字列で決定します。
304 once                    True/False によりファイルを一回またはループ再生するかどうかを決定します。
305 ============    =================================================================================
306
307 この表はクラスのメソッドです。
308
309 ================        =================================================================================
310 メソッド                    説明
311 ================        =================================================================================
312 playsound()             音声ファイルを再生します。
313 ================        =================================================================================
314
315 .. index:: 
316         pair: 2D ゲームエンジン; Map クラス
317
318 Map クラス
319 ==========
320
321 親クラス : Sprite クラス
322
323 この表はクラスの属性です。
324
325 ============    =================================================================================
326 属性                  説明
327 ============    =================================================================================
328 aMap                    数値でマップの中身をリストで決定します。
329 aImages                 マップの各番号で使用されている画像をリストで決定します。
330 BlockWidth              ブロックの幅を数値で決定します (デフォルト = 32)。
331 BlockHeight     ブロックの高さを数値で決定します (デフォルト = 32)。
332 Animate                 アニメーションの状態を True/False で決定します。
333 ============    =================================================================================
334
335 この表はクラスのメソッドです。
336
337 ================        =================================================================================
338 メソッド                    説明
339 ================        =================================================================================
340 getvalue(x,y)           項目の値でマップの可視部分を返します。
341 ================        =================================================================================
342
343 .. index:: 
344         pair: 2D ゲームエンジン; ゲームエンジンの用法 - ゲームウィンドウの作成
345
346 ゲームエンジンの用法 - ゲームウィンドウの作成
347 =============================================
348
349 .. code-block:: ring
350
351         Load "gameengine.ring"  # ゲームエンジンへ制御権を与えます。
352
353         func main               # ゲームエンジンから呼び出されます。
354
355                 oGame = New Game        # Game オブジェクトの作成
356                 {
357                         title = "My First Game"
358                 }                       # イベントループの開始
359
360 .. note:: この命令でゲームエンジンに制御権を委譲します。よって、グローバル変数の定義は "gameengine.ring" を読み込む前に行う必要があります。
361
362 スクリーンショット:
363
364 .. image:: gameengineshot1.png
365         :alt: スクリーンショット
366
367 .. index:: 
368         pair: 2D ゲームエンジン; テキストの描画
369
370 ゲームエンジンの用法 - テキストの描画
371 =====================================
372
373 .. code-block:: ring
374
375         Load "gameengine.ring"  # ゲームエンジンへ制御権を与えます。
376
377         func main               # ゲームエンジンから呼び出されます。
378
379                 oGame = New Game        # Game オブジェクトの作成
380                 {
381                         title = "My First Game"
382                         text {
383                                 x = 10  y=50
384                                 animate = false
385                                 size = 20
386                                 file = "fonts/pirulen.ttf"
387                                 text = "game development using ring is very fun!"
388                                 color = rgb(0,0,0)      
389                         }
390                 }               # イベントループの開始
391
392
393 スクリーンショット:
394
395 .. image:: gameengineshot2.png
396         :alt: スクリーンショット
397
398 .. index:: 
399         pair: 2D ゲームエンジン; テキストの移動
400
401 ゲームエンジンの用法 - テキストの移動
402 =========================================
403
404 .. code-block:: ring
405
406         Load "gameengine.ring"  # ゲームエンジンへ制御権を与えます。
407
408         func main               # ゲームエンジンから呼び出されます。
409
410                 oGame = New Game        # Game オブジェクトの作成
411                 {
412                         title = "My First Game"
413                         text {
414                                 x = 10  y=50
415                                 animate = false
416                                 size = 20
417                                 file = "fonts/pirulen.ttf"
418                                 text = "game development using ring is very fun!"
419                                 color = rgb(0,0,0)      # 配色 = 黒色
420                         }
421                         text {
422                                 x = 10  y=150
423                                 # アニメーション部分 =================================
424                                 animate = true                  # アニメーションの使用
425                                 direction = GE_DIRECTION_INCVERTICAL    # y の増分
426                                 point = 400                     # y=400 になるまで継続
427                                 nStep = 3                       # 毎回 y+= 3 を行う
428                                 #=====================================================
429                                 size = 20
430                                 file = "fonts/pirulen.ttf"
431                                 text = "welcome to the real world!"
432                                 color = rgb(0,0,255)            # 配色 = 青色
433                         }
434                 }                                       # イベントループの開始
435
436 スクリーンショット:
437
438 .. image:: gameengineshot3.png
439         :alt: スクリーンショット
440
441 .. index:: 
442         pair: 2D ゲームエンジン; 音声の再生
443
444 ゲームエンジンの用法 - 音声の再生
445 =====================================
446
447 .. code-block:: ring
448
449         Load "gameengine.ring"  # ゲームエンジンへ制御権を与えます。
450
451         func main               # ゲームエンジンから呼び出されます。
452
453                 oGame = New Game        # Game オブジェクトの作成
454                 {
455                         title = "My First Game"
456                         text {
457                                 x = 10  y=50
458                                 animate = false
459                                 size = 20
460                                 file = "fonts/pirulen.ttf"
461                                 text = "game development using ring is very fun!"
462                                 color = rgb(0,0,0)      # 配色 = 黒色
463                         }
464                         text {
465                                 x = 10  y=150
466                                 # アニメーション部分 ======================================
467                                 animate = true                          # アニメーションの使用
468                                 direction = GE_DIRECTION_INCVERTICAL    # y の増分
469                                 point = 400             # y=400 になるまで継続
470                                 nStep = 3               # 毎回 y+= 3 を行う
471                                 #==========================================================
472                                 size = 20
473                                 file = "fonts/pirulen.ttf"
474                                 text = "welcome to the real world!"
475                                 color = rgb(0,0,255)    # 配色 = 青色
476                         }
477                         Sound {                                 # 音声の再生
478                                 file = "sound/music1.wav"       # イベントループの開始
479                         }               
480                 }                                       # イベントループの開始
481
482 .. index:: 
483         pair: 2D ゲームエンジン; アニメーション
484
485 ゲームエンジンの用法 - アニメーション
486 =========================================
487
488 .. code-block:: ring
489
490         Load "gameengine.ring"  # ゲームエンジンへ制御権を与えます。
491
492         func main               # ゲームエンジンから呼び出されます。
493
494           oGame = New Game      # Game オブジェクトの作成
495           {
496                 title = "My First Game"
497
498                 animate {
499                   file = "images/fire.png"
500                   x = 100
501                   y = 200
502                   framewidth = 40
503                   height = 42
504                   nStep = 3      # ディレイで使用
505                   transparent = true
506                   state = func oGame,oSelf {  # エンジンの各フレームで呼び出されます
507                         oSelf {
508                           nStep--
509                           if nStep = 0
510                                 nStep = 3
511                                 if frame < 13      # 13 フレームから構成されるアニメーション
512                                   frame++   # 次のフレームへ移動
513                                 else
514                                   oGame.remove(oself.nIndex)   # オブジェクトの削除
515                                 ok
516                           ok
517                         }
518                   }
519                  }    
520                 
521
522           }          # イベントループの開始
523
524
525 .. image:: gameengineshot5.png
526         :alt: スクリーンショット
527
528 .. index:: 
529         pair: 2D ゲームエンジン; アニメーションと関数
530
531 ゲームエンジンの用法 - アニメーションと関数
532 ===============================================
533
534 .. code-block:: ring
535
536         Load "gameengine.ring"  # ゲームエンジンへ制御権を与えます。
537
538         func main               # ゲームエンジンから呼び出されます。
539
540           oGame = New Game      # Game オブジェクトの作成
541           {
542                 title = "My First Game"
543                 for x = 70 to 700 step 50
544                   for y = 70 to 500 step 50
545                         showfire(oGame,x,y)
546                   next
547                 next
548
549           }          # イベントループの開始
550
551         func showfire oGame,nX,nY
552           oGame {
553                 animate {
554                   file = "images/fire.png"
555                   x = nX
556                   y = nY
557                   framewidth = 40
558                   height = 42
559                   nStep = 3      # ディレイで使用
560                   transparent = true
561                   state = func oGame,oSelf {  # エンジンの各フレームで呼び出されます
562                         oSelf {
563                           nStep--
564                           if nStep = 0
565                                 nStep = 3
566                                 if frame < 13      # 13 フレームから構成されるアニメーション
567                                   frame++   # 次のフレームへ移動
568                                 else
569                                   frame=1
570                                 ok
571                           ok
572                         }
573                   }
574                  }  
575           }
576
577 .. image:: gameengineshot6.png
578         :alt: スクリーンショット
579
580
581 .. index:: 
582         pair: 2D ゲームエンジン; キーボードによる自動移動
583
584 ゲームエンジンの用法 - スプライト - キーボードによる自動移動
585 ============================================================
586
587 .. code-block:: ring
588
589         Load "gameengine.ring"                          # ゲームエンジンへ制御権を与えます。
590
591         func main                                       # ゲームエンジンから呼び出されます。
592
593                 oGame = New Game                        # Game オブジェクトの作成
594                 {
595                         title = "My First Game"
596                         sprite
597                         {
598                                 type = GE_TYPE_PLAYER           # 用法
599                                 x=400 y=400 width=100 height=100
600                                 file = "images/player.png"      
601                                 transparent = true                      
602                                 Animate=false 
603                                 Move=true       # キーボードの矢印キーで移動できます。
604                                 Scaled=true
605                         }
606                 }                                       # イベントループの開始
607
608 .. image:: gameengineshot7.png
609         :alt: スクリーンショット
610
611
612 .. index:: 
613         pair: 2D ゲームエンジン; スプライト - キー入力イベント
614
615 ゲームエンジンの用法 - スプライト - キー入力イベント
616 ====================================================
617
618 .. code-block:: ring
619
620         Load "gameengine.ring"                          # ゲームエンジンへ制御権を与えます。
621
622         func main                                       # ゲームエンジンから呼び出されます。
623
624                 oGame = New Game                        # Game オブジェクトの作成
625                 {
626                         title = "My First Game"
627                         sprite
628                         {
629                                 type = GE_TYPE_PLAYER           # 用法
630                                 x=400 y=400 width=100 height=100
631                                 file = "images/player.png"      
632                                 transparent = true                      
633                                 Animate=false 
634                                 Move=false                      # カスタム移動
635                                 Scaled=true
636                                 keypress = func oGame,oSelf,nKey {
637                                         oSelf { 
638                                                 Switch nKey     
639                                                 on KEY_LEFT     
640                                                         x -= 10                 
641                                                 on KEY_RIGHT
642                                                         x += 10
643                                                 on KEY_UP
644                                                         y -= 10
645                                                 on KEY_DOWN
646                                                         y += 10
647                                                 off
648                                         }
649                                 }
650                         }
651                 }                                       # イベントループの開始
652
653 .. index:: 
654         pair: 2D ゲームエンジン; スプライト - マウスイベント
655
656 ゲームエンジンの用法 - スプライト - マウスイベント
657 ======================================================
658
659 .. code-block:: ring
660
661         Load "gameengine.ring"                          # ゲームエンジンへ制御権を与えます。
662
663         func main                                       # ゲームエンジンから呼び出されます。
664
665                 oGame = New Game                        # Game オブジェクトの作成
666                 {
667                         title = "My First Game"
668                         sprite
669                         {
670                                 type = GE_TYPE_PLAYER           # 用法
671                                 x=400 y=400 width=100 height=100
672                                 file = "images/player.png"      
673                                 transparent = true                      
674                                 Animate=false 
675                                 Move=false                      # カスタム移動
676                                 Scaled=true
677                                 keypress = func oGame,oSelf,nKey {
678                                         oSelf { 
679                                                 Switch nKey     
680                                                 on KEY_LEFT     
681                                                         x -= 10                 
682                                                 on KEY_RIGHT
683                                                         x += 10
684                                                 on KEY_UP
685                                                         y -= 10
686                                                 on KEY_DOWN
687                                                         y += 10
688                                                 off
689                                         }
690                                 }
691                                 mouse = func oGame,oSelf,nType,aMouseList {
692                                         if nType = GE_MOUSE_UP
693                                                 oSelf {
694                                                         x = aMouseList[GE_MOUSE_X]
695                                                         y = aMouseList[GE_MOUSE_Y]
696                                                 }
697                                         ok
698                                 }
699                         }
700                 }                                       # イベントループの開始
701
702 .. index:: 
703         pair: 2D ゲームエンジン; スプライト - ステートイベント
704
705 ゲームエンジンの用法 - スプライト - ステートイベント
706 ========================================================
707
708 .. code-block:: ring
709
710         Load "gameengine.ring"                          # ゲームエンジンへ制御権を与えます。
711
712         func main                                       # ゲームエンジンから呼び出されます。
713
714                 oGame = New Game                        # Game オブジェクトの作成
715                 {
716                         title = "My First Game"
717                         sprite
718                         {
719                                 type = GE_TYPE_PLAYER           # 用法
720                                 x=400 y=400 width=100 height=100
721                                 file = "images/player.png"      
722                                 transparent = true                      
723                                 Animate=false 
724                                 Move=false                      # カスタム移動
725                                 Scaled=true
726                                 keypress = func oGame,oSelf,nKey {
727                                         oSelf { 
728                                                 Switch nKey     
729                                                 on KEY_LEFT     
730                                                         x -= 10                 
731                                                 on KEY_RIGHT
732                                                         x += 10
733                                                 on KEY_UP
734                                                         y -= 10
735                                                 on KEY_DOWN
736                                                         y += 10
737                                                 off
738                                         }
739                                 }
740                                 mouse = func oGame,oSelf,nType,aMouseList {
741                                         if nType = GE_MOUSE_UP
742                                                 oSelf {
743                                                         x = aMouseList[GE_MOUSE_X]
744                                                         y = aMouseList[GE_MOUSE_Y]
745                                                 }
746                                         ok
747                                 }
748                                 state = func oGame,oSelf {
749                                         oself {
750                                                 if x < 0 x = 0 ok
751                                                 if y < 0 y = 0 ok
752                                                 if x > ogame.width-width  
753                                                         x= ogame.width - width ok
754                                                 if y > ogame.height-height 
755                                                         y=ogame.height - height ok
756                                         }
757                                 }
758                         }
759                 }                                       # イベントループの開始
760
761
762 .. index:: 
763         pair: 2D ゲームエンジン; アニメーション - イベント
764
765 ゲームエンジンの用法 - アニメーション - イベント
766 ====================================================
767
768 .. code-block:: ring
769
770         Load "gameengine.ring"                          # ゲームエンジンへ制御権を与えます。
771
772         func main                                       # ゲームエンジンから呼び出されます。
773
774                 oGame = New Game                        # Game オブジェクトの作成
775                 {
776                         title = "My First Game"
777
778                         animate {
779
780                                 file = "images/fbbird.png"
781                                 x = 10
782                                 y = 10
783                                 framewidth = 20
784                                 scaled = true
785                                 height = 50
786                                 width = 50
787                                 nStep = 3
788                                 transparent = true
789
790                                 state = func oGame,oSelf {
791                                         oSelf {
792
793                                                 # アニメーション
794                                                         nStep--
795                                                         if nStep = 0
796                                                                 nStep = 3
797                                                                 if frame < 3
798                                                                         frame++
799                                                                 else
800                                                                         frame=1
801                                                                 ok
802                                                         ok
803
804                                                 # 下へ移動
805                                                         y += 3
806                                                         if y > 550 y=550 ok
807
808                                         }
809
810                                 }
811
812                                 keypress = func ogame,oself,nKey {
813                                         oself {
814                                                 if nkey = key_space
815                                                         y -= 55
816                                                         if y<=0 y=0 ok
817                                                 ok
818                                         }
819                                 }
820
821                                 mouse = func ogame,oself,nType,aMouseList {
822                                         if nType = GE_MOUSE_UP
823                                                 cFunc = oself.keypress
824                                                 call cFunc(oGame,oSelf,Key_Space)
825                                         ok
826                                 }
827                         }
828                 }                                       # イベントループの開始
829
830 スクリーンショット:
831
832 .. image:: gameengineshot11.png
833         :alt: スクリーンショット
834
835 .. index:: 
836         pair: 2D ゲームエンジン; マップ
837
838
839 ゲームエンジンの用法 - マップ
840 =================================
841
842 .. code-block:: ring
843
844         Load "gameengine.ring"        # ゲームエンジンへ制御権を与えます。
845
846         func main          # ゲームエンジンから呼び出されます。
847
848         oGame = New Game      # Game オブジェクトの作成
849         {
850           title = "My First Game"
851
852           Map {
853
854                 blockwidth = 80
855                 blockheight = 80
856
857                 aMap = [
858                         [0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
859                         [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
860                         [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0],
861                         [0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0],
862                         [0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0],
863                         [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
864                         [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
865                         [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0]
866                 ]
867
868                 aImages = ["images/fbwall.png",
869                          "images/fbwallup.png",
870                          "images/fbwalldown.png"]
871
872                 state = func oGame,oSelf {
873                   oSelf {
874                         x -= 3
875                         if x < - 2100  x = 0  ok
876                   }
877                 }
878
879           }
880         }          # イベントループの開始
881
882
883 スクリーンショット:
884
885 .. image:: gameengineshot12.png
886         :alt: スクリーンショット
887
888
889 .. index:: 
890         pair: 2D ゲームエンジン; マップイベント
891
892 ゲームエンジンの用法 - マップイベント
893 =========================================
894
895 .. code-block:: ring
896
897         Load "gameengine.ring"        # ゲームエンジンへ制御権を与えます。
898
899         func main          # ゲームエンジンから呼び出されます。
900
901           oGame = New Game      # Game オブジェクトの作成
902           {
903                 title = "My First Game"
904
905                 Map {
906
907                   blockwidth = 80
908                   blockheight = 80
909
910                   aMap = [
911                            [0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
912                           [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
913                           [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0],
914                           [0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0],
915                           [0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0],
916                           [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
917                           [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
918                           [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0]
919                   ]
920
921                   aImages = ["images/fbwall.png",
922                                  "images/fbwallup.png",
923                                  "images/fbwalldown.png"]
924
925                   state = func oGame,oSelf {
926                         oSelf {
927                           x -= 3
928                           if x < - 2100  x = 0  ok
929                         }
930                   }
931
932                   mouse = func ogame,oself,nType,aMouseList {
933                         if nType = GE_MOUSE_UP
934                           oSelf {
935                                 mX = aMouseList[GE_MOUSE_X]
936                                 mY = aMouseList[GE_MOUSE_Y]
937                                 nValue = GetValue(mX,mY)
938                                 nRow = GetRow(mX,mY)
939                                 nCol = GetCol(mX,mY)
940                                 Switch nValue
941                                 On 1  aMap[nRow][nCol] = 0
942                                 On 2  aMap[nRow][nCol] = 0
943                                 On 3  aMap[nRow][nCol] = 0
944                                 On 0  aMap[nRow][nCol] = 1
945                                 Off
946                           }
947                         ok
948                   }
949
950                 }
951           }          # イベントループの開始
952
953 スクリーンショット:
954
955 .. image:: gameengineshot13.png
956         :alt: スクリーンショット
957
958 .. index:: 
959         pair: 2D ゲームエンジン; オブジェクトと描画処理
960
961 ゲームエンジンの用法 - オブジェクトと描画処理
962 =============================================
963
964 GameObject クラスからオブジェクトを作成するには、 Object キーワード (ゲームエンジンで定義済み) を使用します。
965
966 用例:
967
968 .. code-block:: ring
969
970         Load "gameengine.ring"                          # ゲームエンジンへ制御権を与えます。
971
972         func main                                       # ゲームエンジンから呼び出されます。
973
974                 oGame = New Game                        # Game オブジェクトの作成
975                 {
976                         title = "My First Game"
977                         Object {
978                                 x = 0 y=300 width = 200 height=200
979                                 draw = func oGame,oSelf {
980                                         oSelf {
981                                                 for t = 1 to 210
982                                                         gl_draw_circle(x,y,t,
983                                                         gl_map_rgb(t*random(255),
984                                                         t*2,t*3),1)
985                                                 next
986                                         }
987                                 }
988                                 state = func oGame,oSelf {
989                                         oSelf { 
990                                                 if x <= 800 
991                                                         x+= 3 
992                                                 else
993                                                         x=0
994                                                 ok
995                                         }
996                                 }
997                                 keypress = func oGame,oSelf,nKey {
998                                         oSelf { 
999                                                 Switch nKey     
1000                                                 on KEY_LEFT     
1001                                                         x -= 10                 
1002                                                 on KEY_RIGHT
1003                                                         x += 10
1004                                                 on KEY_UP
1005                                                         y -= 10
1006                                                 on KEY_DOWN
1007                                                         y += 10
1008                                                 off
1009                                         }
1010                                 }
1011                         }
1012
1013                 }                                       # イベントループの開始
1014
1015 スクリーンショット:
1016
1017 .. image:: gameengineshot14.png
1018         :alt: スクリーンショット
1019
1020 用例:
1021
1022 .. code-block:: ring
1023
1024         Load "gameengine.ring"                          # ゲームエンジンへ制御権を与えます。
1025
1026         func main                                       # ゲームエンジンから呼び出されます。
1027
1028                 oGame = New Game                        # Game オブジェクトの作成
1029                 {
1030                         title = "My First Game"
1031                         Object {
1032                                 x = 400 y=300 width = 200 height=200
1033                                 draw = func oGame,oSelf {
1034                                         oSelf {
1035                                                 for t = 1 to 210
1036                                                         gl_draw_rectangle(x+t,y+t,
1037                                                         x+t*2,y+t*2,
1038                                                         gl_map_rgb(t*random(255),
1039                                                         t*2,t*3),1)
1040                                                         gl_draw_rectangle(x+t*2,y+t*2,
1041                                                         x-t*2,y-t*2,
1042                                                         gl_map_rgb(t*random(255),
1043                                                         t*2,t*3),1)
1044                                                 next
1045                                         }
1046                                 }
1047                                 keypress = func oGame,oSelf,nKey {
1048                                         oSelf { 
1049                                                 Switch nKey     
1050                                                 on KEY_LEFT     
1051                                                         x -= 10                 
1052                                                 on KEY_RIGHT
1053                                                         x += 10
1054                                                 on KEY_UP
1055                                                         y -= 10
1056                                                 on KEY_DOWN
1057                                                         y += 10
1058                                                 off
1059                                         }
1060                                 }
1061                         }
1062
1063                 }                                       # イベントループの開始
1064
1065
1066 スクリーンショット:
1067
1068 .. image:: gameengineshot15.png
1069         :alt: スクリーンショット
1070
1071 .. index:: 
1072         pair: 2D ゲームエンジン; Stars Fighter ゲーム
1073
1074 Stars Fighter ゲーム
1075 ====================
1076
1077 Stars Fighter ゲームのソースコード
1078
1079 .. code-block:: ring
1080
1081         # Ring 標準ライブラリ
1082         # 2D ゲームエンジン
1083         # 2016, Mahmoud Fayed <msfclipper@yahoo.com>
1084
1085         oGameState = NULL
1086
1087         load "gameengine.ring"
1088
1089         func main
1090
1091           oGame = New Game
1092
1093           while true
1094
1095                   oGameState = new GameState
1096
1097                   oGame {
1098                         title = "Stars Fighter!"
1099                         sprite
1100                         {
1101                           file = "images/menu1.jpg"
1102                           x = 0 y=0 width=800 height = 600 scaled = true animate = false
1103                           keypress = func ogame,oself,nKey {
1104                                 if nkey = key_esc or nKey = GE_AC_BACK
1105                                   ogame.shutdown()
1106                                 but nKey = key_space
1107                                   oGameState.startplay=true
1108                                   ogame.shutdown=true
1109                                 ok
1110                           }
1111                           mouse = func ogame,oself,nType,aMouseList {
1112                                 if nType = GE_MOUSE_UP
1113                                   oGameState.startplay=true
1114                                   ogame.shutdown=true
1115                                 ok
1116                           }
1117                         }
1118                         text {
1119                           animate = false
1120                           size = 35
1121                           file = "fonts/pirulen.ttf"
1122                           text = "Stars Fighter"
1123                           x = 10  y=50
1124                         }
1125                         text {
1126                           animate = false
1127                           size = 25
1128                           file = "fonts/pirulen.ttf"
1129                           text = "Version 1.0"
1130                           x = 80  y=100
1131                         }
1132                         text {
1133                           animate = false
1134                           size = 16
1135                           file = "fonts/pirulen.ttf"
1136                           text = "(C) 2016, Mahmoud Fayed"
1137                           x = 45  y=140
1138                         }
1139
1140                         text {
1141                           animate = false
1142                           size = 25
1143                           file = "fonts/pirulen.ttf"
1144                           text = "Press Space to start"
1145                           x = 190  y=470
1146                         }
1147                         text {
1148                           animate = false
1149                           size = 20
1150                           file = "fonts/pirulen.ttf"
1151                           text = "Press Esc to Exit"
1152                           x = 260  y=510
1153                         }
1154                         Sound {
1155                           file = "sound/music1.wav"
1156                         }
1157                   }
1158
1159                   if oGameState.startplay
1160                         oGame.refresh()
1161                         playstart(oGame)
1162                         oGame.refresh()
1163                   ok
1164
1165           end
1166
1167         func playstart oGame
1168
1169           oSound = New Sound {
1170                 file = "sound/music2.wav"
1171           }
1172
1173           while true
1174                 play(oGame)
1175                 if ogame.shutdown = true and oGameState.value = 0
1176                   exit
1177                 ok
1178                 ogame.refresh()
1179           end
1180
1181           oSound.Delete()
1182
1183         func play oGame
1184
1185           oGame
1186           {
1187                 FPS = 60
1188                 FixedFPS = 120
1189                 title = "Stars Fighter!"
1190                 sprite
1191                 {
1192                   file = "images/stars.jpg"
1193                   x = 0
1194                   y = 0
1195                   point = -370
1196                   direction = ge_direction_dec
1197                   type = ge_type_background
1198                   state = func ogame,oself {
1199                           oself {
1200                                 if x < -350
1201                                   direction = ge_direction_inc
1202                                   point = 370
1203                                 but x = 0 and direction = ge_direction_inc
1204                                   direction = ge_direction_dec
1205                                   point = -370
1206                                 ok
1207                           }
1208                         }
1209                 }
1210                 sprite
1211                 {
1212                   file = "images/player.png"
1213                   transparent = true
1214                   type = ge_type_player
1215                   x = 400 y =400 width=100 height=100
1216                   animate=false move=true Scaled=true
1217                   mouse = func ogame,oself,nType,aMouseList {
1218
1219                         if not ( aMouseList[GE_MOUSE_X] >= oSelf.x and 
1220                                          aMouseList[GE_MOUSE_X] <= oSelf.x+oSelf.width and
1221                                          aMouseList[GE_MOUSE_Y] >= oself.y and 
1222                                          aMouseList[GE_MOUSE_Y] <= oSelf.y+oSelf.height )
1223
1224                           if nType = GE_MOUSE_DOWN
1225                                 if aMouseList[1] < oSelf.X  # 左
1226                                   oSelf.X -= 100
1227                                 else
1228                                   oSelf.X += 100
1229                                 ok
1230                                 if aMouseList[2] < oSelf.Y  # 上
1231                                   oSelf.Y -= 100
1232                                 else
1233                                   oSelf.Y += 100
1234                                 ok
1235                           ok
1236
1237                         else
1238                           if nType = GE_MOUSE_UP
1239                                 cFunc = oself.keypress
1240                                 call cFunc(oGame,oSelf,Key_Space)
1241                           ok
1242                         ok
1243                   }
1244                   keypress = func oGame,oself,nkey {
1245                         if nkey = key_space
1246                           ogame {
1247                                 sprite {
1248                                   type = ge_type_fire
1249                                   file  = "images/rocket.png"
1250                                   transparent = true
1251                                         x = oself.x + 30
1252                                   y = oself.y - 30
1253                                   width = 30
1254                                   height = 30
1255                                   point = -30
1256                                   nstep = 20
1257                                   direction = ge_direction_decvertical
1258                                   state = func oGame,oSelf {
1259                                         for x in oGame.aObjects
1260                                           if x.type = ge_type_enemy
1261                                                 if oself.x >= x.x and oself.y >= x.y and
1262                                                   oself.x <= x.x + x.width and
1263                                                   oself.y <= x.y + x.height
1264                                                   showfire(oGame,x.x+40,x.y+40)
1265                                                   ogame.remove(x.nindex)
1266                                                   oGameState.score+=10
1267                                                   oGameState.enemies--
1268                                                   checkwin(oGame)
1269                                                   exit
1270                                                 ok
1271                                           ok
1272                                         next
1273                                   }
1274                                 }
1275                           }
1276                         but nkey = key_esc or nKey = GE_AC_BACK ogame.shutdown()
1277                         ok
1278                   }
1279                   state = func oGame,oSelf {
1280                         oself {
1281                           if x < 0 x = 0 ok
1282                           if y < 0 y = 0 ok
1283                           if x > ogame.screen_w-width  x= ogame.screen_w - width ok
1284                           if y > ogame.screen_h-height y=ogame.screen_h-height ok
1285                         }
1286                   }
1287                 }
1288                 for g = 1 to oGameState.enemies
1289                   sprite
1290                   {
1291                         type = ge_type_enemy
1292                         file = "images/enemy.png"
1293                         transparent = true
1294                         x = g*random(50) y =g width=100 height=100
1295                         animate=true Scaled=true
1296                         direction = ge_direction_random
1297                         state = func oGame,oSelf {
1298                           oself {
1299                                 if x < 0 x = 0 ok
1300                                 if y < 0 y = 0 ok
1301                                 if x > ogame.screen_w-width  x= ogame.screen_w - width ok
1302                                 if y > ogame.screen_h-height y=ogame.screen_h-height ok
1303                           }
1304                           if random(100) = 1
1305                                 ogame {
1306                                   sprite {
1307                                         type = ge_type_fire
1308                                         file  = "images/rocket2.png"
1309                                         transparent = true
1310                                         x = oself.x + 30
1311                                         y = oself.y + oself.height+ 30
1312                                         width = 30
1313                                         height = 30
1314                                         point = ogame.screen_h+30
1315                                         nstep = 10
1316                                         direction = ge_direction_incvertical
1317                                         state = func oGame,oSelf {
1318                                           x =  oGame.aObjects[oGameState.playerindex]
1319                                           if oself.x >= x.x and oself.y >= x.y and
1320                                                  oself.x <= x.x + x.width and
1321                                                  oself.y <= x.y + x.height
1322                                                  if oGameState.value > 0
1323                                                    oGameState.value-=10
1324                                                  ok
1325                                                  ogame.remove(oself.nindex)
1326                                                  checkgameover(oGame)
1327                                           ok
1328                                         }
1329                                   }
1330                                 }
1331                           ok
1332                         }
1333                   }
1334                 next
1335                 text {
1336                   size = 30
1337                   file = "fonts/pirulen.ttf"
1338                   text = "Destroy All Enemies!"
1339                   nstep = 3
1340                   color = GE_COLOR_GREEN
1341                   x = 100  y=50
1342                   direction = ge_direction_incvertical
1343                   point = 500
1344                 }
1345                 text {
1346                   animate = false
1347                   point = 400
1348                   size = 30
1349                   file = "fonts/pirulen.ttf"
1350                   text = "Score : " + oGameState.score
1351                   x = 500  y=10
1352                   state = func oGame,oSelf { oSelf { text = "Score : " + oGameState.score } }
1353                 }
1354                 text {
1355                   animate = false
1356                   point = 400
1357                   size = 30
1358                   file = "fonts/pirulen.ttf"
1359                   text = "Energy : " + oGameState.value
1360                   x = 500  y=50
1361                   state = func oGame,oSelf { oSelf { text = "Energy : " + oGameState.value } }
1362                 }
1363                 text {
1364                   animate = false
1365                   point = 400
1366                   size = 30
1367                   file = "fonts/pirulen.ttf"
1368                   text = "Level : " + oGameState.level
1369                   x = 500  y=90
1370                 }
1371           }
1372
1373
1374         func checkwin ogame
1375           if oGameState.gameresult  return ok
1376           if oGameState.enemies = 0
1377                 oGameState.gameresult = true
1378                 oGame {
1379                   if oGameState.level < 30
1380                   text {
1381                         point = 400
1382                         size = 30
1383                         file = "fonts/pirulen.ttf"
1384                         text = "Level Completed!"
1385                         nStep = 3
1386                         x = 500  y=10
1387                         state = func ogame,oself {
1388                           if oself.y >= 400
1389                                 ogame.shutdown = true
1390                                 oGameState.level++
1391                                 oGameState.enemies = oGameState.level
1392                                 oGameState.gameresult = false
1393                           ok
1394                         }
1395                   }
1396                   else
1397                   text {
1398                         point = 400
1399                         size = 30
1400                         nStep = 3
1401                         file = "fonts/pirulen.ttf"
1402                         text = "You Win !!!"
1403                         x = 500  y=10
1404                         state = func ogame,oself {
1405                           if oself.y >= 400
1406                                 ogame.shutdown = true
1407                                 oGameState.value = 0
1408                           ok
1409                         }
1410                   }
1411                   ok
1412                 }
1413           ok
1414
1415         func checkgameover ogame
1416           if oGameState.gameresult  return ok
1417           if oGameState.value <= 0
1418                 oGameState.gameresult = true
1419                 oGame {
1420                   text {
1421                         point = 400
1422                         size = 30
1423                         nStep = 3
1424                         file = "fonts/pirulen.ttf"
1425                         text = "Game Over !!!"
1426                         x = 500  y=10
1427                         state = func ogame,oself {
1428                           if oself.y >= 400
1429                                 ogame.shutdown = true
1430                           ok
1431                         }
1432                   }
1433                 }
1434                 showfire(oGame,oGame.aObjects[oGameState.PlayerIndex].x+40,
1435                                  oGame.aObjects[oGameState.PlayerIndex].y+40)
1436                 oGame.aObjects[oGameState.PlayerIndex].enabled = false
1437                 oGame.remove(oGameState.PlayerIndex)
1438           ok
1439
1440
1441         func showfire oGame,nX,nY
1442           oGame {
1443                 animate {
1444                   file = "images/fire.png"
1445                   x = nX
1446                   y = nY
1447                   framewidth = 40
1448                   height = 42
1449                   nStep = 3
1450                   transparent = true
1451                   state = func oGame,oSelf {
1452                         oSelf {
1453                           nStep--
1454                           if nStep = 0
1455                                 nStep = 3
1456                                 if frame < 13
1457                                   frame++
1458                                 else
1459                                   frame=1
1460                                   oGame.remove(oself.nIndex)
1461                                 ok
1462                           ok
1463                         }
1464                   }
1465                 }
1466           }
1467
1468
1469         class gamestate
1470           score = 0
1471           level = 1
1472           enemies = 1
1473           value = 100
1474           playerindex = 2
1475           gameresult = false
1476           startplay=false
1477
1478 スクリーンショット:
1479
1480 .. image:: starsfighter.png
1481         :alt: Stars Fighter
1482
1483
1484 .. index:: 
1485         pair: 2D ゲームエンジン; Flappy Bird 3000 ゲーム
1486
1487 Flappy Bird 3000 ゲーム
1488 =======================
1489
1490 Flappy Bird 3000 ゲームのソースコード
1491
1492 .. code-block:: ring
1493
1494         # Ring 標準ライブラリ
1495         # 2D ゲームエンジン
1496         # 2016, Mahmoud Fayed <msfclipper@yahoo.com>
1497
1498         oGameState = NULL
1499
1500         Load "gameengine.ring"
1501
1502         func main
1503
1504           oGame = New Game  
1505
1506
1507           while true
1508
1509                 oGameState = New GameState
1510
1511                 oGame {
1512                   title = "Flappy Bird 3000"
1513                   sprite
1514                   {
1515                         file = "images/fbback.png"
1516                         x = 0 y=0 width=800 height = 600 scaled = true animate = false
1517                         keypress = func ogame,oself,nKey {
1518                           if nkey = key_esc or nKey = GE_AC_BACK
1519                                 ogame.shutdown()
1520                           but nKey = key_space
1521                                 oGameState.startplay=true
1522                                 ogame.shutdown=true
1523                           ok
1524                         }
1525                         mouse = func ogame,oself,nType,aMouseList {
1526                           if nType = GE_MOUSE_UP
1527                                 cFunc = oself.keypress
1528                                 call cFunc(oGame,oSelf,Key_Space)
1529                           ok
1530                         }
1531                   }
1532                   text {
1533                         animate = false
1534                         size = 35
1535                         file = "fonts/pirulen.ttf"
1536                         text = "Flappy Bird 3000"
1537                         x = 150  y=50
1538                   }
1539                   text {
1540                         animate = false
1541                         size = 25
1542                         file = "fonts/pirulen.ttf"
1543                         text = "Version 1.0"
1544                         x = 280  y=100
1545                   }
1546                   text {
1547                         animate = false
1548                         size = 16
1549                         file = "fonts/pirulen.ttf"
1550                         text = "(C) 2016, Mahmoud Fayed"
1551                         x = 245  y=140
1552                   }
1553
1554                   text {
1555                         animate = false
1556                         size = 25
1557                         file = "fonts/pirulen.ttf"
1558                         text = "To Win Get Score = 3000"
1559                         x = 150  y=270
1560                   }
1561
1562                   text {
1563                         animate = false
1564                         size = 25
1565                         file = "fonts/pirulen.ttf"
1566                         text = "Press Space to start"
1567                         x = 190  y=470
1568                   }
1569                   text {
1570                         animate = false
1571                         size = 20
1572                         file = "fonts/pirulen.ttf"
1573                         text = "Press Esc to Exit"
1574                         x = 260  y=510
1575                   }
1576
1577                   animate {
1578                         file = "images/fbbird.png"
1579                         x = 200
1580                         y = 200
1581                         framewidth = 20
1582                         scaled = true
1583                         height = 50
1584                         width = 50
1585                         nStep = 3
1586                         transparent = true
1587                         animate = true
1588                         direction = ge_direction_random
1589                         state = func oGame,oSelf {
1590                           oSelf {
1591                                 nStep--
1592                                 if nStep = 0
1593                                   nStep = 3
1594                                   if frame < 3
1595                                         frame++
1596                                   else
1597                                         frame=1
1598                                   ok
1599                                 ok
1600                                 if x <= 0 x=0 ok
1601                                 if y <= 0 y=0 ok
1602                                 if x >= 750 x= 750 ok
1603                                 if y > 550 y=550 ok
1604                           }
1605                         }
1606                   }
1607
1608                   Sound {
1609                         file = "sound/music2.wav"
1610                   }
1611                 }
1612                 if oGameState.startplay
1613                   oGame.refresh()
1614                   playstart(oGame)
1615                   oGame.refresh()
1616                 ok
1617
1618           end
1619
1620
1621         func playstart oGame
1622
1623           oGame {
1624                 FPS = 60
1625                 FixedFPS = 120
1626                 Title = "Flappy Bird 3000"
1627                 Sprite {
1628                   file = "images/fbback.png"
1629                   x = 0 y=0 width=800 height = 600 scaled = true animate = false
1630                   keypress = func ogame,oself,nKey {
1631                         if nkey = key_esc or nKey = GE_AC_BACK
1632                           ogame.shutdown()
1633                         ok
1634                   }
1635                 }
1636
1637                 Map {
1638                   blockwidth = 80
1639                   blockheight = 80
1640                   aMap = [
1641                            [0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
1642                           [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
1643                           [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0],
1644                           [0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0],
1645                           [0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0],
1646                           [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
1647                           [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
1648                           [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0]
1649                         ]
1650                   newmap(aMap)
1651                   aImages = ["images/fbwall.png","images/fbwallup.png",
1652                           "images/fbwalldown.png"]
1653                   state = func oGame,oSelf {
1654                         if oGameState.gameresult = false
1655                           px = oGame.aObjects[3].x
1656                           py = oGame.aObjects[3].y
1657                           oSelf {
1658                                 x -=  3
1659                                 if x < - 2100
1660                                   x = 0
1661                                   newmap(aMap)
1662                                 ok
1663                                 nCol =  getcol(px,0)
1664                                 if nCol=11 or nCol=15 or nCol=19 or nCol=23 or nCol=27
1665                                   if nCol != oGameState.lastcol
1666                                         oGameState.lastcol = nCol
1667                                         oGameState.Score += 100
1668                                         oGame { Sound {
1669                                           once = true
1670                                           file = "sound/sfx_point.wav"
1671                                         } }
1672                                         checkwin(oGame)
1673                                   ok
1674                                 ok
1675                           }
1676                           if  oSelf.getvalue(px+40,py) != 0 or
1677                                   oSelf.getvalue(px+40,py+40) != 0 or
1678                                   oSelf.getvalue(px,py) != 0 or
1679                                   oSelf.getvalue(px,py+40) != 0
1680                                 oGameState.gameresult = true
1681                                 oGame {
1682                                   text {
1683                                         point = 550
1684                                         size = 30
1685                                         nStep = 3
1686                                         file = "fonts/pirulen.ttf"
1687                                         text = "Game Over !!!"
1688                                         x = 500  y=10
1689                                         state = func ogame,oself {
1690                                           if oself.y >= 550
1691                                                   ogame.shutdown = true
1692                                           ok
1693                                                 if oself.y = 90
1694                                                 ogame {
1695                                                   Sound {
1696                                                         once = true
1697                                                         file = "sound/sfx_die.wav"
1698                                                   }
1699                                                 }
1700                                           ok
1701                                         }
1702                                   }
1703                                   Sound {
1704                                         once = true
1705                                         file = "sound/sfx_hit.wav"
1706                                   }
1707                                 }
1708                           ok
1709                         ok
1710                   }
1711                 }
1712
1713                 animate {
1714                   file = "images/fbbird.png"
1715                   x = 10
1716                   y = 10
1717                   framewidth = 20
1718                   scaled = true
1719                   height = 50
1720                   width = 50
1721                   nStep = 3
1722                   transparent = true
1723                   state = func oGame,oSelf {
1724                         oSelf {
1725                           nStep--
1726                           if nStep = 0
1727                                 nStep = 3
1728                                 if frame < 3
1729                                   frame++
1730                                 else
1731                                   frame=1
1732                                 ok
1733                           ok
1734                         }
1735
1736                         if not oGameState.playerwin
1737                           oGameState.down --
1738                           if oGameState.down = 0
1739                                 oGameState.down = 3
1740                                 oself {
1741                                   y += 25
1742                                   if y > 550 y=550 ok
1743                                 }
1744                           ok
1745                         ok
1746
1747                   }
1748                   keypress = func ogame,oself,nKey {
1749                         if oGameState.gameresult = false
1750                           oself {
1751                                 if nkey = key_space
1752                                   y -= 55
1753                                   oGameState.down = 60
1754                                   if y<=0 y=0 ok
1755                                 ok
1756                           }
1757                         ok
1758                   }
1759                   mouse = func ogame,oself,nType,aMouseList {
1760                         if nType = GE_MOUSE_UP
1761                           cFunc = oself.keypress
1762                           call cFunc(oGame,oSelf,Key_Space)
1763                         ok
1764                   }
1765                 }
1766
1767                 text {
1768                   animate = false
1769                   point = 400
1770                   size = 30
1771                   file = "fonts/pirulen.ttf"
1772                   text = "Score : " + oGameState.score
1773                   x = 500  y=10
1774                   state = func oGame,oSelf {
1775                         oSelf { text = "Score : " + oGameState.score }
1776                   }
1777                 }
1778
1779           }
1780
1781         func newmap aMap
1782           aV = [
1783           [1,1,3,0,0,2,1,1],
1784           [1,3,0,0,0,2,1,1],
1785           [1,1,1,3,0,2,1,1],
1786           [1,1,1,3,0,0,0,0],
1787           [0,0,0,0,2,1,1,1],
1788           [0,0,2,1,1,1,1,1],
1789           [0,0,0,2,1,1,1,1],
1790           [1,1,1,3,0,2,1,1],
1791           [1,1,1,1,1,3,0,0],
1792           [3,0,0,2,1,1,1,1],
1793           [3,0,0,2,3,0,0,2]
1794           ]
1795           for x = 10 to 24 step 4
1796                 aVar = aV[ (random(10)+1) ]
1797                 for y = 1 to 8
1798                   aMap[y][x] = aVar[y]
1799                 next
1800           next
1801
1802         func checkwin ogame
1803           if oGameState.score = 3000
1804                 oGameState.gameresult = true
1805                 oGameState.playerwin = true
1806                 oGame {
1807                   text {
1808                         point = 400
1809                         size = 30
1810                         nStep = 3
1811                         file = "fonts/pirulen.ttf"
1812                         text = "You Win !!!"
1813                         x = 500  y=10
1814                         state = func ogame,oself {
1815                           if oself.y >= 400
1816                                 ogame.shutdown = true
1817                                 oGameState.value = 0
1818                           ok
1819                         }
1820                   }
1821                 }
1822           ok
1823
1824         Class GameState
1825           down = 3
1826           gameresult = false
1827           Score = 0
1828           startplay=false
1829           lastcol = 0
1830           playerwin = false
1831
1832 スクリーンショット:
1833
1834 .. image:: flappybird.png
1835         :alt: Flappy Bird 300
1836
1837
1838 .. index:: 
1839         pair: 2D ゲームエンジン; Super Man 2016 ゲーム
1840
1841 Super Man 2016 ゲーム
1842 =====================
1843
1844 Super Man 2016 ゲームのソースコード
1845
1846 .. code-block:: ring
1847
1848         # Ring 標準ライブラリ
1849         # 2D ゲームエンジン
1850         # 2016, Mahmoud Fayed <msfclipper@yahoo.com>
1851
1852         oGameState = NULL
1853
1854         Load "gameengine.ring"
1855
1856         func main
1857
1858           oGame = New Game
1859
1860           while true
1861
1862                 oGameState = new GameState
1863
1864                 oGame {
1865                   title = "Super Man 2016"
1866                   sprite
1867                   {
1868                         file = "images/superman.jpg"
1869                         x = 0 y=0 width=800 height = 600 scaled = true animate = false
1870                         keypress = func ogame,oself,nKey {
1871                           if nkey = key_esc or nKey = GE_AC_BACK
1872                                 ogame.shutdown()
1873                           but nKey = key_space
1874                                 oGameState.startplay=true
1875                                 ogame.shutdown=true
1876                           ok
1877                         }
1878                         mouse = func ogame,oself,nType,aMouseList {    
1879                           if nType = GE_MOUSE_UP
1880                                 oGameState.startplay=true 
1881                                 ogame.shutdown=true 
1882                           ok
1883                         }
1884                         state = func ogame,oself {
1885                           oself {
1886                                 if x > -500
1887                                   x-=1
1888                                   y-=1
1889                                   width +=1
1890                                   height +=4
1891                                 ok
1892                           }
1893                         }
1894                   }
1895                   text {
1896                         animate = false
1897                         size = 35
1898                         file = "fonts/pirulen.ttf"
1899                         text = "Super Man 2016"
1900                         x = 20  y=30
1901                   }
1902                   text {
1903                         animate = false
1904                         size = 25
1905                         file = "fonts/pirulen.ttf"
1906                         text = "Version 1.0"
1907                         x = 20  y=80
1908                   }
1909                   text {
1910                         animate = false
1911                         size = 16
1912                         file = "fonts/pirulen.ttf"
1913                         text = "(C) 2016, Mahmoud Fayed"
1914                         x = 20  y=120
1915                   }
1916
1917                   text {
1918                         animate = false
1919                         size = 25
1920                         file = "fonts/pirulen.ttf"
1921                         text = "Press Space to start"
1922                         x = 190  y=470
1923                   }
1924                   text {
1925                         animate = false
1926                         size = 20
1927                         file = "fonts/pirulen.ttf"
1928                         text = "Press Esc to Exit"
1929                         x = 260  y=510
1930                   }
1931
1932                   animate {
1933                         file = "images/superman.png"
1934                         x = 200
1935                         y = 200
1936                         framewidth = 68
1937                         scaled = true
1938                         height = 86
1939                         width = 60
1940                         nStep = 10
1941                         transparent = true
1942                         animate = true
1943                         direction = ge_direction_random
1944                         state = func oGame,oSelf {
1945                           oSelf {
1946                                 nStep--
1947                                 if nStep = 0
1948                                   nStep = 10
1949                                   if frame < 1
1950                                         frame++
1951                                   else
1952                                         frame=1
1953                                   ok
1954                                 ok
1955                                 if x <= 0 x=0 ok
1956                                 if y <= 0 y=0 ok
1957                                 if x >= 750 x= 750 ok
1958                                 if y > 550 y=550 ok
1959                           }
1960                         }
1961                   }
1962
1963                   Sound {
1964                         file = "sound/music2.wav"
1965                   }
1966                 }
1967                 if oGameState.startplay
1968                   oGame.refresh()
1969                   playstart(oGame)
1970                   oGame.refresh()
1971                 ok
1972
1973           end
1974
1975
1976         func playstart oGame
1977
1978           oGame {
1979                 FPS = 60
1980                 FixedFPS = 15
1981                 Title = "Super Man 2016"
1982                 Sprite {
1983                   file = "images/supermancity.jpg"
1984                   x = 0 y=0 width=800 height = 600 scaled = true animate = false
1985                 }
1986                 Map {
1987                   blockwidth = 80
1988                   blockheight = 80
1989                   aMap = [
1990                           [0,0,0,4,4,4,0,0,0,1,0,0,0,1,4,4,0,1,0,0,0,0,4,4,0,1,4,
1991         4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,1,0,0,0,1,0,0,0,1,0,3,3,3,5,3,3,3,3,0],
1992                           [0,0,4,0,4,0,4,0,0,1,0,0,0,3,4,4,4,1,0,0,0,0,4,4,0,1,4,
1993         4,4,0,0,4,4,4,4,4,4,4,4,4,4,4,4,1,4,1,0,0,0,1,0,0,0,1,0,4,4,4,4,4,4,4,4,0],
1994                           [0,0,0,4,4,4,0,0,0,1,0,0,0,4,4,4,4,1,0,0,0,0,0,0,0,3,4,
1995         4,4,0,0,4,0,0,0,0,0,0,4,2,0,0,4,1,4,1,4,2,4,1,0,2,0,1,0,4,4,4,4,4,4,4,4,0],
1996                           [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
1997         0,0,0,0,4,4,4,4,4,4,4,4,1,0,0,4,1,4,1,4,1,4,1,0,1,0,1,0,2,2,2,2,2,2,2,2,0],
1998                           [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
1999         0,0,0,0,2,0,0,0,0,0,2,0,3,0,0,0,1,4,1,4,1,4,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0],
2000                           [0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0,2,0,0,0,0,0,
2001         0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,4,3,4,1,4,3,0,1,0,3,0,1,0,0,0,0,0,0,0,0],
2002                           [0,0,2,0,0,2,0,0,2,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,
2003         0,0,0,0,1,0,0,0,0,0,3,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0],
2004                           [0,0,1,0,0,1,0,0,1,3,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,
2005         0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0]
2006                         ]
2007                   aImages = ["images/smwall.png","images/smwallup.png",
2008                           "images/smwalldown.png","images/smstar.png",
2009                           "images/smkey.png","images/smstar2.png"]
2010                 }
2011
2012                 sprite {
2013                   type = ge_type_enemy
2014                   animate = false
2015                   file  = "images/smhome.png"
2016                   x = 5000
2017                   y = 400
2018                   width = 290
2019                   height = 200
2020                   transparent = true
2021
2022                   state = func oGame,oSelf {
2023                         oself {
2024                           x = 5000 +  oGame.aObjects[2].x
2025                           if x < 0 or x > SCREEN_W return ok
2026                         }
2027                         if oGameState.gameresult or oGameState.DoorKey = false  return ok
2028                         if oGame.aObjects[oGameState.playerindex].x > oself.x + 100 and
2029                           oGame.aObjects[oGameState.playerindex].y > oself.y + 50
2030                           oGameState.gameresult = true
2031                           oGame {
2032                                 sprite {
2033                                   file = "images/smwin.jpg"
2034                                   x=0 y=0 width=800 height=600
2035                                   scaled = true animate=false
2036                                   state = func ogame,oself {
2037                                         oself {
2038                                           x-=5
2039                                           y-=5
2040                                           width +=10
2041                                           height +=10
2042                                           if x = -300
2043                                                 ogame.shutdown = true
2044                                           ok
2045                                         }
2046                                   }
2047                                 }
2048                           }
2049                         ok
2050                   }
2051
2052                 }
2053
2054                 animate {
2055                   file = "images/superman.png"
2056                   x = 0
2057                   y = 0
2058                   framewidth = 60
2059                   scaled = true
2060                   height = 86
2061                   width = 60
2062                   nStep = 3
2063                   transparent = true
2064                   state = func oGame,oSelf {
2065
2066                         checkstarskeycol(oGame,oSelf)
2067
2068                         if not oGameState.playerwin
2069                                 oself {
2070                                   file = "images/superman.png"
2071                                   height = 86
2072                                   width = 60
2073                                   for t=1 to 8
2074                                         if checkwall2(oGame,oSelf,0,5,[2,1])
2075                                           y += 5
2076                                         else
2077                                           exit
2078                                         ok
2079                                   next
2080                                   if y > 500 y=500 ok
2081                                 }
2082                         ok
2083
2084                   }
2085                   keypress = func ogame,oself,nKey {
2086                         if oGameState.gameresult = false
2087
2088                           oself {
2089                                 if nkey = key_up  and checkwall(oGame,oSelf,0,-40)
2090                                   oGameState.value -= 1
2091                                   checkgameover(oGame)
2092                                   file = "images/supermanup.png"
2093                                   height = 123
2094                                   dotransparent()
2095                                   y -= 40
2096                                   oGameState.down = 10
2097                                   if y<=0 y=0 ok
2098                                 but nkey = key_down and checkwall(oGame,oSelf,0,40)
2099                                   file = "images/supermandown.png"
2100                                   dotransparent()
2101                                   y += 40
2102                                   if y>=500 y=500 ok
2103                                 but nKey = key_right and checkwall(oGame,oSelf,10,0)
2104                                   file = "images/supermanright.png"
2105                                   dotransparent()
2106                                   x += 10
2107                                   if x >= 440
2108                                         if oGame.aObjects[2].x > -4500
2109                                           oGame.aObjects[2].x -= 50
2110                                           callenemystate(oGame)
2111                                         else
2112                                           if x <= 750
2113                                                 if  checkwall(oGame,oSelf,10,0)
2114                                                   x += 10
2115                                                 ok
2116                                           else
2117                                                 if  checkwall(oGame,oSelf,-10,0)
2118                                                   x -= 10
2119                                                 ok
2120                                           ok
2121                                           return
2122                                         ok
2123                                         x=400
2124                                   ok
2125                                 but nKey = key_left and checkwall(oGame,oSelf,-10,0)
2126                                   file = "images/supermanleft.png"
2127                                   dotransparent()
2128                                   x -= 10
2129                                   if x <= 0
2130                                         x += 10
2131                                         if oGame.aObjects[2].x != 0
2132                                           oGame.aObjects[2].x += 50
2133                                           callenemystate(oGame)
2134                                           x += 50
2135                                         ok
2136                                   ok
2137                                 but nkey = key_esc or nKey = GE_AC_BACK
2138                                   ogame.shutdown()
2139                                 ok
2140                           }
2141                         ok
2142                   }
2143                   mouse = func ogame,oself,nType,aMouseList {  
2144                         if nType = GE_MOUSE_DOWN
2145                           oGameState.moveplayer = TRUE
2146                         But nType = GE_MOUSE_UP
2147                           oGameState.moveplayer = FALSE
2148                         ok
2149                         if oGameState.moveplayer = TRUE
2150                           if aMouseList[GE_MOUSE_X] < oSelf.X  # 左
2151                                 cFunc = oself.keypress  
2152                                 call cFunc(oGame,oSelf,Key_left)
2153                           else
2154                                 cFunc = oself.keypress  
2155                                 call cFunc(oGame,oSelf,Key_right)
2156                           ok
2157                           if aMouseList[GE_MOUSE_Y] < oSelf.Y  # 上
2158                                 cFunc = oself.keypress  
2159                                 call cFunc(oGame,oSelf,Key_up)
2160                           else
2161                                 cFunc = oself.keypress  
2162                                 call cFunc(oGame,oSelf,Key_down)
2163                           ok
2164                         ok        
2165                   }
2166                 }
2167
2168                 addenemy(oGame,600)
2169                 addenemy(oGame,900)
2170                 addenemy(oGame,1550)
2171                 addenemy(oGame,2350)
2172                 addenemy(oGame,3350)
2173                 addenemy(oGame,3500)
2174                 addenemy(oGame,3670)
2175                 addenemy(oGame,3840)
2176
2177                 text {
2178                   animate = false
2179                   point = 400
2180                   size = 30
2181                   file = "fonts/pirulen.ttf"
2182                   text = "Score : " + oGameState.score
2183                   x = 500  y=0
2184                   state = func oGame,oSelf {
2185                         oSelf { text = "Score : " + oGameState.score }
2186                   }
2187                 }
2188
2189                 text {
2190                   animate = false
2191                   point = 400
2192                   size = 30
2193                   file = "fonts/pirulen.ttf"
2194                   text = "Energy : " + oGameState.value
2195                   x = 10  y=0
2196                   state = func oGame,oSelf { oSelf { text = "Energy : " + oGameState.value } }
2197                 }
2198           }
2199
2200
2201         func inlist nValue,aList
2202           for x in aList
2203                 if x = nValue
2204                   return true
2205                 ok
2206           next
2207           return false
2208
2209         func checkwall oGame,oself,diffx,diffy
2210           alist = [1,2,3]
2211           return checkwall2(oGame,oself,diffx,diffy,aList)
2212
2213         func checkwall2 oGame,oself,diffx,diffy,aList
2214           xPos = oSelf.x + diffx
2215           yPos = oSelf.y + diffy
2216           nValue = oGame.aObjects[2].getvalue(xPos,yPos)
2217           nValue = inlist(nValue,aList)
2218           nValue = not nValue
2219           if nValue = 0 return nValue ok
2220
2221           xPos = oSelf.x + diffx
2222           yPos = oSelf.y + diffy + oSelf.height
2223           nValue = oGame.aObjects[2].getvalue(xPos,yPos)
2224           nValue = inlist(nValue,aList)
2225           nValue = not nValue
2226           if nValue = 0 return nValue ok
2227
2228           xPos = oSelf.x + diffx + oSelf.width
2229           yPos = oSelf.y + diffy
2230           nValue = oGame.aObjects[2].getvalue(xPos,yPos)
2231           nValue = inlist(nValue,aList)
2232           nValue = not nValue
2233           if nValue = 0 return nValue ok
2234
2235           xPos = oSelf.x + diffx + oSelf.width
2236           yPos = oSelf.y + diffy + oSelf.height
2237           nValue = oGame.aObjects[2].getvalue(xPos,yPos)
2238           nValue = inlist(nValue,aList)
2239           nValue = not nValue
2240           if nValue = 0 return nValue ok
2241
2242           return nValue
2243
2244         func checkopenwall oGame
2245           if oGameState.score = 900
2246                 oGame.aObjects[2].aMap[3][10] = 3
2247                 oGame.aObjects[2].aMap[4][10] = 0
2248                 oGame.aObjects[2].aMap[5][10] = 0
2249                 oGame.aObjects[2].aMap[6][10] = 0
2250                 oGame.aObjects[2].aMap[7][10] = 0
2251                 oGame.aObjects[2].aMap[8][10] = 0
2252           but oGameState.score = 1800
2253                 oGame.aObjects[2].aMap[3][18] = 3
2254                 oGame.aObjects[2].aMap[4][18] = 0
2255                 oGame.aObjects[2].aMap[5][18] = 0
2256                 oGame.aObjects[2].aMap[6][18] = 0
2257                 oGame.aObjects[2].aMap[7][18] = 0
2258                 oGame.aObjects[2].aMap[8][18] = 0
2259           but oGameState.score = 5500
2260                 oGame.aObjects[2].aMap[1][44] = 0
2261                 oGame.aObjects[2].aMap[2][44] = 0
2262                 oGame.aObjects[2].aMap[3][44] = 2
2263           ok
2264
2265
2266         func checkgameover ogame
2267           if oGameState.gameresult  return ok
2268           if oGameState.value <= 0
2269                 oGameState.value = 0
2270                 oGameState.gameresult = true
2271                 oGame {
2272                   text {
2273                         point = 400
2274                         size = 30
2275                         nStep = 9
2276                         file = "fonts/pirulen.ttf"
2277                         text = "Game Over !!!"
2278                         x = 500  y=10
2279                         state = func ogame,oself {
2280                           if oself.y >= 400
2281                                 ogame.shutdown = true
2282                           ok
2283                         }
2284                   }
2285                 }
2286                 showfire(oGame,oGame.aObjects[oGameState.PlayerIndex].x+40,
2287                          oGame.aObjects[oGameState.PlayerIndex].y+40)
2288                 oGame.aObjects[oGameState.PlayerIndex].enabled = false
2289                 oGame.remove(oGameState.PlayerIndex)
2290           ok
2291
2292
2293         func showfire oGame,nX,nY
2294           oGame {
2295                 animate {
2296                   file = "images/fire.png"
2297                   x = nX
2298                   y = nY
2299                   framewidth = 40
2300                   height = 42
2301                   nStep = 3
2302                   transparent = true
2303                   state = func oGame,oSelf {
2304                         oSelf {
2305                           nStep--
2306                           if nStep = 0
2307                                 nStep = 3
2308                                 if frame < 13
2309                                   frame++
2310                                 else
2311                                   frame=1
2312                                   oGame.remove(oself.nIndex)
2313                                 ok
2314                           ok
2315                         }
2316                   }
2317                 }
2318           }
2319
2320         func addenemy oGame,xPos
2321           oGame {
2322                 lbraceend = false
2323                 sprite {
2324                         type = ge_type_enemy
2325                         file = "images/smenemy.png"
2326                         transparent = true
2327                         x = xPos y =10 width=100 height=100
2328                         animate=true Scaled=true
2329                         direction = GE_DIRECTION_NOMOVE
2330                         temp = xPos
2331                         state = func oGame,oSelf {
2332                           oself {
2333                                 x = oSelf.temp +  oGame.aObjects[2].x
2334                                 if y < 0 y = 0 ok
2335                                 if y > 100 y=100 ok
2336                                 if x > SCREEN_W or x < 0 return ok
2337                           }
2338
2339                           if random(10) = 1
2340                                 if oGameState.gameresult return ok
2341                                 ogame {
2342                                   sprite {
2343                                         type = ge_type_fire
2344                                         file  = "images/smrocket.png"
2345                                         scaled  = true
2346                                         transparent = true
2347                                         x = oself.x + 30
2348                                         y = oself.y + oself.height+ 30
2349                                         width = 30
2350                                         height = 30
2351                                         point = ogame.screen_h+30
2352                                         nstep = 30
2353                                         direction = ge_direction_incvertical
2354                                         xvalue =  oGame.aObjects[2].x
2355                                         temp = oself.x + 30 - xvalue
2356                                         state = func oGame,oSelf {
2357                                           oself { x = oSelf.temp +  oGame.aObjects[2].x  }
2358                                           x =  oGame.aObjects[oGameState.playerindex]
2359                                           if oself.x >= x.x and oself.y >= x.y and
2360                                                  oself.x <= x.x + x.width and
2361                                                  oself.y <= x.y + x.height
2362                                                  if oGameState.value > 0
2363                                                    oGameState.value-=1000
2364                                                  ok
2365                                                  ogame.remove(oself.nindex)
2366                                                  checkgameover(oGame)
2367                                           ok
2368                                         }
2369                                   }
2370                                 }
2371                           ok
2372                         }
2373                   }
2374           }
2375           ogame.lbraceend = true
2376
2377
2378         func checkstarskey oGame,oSelf,nValue,nRow,nCol
2379           switch nValue
2380                 on 4
2381                   oGame.aObjects[2].aMap[nRow][nCol] = 6
2382                   oGameState.Score += 100
2383                   checkopenwall(oGame)
2384                   oGame { Sound {
2385                         once = true
2386                         file = "sound/sfx_point.wav"
2387                   } }
2388                 on 5
2389                   oGame.aObjects[2].aMap[nRow][nCol] = 0
2390                   oGameState.DoorKey = true
2391                   oGameState.Score += 500
2392                   checkopenwall(oGame)
2393                   oGame { Sound {
2394                         once = true
2395                         file = "sound/sfx_point.wav"
2396                   } }
2397           off
2398
2399         func checkstarskeycol oGame,oSelf
2400           nValue = oGame.aObjects[2].getvalue(oSelf.x,oSelf.y)
2401           nRow = oGame.aObjects[2].getrow(oSelf.x,oSelf.y)
2402           nCol = oGame.aObjects[2].getcol(oSelf.x,oSelf.y)
2403           checkstarskey(oGame,oSelf,nValue,nRow,nCol)
2404
2405           nValue = oGame.aObjects[2].getvalue(oSelf.x+oSelf.width,oSelf.y+oSelf.height)
2406           nRow = oGame.aObjects[2].getrow(oSelf.x+oSelf.width,oSelf.y+oSelf.height)
2407           nCol = oGame.aObjects[2].getcol(oSelf.x+oSelf.width,oSelf.y+oSelf.height)
2408           checkstarskey(oGame,oSelf,nValue,nRow,nCol)
2409
2410           nValue = oGame.aObjects[2].getvalue(oSelf.x+oSelf.width,oSelf.y)
2411           nRow = oGame.aObjects[2].getrow(oSelf.x+oSelf.width,oSelf.y)
2412           nCol = oGame.aObjects[2].getcol(oSelf.x+oSelf.width,oSelf.y)
2413           checkstarskey(oGame,oSelf,nValue,nRow,nCol)
2414
2415           nValue = oGame.aObjects[2].getvalue(oSelf.x,oSelf.y+oSelf.height)
2416           nRow = oGame.aObjects[2].getrow(oSelf.x,oSelf.y+oSelf.height)
2417           nCol = oGame.aObjects[2].getcol(oSelf.x,oSelf.y+oSelf.height)
2418           checkstarskey(oGame,oSelf,nValue,nRow,nCol)
2419
2420         func callenemystate oGame
2421           for t in oGame.aObjects
2422                 t {
2423                   if type = GE_TYPE_ENEMY
2424                         call state(oGame,t)
2425                   ok
2426                 }
2427           next
2428
2429         Class GameState
2430
2431           down = 3
2432           gameresult = false
2433           Score = 0
2434           startplay=false
2435           lastcol = 0
2436           playerwin = false
2437           DoorKey = false
2438           playerindex = 4
2439           value = 1000
2440           moveplayer = false
2441
2442 スクリーンショット:
2443
2444 .. image:: superman.png
2445         :alt: Super Man 2016
2446
2447