Emacsã§ç°¡åã«ã²ã¼ã ãä½ããgamegrid.el
ãã®è¨äºã¯ãEmacsアドベントカレンダー 18æ¥ç®ã®è¨äºã§ãã
ã¡ãã£ã¨Emacsã§ããããã£ã¦ *1 ãããçµµçãªãã®ãæ¸ãããããããã調ã¹ã¦ããã¡ã«gamegrid.elã«åºä¼ãã¾ããã
gamegrid.elã¯ãEmacsæ¬ä½ã«å梱ããã¦ãããã¾ãã«gridãªgameãä½ãããã®ããã±ã¼ã¸ã§ãã
gamegrid.elã§èª¿ã¹ãã¨ãããããåºã¦ãã¾ãããemacsã«å
èµããã¦ããpongã¨ãsnakeãtetrisãªããã«ä½¿ããã¦ãã¾ãã
ããã¦ã使ãããããããããããããã£ã¦ã使ã£ã¦ã¿ãçè¨äºããã£ã¦ã使ãæ¹ãããããããªãã£ã(ã¿ã¤ãããªãã£ããã©ãinfoã«è©²å½ã»ã¯ã·ã§ã³ãã£ããããã®ããªï¼)ã®ã§ãå®é使ããã¦ãããã®ãã½ã¼ã¹ã³ã¼ããªã¼ãã£ã³ã°ããªãã使ã£ã¦ã¿ã¾ããã
ã½ã¼ã¹ã³ã¼ããªã¼ãã£ã³ã°ããä¸ã§ã¯ãsnakeã²ã¼ã ã®ã½ã¼ã¹ã³ã¼ããããããããã£ããtetrisã¯ã¡ãã£ã¨è¤éã
github.com
ä½ã£ããã®
ããããä¸ããéã£ã¦ãããã£ã©ãé¿ããã²ã¼ã ããã¼å ¥åå¨ãã®ã¨ãããè¥å¹²ããããã
å 容ã¨è§£èª¬
ç解ãããã¦ãªãã¨ãããããã®ã§ãééãããã°ããµã«ãªãã ããã
ã©ããã£ã¦æç»ããã
(defconst sample1-player 0) (defconst sample1-block 1) (defconst sample1-blank 7) (defconst sample1-border 8) (defconst sample1-space 9)
gamegridã®åã®ã¨ãããgridãã¼ã¹ãªã®ã§ãx, y座æ¨ã«å¯¾ãã¦ããã®ã»ã«ãä½ã§ããããæå®ãããã¨ã«ãªãããã®æå®ã®ããã®å®æ°å®ç¾©ã
(defvar sample1-player-options '(((glyph colorize) (t ?\040)) ((color-x color-x) (mono-x grid-x) (color-tty color-tty)) (((glyph color-x) [1 0 0]) (color-tty "red"))))
(defun sample1-display-options () "." (let ((options (make-vector 256 nil))) (dotimes (c 256) (aset options c (cond ((= c sample1-blank) sample1-blank-options) ((= c sample1-player) sample1-player-options) ((= c sample1-block) sample1-block-options) ((= c sample1-border) sample1-border-options) ((= c sample1-space) sample1-space-options) (t '(nil nil nil))))) options))
å
ã®å®æ°ãããã使ã£ã¦ãã©ã®ã»ã«ãã©ãæç»ãããã決ããã¨ãããXã®å ´åã¯ã [1 0 0]ã®ããã«vectorã§ãr g bã0ãã1ã®ç¯å²ã§è¨å®ããã
ã¿ã¼ããã«ã®å ´åã¯ã"red"ã®ããã«ãæå®ã§ãããã¿ã¼ããã«ã®å ´åã«ãªã«ã使ããã®ãã¯èª¿ã¹ã¦ãªãã
ã¾ããXã使ãå ´åã¯ãç»åãxpmå½¢å¼ã§æå®ã§ããã¯ããæªæå®ã®å ´åã¯ãããã©ã«ãã®ãããã¯ç»åã使ãããã
ãã®è¾ºãé§ä½¿ããããã以ä¸ã®åæåå¦çã§ããããè¨å®ããã
åæåå¦çã¨æ¯ã¿ã¼ã³ã®æç»
åºæ¬çã«ã¯ã¡ã¸ã£ã¼ã¢ã¼ãæ¸ãã¦ä½ãæãããã以å¤ã®gamegridç¹æã®å 容ã ã¨ä»¥ä¸ãªæã
(defun sample1-start-game () "." (interactive) (sample1-reset-game) ;;(use-local-map sample1-mode-map) (gamegrid-start-timer sample1-tick 'sample1-update-game))
gamegrid-start-timerã§ä½ããªç§ééã§ã©ã®é¢æ°ãã³ã¼ã«ããããè¨å®ã§ããããã®ã¿ã¤ãã¼ééãFPSç¶æãããããªä»çµã«ãªã£ã¦ããã©ããã¯æªèª¿æ»ã
sample1-reset-gameã®ä¸ã§ã¯ã (gamegrid-kill-timer)ã§ã¿ã¤ãã¼ã念ã®çºãªã»ãã + 以ä¸ã®ãããªæãã§ãgamegrid-init-bufferã«ãããgamegridã§æç»ããç¯å²ã¨åæå¤ãæå®ãã¦ããã
(defun sample1-init-buffer () "." (gamegrid-init-buffer sample1-width (+ 2 sample1-height) sample1-space) (let ((buffer-read-only nil)) (dotimes (y sample1-height) (dotimes (x sample1-width) (gamegrid-set-cell x y sample1-space)))))
ã¤ãã§ã«ãgamegrid-set-cellã使ããã¨ã§ãæå®ããã»ã«ãå¥ã®å
容ã«å¡ãæ¿ãããã¨ãã§ããã
ãªã®ã§ãupdateã®å
容ããå¤æ´ç¹ãè¨ç®ãã¦ããã£ã©ã移åããå ´åã¯ãåã®æå»ã®ã»ã«ãæ¶ãã¦ãæ°ãã座æ¨ã®ã»ã«ãæç»ãããã¨ãã®å¦çããããã¨ã«ãªãã
ã²ã¼ã ã®çµäº
(defun sample1-stop-game () "." (interactive) (gamegrid-kill-timer) (gamegrid-add-score "sample1-scores" sample1-total-cell))
gamegrid-add-scoreã使ããã¨ã§ããã¤ã¹ã³ã¢ã©ã³ãã³ã°(ãã ããã¼ã«ã«)ãç°¡åã«ä½ãã¦ä¾¿å©
ãã®ä»
ã°ãªãããããã¯ä»¥å¤ã«èªåãæç»ãããã®ã使ãããããã®ã§ã試ãã¦ã¿ããã
ã¾ã¨ã
ãªããæ¨ã使ããããªãããªã¼ã¨æãã®ã§ãããæ´æ°ãæ¿ãããã®ãä½ãã«ã¯é©ãã¦ãªã(çµæ§ãã¥ã¼ãã³ã°ãå¿ è¦)ãããªã®ã§ããã¯ãã¹çãªã²ã¼ã ã¨ãä½ãã®ã«ã¯åãã¦ããã§ãã
*1:æ«æãããã©éä¸ã¾ã§èªåãç§å£ãããããNESã¨ãã¥ã¬ã¼ã¿ä½ãã¨ãã£ãã¨æ¸ãã¦ãããªã®ã§ãgongoããã®ã¢ããã³ãã«ã¬ã³ãã¼ãã¨ã¦ã楽ãã¿ã§ã