Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

Pixelmator Pro AppleScriptコンテストで優勝

Posted on 10月 11, 2020 by Takaaki Naganoya

LateNight Software主催の「Pixelmator Pro AppleScriptコンテスト」で優勝しました。応募作品はPixelmatorもぐらたたきゲームです。

応募するにあたって、まず最初に、「まともにPixelmator Proの機能を活用する」か「Pixelmator Proの機能を無視する」かの2つの方向のどちらを採用するかを考えました。

100行以内というレギュレーションがけっこう厳しかったので、前者のアプローチだとすぐに限界に達するように思われました。それ以前に、使いこなしてもいない、ほぼ初見のアプリケーションを相手に有用なAppleScriptを書くのはほぼ無理といってよいでしょう。実際に対象のアプリケーションを使いこなして、そのアプリケーションが想定しているワークフローをこなしてみて、自分の意図するデータを作って、その作業の中で不満に思ったり効率がよくない点をAppleScriptで補っていくのが「普通のAppleScript」の書かれ方でしょう。

短期間でコンテストに投稿するとなると、ウケ狙いでアプリケーション全体の機能を理解せず一部の機能に着目してまったく関係のない用途のものを作る必要があると判断しました。

もうちょっと使いこなすための期間が長ければ、Pixelmator Proの機能を使い込んで、Pixelmator Proならではのソリューションも出てきたと思います。

なので、Pixelmator Pro AppleScriptコンテストの賞品であるところのPixelmator Pro v1.8を使えれば、「本来こういうものがあるべき」というScriptを書くことも可能だと思われます。

告知ページには、

To celebrate the introduction of AppleScript support in Pixelmator Pro 1.8 I’m giving away three copies of Pixelmator Pro. 

と、明記されているので「Pixelmator Pro」(macOS版)が賞品だと思っていたのですが、なぜか送られてきたのが「Pixelmator Photo」(iOS版)のコードで、何か手違いが生じただけだと思いたいのですが、どんなものなんでしょう? → 報告したらちゃんとPixelmator Proのコードが届きました。ねんのため

Pixelmatorもぐら叩きゲームについて


◀︎開発中のFMバトラー(1999年)

1999年のMacWorldExpo/Tokyoでデモを行った「FMバトラー」で、すでに「まったくゲーム用ではないアプリケーション(FileMaker Pro)を使ってゲームを作るという経験がありました。

基本的には、Pixelmator Pro書類上に並べたレイヤーの表示状態を制御して、パラパラアニメを表示。その一方でModifier Keyのキースキャンを行なって、ユーザーからの操作を受け取っています。

レギュレーションに「Script Debugger上で動作すること」という項目があり、Modifier Keyのスキャンであれば最前面にいないScript Debuggerでも問題なくスキャンできるため、対応が可能でした。

プログラムは、とにかく短く書くことが課題で、初期段階ではキースキャン部分だけで20行を超えていたものを大幅に短くしています。

もぐら叩きの本体部分もモグラが3段階で迫ってくるという設定を作り、step 1とstep 2の状態でユーザーからの入力があったら「お手つき」的な失敗を行ったという処理をしています。step 3の状態でのみもぐらの撃退が可能で、そのことをデータで表現しています。

set moleList to {{"Mole1", false, 20}, {"Mole2", false, 10}, {"Mole3", true, 20}}

良くも悪くも「Pixelmator Proでゲームを作ろう」という着想自体がすべてであり、プログラム自体はそれほど複雑でも高尚でもありません。

–> Download Piyomaru Whack-3-moles Game(実行に必要なPixelmator Pro書類)

