├── .gitignore ├── LICENSE-CODE.txt ├── LICENSE-GRAPHICS.txt ├── LICENSE-SFX.txt ├── README.md ├── android ├── AndroidManifest.xml ├── android.iml ├── assets │ ├── badlogic.jpg │ ├── dialogs.png │ ├── font │ │ ├── intro.fnt │ │ ├── intro.png │ │ ├── pixel5x5.png │ │ ├── pixel5x5.xml │ │ ├── small.fnt │ │ ├── small.png │ │ ├── tahoma-10.fnt │ │ └── tahoma-10.png │ ├── icon128x128.png │ ├── icon16x16.png │ ├── icon32x32.png │ ├── sfx │ │ ├── Flaterectomy - Tox.mp3 │ │ ├── health_low_alarm_loop.mp3 │ │ ├── player_descend.mp3 │ │ ├── sector_cleared_star_award.mp3 │ │ ├── tox_sfx_ak47_fight.mp3 │ │ ├── tox_sfx_ak47_pickup.mp3 │ │ ├── tox_sfx_armor_pickup.mp3 │ │ ├── tox_sfx_bunny_dies.mp3 │ │ ├── tox_sfx_consume_drugs.mp3 │ │ ├── tox_sfx_consume_health.mp3 │ │ ├── tox_sfx_exit.mp3 │ │ ├── tox_sfx_explosion.mp3 │ │ ├── tox_sfx_fast_breathing.mp3 │ │ ├── tox_sfx_glock_fight.mp3 │ │ ├── tox_sfx_glock_pickup.mp3 │ │ ├── tox_sfx_grunt_male1.mp3 │ │ ├── tox_sfx_grunt_male2.mp3 │ │ ├── tox_sfx_grunt_male3.mp3 │ │ ├── tox_sfx_knuckles_fight.mp3 │ │ ├── tox_sfx_knuckles_pickup.mp3 │ │ ├── tox_sfx_levelup.mp3 │ │ ├── tox_sfx_monster_dies1.mp3 │ │ ├── tox_sfx_monster_dies2.mp3 │ │ ├── tox_sfx_monster_dies3.mp3 │ │ ├── tox_sfx_octopus_dies.mp3 │ │ ├── tox_sfx_overdose_alarm.mp3 │ │ ├── tox_sfx_player_dies_male.mp3 │ │ ├── tox_sfx_sawed-off_fight.mp3 │ │ ├── tox_sfx_sawed-off_pickup.mp3 │ │ ├── tox_sfx_smokepuff.mp3 │ │ ├── tox_sfx_star.mp3 │ │ ├── tox_sfx_wasp_dies.mp3 │ │ ├── tox_sfx_weapon-cock.mp3 │ │ └── tox_sfx_withdrawal_alarm.mp3 │ └── tileset.png ├── build.gradle ├── gen │ └── net │ │ └── mostlyoriginal │ │ └── tox │ │ └── android │ │ ├── BuildConfig.java │ │ ├── Manifest.java │ │ └── R.java ├── ic_launcher-web.png ├── libs │ ├── armeabi-v7a │ │ └── libgdx.so │ └── armeabi │ │ └── libgdx.so ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ └── values │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── net │ └── mostlyoriginal │ └── tox │ └── android │ └── AndroidLauncher.java ├── build.gradle ├── core ├── build.gradle ├── core.iml └── src │ └── net │ └── mostlyoriginal │ └── tox │ ├── EntityFactory.java │ ├── EntityUtils.java │ ├── GameScreen.java │ ├── GridGenerator.java │ ├── MyUtil.java │ ├── Score.java │ ├── Settings.java │ ├── TileType.java │ ├── Tox.java │ ├── ToxGame.gwt.xml │ ├── ToxGame.java │ ├── ToxResource.java │ ├── ToxUtil.java │ ├── component │ ├── Animation.java │ ├── Bullet.java │ ├── Cleared.java │ ├── ColorAnimation.java │ ├── Conceal.java │ ├── DissolvesOnTouch.java │ ├── EquipBonus.java │ ├── Exit.java │ ├── Fightable.java │ ├── Health.java │ ├── Inventory.java │ ├── Label.java │ ├── Level.java │ ├── Lootable.java │ ├── Named.java │ ├── Physics.java │ ├── Position.java │ ├── Reward.java │ ├── ScaleAnimation.java │ ├── Selectable.java │ ├── Setting.java │ ├── Terminal.java │ ├── Toxication.java │ └── Trap.java │ ├── screen │ ├── DialogScreen.java │ └── WelcomeScreen.java │ └── system │ ├── AnimationRenderSystem.java │ ├── BacktrackSystem.java │ ├── BulletSystem.java │ ├── CameraShakeSystem.java │ ├── ColorAnimationSystem.java │ ├── CombatSystem.java │ ├── ConcealSystem.java │ ├── ContinueSystem.java │ ├── DissolveSystem.java │ ├── ExitSystem.java │ ├── HighscoreSystem.java │ ├── HudSystem.java │ ├── InventorySystem.java │ ├── LabelRenderSystem.java │ ├── LifetimeSystem.java │ ├── LootSystem.java │ ├── ParticleSystem.java │ ├── PassiveSystem.java │ ├── PetalSystem.java │ ├── PhysicsSystem.java │ ├── PlayerSystem.java │ ├── ScoreSystem.java │ ├── SelectableSystem.java │ ├── SettingSystem.java │ ├── SoundAlertSystem.java │ ├── SoundSystem.java │ ├── StarPlopSystem.java │ ├── ThreatRenderSystem.java │ ├── TitleSystem.java │ ├── TombstoneSystem.java │ ├── TrapSystem.java │ └── UniverseSystem.java ├── desktop ├── build.gradle ├── desktop.iml └── src │ └── net │ └── mostlyoriginal │ └── tox │ └── desktop │ └── DesktopLauncher.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── gwt ├── build.gradle ├── gwt.iml ├── src │ └── net │ │ └── mostlyoriginal │ │ └── tox │ │ ├── GdxDefinition.gwt.xml │ │ └── client │ │ └── GwtLauncher.java └── webapp │ ├── WEB-INF │ └── web.xml │ ├── index.html │ └── net.mostlyoriginal.tox.GdxDefinition │ └── logo.png ├── ios ├── Info.plist.xml ├── build.gradle ├── ios.iml ├── robovm.properties ├── robovm.xml └── src │ └── net │ └── mostlyoriginal │ └── tox │ └── IOSLauncher.java ├── package_desktop.bat ├── package_html5.bat ├── s101plugin.state ├── settings.gradle └── tmp.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /out 3 | build 4 | /gwt/war 5 | /tox.iws 6 | /tox.iml 7 | /tox.ipr 8 | -------------------------------------------------------------------------------- /LICENSE-CODE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Daan van Yperen 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. -------------------------------------------------------------------------------- /LICENSE-GRAPHICS.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | Graphics copyrighted by Michiel Barten, all rights reserved. 4 | 5 | You are free to use the code as you wish, but please replace the graphics if you do so. 6 | 7 | You can contact Michiel at http://www.flaterectomy.com -------------------------------------------------------------------------------- /LICENSE-SFX.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sounds copyrighted by Michiel Barten, all rights reserved. 4 | 5 | You are free to use the code as you wish, but please replace the sounds if you do so. 6 | 7 | You can contact Michiel at http://www.flaterectomy.com -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Tox 2 | === 3 | 4 | #### Summary 5 | 7DRL entry made in 72 hours, strategic dungeon crawler! [Play online](http://ludum.mostlyoriginal.net/game/tox/) 6 | 7 | #### Tech 8 | Running on [LibGDX 1.5.3](https://github.com/libgdx/libgdx) and [Artemis-ODB 1.8.1](https://github.com/junkdog/artemis-odb). 9 | Tested for desktop, html5 via gwt and android. 10 | 11 | #### Grab what you need! 12 | Artemis Entity System takes a way a lot of the lifecycle management, and composition is a natural match for a time constrained Jam. While made in a rush, I hope this code gives you an idea or two how to benefit from using an entity system in your project. This is based on an old version of Artemis so some of the constructs are deprecated. 13 | 14 | #### Usage details 15 | While the meat is with peeking at the systems and components, you might like to compile the game! The project was created using libgdx-setup (not libgdx-setup-ui), which uses gradle for build automation, and snapshot versions of artemis and libgdx. ```gradlew desktop:run``` should run the game. See the [libgdx wiki](https://github.com/libgdx/libgdx/wiki) for how to use gradle with your ide. 16 | 17 | #### License summary 18 | Code and assets are under a separate license. Feel free to do whatever with the code. Graphics, music and sound are copyrighted. 19 | 20 | #### Play it! 21 | It’s a brutal game, but the scenarios aren’t totally random, they just appear that way. There’s always a path of victory! Well, the first few levels at least. 22 | A good way to get started is fighting the weaker guys first. This levels you up which makes the tougher enemies weaker. 23 | Try to get a feel for the sweet spot for dosing yourself, don’t just pick it up whenever you can; when you level you gain hitpoints, drugs heal you up fully, 24 | so taking them later boosts your chance of survival. 25 | Items are really valuable, they alter the gameplay in subtle ways. Be smart about the order you pick them up, and try to figure out what the special items do. 26 | World changes are not just superficial! Keep an eye on what else changes! 27 | 28 | [Play online](http://ludum.mostlyoriginal.net/game/tox/) 29 | -------------------------------------------------------------------------------- /android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /android/android.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 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 | -------------------------------------------------------------------------------- /android/assets/badlogic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/badlogic.jpg -------------------------------------------------------------------------------- /android/assets/dialogs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/dialogs.png -------------------------------------------------------------------------------- /android/assets/font/intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/font/intro.png -------------------------------------------------------------------------------- /android/assets/font/pixel5x5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/font/pixel5x5.png -------------------------------------------------------------------------------- /android/assets/font/pixel5x5.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 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /android/assets/font/small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/font/small.png -------------------------------------------------------------------------------- /android/assets/font/tahoma-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/font/tahoma-10.png -------------------------------------------------------------------------------- /android/assets/icon128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/icon128x128.png -------------------------------------------------------------------------------- /android/assets/icon16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/icon16x16.png -------------------------------------------------------------------------------- /android/assets/icon32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/icon32x32.png -------------------------------------------------------------------------------- /android/assets/sfx/Flaterectomy - Tox.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/Flaterectomy - Tox.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/health_low_alarm_loop.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/health_low_alarm_loop.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/player_descend.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/player_descend.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/sector_cleared_star_award.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/sector_cleared_star_award.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_ak47_fight.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_ak47_fight.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_ak47_pickup.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_ak47_pickup.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_armor_pickup.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_armor_pickup.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_bunny_dies.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_bunny_dies.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_consume_drugs.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_consume_drugs.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_consume_health.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_consume_health.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_exit.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_exit.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_explosion.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_explosion.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_fast_breathing.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_fast_breathing.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_glock_fight.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_glock_fight.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_glock_pickup.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_glock_pickup.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_grunt_male1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_grunt_male1.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_grunt_male2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_grunt_male2.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_grunt_male3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_grunt_male3.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_knuckles_fight.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_knuckles_fight.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_knuckles_pickup.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_knuckles_pickup.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_levelup.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_levelup.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_monster_dies1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_monster_dies1.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_monster_dies2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_monster_dies2.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_monster_dies3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_monster_dies3.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_octopus_dies.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_octopus_dies.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_overdose_alarm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_overdose_alarm.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_player_dies_male.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_player_dies_male.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_sawed-off_fight.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_sawed-off_fight.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_sawed-off_pickup.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_sawed-off_pickup.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_smokepuff.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_smokepuff.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_star.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_star.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_wasp_dies.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_wasp_dies.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_weapon-cock.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_weapon-cock.mp3 -------------------------------------------------------------------------------- /android/assets/sfx/tox_sfx_withdrawal_alarm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/sfx/tox_sfx_withdrawal_alarm.mp3 -------------------------------------------------------------------------------- /android/assets/tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/assets/tileset.png -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | android { 2 | buildToolsVersion "17.0" 3 | compileSdkVersion 17 4 | sourceSets { 5 | main { 6 | manifest.srcFile 'AndroidManifest.xml' 7 | java.srcDirs = ['src'] 8 | resources.srcDirs = ['src'] 9 | aidl.srcDirs = ['src'] 10 | renderscript.srcDirs = ['src'] 11 | res.srcDirs = ['res'] 12 | assets.srcDirs = ['assets'] 13 | } 14 | 15 | instrumentTest.setRoot('tests') 16 | } 17 | } 18 | 19 | // needed to add JNI shared libraries to APK when compiling on CLI 20 | tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask -> 21 | pkgTask.jniFolders = new HashSet() 22 | pkgTask.jniFolders.add(new File(projectDir, 'libs')) 23 | } 24 | 25 | // called every time gradle gets executed, takes the native dependencies of 26 | // the natives configuration, and extracts them to the proper libs/ folders 27 | // so they get packed with the APK. 28 | task copyAndroidNatives() { 29 | file("libs/armeabi/").mkdirs(); 30 | file("libs/armeabi-v7a/").mkdirs(); 31 | file("libs/x86/").mkdirs(); 32 | 33 | configurations.natives.files.each { jar -> 34 | def outputDir = null 35 | if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a") 36 | if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi") 37 | if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86") 38 | if(outputDir != null) { 39 | copy { 40 | from zipTree(jar) 41 | into outputDir 42 | include "*.so" 43 | } 44 | } 45 | } 46 | } 47 | 48 | // sets up the Android Eclipse project, using the old Ant based build. 49 | eclipse { 50 | // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin 51 | // ignores any nodes added in classpath.file.withXml 52 | sourceSets { 53 | main { 54 | java.srcDirs "src", 'gen' 55 | } 56 | } 57 | 58 | jdt { 59 | sourceCompatibility = 1.7 60 | targetCompatibility = 1.7 61 | } 62 | 63 | classpath { 64 | plusConfigurations += project.configurations.compile 65 | containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES' 66 | } 67 | 68 | project { 69 | name = appName + "-android" 70 | natures 'com.android.ide.eclipse.adt.AndroidNature' 71 | buildCommands.clear(); 72 | buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder" 73 | buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder" 74 | buildCommand "org.eclipse.jdt.core.javabuilder" 75 | buildCommand "com.android.ide.eclipse.adt.ApkBuilder" 76 | } 77 | } 78 | 79 | // sets up the Android Idea project, using the old Ant based build. 80 | idea { 81 | module { 82 | sourceDirs += file("src"); 83 | scopes = [ COMPILE: [plus:[project.configurations.compile]]] 84 | 85 | iml { 86 | withXml { 87 | def node = it.asNode() 88 | def builder = NodeBuilder.newInstance(); 89 | builder.current = node; 90 | builder.component(name: "FacetManager") { 91 | facet(type: "android", name: "Android") { 92 | configuration { 93 | option(name: "UPDATE_PROPERTY_FILES", value:"true") 94 | } 95 | } 96 | } 97 | } 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /android/gen/net/mostlyoriginal/tox/android/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package net.mostlyoriginal.tox.android; 4 | 5 | /* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ 6 | public final class BuildConfig { 7 | public final static boolean DEBUG = Boolean.parseBoolean(null); 8 | } -------------------------------------------------------------------------------- /android/gen/net/mostlyoriginal/tox/android/Manifest.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package net.mostlyoriginal.tox.android; 4 | 5 | /* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ 6 | public final class Manifest { 7 | } -------------------------------------------------------------------------------- /android/gen/net/mostlyoriginal/tox/android/R.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package net.mostlyoriginal.tox.android; 4 | 5 | /* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ 6 | public final class R { 7 | } -------------------------------------------------------------------------------- /android/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/ic_launcher-web.png -------------------------------------------------------------------------------- /android/libs/armeabi-v7a/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/libs/armeabi-v7a/libgdx.so -------------------------------------------------------------------------------- /android/libs/armeabi/libgdx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/libs/armeabi/libgdx.so -------------------------------------------------------------------------------- /android/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /android/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-10 15 | -------------------------------------------------------------------------------- /android/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaanVanYperen/odb-tox/1778065351a5888753421e89f983d480b340f806/android/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Tox 5 | 6 | 7 | -------------------------------------------------------------------------------- /android/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /android/src/net/mostlyoriginal/tox/android/AndroidLauncher.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.android; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.badlogic.gdx.backends.android.AndroidApplication; 6 | import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; 7 | import net.mostlyoriginal.tox.ToxGame; 8 | 9 | public class AndroidLauncher extends AndroidApplication { 10 | @Override 11 | protected void onCreate (Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); 14 | initialize(new ToxGame(), config); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | println GradleVersion.current().prettyPrint() 2 | assert gradle.gradleVersion >= "1.10" 3 | 4 | buildscript { 5 | 6 | ext.gdxVersion = '1.5.3' 7 | ext.artemisVersion = '0.8.1' 8 | 9 | repositories { 10 | maven { 11 | url 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/' 12 | } 13 | mavenCentral() 14 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } 15 | } 16 | 17 | dependencies { 18 | classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.3' 19 | classpath 'com.android.tools.build:gradle:0.7.+' 20 | classpath 'com.github.jtakakura:gradle-robovm-plugin:0.0.4' 21 | classpath "com.badlogicgames.gdx:gdx-tools:$gdxVersion" 22 | } 23 | } 24 | 25 | allprojects { 26 | apply plugin: "eclipse" 27 | apply plugin: "idea" 28 | 29 | version = "1.0" 30 | ext.appName = "tox" 31 | 32 | // Uncomment line below with proper parameters to pass to TexturePacker 33 | // and TexturePacker will be invoked automagically whenever the target 34 | // "texurePacker" is invoked, e.g. "./gradlew texturePacker desktop:run" 35 | 36 | // ext.texturePacker = ['images', 'android/assets/data', 'gamegdx'] 37 | 38 | repositories { 39 | mavenCentral() 40 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } 41 | mavenLocal(); 42 | } 43 | } 44 | 45 | project(":core") { 46 | apply plugin: "java" 47 | 48 | dependencies { 49 | compile "com.badlogicgames.gdx:gdx:$gdxVersion" 50 | } 51 | } 52 | 53 | project(":desktop") { 54 | apply plugin: "java" 55 | apply plugin: "application" 56 | 57 | dependencies { 58 | compile project(":core") 59 | compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" 60 | compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" 61 | } 62 | } 63 | 64 | project(":android") { 65 | apply plugin: "android" 66 | 67 | configurations { natives } 68 | 69 | dependencies { 70 | compile project(":core") 71 | compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion" 72 | natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi" 73 | natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a" 74 | } 75 | } 76 | 77 | project(":gwt") { 78 | apply plugin: "gwt" 79 | apply plugin: "war" 80 | webAppDirName = 'webapp' 81 | 82 | dependencies { 83 | compile project(":core") 84 | compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion" 85 | compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources" 86 | compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources" 87 | compile "net.onedaybeard.artemis:artemis-odb-gwt:$artemisVersion" 88 | compile "net.onedaybeard.artemis:artemis-odb-gwt:$artemisVersion:sources" 89 | compile "net.onedaybeard.artemis:artemis-odb:$artemisVersion" 90 | compile "net.onedaybeard.artemis:artemis-odb:$artemisVersion:sources" 91 | } 92 | 93 | gwt { 94 | gwtVersion='2.6.0' // Should match the gwt version used for building the gwt backend 95 | maxHeapSize="4G" // Default 256m is not enough for gwt compiler. GWT is HUNGRY 96 | minHeapSize="2G" 97 | 98 | src = files(file("src/")) // Needs to be in front of "modules" below. 99 | modules 'net.mostlyoriginal.tox.GdxDefinition' 100 | 101 | compiler { 102 | strict = true; 103 | enableClosureCompiler = true; 104 | disableClassMetadata = false; 105 | disableCastChecking = false; 106 | } 107 | } 108 | } 109 | 110 | project(":ios") { 111 | apply plugin: 'java' 112 | apply plugin: 'robovm' 113 | 114 | ext { 115 | mainClassName = "net.mostlyoriginal.tox.IOSLauncher" 116 | roboVMVersion = "0.0.9" 117 | } 118 | 119 | configurations { natives } 120 | 121 | dependencies { 122 | compile "org.robovm:robovm-rt:${roboVMVersion}" 123 | compile "org.robovm:robovm-cocoatouch:${roboVMVersion}" 124 | compile project(":core") 125 | compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion" 126 | compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios" 127 | natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios" 128 | } 129 | } 130 | 131 | 132 | tasks.eclipse.doLast { 133 | delete ".project" 134 | } 135 | 136 | 137 | idea { 138 | project { 139 | jdkName = '1.7' 140 | languageLevel = '1.7' 141 | } 142 | } -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | 3 | sourceCompatibility = 1.7 4 | 5 | dependencies { 6 | compile "com.badlogicgames.gdx:gdx:$gdxVersion" 7 | compile "net.onedaybeard.artemis:artemis-odb:$artemisVersion" 8 | compile "net.onedaybeard.artemis:artemis-odb:$artemisVersion:sources" 9 | } 10 | 11 | sourceSets.main.java.srcDirs = [ "src/" ] 12 | 13 | eclipse.project { 14 | name = appName + "-core" 15 | } 16 | 17 | import com.badlogic.gdx.tools.texturepacker.TexturePacker 18 | task texturePacker << { 19 | if (project.ext.has('texturePacker')) { 20 | logger.info "Calling TexturePacker: "+texturePacker 21 | TexturePacker.process(texturePacker[0], texturePacker[1], texturePacker[2]) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/core.iml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/EntityUtils.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | import com.artemis.Component; 4 | import com.artemis.Entity; 5 | import com.artemis.managers.TagManager; 6 | import com.artemis.utils.Bag; 7 | import net.mostlyoriginal.tox.component.Health; 8 | import net.mostlyoriginal.tox.component.Inventory; 9 | import net.mostlyoriginal.tox.component.Position; 10 | import net.mostlyoriginal.tox.component.Toxication; 11 | 12 | /** 13 | * @author Daan van Yperen 14 | */ 15 | public class EntityUtils { 16 | 17 | /** 18 | * Copy entity from old world into the new one. 19 | * 20 | * This assumes the old world is no longer in use, and is potentially unsafe if it isn't. (The components are not cloned, just reused!) 21 | */ 22 | public static Entity copyEntityFromOldWorld( Entity old ) 23 | { 24 | Entity entity = Tox.world.createEntity(); 25 | 26 | Bag fillBag = new Bag(); 27 | 28 | old.getComponents(fillBag); 29 | for ( Component comp : fillBag ) 30 | { 31 | entity.addComponent(comp); 32 | } 33 | 34 | return entity; 35 | } 36 | 37 | 38 | /** 39 | * Quick hack to transfer player state to the next level. 40 | * 41 | * Kinda funky stuff here. Be weary! 42 | * 43 | * @param x 44 | * @param y 45 | * @param legacyPlayer 46 | * @return 47 | */ 48 | public static Entity cloneLegacyPlayer(int x, int y, Entity legacyPlayer) { 49 | 50 | Entity player = copyEntityFromOldWorld(legacyPlayer); 51 | 52 | player.getComponent(Toxication.class).toxication = 0.5f; 53 | player.getComponent(Health.class).damage = 0; 54 | 55 | Position position = player.getComponent(Position.class); 56 | position.x = x; position.y = y; 57 | 58 | // copy over the old inventory. 59 | Inventory oldInventory = legacyPlayer.getComponent(Inventory.class); 60 | 61 | 62 | Inventory inventory = player.getComponent(Inventory.class); 63 | { 64 | for ( int i =0; i<3;i++) 65 | { 66 | if ( oldInventory.carried[i] != null ) 67 | { 68 | inventory.carried[i] = copyEntityFromOldWorld(oldInventory.carried[i]); 69 | inventory.carried[i].addToWorld(); 70 | } 71 | } 72 | 73 | } 74 | 75 | Tox.world.getManager(TagManager.class).register(EntityFactory.PLAYER_TAG, player); 76 | 77 | return player; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/GridGenerator.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | import com.badlogic.gdx.math.MathUtils; 4 | import com.badlogic.gdx.math.Vector2; 5 | import net.mostlyoriginal.tox.system.CombatSystem; 6 | 7 | /** 8 | * @author Daan van Yperen 9 | */ 10 | public class GridGenerator { 11 | 12 | public final int w; 13 | public final int h; 14 | private final int startingLevel; 15 | 16 | public TileData[][] tile; 17 | 18 | public int exitDepth; 19 | public int exitX; 20 | public int exitY; 21 | public int entranceX; 22 | public int entranceY; 23 | 24 | 25 | public GridGenerator(int w, int h, int startingLevel) { 26 | 27 | this.w = w; 28 | this.h = h; 29 | this.startingLevel = startingLevel ; 30 | tile = new TileData[w][h]; 31 | } 32 | 33 | private void reset() { 34 | exitDepth = -1; 35 | exitX = -1; 36 | exitY = -1; 37 | entranceX = -1; 38 | entranceY = -1; 39 | 40 | for (int x = 0; x < w; x++) 41 | for (int y = 0; y < h; y++) { 42 | tile[x][y] = new TileData(); 43 | } 44 | } 45 | 46 | public void generate() { 47 | 48 | final int playerSimulatedLevel = 1; 49 | final int playerSimulatedHealth = 0; 50 | 51 | //<=(distanceEntranceToExit() <= 4) 52 | while ( (exitDepth <= 6) || (distanceEntranceToExit() <= 4) ) 53 | { 54 | exitDepth = -1; 55 | reset(); 56 | generateBlockedSections(); 57 | generateDrugs(); 58 | generationStep(MathUtils.random(0, w - 1), MathUtils.random(0, h - 1), null); 59 | if ( exitDepth > -1 ) 60 | { 61 | tile[exitX][exitY].type = TileType.EXIT; 62 | tile[exitX][exitY].conceal=false; 63 | } 64 | } 65 | } 66 | 67 | private void generateDrugs() { 68 | if ( MathUtils.random() < 0.6f ) tile[MathUtils.random(0, w - 1)][MathUtils.random(0, h - 1)].type = TileType.DRUG_OTHER_WORLD; 69 | if ( MathUtils.random() < 0.5f ) tile[MathUtils.random(0, w - 1)][MathUtils.random(0, h - 1)].type = TileType.DRUG_SWAP; 70 | } 71 | 72 | private float distanceEntranceToExit() { 73 | float dst = new Vector2(entranceX, entranceY).dst(exitX, exitY); 74 | return dst; 75 | } 76 | 77 | private void generateBlockedSections() { 78 | 79 | for ( int i=0,s=(MathUtils.random(1, 3)+MathUtils.random(1,8)); i = w || y >= h || tile[x][y].depth != -1 93 | || tile[x][y].type == TileType.BLOCKED 94 | || tile[x][y].type == TileType.DRUG_SWAP 95 | || tile[x][y].type == TileType.DRUG_OTHER_WORLD ) 96 | return; 97 | 98 | TileData data = tile[x][y]; 99 | if (origin == null) { 100 | data.type = TileType.ENTRANCE; 101 | data.depth = 0; 102 | data.conceal=false; 103 | data.effectivePlayerLevel = startingLevel; 104 | entranceX = x; 105 | entranceY = y; 106 | } else { 107 | data.depth = origin.depth + 1; 108 | generateTile(x, y, origin); 109 | if (data.depth > exitDepth) { 110 | exitDepth = data.depth; 111 | exitX = x; 112 | exitY = y; 113 | } 114 | } 115 | 116 | for (Direction direction : shuffledDirections()) { 117 | generationStep(x + direction.dx, y + direction.dy, data); 118 | } 119 | } 120 | 121 | private void generateTile(int x, int y, TileData origin) { 122 | 123 | TileData data = tile[x][y]; 124 | 125 | data.effectivePlayerLevel = origin.effectivePlayerLevel; 126 | data.expectedPlayerDamage = origin.expectedPlayerDamage; 127 | 128 | // 1. determine health we can work with. 129 | int health = origin.getHealth(); 130 | 131 | boolean hasHighHealth = origin.effectivePlayerLevel / 2 < health; 132 | boolean hasLowHealth = health < origin.effectivePlayerLevel / 3; 133 | 134 | // conceal any tile. 135 | float concealPercentage = 15; 136 | 137 | // 2. Place tile based on probability. 138 | // 2a. High health? Big chance of monster. 139 | float monsterChance = 25; 140 | float healChance = 25; 141 | float trapChance = 10; 142 | float itemChance = 8; 143 | 144 | if ( hasLowHealth ) 145 | { 146 | healChance = 90; 147 | monsterChance = 0; 148 | trapChance = 0; 149 | itemChance = 20; 150 | } else if ( hasHighHealth ) 151 | { 152 | trapChance = 40; 153 | healChance = 0; 154 | monsterChance = 60; 155 | } 156 | 157 | if ( MathUtils.random(0,100) < concealPercentage ) 158 | { 159 | data.conceal = true; 160 | } 161 | 162 | float chance = MathUtils.random(0, healChance + monsterChance + trapChance + itemChance ); 163 | 164 | chance -= healChance; 165 | if ( chance < 0 && healChance > 0 ) 166 | { 167 | // all damage gone! 168 | data.type = TileType.HEALTH; 169 | data.expectedPlayerDamage = 0; 170 | return; 171 | } 172 | 173 | chance -= monsterChance; 174 | if ( chance < 0 && monsterChance > 0 ) 175 | { 176 | data.type = TileType.MONSTER; 177 | 178 | // Since monsters hit damage below their level, we can take higher level monsters. 179 | float maxMonsterLevel = (origin.getHealth() / CombatSystem.MONSTER_DAMAGE_FACTOR) - 1; 180 | 181 | data.effectLevel = MathUtils.random(1, (int)maxMonsterLevel); 182 | 183 | // level up for winning! 184 | data.effectivePlayerLevel += CombatSystem.DEFEAT_MONSTER_LEVEL_REWARD; 185 | 186 | // but player gets damaged. Combat is brutal. 187 | data.expectedPlayerDamage += (int)(CombatSystem.getDamageByMonsterLevel(data.effectLevel)); 188 | 189 | return; 190 | } 191 | 192 | chance -= trapChance; 193 | if ( chance < 0 && trapChance > 0 ) 194 | { 195 | data.type = TileType.TRAP; 196 | 197 | // traps are basically monsters that you don't level from. :p 198 | 199 | // Since monsters hit damage below their level, we can take higher level monsters. 200 | float maxTrapLevel = (origin.getHealth() / CombatSystem.TRAP_DAMAGE_FACTOR) - 1; 201 | data.effectLevel = MathUtils.random(1, (int)maxTrapLevel); 202 | 203 | // but player gets damaged. Combat is brutal. 204 | data.expectedPlayerDamage += (int)(CombatSystem.getDamageByMonsterLevel(data.effectLevel)); 205 | 206 | return; 207 | } 208 | 209 | chance -= itemChance; 210 | if ( chance < 0 && itemChance > 0 ) 211 | { 212 | 213 | // all damage gone! 214 | data.type = 215 | MathUtils.random() < 0.40f ? TileType.TRINKET : MathUtils.random() < 0.20f ? TileType.ARMOR : TileType.WEAPON; 216 | // @todo weapons give a level boost. 217 | return; 218 | } 219 | 220 | } 221 | 222 | private Direction[] shuffledDirections() { 223 | Direction[] list = Direction.values(); 224 | for (int index = 0; index < list.length; index++) { 225 | Direction tmp = list[index]; 226 | int index2 = index + MathUtils.random(list.length - index - 1); 227 | list[index] = list[index2]; 228 | list[index2] = tmp; 229 | } 230 | return list; 231 | } 232 | 233 | private TileType randomStep(int d) { 234 | 235 | return TileType.NOTHING; 236 | /* 237 | switch ( MathUtils.random(0, 3)) { 238 | case 1 : return TileType.TRAP; 239 | case 2 : return TileType.WEAPON; 240 | case 3 : return TileType.RANDOM; 241 | default: return TileType.MONSTER; 242 | } */ 243 | 244 | 245 | } 246 | 247 | enum Direction { 248 | NORTH(0, 1), SOUTH(0, -1), EAST(1, 0), WEST(-1, 0); 249 | public final int dx; 250 | public final int dy; 251 | 252 | Direction(int dx, int dy) { 253 | this.dx = dx; 254 | this.dy = dy; 255 | } 256 | } 257 | 258 | public static class TileData { 259 | public TileType type = TileType.NOTHING; 260 | public int effectLevel = -1; 261 | public int effectivePlayerLevel = 1; 262 | public int expectedPlayerDamage = 0; 263 | public int depth = -1; 264 | public boolean conceal = false; 265 | 266 | public int getHealth() { return effectivePlayerLevel - expectedPlayerDamage ; } 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/MyUtil.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | import com.badlogic.gdx.math.Vector2; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class MyUtil { 9 | 10 | private static final Vector2 v2tmp = new Vector2(); 11 | 12 | public static float distance( float x1, float y1, float x2, float y2 ) 13 | { 14 | return v2tmp.set(x1,y1).dst(x2,y2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/Score.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | /** 4 | * @author Daan van Yperen 5 | */ 6 | public class Score { 7 | public static final int STARTING_FLOOR = 20; 8 | 9 | public static final int POINTS_MONSTER_KILL = 100; 10 | public static final int POINTS_MONSTER_KILL_PER_LEVEL = 10; 11 | public static final int POINTS_NEXT_LEVEL = 1000; 12 | public static final int POINTS_GRAB_ITEM = 150; 13 | public static final int POINTS_KILL_JAILER = 5000; 14 | 15 | public int floor = STARTING_FLOOR; 16 | public String killer; 17 | public int stars; 18 | public int points = 0; 19 | public int playerLevel=1; 20 | 21 | 22 | public String floorName() { 23 | 24 | if (floor == 1) return "1st floor"; 25 | if (floor == 2) return "2nd floor"; 26 | if (floor == 3) return "3rd floor"; 27 | 28 | return floor + "th floor"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/Settings.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import com.badlogic.gdx.Preferences; 5 | import com.badlogic.gdx.math.MathUtils; 6 | 7 | /** 8 | * @author Daan van Yperen 9 | */ 10 | public class Settings { 11 | 12 | public static final String PREF_MUSIC_ON = "musicOn"; 13 | public static final String PREF_SFX_ON = "sfxOn"; 14 | private static final String PREF_PERSONAL_HIGHSCORE = "highestscore"; 15 | private static final String PREF_PERSONAL_HIGHSCORE_STARS = "highestscorestars"; 16 | private Preferences prefs = Gdx.app.getPreferences("ToxPreferences"); 17 | 18 | public float sfxVolume = 0.3f; 19 | public float musicVolume = 0.2f; 20 | public boolean sfxOn; 21 | public boolean musicOn; 22 | public ToxResource.PlayerModel playerModel = MathUtils.randomBoolean() ? ToxResource.PlayerModel.MALE : ToxResource.PlayerModel.FEMALE; 23 | 24 | public int personalHighscore = 0; 25 | public int personalHighscoreStars = 0; 26 | 27 | public Settings() { 28 | load(); 29 | } 30 | 31 | public void load() 32 | { 33 | sfxOn = prefs.getBoolean(PREF_SFX_ON,true); 34 | musicOn = prefs.getBoolean(PREF_MUSIC_ON,true); 35 | personalHighscore = prefs.getInteger(PREF_PERSONAL_HIGHSCORE,0); 36 | personalHighscoreStars = prefs.getInteger(PREF_PERSONAL_HIGHSCORE_STARS,0); 37 | 38 | } 39 | 40 | public void save() 41 | { 42 | prefs.putBoolean(PREF_SFX_ON, sfxOn); 43 | prefs.putBoolean(PREF_MUSIC_ON, musicOn); 44 | prefs.putInteger(PREF_PERSONAL_HIGHSCORE, personalHighscore); 45 | prefs.putInteger(PREF_PERSONAL_HIGHSCORE_STARS, personalHighscoreStars); 46 | prefs.flush(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/TileType.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | /** 4 | * @author Daan van Yperen 5 | */ 6 | public enum TileType { 7 | 8 | ENTRANCE, 9 | EXIT, 10 | NOTHING, 11 | TRAP, 12 | MONSTER, 13 | WEAPON, BLOCKED, HEALTH, DRUG_SWAP, DRUG_OTHER_WORLD, ARMOR, TRINKET; 14 | } 15 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/Tox.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | import com.artemis.Entity; 4 | import com.artemis.World; 5 | 6 | /** 7 | * @author Daan van Yperen 8 | */ 9 | public abstract class Tox { 10 | public static ToxGame game; 11 | public static GameScreen gameScreen; 12 | public static ToxResource resource; 13 | public static World world; 14 | 15 | public static Settings settings = new Settings(); 16 | 17 | public static Entity legacyPlayer; 18 | public static Score score; 19 | } 20 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/ToxGame.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/ToxGame.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | import com.badlogic.gdx.Game; 4 | import net.mostlyoriginal.tox.screen.DialogScreen; 5 | import net.mostlyoriginal.tox.screen.WelcomeScreen; 6 | 7 | public class ToxGame extends Game { 8 | 9 | public void nextLevel() 10 | { 11 | setScreen(new GameScreen()); 12 | } 13 | 14 | @Override 15 | public void create () { 16 | 17 | Tox.game = this; 18 | Tox.resource = new ToxResource(); 19 | 20 | newGame(); 21 | } 22 | 23 | public void newGame() 24 | { 25 | Tox.score = new Score(); 26 | setScreen(new WelcomeScreen()); 27 | } 28 | 29 | public void gotoMessage(String message, boolean startNewGame, boolean showPerformance) { 30 | setScreen(new DialogScreen(message, startNewGame, showPerformance)); 31 | } 32 | 33 | @Override 34 | public void dispose() { 35 | Tox.resource.dispose(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/ToxUtil.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox; 2 | 3 | import com.artemis.Entity; 4 | import com.artemis.managers.TagManager; 5 | import com.badlogic.gdx.math.Vector2; 6 | import net.mostlyoriginal.tox.component.Position; 7 | 8 | /** 9 | * @author Daan van Yperen 10 | */ 11 | public class ToxUtil { 12 | 13 | private static final Vector2 v2tmp = new Vector2(); 14 | 15 | public static float distance( float x1, float y1, float x2, float y2 ) 16 | { 17 | return v2tmp.set(x1,y1).dst(x2,y2); 18 | } 19 | 20 | public static Entity getPlayer() 21 | { 22 | return Tox.world.getManager(TagManager.class).getEntity("player"); 23 | } 24 | 25 | public static boolean tileWithinReach(Position playerPos, Position tilePos, float maxDistance) { 26 | 27 | if ( maxDistance >= 999 ) return true; 28 | 29 | return ( tilePos.x != playerPos.x || tilePos.y != playerPos.y ) && ToxUtil.distance(tilePos.x, tilePos.y, playerPos.x, playerPos.y) <= maxDistance; 30 | } 31 | 32 | public static boolean isPlayer(Entity e) { 33 | return getPlayer() == e; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Animation.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | import com.badlogic.gdx.graphics.Color; 5 | 6 | /** 7 | * @author Daan van Yperen 8 | */ 9 | public class Animation extends Component { 10 | 11 | public static enum Layer 12 | { 13 | GLOBAL_BACKGROUND, 14 | TILE_BACKGROUND, 15 | TILE, 16 | TILE_UNDER_COVER, 17 | TILE_COVER, 18 | PARTICLE, 19 | PARTICLE2, 20 | SCREEN, 21 | SCREEN_PARTICLE, 22 | SCREEN_PARTICLE2 23 | 24 | }; 25 | 26 | public static final int DEFAULT_SCALE = 2; 27 | 28 | public final Color color = new Color(1,1,1,1); 29 | public String id; 30 | public String behindId; 31 | public float scale = DEFAULT_SCALE; 32 | public float stretchX = 1; 33 | public float age = 0; 34 | public float speed = 1; 35 | public float rotation; 36 | public boolean frozen = false; 37 | public Layer layer = Layer.TILE; 38 | 39 | public Animation(String id) { 40 | this.id = id; 41 | } 42 | public Animation(String id, Layer layer ) { 43 | this.id = id; 44 | this.layer = layer; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Bullet.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Bullet extends Component { 9 | } 10 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Cleared.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * Cleared location. 7 | * 8 | * @author Daan van Yperen 9 | */ 10 | public class Cleared extends Component { 11 | } 12 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/ColorAnimation.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | import com.badlogic.gdx.graphics.Color; 5 | import com.badlogic.gdx.math.Interpolation; 6 | 7 | /** 8 | * @author Daan van Yperen 9 | */ 10 | public class ColorAnimation extends Component { 11 | public Color minColor; 12 | public Color maxColor; 13 | public Interpolation tween; 14 | public float duration = -1; 15 | public Color speed = new Color(1, 1, 1, 1); 16 | public Color age = new Color(0, 0, 0, 0); 17 | 18 | /** 19 | * 20 | * @param minColor 21 | * @param maxColor 22 | * @param tween 23 | * @param speed 24 | * @param duration duration until this ends, or -1 if unending. 25 | */ 26 | public ColorAnimation(Color minColor, Color maxColor, Interpolation tween, float speed, float duration) { 27 | this.minColor = minColor; 28 | this.maxColor = maxColor; 29 | this.tween = tween; 30 | this.duration = duration; 31 | this.speed.r = this.speed.g = this.speed.b = this.speed.a = speed; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Conceal.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | import com.artemis.Entity; 5 | 6 | /** 7 | * Conceal entity until interacted. 8 | * 9 | * @author Daan van Yperen 10 | */ 11 | public class Conceal extends Component { 12 | 13 | public Entity entity; 14 | 15 | public Conceal(Entity entity) { 16 | this.entity = entity; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/DissolvesOnTouch.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class DissolvesOnTouch extends Component { 9 | } 10 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/EquipBonus.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class EquipBonus extends Component { 9 | public int attack=0; 10 | public int defense=0; 11 | public Effect effect = Effect.NONE; 12 | 13 | public static enum Effect { 14 | NONE, 15 | TEDDY, 16 | STASH, 17 | GRENADE, 18 | MEDPACK, 19 | PET, 20 | SPIDERS_ANTS 21 | } 22 | 23 | public EquipBonus() { 24 | } 25 | 26 | public EquipBonus(int attack, int defense) { 27 | this.attack = attack; 28 | this.defense = defense; 29 | } 30 | 31 | public void stack( EquipBonus bonus ) 32 | { 33 | attack += bonus.attack; 34 | defense += bonus.defense; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "EquipBonus{" + 40 | "attack=" + attack + 41 | ", defense=" + defense + 42 | '}'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Exit.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * Lootable item 7 | * 8 | * @author Daan van Yperen 9 | */ 10 | public class Exit extends Component { 11 | } 12 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Fightable.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | import com.badlogic.gdx.math.MathUtils; 5 | 6 | /** 7 | * @author Daan van Yperen 8 | */ 9 | public class Fightable extends Component { 10 | public String deathSfx = "tox_sfx_grunt_male" + MathUtils.random(1, 3); 11 | } 12 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Health.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Health extends Component { 9 | 10 | public float maxHealth; 11 | public float damage; 12 | 13 | public Health(int maxHealth) { 14 | this.maxHealth = maxHealth; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Inventory.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | import com.artemis.Entity; 5 | 6 | /** 7 | * @author Daan van Yperen 8 | */ 9 | public class Inventory extends Component { 10 | 11 | public static enum Slot { 12 | BODY, 13 | HAND, 14 | MISC 15 | } 16 | 17 | public Entity[] carried = new Entity[3]; 18 | } 19 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Label.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Label extends Component { 9 | public String label; 10 | 11 | public Label(String label) { 12 | this.label = label; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Level.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Level extends Component { 9 | public int level = 1; 10 | 11 | public Level(int level) { 12 | this.level = level; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Lootable.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * Lootable item 7 | * 8 | * @author Daan van Yperen 9 | */ 10 | public class Lootable extends Component { 11 | 12 | public Effect effect; 13 | public String pickupSfx; 14 | public String useSfx; 15 | 16 | public static enum Effect { 17 | HEAL, 18 | PHASE, 19 | SWAP, HAND_PICKUP, BODY_PICKUP, MISC_PICKUP; 20 | } 21 | 22 | public boolean consumeInstantly = true; 23 | 24 | public Lootable(Effect effect, String pickupSfx, String useSfx) { 25 | this.effect = effect; 26 | this.pickupSfx = pickupSfx; 27 | this.useSfx = useSfx; 28 | } 29 | 30 | public Lootable() { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Named.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Named extends Component { 9 | public String name; 10 | 11 | public Named(String name) { 12 | this.name = name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Physics.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Physics extends Component { 9 | 10 | public float gravity = 0; 11 | public float velocityX = 0; 12 | public float velocityY = 0; 13 | } 14 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Position.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Position extends Component { 9 | public float x, y; 10 | 11 | public Position(float x, float y) { 12 | this.x = x; 13 | this.y = y; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Reward.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Reward extends Component { 9 | public int points; 10 | 11 | public Reward(int points) { 12 | this.points = points; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/ScaleAnimation.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.badlogic.gdx.math.Interpolation; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class ScaleAnimation { 9 | float scaleXMin=1, scaleXMax=1, durationX=1; 10 | Interpolation scaleX=Interpolation.bounceIn; 11 | float scaleYMin=1, scaleYMax=1, durationY=1; 12 | Interpolation scaleY=Interpolation.bounceIn; 13 | } 14 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Selectable.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Selectable extends Component { 9 | public boolean selected; 10 | public float maxDistance = 40 * Animation.DEFAULT_SCALE; 11 | } 12 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Setting.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Setting extends Component { 9 | 10 | public final SettingType type; 11 | 12 | public static enum SettingType 13 | { 14 | MUSIC, 15 | SFX 16 | } 17 | 18 | public Setting(SettingType type) { 19 | this.type = type; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Terminal.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * Patient is terminal and will be removed after X. 7 | * 8 | * @author Daan van Yperen 9 | */ 10 | public class Terminal extends Component { 11 | 12 | public float survivalDuration; 13 | 14 | public Terminal(float survivalDuration) { 15 | this.survivalDuration = survivalDuration; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Toxication.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Toxication extends Component { 9 | 10 | public float maxToxication; 11 | public float toxication; 12 | 13 | public Toxication(float maxToxication) { 14 | this.maxToxication = maxToxication; 15 | this.toxication = this.maxToxication * 0.5f; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/component/Trap.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.component; 2 | 3 | import com.artemis.Component; 4 | 5 | /** 6 | * @author Daan van Yperen 7 | */ 8 | public class Trap extends Component { 9 | } 10 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/screen/DialogScreen.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.screen; 2 | 3 | import com.artemis.World; 4 | import com.badlogic.gdx.Gdx; 5 | import com.badlogic.gdx.Screen; 6 | import com.badlogic.gdx.graphics.GL20; 7 | import com.badlogic.gdx.graphics.OrthographicCamera; 8 | import net.mostlyoriginal.tox.EntityFactory; 9 | import net.mostlyoriginal.tox.system.ParticleSystem; 10 | import net.mostlyoriginal.tox.Tox; 11 | import net.mostlyoriginal.tox.system.*; 12 | 13 | /** 14 | * @author Daan van Yperen 15 | */ 16 | public class DialogScreen implements Screen { 17 | 18 | private final OrthographicCamera camera; 19 | 20 | public DialogScreen(String messageSpriteId, boolean startNewGame, boolean showPerformance) { 21 | 22 | camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 23 | camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 24 | camera.update(); 25 | 26 | Tox.world = new World(); 27 | 28 | Tox.world.setSystem(new CameraShakeSystem(camera)); 29 | 30 | Tox.world.setSystem(new SelectableSystem()); 31 | Tox.world.setSystem(new SettingSystem()); 32 | 33 | Tox.world.setSystem(new PhysicsSystem()); 34 | Tox.world.setSystem(new ParticleSystem()); 35 | 36 | Tox.world.setSystem(new AnimationRenderSystem(camera)); 37 | if ( showPerformance ) { 38 | Tox.world.setSystem(new TombstoneSystem(camera)); 39 | } 40 | Tox.world.setSystem(new ContinueSystem(startNewGame)); 41 | Tox.world.setSystem(new SoundSystem()); 42 | 43 | Tox.world.setSystem(new StarPlopSystem()); 44 | 45 | Tox.world.initialize(); 46 | 47 | EntityFactory.createGradientBackground().addToWorld(); 48 | EntityFactory.createScreen(messageSpriteId).addToWorld(); 49 | } 50 | 51 | @Override 52 | public void render(float delta) { 53 | 54 | Gdx.gl.glClearColor(0, 0, 0, 1); 55 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 56 | 57 | camera.update(); 58 | Tox.world.setDelta(delta); 59 | Tox.world.process(); 60 | } 61 | 62 | @Override 63 | public void resize(int width, int height) { 64 | 65 | } 66 | 67 | @Override 68 | public void show() { 69 | 70 | } 71 | 72 | @Override 73 | public void hide() { 74 | 75 | } 76 | 77 | @Override 78 | public void pause() { 79 | 80 | } 81 | 82 | @Override 83 | public void resume() { 84 | 85 | } 86 | 87 | @Override 88 | public void dispose() { 89 | 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/screen/WelcomeScreen.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.screen; 2 | 3 | import com.artemis.World; 4 | import com.badlogic.gdx.Gdx; 5 | import com.badlogic.gdx.Screen; 6 | import com.badlogic.gdx.graphics.GL20; 7 | import com.badlogic.gdx.graphics.OrthographicCamera; 8 | import net.mostlyoriginal.tox.EntityFactory; 9 | import net.mostlyoriginal.tox.system.ParticleSystem; 10 | import net.mostlyoriginal.tox.Tox; 11 | import net.mostlyoriginal.tox.system.*; 12 | 13 | /** 14 | * @author Daan van Yperen 15 | */ 16 | public class WelcomeScreen implements Screen { 17 | 18 | private final OrthographicCamera camera; 19 | 20 | public WelcomeScreen() { 21 | 22 | camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 23 | camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 24 | camera.update(); 25 | 26 | Tox.world = new World(); 27 | 28 | Tox.world.setSystem(new CameraShakeSystem(camera)); 29 | 30 | Tox.world.setSystem(new SelectableSystem()); 31 | Tox.world.setSystem(new SettingSystem()); 32 | 33 | Tox.world.setSystem(new PhysicsSystem()); 34 | Tox.world.setSystem(new ParticleSystem()); 35 | 36 | Tox.world.setSystem(new AnimationRenderSystem(camera)); 37 | Tox.world.setSystem(new HighscoreSystem(camera)); 38 | Tox.world.setSystem(new ContinueSystem(false)); 39 | Tox.world.setSystem(new SoundSystem()); 40 | 41 | Tox.world.initialize(); 42 | 43 | EntityFactory.createGradientBackground().addToWorld(); 44 | EntityFactory.createScreen("dialog-welcome").addToWorld(); 45 | } 46 | 47 | @Override 48 | public void render(float delta) { 49 | 50 | Gdx.gl.glClearColor(0, 0, 0, 1); 51 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 52 | 53 | camera.update(); 54 | Tox.world.setDelta(delta); 55 | Tox.world.process(); 56 | } 57 | 58 | @Override 59 | public void resize(int width, int height) { 60 | 61 | } 62 | 63 | @Override 64 | public void show() { 65 | 66 | } 67 | 68 | @Override 69 | public void hide() { 70 | 71 | } 72 | 73 | @Override 74 | public void pause() { 75 | 76 | } 77 | 78 | @Override 79 | public void resume() { 80 | 81 | } 82 | 83 | @Override 84 | public void dispose() { 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/AnimationRenderSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.EntitySystem; 7 | import com.artemis.annotations.Mapper; 8 | import com.artemis.utils.ImmutableBag; 9 | import com.badlogic.gdx.graphics.OrthographicCamera; 10 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 11 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 12 | import net.mostlyoriginal.tox.Tox; 13 | import net.mostlyoriginal.tox.component.Animation; 14 | import net.mostlyoriginal.tox.component.Position; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collections; 18 | import java.util.Comparator; 19 | import java.util.List; 20 | 21 | /** 22 | * @author Daan van Yperen 23 | */ 24 | public class AnimationRenderSystem extends EntitySystem { 25 | 26 | @Mapper 27 | ComponentMapper pm; 28 | 29 | @Mapper 30 | ComponentMapper sm; 31 | 32 | private SpriteBatch batch = new SpriteBatch(); 33 | private OrthographicCamera camera; 34 | private List sortedEntities = new ArrayList(); 35 | private boolean sortedDirty = false; 36 | public Comparator layerSortComperator = new Comparator() { 37 | @Override 38 | public int compare(Entity e1, Entity e2) { 39 | Animation s1 = sm.get(e1); 40 | Animation s2 = sm.get(e2); 41 | return s1.layer.compareTo(s2.layer); 42 | } 43 | }; 44 | 45 | private CombatSystem combatSystem; 46 | public ThreatRenderSystem threatRenderSystem; 47 | 48 | public AnimationRenderSystem(OrthographicCamera camera) { 49 | super(Aspect.getAspectForAll(Position.class, Animation.class)); 50 | this.camera = camera; 51 | } 52 | 53 | @Override 54 | protected void initialize() { 55 | super.initialize(); 56 | 57 | combatSystem = world.getSystem(CombatSystem.class); 58 | threatRenderSystem = world.getSystem(ThreatRenderSystem.class); 59 | } 60 | 61 | @Override 62 | protected void begin() { 63 | batch.setProjectionMatrix(camera.combined); 64 | batch.begin(); 65 | batch.setColor(1f, 1f, 1f, 1f); 66 | } 67 | 68 | @Override 69 | protected void end() { 70 | batch.end(); 71 | } 72 | 73 | @Override 74 | protected void processEntities(ImmutableBag entities) { 75 | 76 | if (sortedDirty) { 77 | sortedDirty = false; 78 | Collections.sort(sortedEntities, layerSortComperator); 79 | } 80 | 81 | boolean renderedThreat=false; 82 | 83 | for (Entity entity : sortedEntities) { 84 | 85 | if ( threatRenderSystem != null && sm.get(entity).layer.ordinal() > Animation.Layer.TILE_COVER.ordinal() ) 86 | { 87 | renderedThreat=true; 88 | renderThreat(); 89 | } 90 | process(entity); 91 | } 92 | 93 | if ( !renderedThreat ) 94 | { 95 | renderThreat(); 96 | } 97 | } 98 | 99 | private void renderThreat() { 100 | if ( threatRenderSystem != null ) 101 | { 102 | threatRenderSystem.batch = this.batch; 103 | threatRenderSystem.setEnabled(true); 104 | threatRenderSystem.process(); 105 | threatRenderSystem.setEnabled(false); 106 | } 107 | } 108 | 109 | protected void process(final Entity entity) { 110 | 111 | final Animation animation = sm.get(entity); 112 | final Position position = pm.get(entity); 113 | 114 | if (!animation.frozen) { 115 | animation.age += world.getDelta() * animation.speed; 116 | } 117 | 118 | 119 | 120 | batch.setColor( animation.color ); 121 | 122 | if ( animation.behindId != null ) drawAnimation(animation, position, animation.behindId); 123 | drawAnimation(animation, position, animation.id); 124 | } 125 | 126 | private void drawAnimation(final Animation animation, final Position position, String id) { 127 | 128 | final com.badlogic.gdx.graphics.g2d.Animation gdxanim = Tox.resource.get(id); 129 | TextureRegion frame = gdxanim.getKeyFrame(animation.age, true); 130 | 131 | if ( animation.rotation != 0 ) 132 | { 133 | batch.draw(frame, 134 | position.x, 135 | position.y, 136 | frame.getRegionWidth() * animation.scale * 0.5f * animation.stretchX, 137 | frame.getRegionHeight() * animation.scale * 0.5f, 138 | frame.getRegionWidth() * animation.scale * animation.stretchX, 139 | frame.getRegionHeight() * animation.scale, 1, 1, 140 | animation.rotation); 141 | } else { 142 | batch.draw(frame, 143 | position.x, 144 | position.y, 145 | frame.getRegionWidth() * animation.scale * animation.stretchX, 146 | frame.getRegionHeight() * animation.scale); 147 | } 148 | } 149 | 150 | @Override 151 | protected boolean checkProcessing() { 152 | return true; 153 | } 154 | 155 | 156 | @Override 157 | protected void inserted(Entity e) { 158 | sortedEntities.add(e); 159 | sortedDirty = true; 160 | } 161 | 162 | @Override 163 | protected void removed(Entity e) { 164 | sortedEntities.remove(e); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/BacktrackSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.systems.EntityProcessingSystem; 8 | import net.mostlyoriginal.tox.Tox; 9 | import net.mostlyoriginal.tox.ToxUtil; 10 | import net.mostlyoriginal.tox.component.*; 11 | 12 | /** 13 | * Allows players to step back to an earlier location. 14 | * 15 | * @author Daan van Yperen 16 | */ 17 | public class BacktrackSystem extends EntityProcessingSystem { 18 | 19 | @Mapper 20 | ComponentMapper pm; 21 | 22 | @Mapper 23 | ComponentMapper sm; 24 | 25 | public BacktrackSystem() { 26 | super(Aspect.getAspectForAll(Position.class, Selectable.class, Cleared.class)); 27 | } 28 | 29 | @Override 30 | protected void process(Entity e) { 31 | if (sm.get(e).selected) { 32 | final Position p = pm.get(e); 33 | Entity player = ToxUtil.getPlayer(); 34 | Tox.world.getSystem(PlayerSystem.class).walkTo(player, p); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/BulletSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.annotations.Wire; 8 | import com.artemis.systems.EntityProcessingSystem; 9 | import com.badlogic.gdx.math.Vector2; 10 | import net.mostlyoriginal.tox.ToxResource; 11 | import net.mostlyoriginal.tox.ToxUtil; 12 | import net.mostlyoriginal.tox.component.*; 13 | 14 | /** 15 | * Bullets auto-target the player! 16 | * 17 | * @author Daan van Yperen 18 | */ 19 | @Wire 20 | public class BulletSystem extends EntityProcessingSystem { 21 | 22 | @Mapper ComponentMapper sm; 23 | @Mapper ComponentMapper pm; 24 | @Mapper ComponentMapper phm; 25 | @Mapper ComponentMapper hm; 26 | @Mapper ComponentMapper am; 27 | public ParticleSystem particleSystem; 28 | public CombatSystem combatSystem; 29 | private PlayerSystem playerSystem; 30 | 31 | public BulletSystem() { 32 | super(Aspect.getAspectForAll(Bullet.class, Position.class, Physics.class)); 33 | } 34 | 35 | private Vector2 tmp = new Vector2(); 36 | 37 | @Override 38 | protected void initialize() { 39 | particleSystem = world.getSystem(ParticleSystem.class); 40 | combatSystem = world.getSystem(CombatSystem.class); 41 | playerSystem = world.getSystem(PlayerSystem.class); 42 | } 43 | 44 | @Override 45 | protected void process(Entity e) { 46 | Position position = pm.get(e); 47 | Position playerPos = pm.get(ToxUtil.getPlayer()); 48 | Physics physics = phm.get(e); 49 | 50 | // create vector that points from bullet to player; 51 | int playerX = (int) (playerPos.x + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f); 52 | int playerY = (int) (playerPos.y + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f); 53 | tmp.set(playerX, playerY) 54 | .sub(position.x + Animation.DEFAULT_SCALE * 5, position.y + Animation.DEFAULT_SCALE * 5); 55 | 56 | if (tmp.len() > 20) { 57 | tmp.nor().scl(1200); 58 | am.get(e).rotation = tmp.angle(); 59 | physics.velocityX = tmp.x; 60 | physics.velocityY = tmp.y; 61 | } else { 62 | particleSystem.explosion(playerX, playerY, Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE); 63 | if (combatSystem.isAlive(ToxUtil.getPlayer())) { 64 | combatSystem.damage(ToxUtil.getPlayer(), Math.max(0.1f, hm.get(ToxUtil.getPlayer()).maxHealth / 10)); 65 | if (!combatSystem.isAlive(ToxUtil.getPlayer())) { 66 | playerSystem.killPlayer("The Jailer"); 67 | } 68 | } 69 | e.deleteFromWorld(); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/CameraShakeSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.systems.VoidEntitySystem; 4 | import com.badlogic.gdx.graphics.OrthographicCamera; 5 | import com.badlogic.gdx.math.MathUtils; 6 | import com.badlogic.gdx.math.Vector2; 7 | import com.badlogic.gdx.math.Vector3; 8 | 9 | /** 10 | * @author Daan van Yperen 11 | */ 12 | public class CameraShakeSystem extends VoidEntitySystem { 13 | private OrthographicCamera camera; 14 | public Vector3 originalCameraPos; 15 | public float shake; 16 | public Vector2 push = new Vector2(); 17 | 18 | public CameraShakeSystem(OrthographicCamera camera) { 19 | this.camera = camera; 20 | originalCameraPos = new Vector3(camera.position); 21 | shake = 0; 22 | } 23 | 24 | public void shake(float pixels) { 25 | shake = pixels; 26 | } 27 | 28 | public void push(float x, float y) { 29 | push.x = x; 30 | push.y = y; 31 | } 32 | 33 | @Override 34 | protected void processSystem() { 35 | camera.position.x = (int)(originalCameraPos.x + MathUtils.random(push.x) + (shake != 0 ? MathUtils.random(-shake, shake) : 0)); 36 | camera.position.y = (int)(originalCameraPos.y + MathUtils.random(push.y) + (shake != 0 ? MathUtils.random(-shake, shake) : 0)); 37 | camera.update(); 38 | 39 | if ( shake > 0 ) 40 | { 41 | shake -= world.delta * 4f; 42 | if ( shake < 0 ) shake=0; 43 | } 44 | decrease(push, world.delta * 16f); 45 | } 46 | 47 | private void decrease(final Vector2 v, final float delta) { 48 | if (v.x > 0) { 49 | v.x -= delta; 50 | if (v.x < 0) { 51 | v.x = 0; 52 | } 53 | } 54 | if (v.x < 0) { 55 | v.x += delta; 56 | if (v.x > 0) { 57 | v.x = 0; 58 | } 59 | } 60 | if (v.y > 0) { 61 | v.y -= delta; 62 | if (v.y < 0) { 63 | v.y = 0; 64 | } 65 | } 66 | if (v.y < 0) { 67 | v.y += delta; 68 | if (v.y > 0) { 69 | v.y = 0; 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/ColorAnimationSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.systems.EntityProcessingSystem; 8 | import net.mostlyoriginal.tox.Tox; 9 | import net.mostlyoriginal.tox.component.Animation; 10 | import net.mostlyoriginal.tox.component.ColorAnimation; 11 | 12 | /** 13 | * @author Daan van Yperen 14 | */ 15 | public class ColorAnimationSystem extends EntityProcessingSystem { 16 | 17 | @Mapper 18 | ComponentMapper am; 19 | 20 | @Mapper 21 | ComponentMapper cm; 22 | 23 | public ColorAnimationSystem() { 24 | super(Aspect.getAspectForAll(Animation.class, ColorAnimation.class)); 25 | } 26 | 27 | @Override 28 | protected void process(final Entity entity) { 29 | final Animation animation = am.get(entity); 30 | final ColorAnimation colorAnimation = cm.get(entity); 31 | 32 | // age colors individually. 33 | colorAnimation.age.r += colorAnimation.speed.r * Tox.world.delta; 34 | colorAnimation.age.g += colorAnimation.speed.g * Tox.world.delta; 35 | colorAnimation.age.b += colorAnimation.speed.b * Tox.world.delta; 36 | colorAnimation.age.a += colorAnimation.speed.a * Tox.world.delta; 37 | 38 | // tween colors individually. 39 | animation.color.r = colorAnimation.tween.apply( colorAnimation.minColor.r, colorAnimation.maxColor.r, 1- Math.abs(colorAnimation.age.r % 2f - 1)); 40 | animation.color.g = colorAnimation.tween.apply( colorAnimation.minColor.g, colorAnimation.maxColor.g, 1- Math.abs(colorAnimation.age.g % 2f - 1)); 41 | animation.color.b = colorAnimation.tween.apply( colorAnimation.minColor.b, colorAnimation.maxColor.b, 1- Math.abs(colorAnimation.age.b % 2f - 1)); 42 | animation.color.a = colorAnimation.tween.apply( colorAnimation.minColor.a, colorAnimation.maxColor.a, 1- Math.abs(colorAnimation.age.a % 2f - 1)); 43 | 44 | if ( colorAnimation.duration != -1 ) 45 | { 46 | colorAnimation.duration -= Tox.world.delta; 47 | if ( colorAnimation.duration <= 0 ) 48 | { 49 | animation.color.set(1f,1f,1f,1f); 50 | entity.removeComponent(ColorAnimation.class).changedInWorld(); 51 | } 52 | 53 | } 54 | } 55 | 56 | @Override 57 | protected boolean checkProcessing() { 58 | return true; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/CombatSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.managers.TagManager; 8 | import com.artemis.systems.EntityProcessingSystem; 9 | import com.badlogic.gdx.graphics.Color; 10 | import com.badlogic.gdx.math.Interpolation; 11 | import com.badlogic.gdx.math.MathUtils; 12 | import net.mostlyoriginal.tox.*; 13 | import net.mostlyoriginal.tox.component.*; 14 | 15 | /** 16 | * @author Daan van Yperen 17 | */ 18 | public class CombatSystem extends EntityProcessingSystem { 19 | 20 | public static final float PLAYER_DAMAGE_FACTOR = 2; 21 | public static final Color TRANSPARENT_BLINK_COLOR = new Color(1f, 1f, 1f, 0f); 22 | @Mapper 23 | ComponentMapper pm; 24 | @Mapper 25 | ComponentMapper sm; 26 | @Mapper 27 | ComponentMapper hm; 28 | @Mapper 29 | ComponentMapper tm; 30 | @Mapper 31 | ComponentMapper am; 32 | @Mapper 33 | ComponentMapper nm; 34 | @Mapper 35 | ComponentMapper fm; 36 | @Mapper 37 | ComponentMapper lom; 38 | 39 | @Mapper 40 | ComponentMapper lm; 41 | 42 | private PlayerSystem playerSystem; 43 | private SelectableSystem selectableSystem; 44 | 45 | public static final int DEFEAT_MONSTER_LEVEL_REWARD = 1; 46 | 47 | // damage monsters deal per monster level. 48 | public static final float MONSTER_DAMAGE_FACTOR = 0.3f; 49 | public static final float TRAP_DAMAGE_FACTOR = MONSTER_DAMAGE_FACTOR; 50 | public ParticleSystem particleSystem; 51 | public InventorySystem inventorySystem; 52 | public CameraShakeSystem cameraShakeSystem; 53 | public SoundSystem soundSystem; 54 | public ScoreSystem scoreSystem; 55 | 56 | public CombatSystem() { 57 | super(Aspect.getAspectForAll(Health.class, Level.class, Selectable.class, Fightable.class)); 58 | } 59 | 60 | 61 | @Override 62 | protected void initialize() { 63 | playerSystem = world.getSystem(PlayerSystem.class); 64 | selectableSystem = world.getSystem(SelectableSystem.class); 65 | particleSystem = world.getSystem(ParticleSystem.class); 66 | inventorySystem = world.getSystem(InventorySystem.class); 67 | cameraShakeSystem = world.getSystem(CameraShakeSystem.class); 68 | soundSystem = world.getSystem(SoundSystem.class); 69 | scoreSystem = world.getSystem(ScoreSystem.class); 70 | } 71 | 72 | public static float getDamageByMonsterLevel(int monsterLevel) { 73 | return (monsterLevel * CombatSystem.MONSTER_DAMAGE_FACTOR); 74 | } 75 | 76 | public static float getDamageByPlayerLevel(int playerLevel) { 77 | return playerLevel * CombatSystem.MONSTER_DAMAGE_FACTOR * CombatSystem.PLAYER_DAMAGE_FACTOR; 78 | } 79 | 80 | 81 | @Override 82 | protected void process(Entity monster) { 83 | if (sm.get(monster).selected) { 84 | playerAttack(monster); 85 | } 86 | } 87 | 88 | private void playerAttack(Entity monster) { 89 | 90 | final Entity player = ToxUtil.getPlayer(); 91 | final EquipBonus playerBonus = inventorySystem.getTotalBonus(player); 92 | 93 | // get effective monster damage. Consider player defensive items. 94 | final float monsterDamage = 95 | getDamageByMonsterLevel( 96 | Math.max(1, lm.get(monster).level - playerBonus.defense)); 97 | 98 | // get effective player attack damage. Consider player offensive items. 99 | final float playerDamage = 1 + getDamageByPlayerLevel( 100 | lm.get(player).level + playerBonus.attack); 101 | 102 | 103 | String fightSfx = combatSfx(player); 104 | 105 | if ( fightSfx != null ) soundSystem.play(fightSfx); 106 | //System.out.println("player attack: " + playerDamage + " monster attack: " + monsterDamage + playerBonus + " MONSTER HP: " + hm.get(monster).maxHealth); 107 | damage(monster, playerDamage); 108 | if (isAlive(monster)) { 109 | Position ppos = pm.get(player); 110 | 111 | particleSystem.combatCloud((int) (ppos.x + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f), (int) (ppos.y + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f), ToxResource.TILE_SIZE, 0.25f); 112 | Position mpos = pm.get(monster); 113 | particleSystem.combatCloud((int) (mpos.x + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f), (int) (mpos.y + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f), ToxResource.TILE_SIZE, 0.25f); 114 | 115 | cameraShakeSystem.push( 116 | MathUtils.clamp(mpos.x - ppos.x, -5, 5), 117 | MathUtils.clamp(mpos.y - ppos.y, -5, 5) ); 118 | 119 | // saved by the grenade! 120 | final Health health = hm.get(player); 121 | if ( health.damage + monsterDamage >= health.maxHealth && inventorySystem.hasEffect(EquipBonus.Effect.GRENADE)) 122 | { 123 | inventorySystem.discardByEffect(EquipBonus.Effect.GRENADE); 124 | particleSystem.explosion((int) (mpos.x + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f), (int) (mpos.y + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f),150f); 125 | damage(monster,9999); 126 | monsterDeath(monster); 127 | } else { 128 | damage(player, monsterDamage); 129 | } 130 | 131 | if(!isAlive(player)) 132 | { 133 | playerSystem.killPlayer("level " + lm.get(monster).level + " " + (nm.has(monster) ? nm.get(monster).name : "Baddy") ); 134 | } else { 135 | playerSystem.tickDrug(); 136 | } 137 | } else { 138 | monsterDeath(monster); 139 | } 140 | } 141 | 142 | // fetch sound that belongs with using the hand weapon 143 | private String combatSfx(Entity player) { 144 | Entity hand = inventorySystem.get(Inventory.Slot.HAND); 145 | if ( hand != null && lom.has(hand) ) 146 | { 147 | Lootable lootable = lom.get(hand); 148 | return lootable.useSfx; 149 | } 150 | return "tox_sfx_knuckles_fight"; 151 | } 152 | 153 | private void monsterDeath(Entity monster) { 154 | scoreSystem.scoreReward(monster); 155 | scoreSystem.score(lm.get(monster).level * Score.POINTS_MONSTER_KILL_PER_LEVEL); 156 | checkBossVictory(monster); 157 | cameraShakeSystem.shake(2); 158 | playerSystem.claimTile(monster); 159 | rewardKill(monster); 160 | } 161 | 162 | private void checkBossVictory(Entity monster) { 163 | Entity boss = world.getManager(TagManager.class).getEntity(EntityFactory.BOSS_TAG); 164 | if ( boss != null && monster == boss ) 165 | { 166 | selectableSystem.selectionCooldown(3); 167 | Tox.gameScreen.isWinCooldown = 3; 168 | } 169 | } 170 | 171 | public boolean isAlive(Entity monster) { 172 | return hm.has(monster); 173 | } 174 | 175 | public void damage(Entity victim, float damage) { 176 | if (hm.has(victim)) { 177 | selectableSystem.selectionCooldown(0.25f); 178 | 179 | final Health health = hm.get(victim); 180 | health.damage += damage; 181 | 182 | if (health.damage >= health.maxHealth) { 183 | kill(victim); 184 | } else if (health.damage >= health.maxHealth / 2 && ToxUtil.isPlayer(victim)) { 185 | blink(victim, Color.WHITE, Color.ORANGE,Interpolation.pow2,2,-1); 186 | } else if (health.damage >= health.maxHealth / 4 * 3) { 187 | blink(victim, Color.WHITE, Color.RED,Interpolation.pow2,2,-1); 188 | } else blink(victim, TRANSPARENT_BLINK_COLOR, Color.WHITE, Interpolation.linear, 4f, 0.5f); 189 | } 190 | } 191 | 192 | private void blink(Entity victim, Color color1, Color color2, Interpolation in, float speed, float duration) { 193 | victim.addComponent(new ColorAnimation(color1, color2, in, speed, duration)).changedInWorld(); 194 | } 195 | 196 | private void kill(Entity e) { 197 | 198 | if ( e == ToxUtil.getPlayer() && inventorySystem.hasEffect(EquipBonus.Effect.MEDPACK)) 199 | { 200 | playerSystem.useMedpack(); 201 | return; 202 | } 203 | 204 | e.removeComponent(Health.class).removeComponent(Selectable.class).removeComponent(ColorAnimation.class).changedInWorld(); 205 | } 206 | 207 | private void rewardKill(Entity monster) { 208 | if (pm.has(monster)) { 209 | Position mpos = pm.get(monster); 210 | soundSystem.playLater(fm.get(monster).deathSfx, 0.5f); 211 | particleSystem.combatCloud((int) (mpos.x + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f), (int) (mpos.y + Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f), ToxResource.TILE_SIZE, 1); 212 | playerSystem.levelUp(); 213 | } 214 | } 215 | 216 | /** 217 | * 218 | * @param victim 219 | * @param min Minimum level of intoxication. 220 | * @param amount boost intoxication by this amount. (can cause overdose) 221 | */ 222 | public void intoxicate(Entity victim, float min, float amount) 223 | { 224 | final Toxication tox = tm.get(victim); 225 | tox.toxication += amount; 226 | if ( tox.toxication <= min ) tox.toxication=min; 227 | if ( tox.toxication >= tox.maxToxication ) 228 | { 229 | playerSystem.killPlayer("Drug overdose"); 230 | } 231 | } 232 | 233 | public void heal(Entity victim) { 234 | if (hm.has(victim)) { 235 | Position pos = pm.get(victim); 236 | selectableSystem.selectionCooldown(MathUtils.random(0.2f,0.3f)); 237 | particleSystem.heal((int)(pos.x +(Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f)), 238 | (int)(pos.y +(Animation.DEFAULT_SCALE * ToxResource.TILE_SIZE * 0.5f))); 239 | final Health health = hm.get(victim); 240 | health.damage = 0; 241 | intoxicate(victim, 0, 0.3f); 242 | blink(victim, Color.GREEN, Color.WHITE,Interpolation.swingOut,0.5f,0.5f); 243 | } 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/ConcealSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.systems.EntityProcessingSystem; 8 | import net.mostlyoriginal.tox.ToxResource; 9 | import net.mostlyoriginal.tox.component.Animation; 10 | import net.mostlyoriginal.tox.component.Conceal; 11 | import net.mostlyoriginal.tox.component.Position; 12 | import net.mostlyoriginal.tox.component.Selectable; 13 | 14 | /** 15 | * @author Daan van Yperen 16 | */ 17 | public class ConcealSystem extends EntityProcessingSystem { 18 | 19 | @Mapper 20 | private ComponentMapper sm; 21 | 22 | @Mapper 23 | private ComponentMapper cm; 24 | 25 | @Mapper 26 | private ComponentMapper pm; 27 | 28 | private SelectableSystem selectableSystem; 29 | private LifetimeSystem lifetimeSystem; 30 | private ParticleSystem particleSystem; 31 | 32 | 33 | public ConcealSystem() { 34 | super(Aspect.getAspectForAll(Conceal.class, Selectable.class)); 35 | } 36 | 37 | @Override 38 | protected void initialize() { 39 | selectableSystem = world.getSystem(SelectableSystem.class); 40 | lifetimeSystem = world.getSystem(LifetimeSystem.class); 41 | particleSystem = world.getSystem(ParticleSystem.class); 42 | } 43 | 44 | @Override 45 | protected void process(Entity e) { 46 | if ( sm.get(e).selected ) 47 | { 48 | unconceal(e,true); 49 | } 50 | } 51 | 52 | public void unconceal(Entity e, boolean forceSelect) { 53 | final Conceal conceal = cm.get(e); 54 | 55 | final Position position = pm.get(e); 56 | 57 | // cover the switch with a cloud. 58 | particleSystem.cloud((int)(position.x + ToxResource.TILE_SIZE* Animation.DEFAULT_SCALE*0.5f), (int)(position.y+ ToxResource.TILE_SIZE* Animation.DEFAULT_SCALE*0.5f), 20); 59 | 60 | // set entity selected, so it gets instantly selected (and triggered) after being revealed. 61 | lifetimeSystem.addToWorldLater(conceal.entity, 0.10f); 62 | if ( forceSelect ) 63 | { 64 | selectableSystem.forceSelect(conceal.entity, 0.8f); 65 | } 66 | conceal.entity = null; 67 | 68 | // no more questionmark required 69 | e.deleteFromWorld(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/ContinueSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.badlogic.gdx.Gdx; 4 | import net.mostlyoriginal.tox.Tox; 5 | 6 | /** 7 | * @author Daan van Yperen 8 | */ 9 | public class ContinueSystem extends PassiveSystem { 10 | 11 | private final boolean startNewGame; 12 | private float cooldown = 0.75f; 13 | 14 | public ContinueSystem( boolean startNewGame ) { 15 | this.startNewGame = startNewGame; 16 | } 17 | 18 | @Override 19 | protected void begin() { 20 | cooldown -= world.delta; 21 | if ( cooldown <= 0 && Gdx.input.isTouched() ) 22 | { 23 | SelectableSystem selectableSystem = world.getSystem(SelectableSystem.class); 24 | if (selectableSystem != null && selectableSystem.selectionCooldown > 0 ) 25 | return; 26 | 27 | if ( startNewGame ) { 28 | Tox.game.newGame(); 29 | } else { 30 | Tox.game.nextLevel(); 31 | } 32 | } 33 | } 34 | 35 | @Override 36 | protected boolean checkProcessing() { 37 | return true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/DissolveSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.systems.EntityProcessingSystem; 8 | import net.mostlyoriginal.tox.component.DissolvesOnTouch; 9 | import net.mostlyoriginal.tox.component.Selectable; 10 | 11 | /** 12 | * @author Daan van Yperen 13 | */ 14 | public class DissolveSystem extends EntityProcessingSystem { 15 | 16 | @Mapper 17 | ComponentMapper sm; 18 | 19 | public DissolveSystem() { 20 | super(Aspect.getAspectForAll(DissolvesOnTouch.class, Selectable.class)); 21 | } 22 | 23 | @Override 24 | protected void process(Entity e) { 25 | if ( sm.get(e).selected ) 26 | { 27 | e.deleteFromWorld(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/ExitSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.systems.EntityProcessingSystem; 8 | import net.mostlyoriginal.tox.EntityFactory; 9 | import net.mostlyoriginal.tox.Tox; 10 | import net.mostlyoriginal.tox.ToxUtil; 11 | import net.mostlyoriginal.tox.component.Exit; 12 | import net.mostlyoriginal.tox.component.Selectable; 13 | 14 | /** 15 | * Allows players to step back to an earlier location. 16 | * @author Daan van Yperen 17 | */ 18 | public class ExitSystem extends EntityProcessingSystem { 19 | 20 | @Mapper 21 | ComponentMapper sm; 22 | public LifetimeSystem lifetimeSystem; 23 | private SoundSystem soundSystem; 24 | public StarPlopSystem starPlopSystem; 25 | private ScoreSystem scoreSystem; 26 | 27 | public ExitSystem() { 28 | super(Aspect.getAspectForAll(Selectable.class, Exit.class)); 29 | } 30 | 31 | @Override 32 | protected void initialize() { 33 | super.initialize(); 34 | lifetimeSystem = world.getSystem(LifetimeSystem.class); 35 | soundSystem = world.getSystem(SoundSystem.class); 36 | starPlopSystem = world.getSystem(StarPlopSystem.class); 37 | scoreSystem = world.getSystem(ScoreSystem.class); 38 | } 39 | 40 | @Override 41 | protected void begin() { 42 | super.begin(); 43 | } 44 | 45 | @Override 46 | protected void process(Entity e) { 47 | if (sm.get(e).selected && !Tox.gameScreen.reachedExit ) { 48 | 49 | scoreSystem.scoreReward(e); 50 | 51 | EntityFactory.createScreen("dialog-stage-clear").addToWorld(); 52 | 53 | int starsGained = Tox.gameScreen.getClearLevel(); 54 | Tox.score.stars += starsGained; 55 | starPlopSystem.plopStars(starsGained); 56 | 57 | Tox.score.floor--; 58 | Tox.gameScreen.reachedExit = true; 59 | Tox.world.getSystem(ContinueSystem.class).setEnabled(true); 60 | 61 | soundSystem.play("tox_sfx_exit"); 62 | 63 | // persist player entity through levels. 64 | Tox.legacyPlayer = ToxUtil.getPlayer(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/HighscoreSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.systems.VoidEntitySystem; 4 | import com.badlogic.gdx.Gdx; 5 | import com.badlogic.gdx.graphics.OrthographicCamera; 6 | import com.badlogic.gdx.graphics.g2d.Batch; 7 | import com.badlogic.gdx.graphics.g2d.BitmapFont; 8 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 9 | import net.mostlyoriginal.tox.Tox; 10 | 11 | /** 12 | * @author Daan van Yperen 13 | */ 14 | public class HighscoreSystem extends VoidEntitySystem { 15 | private final OrthographicCamera camera; 16 | private Batch batch = new SpriteBatch(); 17 | 18 | public HighscoreSystem(OrthographicCamera camera) { 19 | this.camera = camera; 20 | } 21 | 22 | @Override 23 | protected void processSystem() { 24 | batch.setProjectionMatrix(camera.combined); 25 | batch.begin(); 26 | batch.setColor(1f, 1f, 1f, 1f); 27 | BitmapFont font = Tox.resource.bigfont; 28 | 29 | int offsetY = 0; 30 | 31 | if ( Tox.settings.personalHighscore > 0 ) 32 | { 33 | center(Tox.resource.bigfont, "Personal Highscore", 620 + offsetY); 34 | center(Tox.resource.middlefont, ""+Tox.settings.personalHighscore+" points", 560 + offsetY); 35 | } 36 | 37 | batch.end(); 38 | } 39 | 40 | private void center(BitmapFont font,String str, int offsetY) { 41 | if ( str != null ) 42 | { 43 | font.setColor(1f,1f,1f,1f); 44 | font.draw(batch, str, Gdx.graphics.getWidth()/2 - font.getBounds(str).width/2, offsetY ); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/HudSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.ComponentMapper; 4 | import com.artemis.Entity; 5 | import com.artemis.annotations.Mapper; 6 | import com.badlogic.gdx.graphics.OrthographicCamera; 7 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 8 | import com.badlogic.gdx.graphics.g2d.TextureRegion; 9 | import com.badlogic.gdx.math.MathUtils; 10 | import net.mostlyoriginal.tox.Tox; 11 | import net.mostlyoriginal.tox.ToxUtil; 12 | import net.mostlyoriginal.tox.component.Animation; 13 | import net.mostlyoriginal.tox.component.Health; 14 | import net.mostlyoriginal.tox.component.Toxication; 15 | 16 | /** 17 | * @author Daan van Yperen 18 | */ 19 | public class HudSystem extends PassiveSystem { 20 | 21 | public SoundAlertSystem soundAlertSystem; 22 | 23 | @Override 24 | protected boolean checkProcessing() { 25 | return true; 26 | } 27 | 28 | @Mapper 29 | private ComponentMapper hm; 30 | @Mapper 31 | private ComponentMapper tm; 32 | 33 | public final static TextureRegion tmpR = new TextureRegion(); 34 | public final TextureRegion health; 35 | public final TextureRegion toxicity; 36 | 37 | private SpriteBatch batch = new SpriteBatch(); 38 | private OrthographicCamera camera; 39 | 40 | 41 | // damage monsters deal per monster level. 42 | 43 | public HudSystem(OrthographicCamera camera) { 44 | this.camera = camera; 45 | 46 | health = new TextureRegion(Tox.resource.get("bar-health").getKeyFrame(0)); 47 | toxicity = new TextureRegion(Tox.resource.get("bar-tox").getKeyFrame(0)); 48 | tmpR.setTexture(health.getTexture()); 49 | } 50 | 51 | @Override 52 | protected void initialize() { 53 | soundAlertSystem = world.getSystem(SoundAlertSystem.class); 54 | } 55 | 56 | @Override 57 | protected void begin() { 58 | batch.setProjectionMatrix(camera.combined); 59 | batch.begin(); 60 | batch.setColor(1f, 1f, 1f, 1f); 61 | 62 | 63 | final Entity player = ToxUtil.getPlayer(); 64 | float toxFactor = 0; 65 | float healthFactor = 0; 66 | if (player != null && hm.has(player) && tm.has(player)) { 67 | final Health playerHealth = hm.get(player); 68 | final Toxication playerToxication = tm.get(player); 69 | 70 | healthFactor = (playerHealth.maxHealth - playerHealth.damage) / (float) playerHealth.maxHealth; 71 | toxFactor = 1 - (playerToxication.maxToxication - playerToxication.toxication) / (float) playerToxication.maxToxication; 72 | } 73 | renderBar(health, 3 * Animation.DEFAULT_SCALE, 385 * Animation.DEFAULT_SCALE, healthFactor); 74 | renderBar(toxicity, 3 * Animation.DEFAULT_SCALE, 365 * Animation.DEFAULT_SCALE, toxFactor); 75 | } 76 | 77 | private void renderBar(TextureRegion region, int x, int y, float factor) { 78 | 79 | int emptySize = (int) (region.getRegionWidth() * MathUtils.clamp(factor, 0f, 1f)); 80 | 81 | if (emptySize < region.getRegionWidth()) { 82 | tmpR.setRegion( 83 | region.getRegionX() + emptySize, 84 | region.getRegionY(), 85 | region.getRegionWidth() - emptySize, 86 | region.getRegionHeight()); 87 | 88 | batch.draw(tmpR, x + emptySize * Animation.DEFAULT_SCALE, y, tmpR.getRegionWidth() * Animation.DEFAULT_SCALE, tmpR.getRegionHeight() * Animation.DEFAULT_SCALE); 89 | } 90 | } 91 | 92 | @Override 93 | protected void end() { 94 | batch.end(); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/InventorySystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.ComponentMapper; 4 | import com.artemis.Entity; 5 | import com.artemis.annotations.Mapper; 6 | import com.artemis.systems.VoidEntitySystem; 7 | import net.mostlyoriginal.tox.ToxUtil; 8 | import net.mostlyoriginal.tox.component.*; 9 | 10 | /** 11 | * @author Daan van Yperen 12 | */ 13 | public class InventorySystem extends VoidEntitySystem { 14 | 15 | @Mapper 16 | ComponentMapper im; 17 | 18 | @Mapper 19 | ComponentMapper pm; 20 | 21 | @Mapper 22 | ComponentMapper am; 23 | 24 | @Mapper 25 | ComponentMapper ebm; 26 | 27 | public Inventory getPlayerInventory() { 28 | Entity player = ToxUtil.getPlayer(); 29 | if (player != null && im.has(player)) { 30 | return im.get(player); 31 | } 32 | return null; 33 | } 34 | 35 | public void equip(Entity item, Inventory.Slot slot) { 36 | emptySlot(slot); 37 | equipInSlot(slot, item); 38 | } 39 | 40 | private void equipInSlot(Inventory.Slot slot, Entity item) { 41 | Inventory inventory = getPlayerInventory(); 42 | if (inventory != null) { 43 | inventory.carried[slot.ordinal()] = item; 44 | item.removeComponent(Selectable.class).changedInWorld(); 45 | 46 | if ( am.has(item) ) 47 | { 48 | final Animation animation = am.get(item); 49 | animation.behindId = "inventory-item-background"; 50 | } 51 | 52 | // move item to correct slot. 53 | if (pm.has(item)) { 54 | Position p = pm.get(item); 55 | switch (slot) { 56 | case BODY: 57 | p.x = 125 * Animation.DEFAULT_SCALE; 58 | p.y = 360 * Animation.DEFAULT_SCALE; 59 | break; 60 | case HAND: 61 | p.x = 162 * Animation.DEFAULT_SCALE; 62 | p.y = 360 * Animation.DEFAULT_SCALE; 63 | break; 64 | case MISC: 65 | p.x = 199 * Animation.DEFAULT_SCALE; 66 | p.y = 360 * Animation.DEFAULT_SCALE; 67 | break; 68 | } 69 | } 70 | } 71 | } 72 | 73 | private void emptySlot(Inventory.Slot slot) { 74 | Inventory inventory = getPlayerInventory(); 75 | if (inventory != null) { 76 | Entity item = inventory.carried[slot.ordinal()]; 77 | if (item != null) { 78 | item.deleteFromWorld(); 79 | inventory.carried[slot.ordinal()] = null; 80 | } 81 | } 82 | } 83 | 84 | @Override 85 | protected void processSystem() { 86 | 87 | } 88 | 89 | /** 90 | * @param entity entity to check. 91 | * @return All inventory bonuses stacked. 92 | */ 93 | public EquipBonus getTotalBonus(Entity entity) { 94 | EquipBonus sumEquipBonus = new EquipBonus(); 95 | 96 | Inventory inventory = im.get(entity); 97 | if (inventory != null) { 98 | for (int i = 0, s = inventory.carried.length; i < s; i++) { 99 | if (inventory.carried[i] != null && ebm.has(inventory.carried[i])) { 100 | sumEquipBonus.stack(ebm.get(inventory.carried[i])); 101 | } 102 | } 103 | } 104 | 105 | return sumEquipBonus; 106 | } 107 | 108 | /** 109 | * Check if any of our inventory items has specified effect. 110 | * @param effect 111 | * @return 112 | */ 113 | public boolean hasEffect(EquipBonus.Effect effect) { 114 | Inventory inventory = im.get(ToxUtil.getPlayer()); 115 | if (inventory != null) { 116 | for (int i = 0, s = inventory.carried.length; i < s; i++) { 117 | if (inventory.carried[i] != null && ebm.has(inventory.carried[i])) { 118 | if ( ebm.get(inventory.carried[i]).effect == effect ) 119 | return true; 120 | } 121 | } 122 | } 123 | return false; 124 | } 125 | 126 | public void discardByEffect(EquipBonus.Effect effect) { 127 | Inventory inventory = im.get(ToxUtil.getPlayer()); 128 | if (inventory != null) { 129 | for (int i = 0, s = inventory.carried.length; i < s; i++) { 130 | if (inventory.carried[i] != null && ebm.has(inventory.carried[i])) { 131 | if ( ebm.get(inventory.carried[i]).effect == effect ) 132 | { 133 | inventory.carried[i].deleteFromWorld(); 134 | inventory.carried[i] = null; 135 | } 136 | } 137 | } 138 | } 139 | } 140 | 141 | public Entity get(Inventory.Slot slot) { 142 | Inventory inventory = im.get(ToxUtil.getPlayer()); 143 | if (inventory != null) { 144 | return inventory.carried[slot.ordinal()]; 145 | } 146 | return null; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /core/src/net/mostlyoriginal/tox/system/LabelRenderSystem.java: -------------------------------------------------------------------------------- 1 | package net.mostlyoriginal.tox.system; 2 | 3 | import com.artemis.Aspect; 4 | import com.artemis.ComponentMapper; 5 | import com.artemis.Entity; 6 | import com.artemis.annotations.Mapper; 7 | import com.artemis.systems.EntityProcessingSystem; 8 | import com.badlogic.gdx.graphics.OrthographicCamera; 9 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; 10 | import net.mostlyoriginal.tox.Tox; 11 | import net.mostlyoriginal.tox.component.Label; 12 | import net.mostlyoriginal.tox.component.Position; 13 | 14 | /** 15 | * @author Daan van Yperen 16 | */ 17 | public class LabelRenderSystem extends EntityProcessingSystem { 18 | 19 | @Mapper 20 | ComponentMapper pm; 21 | 22 | @Mapper 23 | ComponentMapper