├── monkey.jungle ├── resources-edge ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources ├── images │ ├── cloud.png │ ├── dino.png │ ├── ground.png │ ├── b-cactus-1.png │ ├── b-cactus-2.png │ ├── b-cactus-3.png │ ├── dino-bump.png │ ├── s-cactus-1.png │ ├── s-cactus-2.png │ ├── s-cactus-3.png │ ├── restart-btn.png │ ├── pterodactyl-up.png │ ├── dino-left-leg-up.png │ ├── dino-right-leg-up.png │ ├── pterodactyl-down.png │ ├── dino-crouched-left-leg-up.png │ └── dino-crouched-right-leg-up.png ├── drawables │ ├── launcher_icon.png │ ├── backdrop.xml │ └── drawables.xml ├── properties.xml ├── menus │ └── menu.xml ├── strings │ └── strings.xml └── layouts │ └── about.xml ├── resources-edge1030 ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-edge530 ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-edge820 ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-edge830 ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-edge_1000 ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-edge_520 ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-oregon7xx ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-rino7xx ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-edge520plus ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-edgeexplore ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-vivoactive_hr ├── properties.xml ├── drawebles │ └── backdrop.xml └── layouts │ └── about.xml ├── resources-edge1030bontrager ├── properties.xml └── drawebles │ └── backdrop.xml ├── resources-round-218x218 ├── properties.xml ├── drawebles │ └── backdrop.xml └── layouts │ └── about.xml ├── resources-round-240x240 ├── properties.xml ├── drawebles │ └── backdrop.xml └── layouts │ └── about.xml ├── resources-round-260x260 ├── properties.xml ├── drawebles │ └── backdrop.xml └── layouts │ └── about.xml ├── resources-round-280x280 ├── properties.xml ├── drawebles │ └── backdrop.xml └── layouts │ └── about.xml ├── resources-round-390x390 ├── properties.xml ├── drawebles │ └── backdrop.xml └── layouts │ └── about.xml ├── properties.example.mk ├── source ├── trexGame │ ├── enums │ │ └── keys.mc │ ├── Constants.mc │ ├── GameCharacter.mc │ ├── Ground.mc │ ├── Cloud.mc │ ├── Obstacle.mc │ ├── Trex.mc │ └── TrexGameProcess.mc ├── GarminTrexGameAboutView.mc ├── GameManager.mc ├── GarminTrexGameAboutViewDelegate.mc ├── App.mc ├── GarminTrexGameMenuDelegate.mc ├── GarminTrexGameView.mc └── GarminTrexGameInputDelegate.mc ├── .project ├── GarminTrexGame.iml ├── Makefile ├── LICENSE ├── README.md ├── .gitignore └── manifest.xml /monkey.jungle: -------------------------------------------------------------------------------- 1 | project.manifest = manifest.xml 2 | -------------------------------------------------------------------------------- /resources-edge/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 307 3 | -------------------------------------------------------------------------------- /resources/images/cloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/cloud.png -------------------------------------------------------------------------------- /resources/images/dino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/dino.png -------------------------------------------------------------------------------- /resources-edge1030/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 347 3 | -------------------------------------------------------------------------------- /resources-edge530/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 253 3 | -------------------------------------------------------------------------------- /resources-edge820/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 213 3 | -------------------------------------------------------------------------------- /resources-edge830/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 213 3 | -------------------------------------------------------------------------------- /resources-edge_1000/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 307 3 | -------------------------------------------------------------------------------- /resources-edge_520/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 243 3 | -------------------------------------------------------------------------------- /resources-oregon7xx/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 283 3 | -------------------------------------------------------------------------------- /resources-rino7xx/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 273 3 | -------------------------------------------------------------------------------- /resources/images/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/ground.png -------------------------------------------------------------------------------- /resources-edge520plus/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 253 3 | -------------------------------------------------------------------------------- /resources-edgeexplore/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 287 3 | -------------------------------------------------------------------------------- /resources-vivoactive_hr/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 173 3 | -------------------------------------------------------------------------------- /resources/images/b-cactus-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/b-cactus-1.png -------------------------------------------------------------------------------- /resources/images/b-cactus-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/b-cactus-2.png -------------------------------------------------------------------------------- /resources/images/b-cactus-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/b-cactus-3.png -------------------------------------------------------------------------------- /resources/images/dino-bump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/dino-bump.png -------------------------------------------------------------------------------- /resources/images/s-cactus-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/s-cactus-1.png -------------------------------------------------------------------------------- /resources/images/s-cactus-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/s-cactus-2.png -------------------------------------------------------------------------------- /resources/images/s-cactus-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/s-cactus-3.png -------------------------------------------------------------------------------- /resources-edge1030bontrager/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 347 3 | -------------------------------------------------------------------------------- /resources-round-218x218/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 163 3 | 4 | -------------------------------------------------------------------------------- /resources-round-240x240/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 173 3 | 4 | -------------------------------------------------------------------------------- /resources-round-260x260/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 183 3 | 4 | -------------------------------------------------------------------------------- /resources-round-280x280/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 193 3 | 4 | -------------------------------------------------------------------------------- /resources-round-390x390/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 263 3 | 4 | -------------------------------------------------------------------------------- /resources/images/restart-btn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/restart-btn.png -------------------------------------------------------------------------------- /resources/images/pterodactyl-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/pterodactyl-up.png -------------------------------------------------------------------------------- /resources/drawables/launcher_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/drawables/launcher_icon.png -------------------------------------------------------------------------------- /resources/images/dino-left-leg-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/dino-left-leg-up.png -------------------------------------------------------------------------------- /resources/images/dino-right-leg-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/dino-right-leg-up.png -------------------------------------------------------------------------------- /resources/images/pterodactyl-down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/pterodactyl-down.png -------------------------------------------------------------------------------- /resources/images/dino-crouched-left-leg-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/dino-crouched-left-leg-up.png -------------------------------------------------------------------------------- /resources/images/dino-crouched-right-leg-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andryuha49/GarminTrexGame/HEAD/resources/images/dino-crouched-right-leg-up.png -------------------------------------------------------------------------------- /properties.example.mk: -------------------------------------------------------------------------------- 1 | DEVICE=vivoactive 2 | SDK_HOME=/data/garmin/connectiq-sdk-3.1.7 3 | PRIVATE_KEY=/data/garmin/developer_key.der 4 | DEPLOY=/data/garmin/APPS/ 5 | -------------------------------------------------------------------------------- /source/trexGame/enums/keys.mc: -------------------------------------------------------------------------------- 1 | module TrexGame { 2 | module Enums { 3 | 4 | module Keys { 5 | enum { 6 | HIGH_SCORE_KEY 7 | } 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /resources/properties.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 137 6 | -------------------------------------------------------------------------------- /resources/menus/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /source/trexGame/Constants.mc: -------------------------------------------------------------------------------- 1 | module TrexGame { 2 | module Constants { 3 | const PIXELS_SPEED = 9; 4 | const CLOUD_PIXELS_SPEED = 1; 5 | 6 | const SCORE_TIMER_INTERVAL = 100; 7 | 8 | const START_TIMER_INTERVAL = 140; 9 | } 10 | } -------------------------------------------------------------------------------- /resources/drawables/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge1030/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge530/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge820/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge830/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge_1000/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge_520/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-oregon7xx/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-rino7xx/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge520plus/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edgeexplore/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-round-218x218/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-round-240x240/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-round-260x260/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-round-280x280/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-round-390x390/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-vivoactive_hr/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources-edge1030bontrager/drawebles/backdrop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /source/GarminTrexGameAboutView.mc: -------------------------------------------------------------------------------- 1 | using Toybox.WatchUi; 2 | 3 | class GarminTrexGameAboutView extends WatchUi.View { 4 | function initialize() { 5 | View.initialize(); 6 | } 7 | 8 | // Load your resources here 9 | function onLayout(dc) { 10 | setLayout(Rez.Layouts.AboutLayout(dc)); 11 | } 12 | } -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | GarminTrexGame 4 | 5 | 6 | 7 | 8 | 9 | connectiq.builder 10 | 11 | 12 | 13 | 14 | 15 | connectiq.projectNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /source/GameManager.mc: -------------------------------------------------------------------------------- 1 | using Toybox.Application; 2 | 3 | class GameManager { 4 | var game; 5 | 6 | function initialize() { 7 | 8 | } 9 | 10 | function getCurrentGame() { 11 | return game; 12 | } 13 | 14 | function makeNewGame() { 15 | if(game != null) { 16 | game.end(); 17 | } 18 | game = new TrexGame.TrexGameProcess(); 19 | game.start(1); 20 | 21 | return game; 22 | } 23 | 24 | function drawGameLayout(dc) { 25 | var game = new TrexGame.TrexGameProcess(); 26 | game.drawLayout(dc); 27 | } 28 | } -------------------------------------------------------------------------------- /source/GarminTrexGameAboutViewDelegate.mc: -------------------------------------------------------------------------------- 1 | using Toybox.System; 2 | using Toybox.WatchUi; 3 | 4 | class GarminTrexGameAboutViewDelegate extends WatchUi.InputDelegate { 5 | function initialize() { 6 | InputDelegate.initialize(); 7 | } 8 | 9 | function onKey(keyEvent) { 10 | WatchUi.popView(WatchUi.SLIDE_DOWN); 11 | return true; 12 | } 13 | 14 | function onTap(clickEvent) { 15 | WatchUi.popView(WatchUi.SLIDE_DOWN); 16 | return true; 17 | } 18 | 19 | function onSwipe(swipeEvent) { 20 | WatchUi.popView(WatchUi.SLIDE_DOWN); 21 | return true; 22 | } 23 | } -------------------------------------------------------------------------------- /resources/strings/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GarminTrexGame 3 | 0.0.5 4 | VER: 5 | 6 | Author: 7 | Home page: 8 | 9 | GAME OVER 10 | 11 | Play 12 | About 13 | Exit 14 | 15 | //github.com/andryuha49/ 16 | GarminTrexGame 17 | Andriy Zherdiy 18 | 19 | -------------------------------------------------------------------------------- /source/trexGame/GameCharacter.mc: -------------------------------------------------------------------------------- 1 | using Toybox.WatchUi; 2 | 3 | module TrexGame { 4 | class GameCharacter { 5 | var bitmap; 6 | var xPosition = 0; 7 | var yPosition = 0; 8 | 9 | function initialize(rezId, locX, locY) { 10 | xPosition = locX; 11 | yPosition = locY; 12 | bitmap = new WatchUi.Bitmap({:rezId=>rezId,:locX=>locX,:locY=>locY}); 13 | } 14 | 15 | function getDimensions() { 16 | return bitmap.getDimensions(); 17 | } 18 | 19 | function getX() { 20 | return xPosition; 21 | } 22 | 23 | function getY() { 24 | return yPosition; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /GarminTrexGame.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /source/App.mc: -------------------------------------------------------------------------------- 1 | using Toybox.Application; 2 | using Toybox.WatchUi; 3 | 4 | class App extends Application.AppBase { 5 | var gameManager; 6 | 7 | function initialize() { 8 | AppBase.initialize(); 9 | gameManager = new GameManager(); 10 | } 11 | 12 | // onStart() is called on application start up 13 | function onStart(state) { 14 | } 15 | 16 | // onStop() is called when your application is exiting 17 | function onStop(state) { 18 | } 19 | 20 | // Return the initial view of your application here 21 | function getInitialView() { 22 | return [ 23 | new GarminTrexGameView(gameManager), 24 | new GarminTrexGameInputDelegate(gameManager) 25 | ]; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /source/GarminTrexGameMenuDelegate.mc: -------------------------------------------------------------------------------- 1 | using Toybox.WatchUi; 2 | using Toybox.System; 3 | 4 | class GarminTrexGameMenuDelegate extends WatchUi.MenuInputDelegate { 5 | hidden var gameManager; 6 | 7 | function initialize(pGameManager) { 8 | MenuInputDelegate.initialize(); 9 | gameManager = pGameManager; 10 | } 11 | 12 | function onMenuItem(item) { 13 | if (item == :play) { 14 | var curentGame = gameManager.makeNewGame(); 15 | curentGame.start(1); 16 | } else if (item == :about) { 17 | WatchUi.pushView(new GarminTrexGameAboutView(), new GarminTrexGameAboutViewDelegate(), WatchUi.SLIDE_UP); 18 | } else if (item == :exit) { 19 | System.exit(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /source/trexGame/Ground.mc: -------------------------------------------------------------------------------- 1 | using Toybox.WatchUi; 2 | 3 | module TrexGame { 4 | class Ground { 5 | 6 | hidden var groundYPosition; 7 | hidden var screenWidth; 8 | hidden var groundBitmap; 9 | hidden var step = 0; 10 | 11 | function initialize(pGroundYPosition, pScreenWidth) { 12 | screenWidth = pScreenWidth; 13 | groundYPosition = pGroundYPosition - 13; 14 | groundBitmap = new WatchUi.Bitmap({:rezId=>Rez.Drawables.ground,:locX=>0,:locY=>groundYPosition}); 15 | } 16 | 17 | function draw(dc) { 18 | groundBitmap.draw(dc); 19 | } 20 | 21 | function move() { 22 | var width = groundBitmap.getDimensions()[0]; 23 | if (width < screenWidth + step) { 24 | step = 0; 25 | } 26 | groundBitmap.setLocation(0 - step, groundYPosition); 27 | step = step + Constants.PIXELS_SPEED; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /resources/layouts/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include properties.mk 2 | 3 | appName = `grep entry manifest.xml | sed 's/.*entry="\([^"]*\).*/\1/'` 4 | devices = `grep 'iq:product id' manifest.xml | sed 's/.*iq:product id="\([^"]*\).*/\1/'` 5 | 6 | build: 7 | $(SDK_HOME)/bin/monkeyc \ 8 | --jungles ./monkey.jungle \ 9 | --release \ 10 | --device $(DEVICE) \ 11 | --output bin/$(appName).prg \ 12 | --private-key $(PRIVATE_KEY) \ 13 | --warn 14 | 15 | buildall: 16 | @for device in $(devices); do \ 17 | echo "-----"; \ 18 | echo "Building for" $$device; \ 19 | $(SDK_HOME)/bin/monkeyc \ 20 | --jungles ./monkey.jungle \ 21 | --device $$device \ 22 | --output bin/$(appName)-$$device.prg \ 23 | --private-key $(PRIVATE_KEY) \ 24 | --warn; \ 25 | done 26 | 27 | run: build 28 | @$(SDK_HOME)/bin/connectiq;\ 29 | sleep 3 &&\ 30 | $(SDK_HOME)/bin/monkeydo bin/$(appName).prg $(DEVICE) 31 | 32 | deploy: build 33 | @cp bin/$(appName).prg $(DEPLOY) 34 | 35 | package: 36 | @$(SDK_HOME)/bin/monkeyc \ 37 | --jungles ./monkey.jungle \ 38 | --package-app \ 39 | --release \ 40 | --output bin/$(appName).iq \ 41 | --private-key $(PRIVATE_KEY) \ 42 | --warn 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Andriy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /resources-round-218x218/layouts/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /resources-round-240x240/layouts/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /resources-round-260x260/layouts/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /resources-round-280x280/layouts/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /resources-round-390x390/layouts/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /resources-vivoactive_hr/layouts/about.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | -------------------------------------------------------------------------------- /source/GarminTrexGameView.mc: -------------------------------------------------------------------------------- 1 | using Toybox.WatchUi; 2 | using Toybox.Timer; 3 | 4 | using Toybox.Math; 5 | 6 | class GarminTrexGameView extends WatchUi.View { 7 | var gameManager; 8 | var screenWidth; 9 | 10 | function initialize(pGameManager) { 11 | WatchUi.View.initialize(); 12 | gameManager = pGameManager; 13 | } 14 | 15 | // Load your resources here 16 | function onLayout(dc) { 17 | screenWidth = dc.getWidth(); 18 | } 19 | 20 | // Called when this View is brought to the foreground. Restore 21 | // the state of this View and prepare it to be shown. This includes 22 | // loading resources into memory. 23 | function onShow() { 24 | } 25 | 26 | // Update the view 27 | function onUpdate(dc) { 28 | var game = gameManager.getCurrentGame(); 29 | if (game != null) { 30 | game.onUpdate(dc); 31 | } else { 32 | gameManager.drawGameLayout(dc); 33 | } 34 | } 35 | 36 | // Called when this View is removed from the screen. Save the 37 | // state of this View here. This includes freeing resources from 38 | // memory. 39 | function onHide() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /source/trexGame/Cloud.mc: -------------------------------------------------------------------------------- 1 | using Toybox.WatchUi; 2 | 3 | module TrexGame { 4 | class Cloud { 5 | 6 | hidden var cloudBitmap; 7 | hidden var cloudYPosition = 30; 8 | hidden var screenWidth; 9 | hidden var step = 0; 10 | 11 | function initialize(pGroundYPosition, pScreenWidth) { 12 | screenWidth = pScreenWidth; 13 | cloudYPosition = pGroundYPosition - 107; 14 | cloudBitmap = new WatchUi.Bitmap({:rezId=>Rez.Drawables.cloud,:locX=>pScreenWidth,:locY=>cloudYPosition}); 15 | } 16 | 17 | function draw(dc) { 18 | cloudBitmap.draw(dc); 19 | } 20 | 21 | function move() { 22 | var width = cloudBitmap.getDimensions()[0]; 23 | if (step - width > screenWidth) { 24 | makeNewCloud(); 25 | } 26 | 27 | cloudBitmap.setLocation(screenWidth - step, cloudYPosition); 28 | step = step + Constants.CLOUD_PIXELS_SPEED; 29 | } 30 | 31 | hidden function makeNewCloud() { 32 | step = 0; 33 | var r = Math.rand() % 2; 34 | cloudYPosition = r == 0 ? 20 : 30; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /resources/drawables/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Garmin Trex Game 2 | This is implementation of T-Rex dino game from Chrome offline mode 3 | # 4 | 5 | This is a seed project for writing [Garmin Connect IQ](http://developer.garmin.com/connect-iq/) applications. Instead of using the Eclipse plugin (which works rather poorly...), 6 | you can use any text editor of your choice and **compile**, **run** or **package** your project using *make*. 7 | 8 | ## Links 9 | - [Garmin Connect IQ store](https://apps.garmin.com/en-US/apps/c3f58c63-8e46-49cd-9baa-fb0196da0165) 10 | - [Demo video](https://youtu.be/qg9V9x0KdGc) 11 | - [](https://youtu.be/qg9V9x0KdGc) 12 | 13 | ## Setup 14 | All you'll need to get started is edit (create) the ```properties.mk``` file. Here's a description of the variables: 15 | 16 | - **DEVICE** - device type you want to use for simulation (e.g. fenix3, vivoactive, epix...) 17 | - **SDK_HOME** - home folder of your SDK (e.g. /Users/me/connectiq-sdk-mac-3.0.4) 18 | - **PRIVATE_KEY** - path to your generated RSA private key for signing apps (needed since CIQ 1.3) (e.g. /home/.ssh/key/id_rsa_garmin.der) 19 | - **DEPLOY** - if you want to hot-deploy to your device, that's the mounted path for the APPS folder (e.g. /Volumes/GARMIN/GARMIN/APPS/) 20 | 21 | ## Targets 22 | - **build** - compiles the app 23 | - **buildall** - compiles the app separately for every device in the SUPPORTED_DEVICES_LIST, packaging appropriate resources. Make sure to have your resource folders named correctly (e.g. /resources-fenix3_hr) 24 | - **run** - compiles and starts the simulator 25 | - **deploy** - if your device is connected via USB, compile and deploy the app to the device 26 | - **package** - create an .iq file for app store submission 27 | 28 | ## How to use? 29 | To execute the **run** target, run ```make run``` from the home folder of your app 30 | 31 | ##### or use **Eclipse** plugin. -------------------------------------------------------------------------------- /source/GarminTrexGameInputDelegate.mc: -------------------------------------------------------------------------------- 1 | using Toybox.System; 2 | using Toybox.WatchUi; 3 | 4 | class GarminTrexGameInputDelegate extends WatchUi.InputDelegate { 5 | hidden var gameManager; 6 | 7 | function initialize(pGameManager) { 8 | InputDelegate.initialize(); 9 | gameManager = pGameManager; 10 | } 11 | 12 | function onKey(keyEvent) { 13 | var key = keyEvent.getKey(); 14 | if (key == WatchUi.KEY_MENU) { 15 | openMenu(); 16 | } 17 | if (key == WatchUi.KEY_ESC) { 18 | openMenu(); 19 | } 20 | if (key == WatchUi.KEY_ENTER || key == WatchUi.KEY_UP) { 21 | onGameTap(); 22 | } 23 | return true; 24 | } 25 | 26 | function onKeyPressed(keyEvent) { 27 | var key = keyEvent.getKey(); 28 | if (key == WatchUi.KEY_DOWN) { 29 | onCrouch(true); 30 | } 31 | return true; 32 | } 33 | 34 | function onKeyReleased(keyEvent) { 35 | var key = keyEvent.getKey(); 36 | if (key == WatchUi.KEY_DOWN) { 37 | onCrouch(false); 38 | } 39 | return true; 40 | } 41 | 42 | function onTap(clickEvent) { 43 | onGameTap(); 44 | return true; 45 | } 46 | 47 | function onSwipe(swipeEvent) { 48 | return true; 49 | } 50 | 51 | hidden function openMenu() { 52 | WatchUi.pushView(new Rez.Menus.MainMenu(), new GarminTrexGameMenuDelegate(gameManager), WatchUi.SLIDE_UP); 53 | } 54 | 55 | hidden function onGameTap() { 56 | var currentGame = gameManager.getCurrentGame(); 57 | if (currentGame == null) { 58 | currentGame = gameManager.makeNewGame(); 59 | } 60 | currentGame.onTap(); 61 | } 62 | 63 | hidden function onCrouch(crouched) { 64 | var currentGame = gameManager.getCurrentGame(); 65 | if (currentGame != null) { 66 | currentGame.crouch(crouched); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | .idea 107 | properties.mk 108 | -------------------------------------------------------------------------------- /source/trexGame/Obstacle.mc: -------------------------------------------------------------------------------- 1 | using Toybox.Math; 2 | 3 | module TrexGame { 4 | class Obstacle extends GameCharacter { 5 | 6 | hidden var groundYPosition; 7 | hidden var screenWidth; 8 | hidden var step = 0; 9 | 10 | var isPtarodactyl = false; 11 | var isPtarodactylUp = false; 12 | 13 | hidden const obsticles = { 14 | 0 => Rez.Drawables.sCactus1, 15 | 1 => Rez.Drawables.sCactus2, 16 | 2 => Rez.Drawables.sCactus3, 17 | 3 => Rez.Drawables.bCactus1, 18 | 4 => Rez.Drawables.bCactus2, 19 | 5 => Rez.Drawables.bCactus3, 20 | 21 | 6 => Rez.Drawables.pterodactylUp 22 | }; 23 | 24 | function initialize(pGroundYPosition, pScreenWidth) { 25 | GameCharacter.initialize(Rez.Drawables.sCactus1, pScreenWidth, 0); 26 | 27 | groundYPosition = pGroundYPosition; 28 | screenWidth = pScreenWidth; 29 | 30 | makeNewObsticle(); 31 | } 32 | 33 | function move() { 34 | var width = bitmap.getDimensions()[0]; 35 | if (step - width > screenWidth) { 36 | makeNewObsticle(); 37 | } 38 | xPosition = screenWidth - step; 39 | bitmap.setLocation(xPosition, yPosition); 40 | step = step + Constants.PIXELS_SPEED; 41 | } 42 | 43 | function draw(dc) { 44 | if (isPtarodactyl == true) { 45 | if (isPtarodactylUp == true) { 46 | bitmap.setBitmap(Rez.Drawables.pterodactylUp); 47 | isPtarodactylUp = false; 48 | } else { 49 | bitmap.setBitmap(Rez.Drawables.pterodactylDown); 50 | isPtarodactylUp = true; 51 | } 52 | } 53 | 54 | bitmap.draw(dc); 55 | } 56 | 57 | function getDimensions() { 58 | return bitmap.getDimensions(); 59 | } 60 | 61 | function makeNewObsticle() { 62 | step = 0; 63 | var random = Math.rand() % 7; // 7 - max obstacles count 64 | 65 | bitmap.setBitmap(obsticles[random]); 66 | // is pterodactyl 67 | if (random == 6) { 68 | makePtarodactyl(); 69 | } else { 70 | makeCactus(); 71 | } 72 | } 73 | 74 | function makePtarodactyl() { 75 | isPtarodactyl = true; 76 | isPtarodactylUp = true; 77 | var height = bitmap.getDimensions()[1]; 78 | var positio = Math.rand() % 2; 79 | yPosition = groundYPosition - height - (positio == 0 ? 20 : 50); 80 | } 81 | 82 | function makeCactus() { 83 | isPtarodactyl = false; 84 | var height = bitmap.getDimensions()[1]; 85 | yPosition = groundYPosition - height; 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | eng 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /source/trexGame/Trex.mc: -------------------------------------------------------------------------------- 1 | module TrexGame { 2 | class Trex extends GameCharacter { 3 | hidden const trexHeight = 47; 4 | hidden const trexCrouchedHeight = 30; 5 | hidden const trexXPosition = 5; 6 | 7 | hidden var trexLeftLegUpBitmap; 8 | hidden var trexRightLegUpBitmap; 9 | 10 | hidden var isJumping = false; 11 | hidden var isJumpingUp = false; 12 | hidden var isJumpingDown = false; 13 | 14 | hidden var isCrouched = false; 15 | 16 | hidden var isLeftLegUp = null; 17 | hidden var isBumped = false; 18 | 19 | hidden var topJumpPosition; 20 | hidden var defaultYPosition; 21 | 22 | function initialize(groundYPosition) { 23 | defaultYPosition = groundYPosition - trexHeight; 24 | topJumpPosition = defaultYPosition - trexHeight * 1.7; 25 | 26 | GameCharacter.initialize(Rez.Drawables.dino, trexXPosition, defaultYPosition); 27 | } 28 | 29 | function draw(dc) { 30 | if (isBumped == true) { 31 | bitmap.setBitmap(Rez.Drawables.dinoBump); 32 | } else if (isJumping) { 33 | bitmap.setBitmap(Rez.Drawables.dino); 34 | } else { 35 | if (isLeftLegUp == null) { 36 | bitmap.setBitmap(Rez.Drawables.dino); 37 | } else { 38 | bitmap.setLocation(xPosition, getY()); 39 | if (isLeftLegUp == true) { 40 | bitmap.setBitmap(isCrouched ? Rez.Drawables.dinoCrouchedLeftLegUp : Rez.Drawables.dinoLeftLegUp); 41 | } else { 42 | bitmap.setBitmap(isCrouched ? Rez.Drawables.dinoCrouchedRightLegUp : Rez.Drawables.dinoRightLegUp); 43 | } 44 | } 45 | } 46 | bitmap.draw(dc); 47 | } 48 | 49 | function move() { 50 | if (isJumping == true) { 51 | if (isJumpingUp == true) { 52 | var y = yPosition - Constants.PIXELS_SPEED; 53 | if (y > topJumpPosition) { 54 | yPosition = y; 55 | } else { 56 | isJumpingUp = false; 57 | isJumpingDown = true; 58 | } 59 | } else { 60 | var y = yPosition + Constants.PIXELS_SPEED; 61 | if (y < defaultYPosition) { 62 | yPosition = y; 63 | } else { 64 | yPosition = defaultYPosition; 65 | isJumping = false; 66 | } 67 | } 68 | } else { 69 | if (isLeftLegUp == true) { 70 | isLeftLegUp = false; 71 | } else { 72 | isLeftLegUp = true; 73 | } 74 | } 75 | bitmap.setLocation(xPosition, yPosition); 76 | } 77 | 78 | function jump() { 79 | isBumped = false; 80 | makeJumpAnimation(); 81 | } 82 | 83 | function crouch(crouched) { 84 | isCrouched = crouched; 85 | } 86 | 87 | function bump() { 88 | isJumping = false; 89 | isCrouched = false; 90 | 91 | isBumped = true; 92 | } 93 | 94 | function getY() { 95 | return isCrouched && !isJumping ? yPosition + 17 : yPosition; 96 | } 97 | 98 | hidden function makeJumpAnimation() { 99 | if (isJumping != true) { 100 | isJumping = true; 101 | makeJumpUpAnimation(); 102 | } 103 | } 104 | 105 | function makeJumpUpAnimation() { 106 | isJumpingUp = true; 107 | isJumpingDown = false; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /source/trexGame/TrexGameProcess.mc: -------------------------------------------------------------------------------- 1 | using Toybox.Timer; 2 | using Toybox.WatchUi; 3 | using Toybox.Math; 4 | using Toybox.Application; 5 | 6 | module TrexGame { 7 | class TrexGameProcess extends WatchUi.InputDelegate { 8 | hidden var timerInterval = Constants.START_TIMER_INTERVAL; 9 | 10 | hidden var restartBtn; 11 | hidden var gameTimer; 12 | hidden var scoreTimer; 13 | hidden var score = 0; 14 | hidden var highScore = 0; 15 | hidden var gameLevel = 1; 16 | 17 | hidden var isGameOver = false; 18 | 19 | hidden var screenWidth = 300; 20 | hidden var screenHeight = 200; 21 | hidden var screenShape; 22 | 23 | hidden var groundYPosition = 137; 24 | 25 | hidden var backdrop; 26 | hidden var cloud; 27 | hidden var clouds = []; 28 | 29 | hidden var cactus; 30 | hidden var cactuses = []; 31 | 32 | hidden var obstacle; 33 | 34 | hidden var trex; 35 | hidden var ground; 36 | 37 | var obstacleLines; 38 | var trexLines; 39 | 40 | function initialize() { 41 | InputDelegate.initialize(); 42 | 43 | var settings = System.getDeviceSettings(); 44 | screenWidth = settings.screenWidth; 45 | screenHeight = settings.screenHeight; 46 | screenShape = settings.screenShape; 47 | 48 | backdrop = new Rez.Drawables.backdrop(); 49 | 50 | groundYPosition = WatchUi.loadResource(Rez.Strings.properties_GroundPosition).toNumber(); 51 | //Application.AppBase.getProperty("GroundPosition"); 52 | 53 | scoreTimer = new Timer.Timer(); 54 | } 55 | 56 | function drawLayout(dc) { 57 | makeGameObjects(); 58 | 59 | backdrop.draw(dc); 60 | cloud.draw(dc); 61 | ground.draw(dc); 62 | trex.draw(dc); 63 | } 64 | 65 | function start(level) { 66 | score = 0; 67 | timerInterval = Constants.START_TIMER_INTERVAL; 68 | isGameOver = false; 69 | if (level != null) { 70 | gameLevel = level; 71 | } 72 | 73 | makeGameObjects(); 74 | 75 | var app = Application.getApp(); 76 | var hiScore = app.getProperty(Enums.Keys.HIGH_SCORE_KEY); 77 | if (hiScore != null) { 78 | highScore = hiScore; 79 | } 80 | 81 | scoreTimer.start(method(:scoreTimerCallback), Constants.SCORE_TIMER_INTERVAL, true); 82 | restartTimer(); 83 | 84 | onTap(); 85 | } 86 | 87 | hidden function restartTimer() { 88 | if (gameTimer == null) { 89 | gameTimer = new Timer.Timer(); 90 | } else { 91 | gameTimer.stop(); 92 | } 93 | gameTimer.start( method(:timerCallback), timerInterval, true ); 94 | } 95 | 96 | hidden function makeGameObjects() { 97 | cloud = new Cloud(groundYPosition, screenWidth); 98 | ground = new Ground(groundYPosition, screenWidth); 99 | obstacle = new Obstacle(groundYPosition, screenWidth); 100 | trex = new Trex(groundYPosition); 101 | } 102 | 103 | function onTap() { 104 | if (isGameOver == true) { 105 | start(gameLevel); 106 | } 107 | trex.jump(); 108 | return true; 109 | } 110 | 111 | function crouch(crouched) { 112 | trex.crouch(crouched); 113 | } 114 | 115 | function onUpdate(dc) { 116 | dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight()); 117 | 118 | backdrop.draw(dc); 119 | cloud.draw(dc); 120 | ground.draw(dc); 121 | trex.draw(dc); 122 | 123 | obstacle.draw(dc); 124 | 125 | dc.setColor(Graphics.COLOR_DK_GRAY, Graphics.COLOR_TRANSPARENT); 126 | drawScores(dc); 127 | 128 | if (isGameOver == true) { 129 | drawGameOver(dc); 130 | } 131 | 132 | // draw lines ariund the characters for debugging 133 | // drawLines(dc); 134 | } 135 | 136 | hidden function drawLines(dc) { 137 | if (obstacleLines != null) { 138 | for (var i = 0; i < obstacleLines.size(); i++) { 139 | dc.drawLine(obstacleLines[i][0], obstacleLines[i][1], obstacleLines[i][2], obstacleLines[i][3]); 140 | } 141 | } 142 | 143 | if (trexLines != null) { 144 | for (var i = 0; i < trexLines.size(); i++) { 145 | dc.drawLine(trexLines[i][0], trexLines[i][1], trexLines[i][2], trexLines[i][3]); 146 | } 147 | } 148 | } 149 | 150 | function end() { 151 | if (gameTimer != null) { 152 | gameTimer.stop(); 153 | } 154 | scoreTimer.stop(); 155 | } 156 | 157 | function timerCallback() { 158 | // pause for first dino jump 159 | if (score > 25) { 160 | obstacle.move(); 161 | } 162 | ground.move(); 163 | cloud.move(); 164 | trex.move(); 165 | 166 | checkBumping(); 167 | 168 | WatchUi.requestUpdate(); 169 | } 170 | 171 | function scoreTimerCallback() { 172 | score = score + 1; 173 | updateTimer(); 174 | } 175 | 176 | hidden function updateTimer() { 177 | if (timerInterval > 50 && score % 100 == 0) { 178 | timerInterval = timerInterval - 10; 179 | restartTimer(); 180 | } 181 | } 182 | 183 | hidden function checkBumping() { 184 | obstacleLines = getCharacterLines(obstacle, 10, 10, 5, 5); 185 | trexLines = getCharacterLines(trex, 5, 5, 10, 10); 186 | 187 | for (var i = 0; i < obstacleLines.size(); i++) { 188 | var isIntersection = shapeIntersection(obstacleLines[i], trexLines); 189 | if (isIntersection == true) { 190 | gameOver(); 191 | return; 192 | } 193 | } 194 | } 195 | 196 | hidden function getCharacterLines(character, offsetTop, offsetRight, offsetBottom, offsetLeft) { 197 | var width = character.getDimensions()[0]; 198 | var height = character.getDimensions()[1]; 199 | 200 | var x = character.getX(); 201 | var y = character.getY(); 202 | 203 | var lines = [ 204 | // top 205 | [ 206 | x + offsetLeft, 207 | y + offsetTop, 208 | x + width - offsetRight, 209 | y + offsetTop 210 | ], 211 | // right 212 | [ 213 | x + width - offsetRight, 214 | y + offsetTop, 215 | x + width - offsetRight, 216 | y + height - offsetBottom 217 | ], 218 | // bottom 219 | [ 220 | x + width - offsetRight, 221 | y + height - offsetBottom, 222 | x + offsetLeft, 223 | y + height - offsetBottom 224 | ], 225 | // left 226 | [ 227 | x + offsetLeft, 228 | y + height - offsetBottom, 229 | x + offsetLeft, 230 | y + offsetTop 231 | ] 232 | ]; 233 | 234 | return lines; 235 | } 236 | 237 | function gameOver() { 238 | isGameOver = true; 239 | end(); 240 | trex.bump(); 241 | updateHighScrore(); 242 | 243 | WatchUi.requestUpdate(); 244 | } 245 | 246 | hidden function updateHighScrore() { 247 | if (score > highScore) { 248 | highScore = score; 249 | var app = Application.getApp(); 250 | app.setProperty(Enums.Keys.HIGH_SCORE_KEY, highScore); 251 | } 252 | } 253 | 254 | hidden function drawGameOver(dc) { 255 | if (restartBtn == null) { 256 | restartBtn = new WatchUi.Bitmap( 257 | {:rezId=>Rez.Drawables.restartBtn,:locX=>WatchUi.LAYOUT_HALIGN_CENTER,:locY=>groundYPosition - 65} 258 | ); 259 | } 260 | restartBtn.draw(dc); 261 | dc.drawText( 262 | screenWidth / 2, 263 | groundYPosition - 100, 264 | Graphics.FONT_MEDIUM, 265 | WatchUi.loadResource(Rez.Strings.gameOver), // GAME OVER 266 | Graphics.TEXT_JUSTIFY_CENTER 267 | ); 268 | } 269 | 270 | // check line and shape intersection 271 | hidden function shapeIntersection(lineCoordinates, shapeLines) { 272 | for(var i = 0; i < shapeLines.size(); i++) { 273 | var isIntersection = 274 | linesIntersection( 275 | lineCoordinates[0], lineCoordinates[1], lineCoordinates[2], lineCoordinates[3], 276 | shapeLines[i][0], shapeLines[i][1], shapeLines[i][2], shapeLines[i][3] 277 | ); 278 | if (isIntersection == true) { 279 | return true; 280 | } 281 | } 282 | return false; 283 | } 284 | 285 | hidden function linesIntersection(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2) { 286 | var v1 = (bx2 - bx1) * (ay1 - by1) - (by2 - by1) * (ax1 - bx1); 287 | var v2 = (bx2 - bx1) * (ay2 - by1) - (by2 - by1) * (ax2 - bx1); 288 | var v3 = (ax2 - ax1) * (by1 - ay1) - (ay2 - ay1) * (bx1 - ax1); 289 | var v4 = (ax2 - ax1) * (by2 - ay1) - (ay2 - ay1) * (bx2 - ax1); 290 | 291 | var res = (v1 * v2 < 0) && (v3 * v4 < 0); 292 | return res; 293 | } 294 | 295 | hidden function drawScores(dc) { 296 | drawCurrentScore(dc); 297 | drawHighScore(dc); 298 | } 299 | 300 | hidden function drawCurrentScore(dc) { 301 | var x; 302 | var y = 2; 303 | var justify; 304 | if (screenShape == System.SCREEN_SHAPE_ROUND || screenShape == System.SCREEN_SHAPE_SEMI_ROUND) { 305 | x = screenWidth / 2; 306 | justify = Graphics.TEXT_JUSTIFY_CENTER; 307 | } else { 308 | x = screenWidth - 5; 309 | justify = Graphics.TEXT_JUSTIFY_RIGHT; 310 | } 311 | dc.drawText(x, y, Graphics.FONT_SMALL, formatScoreNumber(score), justify); 312 | } 313 | 314 | hidden function drawHighScore(dc) { 315 | var x; 316 | var y = 2; 317 | var justify; 318 | if (screenShape == System.SCREEN_SHAPE_ROUND || screenShape == System.SCREEN_SHAPE_SEMI_ROUND) { 319 | x = screenWidth / 2; 320 | y = screenHeight - 38; 321 | justify = Graphics.TEXT_JUSTIFY_CENTER; 322 | } else { 323 | x = 5; 324 | justify = Graphics.TEXT_JUSTIFY_LEFT; 325 | } 326 | dc.drawText(x, y, Graphics.FONT_SMALL, "HI " + formatScoreNumber(highScore), justify); 327 | } 328 | 329 | hidden function formatScoreNumber(number) { 330 | if (number < 10) { 331 | return "0000" + number; 332 | } 333 | if (number < 100) { 334 | return "000" + number; 335 | } 336 | if (number < 1000) { 337 | return "00" + number; 338 | } 339 | if (number < 10000) { 340 | return "0" + number; 341 | } 342 | if (number > 99999) { 343 | return "99999"; 344 | } 345 | return "" + number; 346 | } 347 | } 348 | } 349 | --------------------------------------------------------------------------------