プログラム自体を掲載していてもあまり参考にならないとは思いますが、本来作りたかった「もぐらが同時に3匹出てくるもぐら叩きゲーム」は見てみたいので、より高度なバージョンに書き換えた人がいればぜひ見せてください(^ー^;

最後に、Pixelmator Proもぐらたたきのグラフィックについて。8bit時代のピコピコゲーム(この部分、Google翻訳で非日本語話者に意味が通じるのだろうか?)を彷彿とさせる簡単さで「たいした手数はかけていない」ことが伝わることを重視しています。Pixelmator Proは写真の加工など高い能力を持ったグラフィックソフトなわけですが、あえてグラフィックソフトらしい写実的かつ写真をベースとした生々しいもぐらの絵を使うことは避けました。

また、あからさまにゲームであることがわかるよう背景も単純な色とし、一般的なPixelmator Proの利用シーンとは異なる状況下にあることをユーザーに知らせるように設計しました。絵心のある人ならもっと凝ったグラフィックを描いて表示するはずですが、そういう作り込み要素を排することで「自分にも作れそうだ」という印象を持ってもらうことを重視しています。あと、生き物の殺生を思わせるような生々しい表現(流血とか)は避けています。

AppleScript名:Mole Game v1.1.1a.scpt
–  Created by: Takaaki Naganoya
–  Created on: 2020/09/29
–  Copyright © 2020 Piyomaru Software, All Rights Reserved
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit" — for NSEvent

set aScore to 0
set aMiss to 0
set maxMole to 3 —change mole attack number
set delayCount to 300 –delay speed. Faster machine needs larger number.

tell application "Pixelmator Pro"
  activate
  
if (exists of document "Piyomaru Whack-3-moles Game") = false then
    display dialog "There is no Piyomaru document" buttons {"OK"} default button 1 with icon 1
    
return
  end if
  
  
tell document "Piyomaru Whack-3-moles Game"
    set visible of layer "Mole1" to false
    
set visible of layer "Mole2" to false
    
set visible of layer "Mole3" to false
    
set visible of layer "Mole3Hit" to false
    
set visible of layer "Mole3Miss" to false
    
    
repeat 10 times
      tell layer "Title"
        set its visible to true
        
set keyRes to keyscanWait(delayCount, true) of me
        
set its visible to false
        
set keyRes to keyscanWait(delayCount, true) of me
        
if keyRes = true then exit repeat
      end tell
    end repeat
    
    
delay 1
    
    
set moleList to {{"Mole1", false, 20}, {"Mole2", false, 10}, {"Mole3", true, 20}}
    
repeat maxMole times
      repeat with i in moleList
        copy i to {layerName, hitLogic, delayTime}
        
set visible of layer layerName to true
        
set keyRes to keyscanWait((random number from 1 to delayTime) * delayCount, hitLogic) of me
        
set visible of layer layerName to false
        
        
if keyRes = true then
          set hitF to true
          
set aScore to aScore + 1
          
beep
          
set visible of layer "Mole3Hit" to true
          
delay 1
          
set visible of layer "Mole3Hit" to false
          
exit repeat
        else if keyRes = false then
          set aMiss to aMiss + 1
          
repeat 3 times
            set visible of layer "Mole3Miss" to true
            
delay 0.5
            
set visible of layer "Mole3Miss" to false
            
delay 0.5
          end repeat
          
set keyRes to true –To Skip See off action
          
exit repeat
        end if
      end repeat
      
      
if keyRes is not equal to true then
        set aMiss to aMiss + 1
        
repeat 3 times
          set visible of layer "Mole3Miss" to true
          
delay 0.5
          
set visible of layer "Mole3Miss" to false
          
delay 0.5
        end repeat
      end if
    end repeat
    
    
display dialog "Score:" & (aScore as string) & return & "Miss:" & (aMiss as string) with title "GAME OVER" buttons {"OK"} default button 1 with icon 1
    
  end tell
end tell

on keyscanWait(delayLoop, hitLogic)
  repeat delayLoop times
    set commandStatus to not ((((current application’s NSEvent’s modifierFlags() as integer) div (current application’s NSShiftKeyMask as integer)) mod 2) = 0)
    
if commandStatus = true then return hitLogic
  end repeat
  
return missing value
end keyscanWait

★Click Here to Open This Script 

More from my site

  • FileMaker選手権2020に3作品応募、3作品入賞FileMaker選手権2020に3作品応募、3作品入賞
  • Pixelmator Pro AppleScriptコンテストに「もぐら叩きゲーム」を応募Pixelmator Pro AppleScriptコンテストに「もぐら叩きゲーム」を応募
  • Pixelmator Pro 1.8 AppleScriptコンテスト開催Pixelmator Pro 1.8 AppleScriptコンテスト開催
  • Pixelmator Proでアイコン書き出しv2Pixelmator Proでアイコン書き出しv2
  • Pixelmator Pro v2.4.1で新機能追加+AppleScriptコマンド追加Pixelmator Pro v2.4.1で新機能追加+AppleScriptコマンド追加
  • Pixelmator Proで指定の画像を複数の3D LUTを用いてカラー調整して画像書き出しPixelmator Proで指定の画像を複数の3D LUTを用いてカラー調整して画像書き出し
(Visited 69 times, 1 visits today)
Posted in GAME | Tagged 10.15savvy Pixelmator Pro | 1 Comment

1 thoughts on “<span>Pixelmator Pro AppleScriptコンテストで優勝</span>”

  1. 12/10/21
    5:04 PM
    2021年12月10日
    5:04 PM

    Reply

    2020年に書いた価値あるAppleScript – AppleScriptの穴 says:

    […] Pixelmator Pro AppleScriptコンテストで優勝 […]

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • UI Browserがgithub上でソース公開され、オープンソースに
  • Xcode 14.2でAppleScript App Templateを復活させる
  • macOS 13 TTS Voice環境に変更
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • AS関連データの取り扱いを容易にする(はずの)privateDataTypeLib
  • macOS 12.5.1、11.6.8でFinderのselectionでスクリーンショット画像をopenできない問題
  • macOS 13でNSNotFoundバグふたたび
  • ChatGPTでchatに対する応答文を取得
  • 新発売:iWork Scripting Book with AppleScript
  • Finderの隠し命令openVirtualLocationが発見される
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • あのコン過去ログビューワー(暫定版)

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (185) 13.0savvy (55) CotEditor (60) Finder (47) iTunes (19) Keynote (98) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (56) Pages (37) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC