├── README.md ├── assets ├── assets.md ├── textures │ └── citySheet.png └── tilemap │ ├── TrafficMap.tmx │ ├── mapTile_002.png │ ├── mapTile_003.png │ ├── mapTile_006.png │ ├── mapTile_007.png │ ├── mapTile_017.png │ ├── mapTile_018.png │ ├── mapTile_021.png │ ├── mapTile_022.png │ ├── mapTile_023.png │ ├── mapTile_027.png │ ├── mapTile_028.png │ ├── mapTile_036.png │ ├── mapTile_037.png │ ├── mapTile_042.png │ ├── mapTile_043.png │ └── mapTile_082.png ├── go.mod ├── go.sum ├── systems ├── citybuilding.go ├── hudText.go └── money.go └── traffic.go /README.md: -------------------------------------------------------------------------------- 1 | # TrafficManager 2 | 3 | [![Gitter](https://badges.gitter.im/EngoEngine/TrafficManager.svg)](https://gitter.im/EngoEngine/TrafficManager?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -------------------------------------------------------------------------------- /assets/assets.md: -------------------------------------------------------------------------------- 1 | This file is just here to give credit and locations for the assets used in 2 | this project. 3 | 4 | ### tilemap/TrafficMap.tmx and associated pngs 5 | 6 | The background tilemap was created from tiles made by [Kenney](www.kenney.nl) 7 | and were obtained from 8 | [OpenGameArt.org](https://opengameart.org/content/map-pack-180-assets). 9 | 10 | The map itself was created in [Tiled Map Editor](https://www.mapeditor.org). 11 | 12 | ### textures/citySheet.png 13 | 14 | The city tiles were made by [Kenney](www.kenney.nl) and were obtained from 15 | [OpenGameArt.org](https://opengameart.org/content/roguelike-modern-city-pack). 16 | 17 | ### Fonts 18 | 19 | The fonts used are Go's fonts [Go](golang.org/x/image/font/gofont). 20 | -------------------------------------------------------------------------------- /assets/textures/citySheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/textures/citySheet.png -------------------------------------------------------------------------------- /assets/tilemap/TrafficMap.tmx: -------------------------------------------------------------------------------- 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 | eJxjZmBgYCGAGYnETEDMDsQcBDArkZht1LwhaR6xmHPUPDjmQsPUNo8Y84nxL73Mw4a5B8A8UuwYCubxADEviZgPB+YHYgB0Bwwz 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /assets/tilemap/mapTile_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_002.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_003.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_006.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_007.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_017.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_017.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_018.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_018.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_021.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_021.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_022.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_022.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_023.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_023.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_027.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_027.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_028.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_028.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_036.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_036.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_037.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_037.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_042.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_042.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_043.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_043.png -------------------------------------------------------------------------------- /assets/tilemap/mapTile_082.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngoEngine/TrafficManager/3fc2a2b723945750ef6964d885600f1b0f04e457/assets/tilemap/mapTile_082.png -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/EngoEngine/TrafficManager 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/EngoEngine/ecs v1.0.5 7 | github.com/EngoEngine/engo v1.0.5 8 | github.com/EngoEngine/gl v1.0.11 // indirect 9 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265 // indirect 10 | github.com/go-gl/mathgl v1.0.0 // indirect 11 | github.com/hajimehoshi/go-mp3 v0.3.1 // indirect 12 | github.com/hajimehoshi/oto v0.7.1 // indirect 13 | github.com/jfreymuth/oggvorbis v1.0.3 // indirect 14 | github.com/srwiley/oksvg v0.0.0-20210209000435-a757b9cbd472 // indirect 15 | github.com/veandco/go-sdl2 v0.4.5 // indirect 16 | github.com/vulkan-go/vulkan v0.0.0-20201213112254-a536091a798a // indirect 17 | golang.org/x/exp v0.0.0-20210212053707-62dc52270d37 // indirect 18 | golang.org/x/image v0.0.0-20210216034530-4410531fe030 19 | golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f // indirect 20 | golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect 21 | golang.org/x/sys v0.0.0-20210217105451-b926d437f341 // indirect 22 | golang.org/x/text v0.3.5 // indirect 23 | ) 24 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 2 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 3 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 4 | github.com/EngoEngine/ecs v1.0.4/go.mod h1:B/+b8S8xOPXaI05sFRBQ94nWHFxerBuSUPa4EXDNodg= 5 | github.com/EngoEngine/ecs v1.0.5 h1:S21KTClrAqC862BFR5wTkd6uEYQ0Aw/ob9RjKPt0e30= 6 | github.com/EngoEngine/ecs v1.0.5/go.mod h1:A8AYbzKIsl+t4qafmLL3t4H6cXdfGo4CIHl7EN100iM= 7 | github.com/EngoEngine/engo v1.0.5 h1:uUS+ePuY0jfrdgsiu9DksgIXutajbRxJotguHjyhblE= 8 | github.com/EngoEngine/engo v1.0.5/go.mod h1:jYnT3CutNgI034WhhzsSo0oXjcFoJW4o22CCfTd92wE= 9 | github.com/EngoEngine/gl v1.0.10/go.mod h1:8f1reqqWMIXn6FSdcjwo6ayoZfrEqiv/0ulVHb4LGf4= 10 | github.com/EngoEngine/gl v1.0.11 h1:e0WdnP19ElyMjFVm2eXQ9rVIdxEl9v1u99T7by/xTPM= 11 | github.com/EngoEngine/gl v1.0.11/go.mod h1:8f1reqqWMIXn6FSdcjwo6ayoZfrEqiv/0ulVHb4LGf4= 12 | github.com/EngoEngine/math v1.0.4 h1:ejDfSg48ynB9T6btiu9EHjZmpQgW/zHf3IeC7SqXXv8= 13 | github.com/EngoEngine/math v1.0.4/go.mod h1:d8SnfwiaImse0lB3JuR91B2CShZmMxaTWaWZ/ZxDxAU= 14 | github.com/Noofbiz/sdlMojaveFix v0.0.1 h1:Vz4HSG7QQ5gkOWeZsSUFCGJAvMoRUHloTwF80lF0a9M= 15 | github.com/Noofbiz/sdlMojaveFix v0.0.1/go.mod h1:ZvRLF4Dk75OnTtHfCMClqgwrX0u531XWaai0lNGzKWE= 16 | github.com/Noofbiz/tmx v0.2.0 h1:5bVZn4FN+8HVhvl2XmAiI9RFlo9/6xauhco1KGcJ+38= 17 | github.com/Noofbiz/tmx v0.2.0/go.mod h1:gL6mQUTp1Vi9pq/gmCgyotzJ35lOQF2C2NKJrQtltAE= 18 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 19 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 20 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 21 | github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw= 22 | github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= 23 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 24 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200420212212-258d9bec320e/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 25 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265 h1:BcbKYUZo/TKPsiSh7LymK3p+TNAJJW3OfGO/21sBbiA= 26 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 27 | github.com/go-gl/mathgl v0.0.0-20190713194549-592312d8590a/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= 28 | github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68= 29 | github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ= 30 | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= 31 | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= 32 | github.com/hajimehoshi/go-mp3 v0.2.1/go.mod h1:Rr+2P46iH6PwTPVgSsEwBkon0CK5DxCAeX/Rp65DCTE= 33 | github.com/hajimehoshi/go-mp3 v0.3.1 h1:pn/SKU1+/rfK8KaZXdGEC2G/KCB2aLRjbTCrwKcokao= 34 | github.com/hajimehoshi/go-mp3 v0.3.1/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM= 35 | github.com/hajimehoshi/oto v0.3.4/go.mod h1:PgjqsBJff0efqL2nlMJidJgVJywLn6M4y8PI4TfeWfA= 36 | github.com/hajimehoshi/oto v0.5.4/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI= 37 | github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI= 38 | github.com/hajimehoshi/oto v0.7.1 h1:I7maFPz5MBCwiutOrz++DLdbr4rTzBsbBuV2VpgU9kk= 39 | github.com/hajimehoshi/oto v0.7.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos= 40 | github.com/jfreymuth/oggvorbis v1.0.1/go.mod h1:NqS+K+UXKje0FUYUPosyQ+XTVvjmVjps1aEZH1sumIk= 41 | github.com/jfreymuth/oggvorbis v1.0.3 h1:MLNGGyhOMiVcvea9Dp5+gbs2SAwqwQbtrWnonYa0M0Y= 42 | github.com/jfreymuth/oggvorbis v1.0.3/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII= 43 | github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0= 44 | github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE= 45 | github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ= 46 | github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= 47 | github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 48 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 49 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 50 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 51 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 52 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 53 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 54 | github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564/go.mod h1:afMbS0qvv1m5tfENCwnOdZGOF8RGR/FsZ7bvBxQGZG4= 55 | github.com/srwiley/oksvg v0.0.0-20210209000435-a757b9cbd472 h1:wjPUVI4pltNGVSisFNXN4LNjAnkFlT8c6f1sZPPOCLg= 56 | github.com/srwiley/oksvg v0.0.0-20210209000435-a757b9cbd472/go.mod h1:afMbS0qvv1m5tfENCwnOdZGOF8RGR/FsZ7bvBxQGZG4= 57 | github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 h1:m59mIOBO4kfcNCEzJNy71UkeF4XIx2EVmL9KLwDQdmM= 58 | github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU= 59 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 60 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 61 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= 62 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 63 | github.com/veandco/go-sdl2 v0.4.4/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg= 64 | github.com/veandco/go-sdl2 v0.4.5 h1:GFIjMabK7y2XWpr9sGvN7RDKHt7vrA7XPTUW60eOw+Y= 65 | github.com/veandco/go-sdl2 v0.4.5/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= 66 | github.com/vulkan-go/glfw v0.0.0-20190520160600-32f33e359ff2 h1:jPnSXM1EM+6J1MbKbUZvQWkuS6Z9lPWRxTHn1NPsyNY= 67 | github.com/vulkan-go/glfw v0.0.0-20190520160600-32f33e359ff2/go.mod h1:qui9jo5J26j9fXv2x3bySGThxYkQZt4SgsPIZRtZAbQ= 68 | github.com/vulkan-go/vulkan v0.0.0-20200123094538-aa511c71e200/go.mod h1:X6Qqg0j5A5cYHhFXUOl6TL/vYdyh/ajvyCvh+sEHQFI= 69 | github.com/vulkan-go/vulkan v0.0.0-20201213112254-a536091a798a h1:kL+7LxSPkGCqpvgVLWMt9MOYD5PSKL6Kc1+z9K7K2GE= 70 | github.com/vulkan-go/vulkan v0.0.0-20201213112254-a536091a798a/go.mod h1:X6Qqg0j5A5cYHhFXUOl6TL/vYdyh/ajvyCvh+sEHQFI= 71 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 72 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 73 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 74 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 75 | golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= 76 | golang.org/x/exp v0.0.0-20200513190911-00229845015e/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= 77 | golang.org/x/exp v0.0.0-20210212053707-62dc52270d37 h1:8LMx3JFCswBZrnLWtxzpogDG5g1Hb7KWy/16Msz0hQk= 78 | golang.org/x/exp v0.0.0-20210212053707-62dc52270d37/go.mod h1:I6l2HNBLBZEcrOoCpyKLdY2lHoRZ8lI4x60KMCQDft4= 79 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 80 | golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 81 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 82 | golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 83 | golang.org/x/image v0.0.0-20210216034530-4410531fe030 h1:lP9pYkih3DUSC641giIXa2XqfTIbbbRr0w2EOTA7wHA= 84 | golang.org/x/image v0.0.0-20210216034530-4410531fe030/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 85 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 86 | golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 87 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 88 | golang.org/x/mobile v0.0.0-20200212152714-2b26a4705d24/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= 89 | golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= 90 | golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= 91 | golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f h1:aEcjdTsycgPqO/caTgnxfR9xwWOltP/21vtJyFztEy0= 92 | golang.org/x/mobile v0.0.0-20210208171126-f462b3930c8f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= 93 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 94 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 95 | golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 96 | golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 97 | golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 98 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 99 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 100 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 101 | golang.org/x/net v0.0.0-20200505041828-1ed23360d12c/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 102 | golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= 103 | golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 104 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 105 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 106 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 107 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 108 | golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 109 | golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 110 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 111 | golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 112 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 113 | golang.org/x/sys v0.0.0-20210217105451-b926d437f341 h1:2/QtM1mL37YmcsT8HaDNHDgTqqFVw+zr8UzMiBVLzYU= 114 | golang.org/x/sys v0.0.0-20210217105451-b926d437f341/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 115 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 116 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 117 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 118 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 119 | golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= 120 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 121 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 122 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 123 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 124 | golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 125 | golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 126 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 127 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 128 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 129 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= 130 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 131 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 132 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 133 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 134 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 135 | -------------------------------------------------------------------------------- /systems/citybuilding.go: -------------------------------------------------------------------------------- 1 | package systems 2 | 3 | import ( 4 | "github.com/EngoEngine/ecs" 5 | "github.com/EngoEngine/engo" 6 | "github.com/EngoEngine/engo/common" 7 | 8 | "math/rand" 9 | "time" 10 | ) 11 | 12 | // Spritesheet contains the sprites for the city buildings, cars, and roads 13 | var Spritesheet *common.Spritesheet 14 | 15 | var cities = [...][12]int{ 16 | {99, 100, 101, 17 | 454, 269, 455, 18 | 415, 195, 416, 19 | 452, 306, 453, 20 | }, 21 | {99, 100, 101, 22 | 268, 269, 270, 23 | 268, 269, 270, 24 | 305, 306, 307, 25 | }, 26 | {75, 76, 77, 27 | 446, 261, 447, 28 | 446, 261, 447, 29 | 444, 298, 445, 30 | }, 31 | {75, 76, 77, 32 | 407, 187, 408, 33 | 407, 187, 408, 34 | 444, 298, 445, 35 | }, 36 | {75, 76, 77, 37 | 186, 150, 188, 38 | 186, 150, 188, 39 | 297, 191, 299, 40 | }, 41 | {83, 84, 85, 42 | 413, 228, 414, 43 | 411, 191, 412, 44 | 448, 302, 449, 45 | }, 46 | {83, 84, 85, 47 | 227, 228, 229, 48 | 190, 191, 192, 49 | 301, 302, 303, 50 | }, 51 | {91, 92, 93, 52 | 241, 242, 243, 53 | 278, 279, 280, 54 | 945, 946, 947, 55 | }, 56 | {91, 92, 93, 57 | 241, 242, 243, 58 | 278, 279, 280, 59 | 945, 803, 947, 60 | }, 61 | {91, 92, 93, 62 | 238, 239, 240, 63 | 238, 239, 240, 64 | 312, 313, 314, 65 | }, 66 | } 67 | 68 | // City is a city tile 69 | type City struct { 70 | ecs.BasicEntity 71 | common.RenderComponent 72 | common.SpaceComponent 73 | } 74 | 75 | // CityBuildingSystem builds random cities as the game progresses 76 | type CityBuildingSystem struct { 77 | world *ecs.World 78 | 79 | usedTiles []int 80 | 81 | elapsed, buildTime float32 82 | built int 83 | } 84 | 85 | // New is the initialisation of the System 86 | func (cb *CityBuildingSystem) New(w *ecs.World) { 87 | cb.world = w 88 | 89 | Spritesheet = common.NewSpritesheetWithBorderFromFile("textures/citySheet.png", 16, 16, 1, 1) 90 | 91 | rand.Seed(time.Now().UnixNano()) 92 | 93 | cb.updateBuildTime() 94 | } 95 | 96 | // Update is ran every frame, with `dt` being the time 97 | // in seconds since the last frame 98 | func (cb *CityBuildingSystem) Update(dt float32) { 99 | cb.elapsed += dt 100 | if cb.elapsed >= cb.buildTime { 101 | cb.generateCity() 102 | cb.elapsed = 0 103 | cb.updateBuildTime() 104 | cb.built++ 105 | } 106 | } 107 | 108 | // Remove is called whenever an Entity is removed from the scene, and thus from this system 109 | func (*CityBuildingSystem) Remove(ecs.BasicEntity) {} 110 | 111 | // generateCity randomly generates a city in a random location on the map 112 | func (cb *CityBuildingSystem) generateCity() { 113 | x := rand.Intn(18) 114 | y := rand.Intn(18) 115 | t := x + y*18 116 | 117 | for cb.isTileUsed(t) { 118 | if len(cb.usedTiles) > 300 { 119 | break //to avoid infinite loop 120 | } 121 | x = rand.Intn(18) 122 | y = rand.Intn(18) 123 | t = x + y*18 124 | } 125 | cb.usedTiles = append(cb.usedTiles, t) 126 | 127 | city := rand.Intn(len(cities)) 128 | cityTiles := make([]*City, 0) 129 | for i := 0; i < 3; i++ { 130 | for j := 0; j < 4; j++ { 131 | tile := &City{BasicEntity: ecs.NewBasic()} 132 | tile.SpaceComponent.Position = engo.Point{ 133 | X: float32(((x+1)*64)+8) + float32(i*16), 134 | Y: float32(((y + 1) * 64)) + float32(j*16), 135 | } 136 | tile.RenderComponent.Drawable = Spritesheet.Cell(cities[city][i+3*j]) 137 | tile.RenderComponent.SetZIndex(1) 138 | cityTiles = append(cityTiles, tile) 139 | } 140 | } 141 | 142 | for _, system := range cb.world.Systems() { 143 | switch sys := system.(type) { 144 | case *common.RenderSystem: 145 | for _, v := range cityTiles { 146 | sys.Add(&v.BasicEntity, &v.RenderComponent, &v.SpaceComponent) 147 | } 148 | } 149 | } 150 | 151 | engo.Mailbox.Dispatch(HUDTextMessage{ 152 | BasicEntity: ecs.NewBasic(), 153 | SpaceComponent: common.SpaceComponent{ 154 | Position: engo.Point{X: float32((x + 1) * 64), Y: float32((y + 1) * 64)}, 155 | Width: 64, 156 | Height: 64, 157 | }, 158 | MouseComponent: common.MouseComponent{}, 159 | Line1: "Town", 160 | Line2: "Just built!", 161 | Line3: "A town generates", 162 | Line4: "$100 per day.", 163 | }) 164 | 165 | engo.Mailbox.Dispatch(CityUpdateMessage{ 166 | New: CityTypeNew, 167 | }) 168 | } 169 | 170 | func (cb *CityBuildingSystem) isTileUsed(tile int) bool { 171 | for _, t := range cb.usedTiles { 172 | if tile == t { 173 | return true 174 | } 175 | } 176 | return false 177 | } 178 | 179 | func (cb *CityBuildingSystem) updateBuildTime() { 180 | switch { 181 | case cb.built < 2: 182 | cb.buildTime = 5*rand.Float32() + 10 // 10 to 15 seconds 183 | case cb.built < 8: 184 | cb.buildTime = 30*rand.Float32() + 60 // 60 to 90 seconds 185 | case cb.built < 18: 186 | cb.buildTime = 60*rand.Float32() + 30 // 30 to 90 seconds 187 | case cb.built < 28: 188 | cb.buildTime = 35*rand.Float32() + 30 // 30 to 65 seconds 189 | case cb.built < 33: 190 | cb.buildTime = 30*rand.Float32() + 30 // 30 to 60 seconds 191 | default: 192 | cb.buildTime = 20*rand.Float32() + 20 // 20 to 40 seconds 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /systems/hudText.go: -------------------------------------------------------------------------------- 1 | package systems 2 | 3 | import ( 4 | "fmt" 5 | "image/color" 6 | 7 | "github.com/EngoEngine/ecs" 8 | "github.com/EngoEngine/engo" 9 | "github.com/EngoEngine/engo/common" 10 | ) 11 | 12 | type mouseTracker struct { 13 | ecs.BasicEntity 14 | common.MouseComponent 15 | } 16 | 17 | // Text is an entity containing text printed to the screen 18 | type Text struct { 19 | ecs.BasicEntity 20 | common.SpaceComponent 21 | common.RenderComponent 22 | } 23 | 24 | // HUDTextMessage updates the HUD text based on messages sent from other systems 25 | type HUDTextMessage struct { 26 | ecs.BasicEntity 27 | common.SpaceComponent 28 | common.MouseComponent 29 | Line1, Line2, Line3, Line4 string 30 | } 31 | 32 | // HUDTextMessageType is the type for an HUDTextMessage 33 | const HUDTextMessageType string = "HUDTextMessage" 34 | 35 | // Type implements the engo.Message Interface 36 | func (HUDTextMessage) Type() string { 37 | return HUDTextMessageType 38 | } 39 | 40 | // HUDMoneyMessage updates the HUD text when changes are made to the amount of 41 | // money available to the player 42 | type HUDMoneyMessage struct { 43 | Amount int 44 | } 45 | 46 | // HUDMoneyMessageType is the type for an HUDMoneyMessage 47 | const HUDMoneyMessageType string = "HUDMoneyMessage" 48 | 49 | // Type implements the engo.Message interface 50 | func (HUDMoneyMessage) Type() string { 51 | return HUDMoneyMessageType 52 | } 53 | 54 | // HUDTextEntity is an entity for the text system. This keeps track of the position 55 | // size and text associated with that position. 56 | type HUDTextEntity struct { 57 | *ecs.BasicEntity 58 | *common.SpaceComponent 59 | *common.MouseComponent 60 | Line1, Line2, Line3, Line4 string 61 | } 62 | 63 | // HUDTextSystem prints the text to our HUD based on the current state of the game 64 | type HUDTextSystem struct { 65 | text1, text2, text3, text4, money Text 66 | 67 | entities []HUDTextEntity 68 | 69 | updateMoney bool 70 | amount int 71 | } 72 | 73 | // New is called when the system is added to the world. 74 | // Adds text to our HUD that will update based on the state of the game, then 75 | // listens for messages to update the text. 76 | func (h *HUDTextSystem) New(w *ecs.World) { 77 | fnt := &common.Font{ 78 | URL: "go.ttf", 79 | FG: color.Black, 80 | Size: 20, 81 | } 82 | fnt.CreatePreloaded() 83 | 84 | h.text1 = Text{BasicEntity: ecs.NewBasic()} 85 | h.text1.RenderComponent.Drawable = common.Text{ 86 | Font: fnt, 87 | Text: "Nothing Selected!", 88 | } 89 | h.text1.SetShader(common.TextHUDShader) 90 | h.text1.RenderComponent.SetZIndex(1001) 91 | h.text1.SpaceComponent = common.SpaceComponent{ 92 | Position: engo.Point{X: 0, Y: engo.WindowHeight() - 200}, 93 | } 94 | for _, system := range w.Systems() { 95 | switch sys := system.(type) { 96 | case *common.RenderSystem: 97 | sys.Add(&h.text1.BasicEntity, &h.text1.RenderComponent, &h.text1.SpaceComponent) 98 | } 99 | } 100 | 101 | h.text2 = Text{BasicEntity: ecs.NewBasic()} 102 | h.text2.RenderComponent.Drawable = common.Text{ 103 | Font: fnt, 104 | Text: "click on an element", 105 | } 106 | h.text2.SetShader(common.TextHUDShader) 107 | h.text2.RenderComponent.SetZIndex(1001) 108 | h.text2.SpaceComponent = common.SpaceComponent{ 109 | Position: engo.Point{X: 0, Y: engo.WindowHeight() - 180}, 110 | } 111 | for _, system := range w.Systems() { 112 | switch sys := system.(type) { 113 | case *common.RenderSystem: 114 | sys.Add(&h.text2.BasicEntity, &h.text2.RenderComponent, &h.text2.SpaceComponent) 115 | } 116 | } 117 | 118 | h.text3 = Text{BasicEntity: ecs.NewBasic()} 119 | h.text3.RenderComponent.Drawable = common.Text{ 120 | Font: fnt, 121 | Text: "to get info", 122 | } 123 | h.text3.SetShader(common.TextHUDShader) 124 | h.text3.RenderComponent.SetZIndex(1001) 125 | h.text3.SpaceComponent = common.SpaceComponent{ 126 | Position: engo.Point{X: 0, Y: engo.WindowHeight() - 160}, 127 | } 128 | for _, system := range w.Systems() { 129 | switch sys := system.(type) { 130 | case *common.RenderSystem: 131 | sys.Add(&h.text3.BasicEntity, &h.text3.RenderComponent, &h.text3.SpaceComponent) 132 | } 133 | } 134 | 135 | h.text4 = Text{BasicEntity: ecs.NewBasic()} 136 | h.text4.RenderComponent.Drawable = common.Text{ 137 | Font: fnt, 138 | Text: "about it.", 139 | } 140 | h.text4.SetShader(common.TextHUDShader) 141 | h.text4.RenderComponent.SetZIndex(1001) 142 | h.text4.SpaceComponent = common.SpaceComponent{ 143 | Position: engo.Point{X: 0, Y: engo.WindowHeight() - 140}, 144 | } 145 | for _, system := range w.Systems() { 146 | switch sys := system.(type) { 147 | case *common.RenderSystem: 148 | sys.Add(&h.text4.BasicEntity, &h.text4.RenderComponent, &h.text4.SpaceComponent) 149 | } 150 | } 151 | 152 | h.money = Text{BasicEntity: ecs.NewBasic()} 153 | h.money.RenderComponent.Drawable = common.Text{ 154 | Font: fnt, 155 | Text: "$0", 156 | } 157 | h.money.SetShader(common.TextHUDShader) 158 | h.money.RenderComponent.SetZIndex(1001) 159 | h.money.SpaceComponent = common.SpaceComponent{ 160 | Position: engo.Point{X: 0, Y: engo.WindowHeight() - 40}, 161 | } 162 | for _, system := range w.Systems() { 163 | switch sys := system.(type) { 164 | case *common.RenderSystem: 165 | sys.Add(&h.money.BasicEntity, &h.money.RenderComponent, &h.money.SpaceComponent) 166 | } 167 | } 168 | 169 | engo.Mailbox.Listen(HUDTextMessageType, func(m engo.Message) { 170 | msg, ok := m.(HUDTextMessage) 171 | if !ok { 172 | return 173 | } 174 | for _, system := range w.Systems() { 175 | switch sys := system.(type) { 176 | case *common.MouseSystem: 177 | sys.Add(&msg.BasicEntity, &msg.MouseComponent, &msg.SpaceComponent, nil) 178 | case *HUDTextSystem: 179 | sys.Add(&msg.BasicEntity, &msg.SpaceComponent, &msg.MouseComponent, msg.Line1, msg.Line2, msg.Line3, msg.Line4) 180 | } 181 | } 182 | }) 183 | 184 | engo.Mailbox.Listen(HUDMoneyMessageType, func(m engo.Message) { 185 | msg, ok := m.(HUDMoneyMessage) 186 | if !ok { 187 | return 188 | } 189 | h.amount = msg.Amount 190 | h.updateMoney = true 191 | }) 192 | } 193 | 194 | // Add adds an entity to the system 195 | func (h *HUDTextSystem) Add(b *ecs.BasicEntity, s *common.SpaceComponent, m *common.MouseComponent, l1, l2, l3, l4 string) { 196 | h.entities = append(h.entities, HUDTextEntity{b, s, m, l1, l2, l3, l4}) 197 | } 198 | 199 | // Update is called each frame to update the system. 200 | func (h *HUDTextSystem) Update(dt float32) { 201 | for _, e := range h.entities { 202 | if e.MouseComponent.Clicked { 203 | txt := h.text1.RenderComponent.Drawable.(common.Text) 204 | txt.Text = e.Line1 205 | h.text1.RenderComponent.Drawable = txt 206 | txt = h.text2.RenderComponent.Drawable.(common.Text) 207 | txt.Text = e.Line2 208 | h.text2.RenderComponent.Drawable = txt 209 | txt = h.text3.RenderComponent.Drawable.(common.Text) 210 | txt.Text = e.Line3 211 | h.text3.RenderComponent.Drawable = txt 212 | txt = h.text4.RenderComponent.Drawable.(common.Text) 213 | txt.Text = e.Line4 214 | h.text4.RenderComponent.Drawable = txt 215 | } 216 | } 217 | if h.updateMoney { 218 | txt := h.money.RenderComponent.Drawable.(common.Text) 219 | txt.Text = fmt.Sprintf("$%v", h.amount) 220 | h.money.RenderComponent.Drawable = txt 221 | } 222 | } 223 | 224 | // Remove takes an enitty out of the system. 225 | func (h *HUDTextSystem) Remove(basic ecs.BasicEntity) { 226 | delete := -1 227 | for index, e := range h.entities { 228 | if e.BasicEntity.ID() == basic.ID() { 229 | delete = index 230 | break 231 | } 232 | } 233 | if delete >= 0 { 234 | h.entities = append(h.entities[:delete], h.entities[delete+1:]...) 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /systems/money.go: -------------------------------------------------------------------------------- 1 | package systems 2 | 3 | import ( 4 | "github.com/EngoEngine/ecs" 5 | "github.com/EngoEngine/engo" 6 | ) 7 | 8 | // CityType keeps track of the type of city 9 | type CityType int 10 | 11 | const ( 12 | // CityTypeNew is a brand new city 13 | CityTypeNew = iota 14 | // CityTypeTown is a town, the lowest level 15 | CityTypeTown 16 | // CityTypeCity is a city, the moderate city type 17 | CityTypeCity 18 | // CityTypeMetro is a metro area, the largest city type 19 | CityTypeMetro 20 | ) 21 | 22 | // CityUpdateMessage updates the city types when sent from Old to New 23 | type CityUpdateMessage struct { 24 | Old, New CityType 25 | } 26 | 27 | // CityUpdateMessageType is the type of the CityUpdateMessage 28 | const CityUpdateMessageType string = "CityUpdateMessage" 29 | 30 | // Type implements the engo.Message interface 31 | func (CityUpdateMessage) Type() string { 32 | return CityUpdateMessageType 33 | } 34 | 35 | // AddOfficerMessage tells the system to add an officer 36 | type AddOfficerMessage struct{} 37 | 38 | // AddOfficerMessageType is the type of an AddOfficerMessage 39 | const AddOfficerMessageType string = "AddOfficerMessage" 40 | 41 | // Type implements the engo.Message interface 42 | func (AddOfficerMessage) Type() string { 43 | return AddOfficerMessageType 44 | } 45 | 46 | // MoneySystem keeps track of money available to the player 47 | type MoneySystem struct { 48 | amount int 49 | towns, cities, metros int 50 | officers int 51 | elapsed float32 52 | } 53 | 54 | // New listens to messages to update the number of cities and police in the game. 55 | func (m *MoneySystem) New(w *ecs.World) { 56 | engo.Mailbox.Listen(CityUpdateMessageType, func(msg engo.Message) { 57 | upd, ok := msg.(CityUpdateMessage) 58 | if !ok { 59 | return 60 | } 61 | switch upd.New { 62 | case CityTypeNew: 63 | m.towns++ 64 | case CityTypeTown: 65 | m.towns++ 66 | if upd.Old == CityTypeTown { 67 | m.towns-- 68 | } else if upd.Old == CityTypeCity { 69 | m.cities-- 70 | } else if upd.Old == CityTypeMetro { 71 | m.metros-- 72 | } 73 | case CityTypeCity: 74 | m.cities++ 75 | if upd.Old == CityTypeTown { 76 | m.towns-- 77 | } else if upd.Old == CityTypeCity { 78 | m.cities-- 79 | } else if upd.Old == CityTypeMetro { 80 | m.metros-- 81 | } 82 | case CityTypeMetro: 83 | m.metros++ 84 | if upd.Old == CityTypeTown { 85 | m.towns-- 86 | } else if upd.Old == CityTypeCity { 87 | m.cities-- 88 | } else if upd.Old == CityTypeMetro { 89 | m.metros-- 90 | } 91 | } 92 | }) 93 | 94 | engo.Mailbox.Listen(AddOfficerMessageType, func(engo.Message) { 95 | m.officers++ 96 | }) 97 | } 98 | 99 | // Update keeps track of how much time has passed since the last addtion of money. 100 | // When enough time passes, it adds money based on the number and type of cities 101 | // and subtracts money based on the size of the police force employed. 102 | func (m *MoneySystem) Update(dt float32) { 103 | m.elapsed += dt 104 | if m.elapsed > 10 { 105 | m.amount += m.towns*100 + m.cities*500 + m.metros*1000 106 | m.amount -= m.officers * 20 107 | engo.Mailbox.Dispatch(HUDMoneyMessage{ 108 | Amount: m.amount, 109 | }) 110 | m.elapsed = 0 111 | } 112 | } 113 | 114 | // Remove doesn't do anything since the system has no entities. 115 | func (m *MoneySystem) Remove(b ecs.BasicEntity) {} 116 | -------------------------------------------------------------------------------- /traffic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "image" 6 | "image/color" 7 | 8 | "github.com/EngoEngine/ecs" 9 | "github.com/EngoEngine/engo" 10 | "github.com/EngoEngine/engo/common" 11 | "golang.org/x/image/font/gofont/gosmallcaps" 12 | 13 | // EDIT THE FOLLOWING IMPORT TO YOUR systems package 14 | "github.com/EngoEngine/TrafficManager/systems" 15 | ) 16 | 17 | const ( 18 | KeyboardScrollSpeed = 400 19 | EdgeScrollSpeed = KeyboardScrollSpeed 20 | EdgeWidth = 20 21 | ZoomSpeed = -0.125 22 | ) 23 | 24 | type myScene struct{} 25 | 26 | type HUD struct { 27 | ecs.BasicEntity 28 | common.RenderComponent 29 | common.SpaceComponent 30 | } 31 | 32 | type Tile struct { 33 | ecs.BasicEntity 34 | common.RenderComponent 35 | common.SpaceComponent 36 | } 37 | 38 | // Type uniquely defines your game type 39 | func (*myScene) Type() string { return "myGame" } 40 | 41 | // Preload is called before loading any assets from the disk, to allow you to register / queue them 42 | func (*myScene) Preload() { 43 | engo.Files.Load("textures/citySheet.png", "tilemap/TrafficMap.tmx") 44 | engo.Files.LoadReaderData("go.ttf", bytes.NewReader(gosmallcaps.TTF)) 45 | } 46 | 47 | // Setup is called before the main loop starts. It allows you to add entities and systems to your Scene. 48 | func (*myScene) Setup(u engo.Updater) { 49 | world, _ := u.(*ecs.World) 50 | common.SetBackground(color.White) 51 | 52 | world.AddSystem(&common.RenderSystem{}) 53 | world.AddSystem(&common.MouseSystem{}) 54 | 55 | kbs := common.NewKeyboardScroller(KeyboardScrollSpeed, engo.DefaultHorizontalAxis, engo.DefaultVerticalAxis) 56 | world.AddSystem(kbs) 57 | world.AddSystem(&common.EdgeScroller{EdgeScrollSpeed, EdgeWidth}) 58 | world.AddSystem(&common.MouseZoomer{ZoomSpeed}) 59 | 60 | world.AddSystem(&systems.CityBuildingSystem{}) 61 | world.AddSystem(&systems.HUDTextSystem{}) 62 | world.AddSystem(&systems.MoneySystem{}) 63 | 64 | hud := HUD{BasicEntity: ecs.NewBasic()} 65 | hud.SpaceComponent = common.SpaceComponent{ 66 | Position: engo.Point{0, engo.WindowHeight() - 200}, 67 | Width: 200, 68 | Height: 200, 69 | } 70 | 71 | hudImage := image.NewUniform(color.RGBA{205, 205, 205, 255}) 72 | hudNRGBA := common.ImageToNRGBA(hudImage, 200, 200) 73 | hudImageObj := common.NewImageObject(hudNRGBA) 74 | hudTexture := common.NewTextureSingle(hudImageObj) 75 | 76 | hud.RenderComponent = common.RenderComponent{ 77 | Repeat: common.Repeat, 78 | Drawable: hudTexture, 79 | Scale: engo.Point{1, 1}, 80 | } 81 | hud.RenderComponent.SetShader(common.HUDShader) 82 | hud.RenderComponent.SetZIndex(1000) 83 | 84 | for _, system := range world.Systems() { 85 | switch sys := system.(type) { 86 | case *common.RenderSystem: 87 | sys.Add(&hud.BasicEntity, &hud.RenderComponent, &hud.SpaceComponent) 88 | } 89 | } 90 | 91 | resource, err := engo.Files.Resource("tilemap/TrafficMap.tmx") 92 | if err != nil { 93 | panic(err) 94 | } 95 | tmxResource := resource.(common.TMXResource) 96 | levelData := tmxResource.Level 97 | 98 | tiles := make([]*Tile, 0) 99 | for _, tileLayer := range levelData.TileLayers { 100 | for _, tileElement := range tileLayer.Tiles { 101 | if tileElement.Image != nil { 102 | tile := &Tile{BasicEntity: ecs.NewBasic()} 103 | tile.RenderComponent = common.RenderComponent{ 104 | Drawable: tileElement.Image, 105 | Scale: engo.Point{1, 1}, 106 | } 107 | tile.SpaceComponent = common.SpaceComponent{ 108 | Position: tileElement.Point, 109 | Width: 0, 110 | Height: 0, 111 | } 112 | tiles = append(tiles, tile) 113 | } 114 | } 115 | } 116 | // add the tiles to the RenderSystem 117 | for _, system := range world.Systems() { 118 | switch sys := system.(type) { 119 | case *common.RenderSystem: 120 | for _, v := range tiles { 121 | sys.Add(&v.BasicEntity, &v.RenderComponent, &v.SpaceComponent) 122 | } 123 | } 124 | } 125 | 126 | common.CameraBounds = levelData.Bounds() 127 | } 128 | 129 | func main() { 130 | opts := engo.RunOptions{ 131 | Title: "TrafficManager", 132 | Width: 800, 133 | Height: 800, 134 | StandardInputs: true, 135 | } 136 | 137 | engo.Run(opts, &myScene{}) 138 | } 139 | --------------------------------------------------------------------------------