commit da53dcc74e6de2cc8c9ed10988b73d9c3fca7a95 Author: Stefano Rossi Date: Thu Jul 10 03:34:34 2025 +0200 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7464918 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..476d096 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4002995 --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ +# DON'T BE A DICK PUBLIC LICENSE + +> Version 1.1, December 2016 + +> Copyright (C) 2024 Rossi Stefano + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document. + +> DON'T BE A DICK PUBLIC LICENSE +> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +1. Do whatever you like with the original work, just don't be a dick. + + Being a dick includes - but is not limited to - the following instances: + + 1a. Outright copyright infringement - Don't just copy this and change the name. + 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick. + 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick. + +2. If you become rich through modifications, related works/services, or supporting the original work, +share the love. Only a dick would make loads off this work and not buy the original work's +creator(s) a pint. + +3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes +you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0e1aa64 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# SuppaMario + +This is a concept for a clone of super Mario. +With the possibility to create your own maps. + +![ezgif-2-db46d0ad92.gif](images/ezgif-2-db46d0ad92.gif) + +## Description + +![Scheme](images/suppamario.png) + +You can create you own map modifying the map file: + +`\suppaMariov6\build\classes\mappe\map1.txt` + +![Scheme](images/suppamario2.png) + +- Idle cycle background. Speeding according to mario movement speed +- Mario can move left and right, jump and crouch +- Collide with solid blocks +- Dies when hit by lateral collision with koopa, by deadly blocks (water) or + falling out of the map +- Has dead, jump and crouch animation +- Background and death animation music +- The map is loaded from an external file, you can build with: + - 2 solid block (bricks) + - 1 pass-through block (clouds) + - 1 deadly block (water) +- Implemented 2 walking koopa enemies, they die and disappear on upper + collision with mario + +## Requirements + +- Java (6 to) 8 (max, recommended) +- NetBeans (highly recommended) + +Java Applets have been dropped with Java 9. So you need an older versione to run this project. +Java 8 is the preferred version. Until Java 6 should be ok. + +Problems running the project are expected, applets are deprecated and not supported by modern browsers.** + +This is a NetBeans Project. Using NetBeans isn't mandatory but recommended for the built-in applet runner. +You can run the GrigliaApplet.java class with netbeans. + +[NetBeans Instructions](https://netbeans.apache.org/tutorial/main/kb/docs/java/javase-jdk8/) + +Alternatively, you can use IntellijJ IDEA with the [Applet runner plugin](https://plugins.jetbrains.com/plugin/16682-applet-runner) (not tested). + +## Installation and run + +Clone the repo: + +```bash +https://gitlab.com/stefanorossiti/SuppaMario.git +``` + +Run `SuppaMarioApplet.java` with your preferred IDE (NetBeans is recommended) +using java 8. + +## License + +All my work is released under [DBAD](https://www.dbad-license.org/) license. \ No newline at end of file diff --git a/SuppaMario.iml b/SuppaMario.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/SuppaMario.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/applet.policy b/applet.policy new file mode 100644 index 0000000..53a9d40 --- /dev/null +++ b/applet.policy @@ -0,0 +1,3 @@ +grant { +permission java.security.AllPermission; +}; diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..c1e83a8 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project suppaMario. + + + diff --git a/build/SuppaMarioApplet.html b/build/SuppaMarioApplet.html new file mode 100644 index 0000000..78b6e15 --- /dev/null +++ b/build/SuppaMarioApplet.html @@ -0,0 +1,28 @@ + + + Applet HTML Page + + + + + +


Applet HTML Page

+ +

+ +

+ +
Generated by NetBeans IDE + + diff --git a/build/classes/.netbeans_automatic_build b/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/.netbeans_update_resources b/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/img/background/background.png b/build/classes/img/background/background.png new file mode 100644 index 0000000..45b82ad Binary files /dev/null and b/build/classes/img/background/background.png differ diff --git a/build/classes/img/enemies/koopaTroopa/greenHidden.gif b/build/classes/img/enemies/koopaTroopa/greenHidden.gif new file mode 100644 index 0000000..6b703ce Binary files /dev/null and b/build/classes/img/enemies/koopaTroopa/greenHidden.gif differ diff --git a/build/classes/img/enemies/koopaTroopa/greenSemiHidd.gif b/build/classes/img/enemies/koopaTroopa/greenSemiHidd.gif new file mode 100644 index 0000000..87085b2 Binary files /dev/null and b/build/classes/img/enemies/koopaTroopa/greenSemiHidd.gif differ diff --git a/build/classes/img/enemies/koopaTroopa/greenWalking.gif b/build/classes/img/enemies/koopaTroopa/greenWalking.gif new file mode 100644 index 0000000..2b73e59 Binary files /dev/null and b/build/classes/img/enemies/koopaTroopa/greenWalking.gif differ diff --git a/build/classes/img/enemies/koopaTroopa/shell.png b/build/classes/img/enemies/koopaTroopa/shell.png new file mode 100644 index 0000000..44dbd8d Binary files /dev/null and b/build/classes/img/enemies/koopaTroopa/shell.png differ diff --git a/build/classes/img/enemies/koopaTroopa/smw2_koopatroopa-green_sheet.png b/build/classes/img/enemies/koopaTroopa/smw2_koopatroopa-green_sheet.png new file mode 100644 index 0000000..1b5a357 Binary files /dev/null and b/build/classes/img/enemies/koopaTroopa/smw2_koopatroopa-green_sheet.png differ diff --git a/build/classes/img/mario/die1.gif b/build/classes/img/mario/die1.gif new file mode 100644 index 0000000..89fc664 Binary files /dev/null and b/build/classes/img/mario/die1.gif differ diff --git a/build/classes/img/mario/die2.gif b/build/classes/img/mario/die2.gif new file mode 100644 index 0000000..b6df428 Binary files /dev/null and b/build/classes/img/mario/die2.gif differ diff --git a/build/classes/img/mario/die3.gif b/build/classes/img/mario/die3.gif new file mode 100644 index 0000000..df24a6c Binary files /dev/null and b/build/classes/img/mario/die3.gif differ diff --git a/build/classes/img/mario/die4.gif b/build/classes/img/mario/die4.gif new file mode 100644 index 0000000..5eded9e Binary files /dev/null and b/build/classes/img/mario/die4.gif differ diff --git a/build/classes/img/mario/die5.gif b/build/classes/img/mario/die5.gif new file mode 100644 index 0000000..91edf5f Binary files /dev/null and b/build/classes/img/mario/die5.gif differ diff --git a/build/classes/img/mario/die6.gif b/build/classes/img/mario/die6.gif new file mode 100644 index 0000000..26e9b5c Binary files /dev/null and b/build/classes/img/mario/die6.gif differ diff --git a/build/classes/img/mario/die7.gif b/build/classes/img/mario/die7.gif new file mode 100644 index 0000000..7671b02 Binary files /dev/null and b/build/classes/img/mario/die7.gif differ diff --git a/build/classes/img/mario/marioDucked.gif b/build/classes/img/mario/marioDucked.gif new file mode 100644 index 0000000..2a5c35b Binary files /dev/null and b/build/classes/img/mario/marioDucked.gif differ diff --git a/build/classes/img/mario/marioDuckedb.gif b/build/classes/img/mario/marioDuckedb.gif new file mode 100644 index 0000000..163b3ab Binary files /dev/null and b/build/classes/img/mario/marioDuckedb.gif differ diff --git a/build/classes/img/mario/marioJump.gif b/build/classes/img/mario/marioJump.gif new file mode 100644 index 0000000..af863a0 Binary files /dev/null and b/build/classes/img/mario/marioJump.gif differ diff --git a/build/classes/img/mario/marioJumpb.gif b/build/classes/img/mario/marioJumpb.gif new file mode 100644 index 0000000..da97b94 Binary files /dev/null and b/build/classes/img/mario/marioJumpb.gif differ diff --git a/build/classes/img/mario/marioRun1.gif b/build/classes/img/mario/marioRun1.gif new file mode 100644 index 0000000..9e6bdf7 Binary files /dev/null and b/build/classes/img/mario/marioRun1.gif differ diff --git a/build/classes/img/mario/marioRun1b.gif b/build/classes/img/mario/marioRun1b.gif new file mode 100644 index 0000000..4602371 Binary files /dev/null and b/build/classes/img/mario/marioRun1b.gif differ diff --git a/build/classes/img/mario/marioRun2.gif b/build/classes/img/mario/marioRun2.gif new file mode 100644 index 0000000..9970492 Binary files /dev/null and b/build/classes/img/mario/marioRun2.gif differ diff --git a/build/classes/img/mario/marioRun2b.gif b/build/classes/img/mario/marioRun2b.gif new file mode 100644 index 0000000..8a21429 Binary files /dev/null and b/build/classes/img/mario/marioRun2b.gif differ diff --git a/build/classes/img/mario/marioRun3.gif b/build/classes/img/mario/marioRun3.gif new file mode 100644 index 0000000..83629a9 Binary files /dev/null and b/build/classes/img/mario/marioRun3.gif differ diff --git a/build/classes/img/mario/marioRun3b.gif b/build/classes/img/mario/marioRun3b.gif new file mode 100644 index 0000000..af0c153 Binary files /dev/null and b/build/classes/img/mario/marioRun3b.gif differ diff --git a/build/classes/img/mario/marioStop.gif b/build/classes/img/mario/marioStop.gif new file mode 100644 index 0000000..dfe75ff Binary files /dev/null and b/build/classes/img/mario/marioStop.gif differ diff --git a/build/classes/img/mario/marioStopb.gif b/build/classes/img/mario/marioStopb.gif new file mode 100644 index 0000000..9ff7dd5 Binary files /dev/null and b/build/classes/img/mario/marioStopb.gif differ diff --git a/build/classes/img/scenery/block.gif b/build/classes/img/scenery/block.gif new file mode 100644 index 0000000..ce33f3a Binary files /dev/null and b/build/classes/img/scenery/block.gif differ diff --git a/build/classes/img/scenery/bridge.html b/build/classes/img/scenery/bridge.html new file mode 100644 index 0000000..c3f27d4 --- /dev/null +++ b/build/classes/img/scenery/bridge.html @@ -0,0 +1,39 @@ + + + +Super Mario Bros. Scenery Sprites + + + + +

Super Mario Bros. Scenery Sprites

+
+
+VideoGameSprites.net > Super Mario Bros. +
+
+
+
+

Background Color

+ + +

+
+
+ hills

+ trees

+ bushes

+ clouds

+ waves
+ fireworks

+
+
+ block

+ ground

+ bridge

+ Coin Heaven cloud

+ coral

+ giant mushroom
+
+ +
\ No newline at end of file diff --git a/build/classes/img/scenery/bridge_files/Block.gif b/build/classes/img/scenery/bridge_files/Block.gif new file mode 100644 index 0000000..ce33f3a Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Block.gif differ diff --git a/build/classes/img/scenery/bridge_files/Bridge.gif b/build/classes/img/scenery/bridge_files/Bridge.gif new file mode 100644 index 0000000..63d7458 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Bridge.gif differ diff --git a/build/classes/img/scenery/bridge_files/Bush - Double.gif b/build/classes/img/scenery/bridge_files/Bush - Double.gif new file mode 100644 index 0000000..5228dc4 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Bush - Double.gif differ diff --git a/build/classes/img/scenery/bridge_files/Bush - Single.gif b/build/classes/img/scenery/bridge_files/Bush - Single.gif new file mode 100644 index 0000000..73e5e64 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Bush - Single.gif differ diff --git a/build/classes/img/scenery/bridge_files/Bush - Triple.gif b/build/classes/img/scenery/bridge_files/Bush - Triple.gif new file mode 100644 index 0000000..55530e5 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Bush - Triple.gif differ diff --git a/build/classes/img/scenery/bridge_files/Cloud - Double.gif b/build/classes/img/scenery/bridge_files/Cloud - Double.gif new file mode 100644 index 0000000..aa2d881 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Cloud - Double.gif differ diff --git a/build/classes/img/scenery/bridge_files/Cloud - Single.gif b/build/classes/img/scenery/bridge_files/Cloud - Single.gif new file mode 100644 index 0000000..702cbf1 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Cloud - Single.gif differ diff --git a/build/classes/img/scenery/bridge_files/Cloud - Triple.gif b/build/classes/img/scenery/bridge_files/Cloud - Triple.gif new file mode 100644 index 0000000..d75a894 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Cloud - Triple.gif differ diff --git a/build/classes/img/scenery/bridge_files/Coin Heaven Cloud.gif b/build/classes/img/scenery/bridge_files/Coin Heaven Cloud.gif new file mode 100644 index 0000000..212b283 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Coin Heaven Cloud.gif differ diff --git a/build/classes/img/scenery/bridge_files/Coral.gif b/build/classes/img/scenery/bridge_files/Coral.gif new file mode 100644 index 0000000..e2fed75 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Coral.gif differ diff --git a/build/classes/img/scenery/bridge_files/Firework1.gif b/build/classes/img/scenery/bridge_files/Firework1.gif new file mode 100644 index 0000000..a978eb3 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Firework1.gif differ diff --git a/build/classes/img/scenery/bridge_files/Firework2.gif b/build/classes/img/scenery/bridge_files/Firework2.gif new file mode 100644 index 0000000..81a4715 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Firework2.gif differ diff --git a/build/classes/img/scenery/bridge_files/Firework3.gif b/build/classes/img/scenery/bridge_files/Firework3.gif new file mode 100644 index 0000000..4bb3733 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Firework3.gif differ diff --git a/build/classes/img/scenery/bridge_files/Giant Mushroom.gif b/build/classes/img/scenery/bridge_files/Giant Mushroom.gif new file mode 100644 index 0000000..8ad337a Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Giant Mushroom.gif differ diff --git a/build/classes/img/scenery/bridge_files/Ground.gif b/build/classes/img/scenery/bridge_files/Ground.gif new file mode 100644 index 0000000..e5281e9 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Ground.gif differ diff --git a/build/classes/img/scenery/bridge_files/Hill - Large.gif b/build/classes/img/scenery/bridge_files/Hill - Large.gif new file mode 100644 index 0000000..df4aa94 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Hill - Large.gif differ diff --git a/build/classes/img/scenery/bridge_files/Hill - Small.gif b/build/classes/img/scenery/bridge_files/Hill - Small.gif new file mode 100644 index 0000000..a76eba5 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Hill - Small.gif differ diff --git a/build/classes/img/scenery/bridge_files/Tree - Large.gif b/build/classes/img/scenery/bridge_files/Tree - Large.gif new file mode 100644 index 0000000..5c66c54 Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Tree - Large.gif differ diff --git a/build/classes/img/scenery/bridge_files/Tree - Small.gif b/build/classes/img/scenery/bridge_files/Tree - Small.gif new file mode 100644 index 0000000..299920b Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Tree - Small.gif differ diff --git a/build/classes/img/scenery/bridge_files/Waves.gif b/build/classes/img/scenery/bridge_files/Waves.gif new file mode 100644 index 0000000..7bfc57e Binary files /dev/null and b/build/classes/img/scenery/bridge_files/Waves.gif differ diff --git a/build/classes/img/scenery/bushb.gif b/build/classes/img/scenery/bushb.gif new file mode 100644 index 0000000..55530e5 Binary files /dev/null and b/build/classes/img/scenery/bushb.gif differ diff --git a/build/classes/img/scenery/bushs.gif b/build/classes/img/scenery/bushs.gif new file mode 100644 index 0000000..5228dc4 Binary files /dev/null and b/build/classes/img/scenery/bushs.gif differ diff --git a/build/classes/img/scenery/bushss.gif b/build/classes/img/scenery/bushss.gif new file mode 100644 index 0000000..73e5e64 Binary files /dev/null and b/build/classes/img/scenery/bushss.gif differ diff --git a/build/classes/img/scenery/coinheavencloud.gif b/build/classes/img/scenery/coinheavencloud.gif new file mode 100644 index 0000000..212b283 Binary files /dev/null and b/build/classes/img/scenery/coinheavencloud.gif differ diff --git a/build/classes/img/scenery/coral.gif b/build/classes/img/scenery/coral.gif new file mode 100644 index 0000000..e2fed75 Binary files /dev/null and b/build/classes/img/scenery/coral.gif differ diff --git a/build/classes/img/scenery/fwks1.gif b/build/classes/img/scenery/fwks1.gif new file mode 100644 index 0000000..a978eb3 Binary files /dev/null and b/build/classes/img/scenery/fwks1.gif differ diff --git a/build/classes/img/scenery/fwks2.gif b/build/classes/img/scenery/fwks2.gif new file mode 100644 index 0000000..81a4715 Binary files /dev/null and b/build/classes/img/scenery/fwks2.gif differ diff --git a/build/classes/img/scenery/fwks3.gif b/build/classes/img/scenery/fwks3.gif new file mode 100644 index 0000000..4bb3733 Binary files /dev/null and b/build/classes/img/scenery/fwks3.gif differ diff --git a/build/classes/img/scenery/giantmushroom.gif b/build/classes/img/scenery/giantmushroom.gif new file mode 100644 index 0000000..8ad337a Binary files /dev/null and b/build/classes/img/scenery/giantmushroom.gif differ diff --git a/build/classes/img/scenery/ground.gif b/build/classes/img/scenery/ground.gif new file mode 100644 index 0000000..e5281e9 Binary files /dev/null and b/build/classes/img/scenery/ground.gif differ diff --git a/build/classes/img/scenery/hillb.gif b/build/classes/img/scenery/hillb.gif new file mode 100644 index 0000000..df4aa94 Binary files /dev/null and b/build/classes/img/scenery/hillb.gif differ diff --git a/build/classes/img/scenery/hills.gif b/build/classes/img/scenery/hills.gif new file mode 100644 index 0000000..a76eba5 Binary files /dev/null and b/build/classes/img/scenery/hills.gif differ diff --git a/build/classes/img/scenery/treeg.gif b/build/classes/img/scenery/treeg.gif new file mode 100644 index 0000000..5c66c54 Binary files /dev/null and b/build/classes/img/scenery/treeg.gif differ diff --git a/build/classes/img/scenery/trees.gif b/build/classes/img/scenery/trees.gif new file mode 100644 index 0000000..5c66c54 Binary files /dev/null and b/build/classes/img/scenery/trees.gif differ diff --git a/build/classes/img/scenery/wawes.gif b/build/classes/img/scenery/wawes.gif new file mode 100644 index 0000000..7bfc57e Binary files /dev/null and b/build/classes/img/scenery/wawes.gif differ diff --git a/build/classes/mappe/map1.txt b/build/classes/mappe/map1.txt new file mode 100644 index 0000000..203bde3 --- /dev/null +++ b/build/classes/mappe/map1.txt @@ -0,0 +1,28 @@ +! Author: BBC Games +! +! +! SuppaMario lvl1 +! tile map 200x15 +! Legenda: +! = nothing +! b = ground block +! w = wawes +! c = coin heaven cloud +! g = ground +!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg +gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg +ggggg gggg +ggg gggggggggggc ggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg +ggg ggggggg c gggg c c +ggg bbbbbb c c ccccgg +gggggggggg bbbbbb gggggggggggggg ggggggggggggggggggggggggggggggg gggggggggggggggggggggggggggggggggggg +ggg ggggg c c ggg cc c +ggg bbbbb ggg ggggggg ggggggggggggggggggggggggggggggggggggggg gg gggg ggggggggggggggggggg +ggg bbb ggggg +gggc bbbbbbbbbbbbbbbbbbbb b ggggggggggggggggggggg bbbbbb bbbbbbbbbb c c cc c c c c c +ggg ggg gggggggggggggggggggggg ggg bbbbbbb bbbbbbbbbbbbbb +ggg g ggggggggggggggggggggggggggggggggggggggggwwwggggggggbbbbbbbbbbbbbbbbbbgggggggggggggggggggggggggggggggggggggggggggggggggggggggwwwwwwwwwwwwww +gggggggggg gggggwwwwwgg ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggwwwwwwwggggggggggww +gggggggggg gggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww +!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/build/classes/midi/1up.mid b/build/classes/midi/1up.mid new file mode 100644 index 0000000..4de09b3 Binary files /dev/null and b/build/classes/midi/1up.mid differ diff --git a/build/classes/midi/battle.mid b/build/classes/midi/battle.mid new file mode 100644 index 0000000..bd899af Binary files /dev/null and b/build/classes/midi/battle.mid differ diff --git a/build/classes/midi/beatbrowser.mid b/build/classes/midi/beatbrowser.mid new file mode 100644 index 0000000..35b5be8 Binary files /dev/null and b/build/classes/midi/beatbrowser.mid differ diff --git a/build/classes/midi/castle.mid b/build/classes/midi/castle.mid new file mode 100644 index 0000000..54c0bf2 Binary files /dev/null and b/build/classes/midi/castle.mid differ diff --git a/build/classes/midi/die.wav b/build/classes/midi/die.wav new file mode 100644 index 0000000..5ec9a5b Binary files /dev/null and b/build/classes/midi/die.wav differ diff --git a/build/classes/midi/jump.wav b/build/classes/midi/jump.wav new file mode 100644 index 0000000..414aad7 Binary files /dev/null and b/build/classes/midi/jump.wav differ diff --git a/build/classes/midi/lvl1.mid b/build/classes/midi/lvl1.mid new file mode 100644 index 0000000..4774d61 Binary files /dev/null and b/build/classes/midi/lvl1.mid differ diff --git a/build/classes/midi/star.mid b/build/classes/midi/star.mid new file mode 100644 index 0000000..e3d8c41 Binary files /dev/null and b/build/classes/midi/star.mid differ diff --git a/build/classes/midi/underground.mid b/build/classes/midi/underground.mid new file mode 100644 index 0000000..5a1c809 Binary files /dev/null and b/build/classes/midi/underground.mid differ diff --git a/build/classes/suppamario/Animation$AnimFrame.class b/build/classes/suppamario/Animation$AnimFrame.class new file mode 100644 index 0000000..0ad9770 Binary files /dev/null and b/build/classes/suppamario/Animation$AnimFrame.class differ diff --git a/build/classes/suppamario/Animation.class b/build/classes/suppamario/Animation.class new file mode 100644 index 0000000..7f21933 Binary files /dev/null and b/build/classes/suppamario/Animation.class differ diff --git a/build/classes/suppamario/Background.class b/build/classes/suppamario/Background.class new file mode 100644 index 0000000..185129c Binary files /dev/null and b/build/classes/suppamario/Background.class differ diff --git a/build/classes/suppamario/Enemy.class b/build/classes/suppamario/Enemy.class new file mode 100644 index 0000000..d081c23 Binary files /dev/null and b/build/classes/suppamario/Enemy.class differ diff --git a/build/classes/suppamario/KoopaTroopa.class b/build/classes/suppamario/KoopaTroopa.class new file mode 100644 index 0000000..65a2592 Binary files /dev/null and b/build/classes/suppamario/KoopaTroopa.class differ diff --git a/build/classes/suppamario/Mario.class b/build/classes/suppamario/Mario.class new file mode 100644 index 0000000..b52e38a Binary files /dev/null and b/build/classes/suppamario/Mario.class differ diff --git a/build/classes/suppamario/SuppaMarioApplet.class b/build/classes/suppamario/SuppaMarioApplet.class new file mode 100644 index 0000000..db1bce8 Binary files /dev/null and b/build/classes/suppamario/SuppaMarioApplet.class differ diff --git a/build/classes/suppamario/Tile.class b/build/classes/suppamario/Tile.class new file mode 100644 index 0000000..801476c Binary files /dev/null and b/build/classes/suppamario/Tile.class differ diff --git a/images/ezgif-2-db46d0ad92.gif b/images/ezgif-2-db46d0ad92.gif new file mode 100644 index 0000000..9d8ddbb Binary files /dev/null and b/images/ezgif-2-db46d0ad92.gif differ diff --git a/images/suppamario.png b/images/suppamario.png new file mode 100644 index 0000000..7a65445 Binary files /dev/null and b/images/suppamario.png differ diff --git a/images/suppamario2.png b/images/suppamario2.png new file mode 100644 index 0000000..a7cd945 Binary files /dev/null and b/images/suppamario2.png differ diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..ec15c03 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1799 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..91741f9 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c7b0c067 +build.xml.script.CRC32=245a017c +build.xml.stylesheet.CRC32=f85dc8f2@1.111.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=c7b0c067 +nbproject/build-impl.xml.script.CRC32=81cc81d6 +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.111.0.48 diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..a8e158b --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,8 @@ +compile.on.save=true +do.depend=false +do.jar=true +do.jlink=false +javac.debug=true +javadoc.preview=true +jlink.strip=false +user.properties.file=C:\\Users\\Administrator\\AppData\\Roaming\\NetBeans\\22\\build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..6807a2b --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..49ecd59 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,89 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=suppaMario +application.vendor=Administrator +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/suppaMario.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=false +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jlink.launcher=false +jlink.launcher.name=suppaMario +main.class=suppamario.SuppaMarioApplet +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=Zulu_8.0.412_8 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs=-Djava.security.policy=applet.policy +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..9bd9bf1 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + suppaMario + + + + + + + + + + diff --git a/src/suppamario/Animation.java b/src/suppamario/Animation.java new file mode 100644 index 0000000..12d9d4f --- /dev/null +++ b/src/suppamario/Animation.java @@ -0,0 +1,110 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package suppamario; + +import java.awt.Image; +import java.util.ArrayList; + +/** + * + * @author BBC + */ +public class Animation { + + private ArrayList frames; + private int currentFrame; //index del frame attivo + private long animTime; //tempo passato per questo frame + private long totalDuration; //durata del frame + + //costruttore + public Animation() { + frames = new ArrayList(); + totalDuration = 0; + + synchronized (this) { + animTime = 0; + currentFrame = 0; + } + } + + public synchronized void addFrame(Image image, long duration) { + totalDuration += duration; + frames.add(new AnimFrame(image, totalDuration)); + } + + public synchronized void reset() { + this.setCurrentFrame(0); + this.setAnimTime(0); + } + + public synchronized void update(long elapsedTime) { + //se ho piu di un frame + if (frames.size() > 1) { + //incremento il timer + animTime += elapsedTime; + //se ha fatto tutta l animazione + if (animTime >= totalDuration) { + //resetto il tempo dell animazione ma tengo conto + //del tempo in piu che e passato e imposto il frame corr a 0 + animTime = animTime % totalDuration; + currentFrame = 0; + } + + //se il tempo dell animazione e maggiore della durata + //del frame vado a quello dopo, controllo ogni frame + while (animTime > getFrame(currentFrame).endTime) { + currentFrame++; + } + } + } + + //GETTER + public synchronized Image getImage() { + if (frames.isEmpty()) { + return null; + } else { + return getFrame(currentFrame).image; + } + } + + private AnimFrame getFrame(int i) { + return (AnimFrame) frames.get(i); + } + + public void setFrames(ArrayList frames) { + this.frames = frames; + } + + public void setCurrentFrame(int currentFrame) { + this.currentFrame = currentFrame; + } + + public void setAnimTime(long animTime) { + this.animTime = animTime; + } + + public void setTotalDuration(long totalDuration) { + this.totalDuration = totalDuration; + } + + //NUOVA CLASSE + private class AnimFrame { + Image image; + long endTime; + + public AnimFrame(Image image, long endTime) { + this.image = image; + this.endTime = endTime; + } + + public long getEndTime(){ + return this.endTime; + } + + public void setImg(Image img){ + this.image = img; + } + } +} diff --git a/src/suppamario/Background.java b/src/suppamario/Background.java new file mode 100644 index 0000000..af7cbf7 --- /dev/null +++ b/src/suppamario/Background.java @@ -0,0 +1,78 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package suppamario; + +/** + * + * @author BBC + */ +public class Background { + //con queste variabili conteggio i bgs istanziati e la somma della + //loro lunghezza in modo da permette piu background consecutivi + // MASSIMO 2 ISTANZE DI BG ALTRIMENTI NON FUNZIONA + private static int cntBgs = 0, totWbgs = 0; + + final static int SPEEDMOV = 2, SPEEDSTOP = 1; + private static int speedX = SPEEDSTOP; + + private int bgX; //coord x che viene incrementata + private int bgW; + private int bgH; + + //costruttore + public Background(int bgW, int bgH) { + this.bgW = bgW; + this.bgH = bgH; + this.bgX = Background.totWbgs; + + Background.cntBgs++; + totWbgs += bgW; + } + + //METODI + public synchronized void update() { + //scrollo in x in base alla velocita x + this.bgX -= speedX; + + //se sono fuori dai limiti resetto la sua posizione a dx + if (speedX >= SPEEDSTOP + SPEEDMOV && this.bgX <= -this.bgW) { + this.bgX = bgW; + //se la velocita e negativa il controllo e diverso + //per assicurare il bg anche andando a sx + }else if(speedX <= SPEEDSTOP - SPEEDMOV && this.bgX >= this.bgW){ + this.bgX = -this.bgW; + } + } + + public synchronized void moveLeft(){ + speedX = SPEEDSTOP - SPEEDMOV; + } + + public synchronized void moveRight(){ + speedX = SPEEDSTOP + SPEEDMOV; + } + + public synchronized void moveStop(){ + speedX = SPEEDSTOP; + } + + //GETTER + public int getBgX() { + return bgX; + } + + public int getBgW() { + return bgW; + } + + public int getBgH() { + return bgH; + } + + public int getSpeedX() { + return speedX; + } + +} diff --git a/src/suppamario/Enemy.java b/src/suppamario/Enemy.java new file mode 100644 index 0000000..ae9b6f5 --- /dev/null +++ b/src/suppamario/Enemy.java @@ -0,0 +1,144 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package suppamario; + +import java.awt.Rectangle; + +/** + * + * @author BBC + */ +public class Enemy{ + + int maxHealth, currentHealth, power, speedX, centerX, centerY; + boolean visible = true, died = false; + Background bg = SuppaMarioApplet.getBg1(); + Rectangle collision = new Rectangle(0, 0, 0, 0); + + public Enemy(int maxHealth){ + this.maxHealth = maxHealth; + this.currentHealth = this.maxHealth; + } + + //METODI + public void update() { + if (visible && currentHealth != 1) { + //se mario va a destra e il bg a sx muovo a dx + if (bg.getSpeedX() == bg.SPEEDSTOP - bg.SPEEDMOV) { + speedX = bg.SPEEDMOV * 2; + //se mario va a sx e il bg a dx muovo a sx + } else if (bg.getSpeedX() == bg.SPEEDSTOP + bg.SPEEDMOV) { + speedX = -bg.SPEEDMOV * 2; + //se il bg non si muove + } else { + speedX = 0; + } + + centerX += speedX - 1; //spostamento in base al tilde piu il suo spostamento di 1 + + collision.setBounds(centerX - 12, centerY - 16, 23, 32); + } + } + + boolean checkCollision(Rectangle inRect) { + return collision.intersects(inRect); + } + + void hitten() { + if(--this.currentHealth == 0){ + die(); + } + } + + public void die() { + this.visible=false; + this.died = true; + } + + public void attack() { + } + + //GETTER + public int getMaxHealth() { + return maxHealth; + } + + public int getCurrentHealth() { + return currentHealth; + } + + public boolean isVisible() { + return visible; + } + + public int getPower() { + return power; + } + + public int getSpeedX() { + return speedX; + } + + public int getCenterX() { + return centerX; + } + + public int getCenterY() { + return centerY; + } + + public Background getBg() { + return bg; + } + + public Rectangle getCollision() { + return collision; + } + + //SETTER + public void setMaxHealth(int maxHealth) { + this.maxHealth = maxHealth; + } + + public void setCurrentHealth(int currentHealth) { + this.currentHealth = currentHealth; + } + + public void setPower(int power) { + this.power = power; + } + + public void setSpeedX(int speedX) { + this.speedX = speedX; + } + + public void setCenterX(int centerX) { + this.centerX = centerX; + } + + public void setCenterY(int centerY) { + this.centerY = centerY; + } + + public void setBg(Background bg) { + this.bg = bg; + } + + public void setCollision(Rectangle collision) { + this.collision = collision; + } + + public void setVisible(boolean visibility) { + this.visible = visibility; + } + + public boolean isDied() { + return died; + } + + public void setDied(boolean died) { + this.died = died; + } +} diff --git a/src/suppamario/KoopaTroopa.java b/src/suppamario/KoopaTroopa.java new file mode 100644 index 0000000..030c278 --- /dev/null +++ b/src/suppamario/KoopaTroopa.java @@ -0,0 +1,59 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package suppamario; + +/** + * + * @author BBC + */ +public class KoopaTroopa extends Enemy implements Runnable{ + Thread th; + + public KoopaTroopa(int centerX, int centerY){ + super(2); + this.setCenterX(centerX); + this.setCenterY(centerY); + } + + @Override + void hitten() { + if(--currentHealth == 0){ + die(); + } + speedX = 0; + + collision.setBounds(centerX - 12, centerY, 23, 16); + + th = new Thread(this); + th.start(); + } + + @Override + public void run() { + try { + //aspetto un lasso di tempo e poi incremento la vita del kt + Thread.sleep(2000); + + currentHealth++; + + if (visible) { + //se mario va a destra e il bg a sx muovo a dx + if (bg.getSpeedX() == bg.SPEEDSTOP - bg.SPEEDMOV) { + speedX = bg.SPEEDMOV * 2; + //se mario va a sx e il bg a dx muovo a sx + } else if (bg.getSpeedX() == bg.SPEEDSTOP + bg.SPEEDMOV) { + speedX = -bg.SPEEDMOV * 2; + //se il bg non si muove + } else { + speedX = 0; + } + } + + System.out.println("speedx " + speedX); + } catch (InterruptedException ex) { + //interrupted + } + } +} diff --git a/src/suppamario/Mario.java b/src/suppamario/Mario.java new file mode 100644 index 0000000..cba7d85 --- /dev/null +++ b/src/suppamario/Mario.java @@ -0,0 +1,395 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package suppamario; + +import java.awt.Rectangle; + +/** + * + * @author BBC + */ +public class Mario { + //costanti + + final int JUMPSPEED = -16; + final int MOVESPEED = 7; + //vado a leggere i bgs della classe istanziante + private static Background bg1 = SuppaMarioApplet.getBg1(); + private static Background bg2 = SuppaMarioApplet.getBg2(); + //rectangle per le collision + //collisione testa + static Rectangle rUpCollision = new Rectangle(0, 0, 0, 0); + //collisione piedi + static Rectangle rDownCollision = new Rectangle(0, 0, 0, 0); + //posizioneato sotto ai piedi serve per vedere se si sta camminando sul vuoto + static Rectangle rLeftCollision = new Rectangle(0, 0, 0, 0); + static Rectangle rRightCollision = new Rectangle(0, 0, 0, 0); + static Rectangle rSurroundingMario = new Rectangle(0, 0, 0, 0); + //coord centrali di mario (sprite) + private int centerX; + private int centerY; + private int jumpX; //ogni volta che mario tocca il suolo viene memorizzata la posizione in x e y in modo che + private int jumpY; //se muore viene rispristinata la sua ultima posizioneda vivo + //variabili di controllo movimento + private boolean movingLeft = false; + private boolean movingRight = false; + private boolean ducked = false; + private boolean dead = false; + //dienta true se sta saltando + private boolean jumped = false; + private boolean turnedRight = true; + private int speedX; + private int speedY; + private boolean cantMooveLeft; + private boolean cantMooveRight; + private boolean cantFall; + + public Mario(int x, int y) { + this.centerX = x; + this.centerY = y; + this.jumped = false; + this.cantFall = false; + this.speedX = 0; + this.speedY = 0; + } + + //questo metodo sposta il bg o mario in base alle velocita + public void update() { + //se mario non e morto esegue lo spostamento normale, se no lo spostamento di morte + if (!this.dead) { + //sposto in x + if (speedX < 0 && !cantMooveLeft) { + // evito di andare troppo a sx + if (centerX + speedX >= 100) { + //se la velocita e negativa vado a sx + centerX += speedX; + } else { + //se sono troppo a dx muovo solo il bg + bg1.moveLeft(); + bg2.moveLeft(); + } + } else if (speedX > 0 && !cantMooveRight) { + //se la velocita e positiva controllo dove sono + if (centerX <= 500) { + //se non sono troppo a destra sposto mario a dx + centerX += speedX; + } else { + //se sono troppo a dx muovo solo il bg + bg1.moveRight(); + bg2.moveRight(); + } + } + + //se puo scendere scende + //aumento di uno la velocita in y + if(!cantFall || jumped){ + speedY += 1; //decellero fino a portarlo a terra + centerY += speedY; + } + //aggiorno le coordinate delle collisioni + rSurroundingMario.setBounds(this.getCenterX() - 22, this.getCenterY() - 19, 44, 37); + rUpCollision.setBounds(this.getCenterX() - 5, this.getCenterY() - 14, 10, 1); //spessore fine solo per la collisione superiore + rDownCollision.setBounds(this.getCenterX() - 13, this.getCenterY() + 16, 26, 1); // + rLeftCollision.setBounds(this.getCenterX() - 17, this.getCenterY(), 1, 1); // + rRightCollision.setBounds(this.getCenterX() + 17, this.getCenterY(), 1, 1); // + + //controlla se e cadut troppo in basso da morire + if (this.centerY > 480) { + die(); + } + + cantMooveLeft = false; + cantMooveRight = false; + cantFall = false; + + //altrimenti se e morto + } else { + speedY += 1; + centerY += speedY; + } + } + + void revive() { + this.centerX = this.jumpX; + this.centerY = this.jumpY; + this.speedX = 0; + this.speedY = 0; + + this.dead = false; + } + + void saveCheckPoint() { + //se mario non e morto salvo le coord di rinascita per quando muore + if (!this.dead && this.speedY == 0) { + if (movingLeft) { + this.jumpX = this.centerX + 20; + } else if (movingRight) { + this.jumpX = this.centerX - 20; + } else { + this.jumpX = this.centerX; + } + + this.jumpY = this.centerY - 10; + } + } + + void stop() { + speedX = 0; + bg1.moveStop(); + bg2.moveStop(); + movingLeft = false; + movingRight = false; + } + + //se il salto sta ancora andando verso l alto lo fermo prematuramente + void stopJumping() { + if (speedY < 0) { + speedY = 0; + jumped = false; + } + } + + //METODI GENERALI + public void moveRight() { + if (!ducked && !movingLeft && !cantMooveRight) { + speedX = MOVESPEED; + movingLeft = false; + movingRight = true; + turnedRight = true; + cantMooveLeft = false; + } + } + + public void moveLeft() { + if (!ducked && !movingRight && !cantMooveLeft) { + speedX = -MOVESPEED; + movingLeft = true; + movingRight = false; + turnedRight = false; + cantMooveRight = false; + } + } + + public void jump() { + //se e vivo salta + if (!this.dead && !this.jumped) { + speedY = JUMPSPEED; + jumped = true; + ducked = false; + } + } + + void upCollisionDetected() { + this.speedY = 0; + //dopo aver azzerato la velocita allora imposto la posizione di mario e del suo rettangolo sup appena sotto al tile colliso + rUpCollision.setLocation((int) rUpCollision.getLocation().getX(), (int) (rUpCollision.getLocation().getY() - (rUpCollision.getLocation().getY() % 32) + 32)); + this.centerY = (int) rUpCollision.getLocation().getY() + 16; + //METTERE Y SOTTO IL BLOCCO + } + + void downCollisionDetected() { + //dopo aver azzerato la velocita allora imposto la posizione di mario e del suo rettangolo inf appena sotto al tile colliso + //esegue solo se sta salendo o salendo + rUpCollision.setLocation((int) rUpCollision.getLocation().getX(), (int) (rUpCollision.getLocation().getY() - (rUpCollision.getLocation().getY() % 32))); + this.centerY = (int) rUpCollision.getLocation().getY() + 16; + this.speedY = 0; + this.jumped = false; + this.cantFall = true; + + saveCheckPoint(); + } + + void leftCollisionDetected() { + cantMooveLeft = true; + //cosi fermo lo spostmanto dei bg + stop(); + } + + void rightCollisionDetected() { + cantMooveRight = true; + stop(); + } + + public void die() { + if (!this.dead) { + this.dead = true; + setSpeedY(-20); + + rUpCollision.setLocation((int) rUpCollision.getLocation().getX(), (int) (rUpCollision.getLocation().getY() - (rUpCollision.getLocation().getY() % 32))); + this.centerY = (int) rUpCollision.getLocation().getY() + 16; + } + } + + //GETTER + boolean getJump() { + return this.jumped; + } + + public int getCenterX() { + return centerX; + } + + public int getCenterY() { + return centerY; + } + + public boolean isJumped() { + return jumped; + } + + public boolean isDucked() { + return this.ducked; + } + + public boolean isMoving() { + return (movingLeft || movingRight); + } + + public static Rectangle getrSurroundingMario() { + return rSurroundingMario; + } + + public int getJumpX() { + return jumpX; + } + + public int getJumpY() { + return jumpY; + } + + public boolean isTurnedRight() { + return turnedRight; + } + + public int getJUMPSPEED() { + return JUMPSPEED; + } + + public int getMOVESPEED() { + return MOVESPEED; + } + + public static Background getBg1() { + return bg1; + } + + public static Background getBg2() { + return bg2; + } + + public static Rectangle getrUpCollision() { + return rUpCollision; + } + + public static Rectangle getrDownCollision() { + return rDownCollision; + } + + public static Rectangle getrLeftCollision() { + return rLeftCollision; + } + + public static Rectangle getrRightCollision() { + return rRightCollision; + } + + public boolean isMovingLeft() { + return movingLeft; + } + + public boolean isMovingRight() { + return movingRight; + } + + public int getSpeedX() { + return speedX; + } + + public int getSpeedY() { + return speedY; + } + + public boolean isCantMooveLeft() { + return cantMooveLeft; + } + + public boolean isCantMooveRight() { + return cantMooveRight; + } + + public boolean isDead() { + return this.dead; + } + + //SETTER + void setDuck(boolean isDucked) { + this.ducked = isDucked; + this.stop(); + } + + public static void setBg1(Background bg1) { + Mario.bg1 = bg1; + } + + public static void setBg2(Background bg2) { + Mario.bg2 = bg2; + } + + public static void setrUpCollision(Rectangle rUpCollision) { + Mario.rUpCollision = rUpCollision; + } + + public static void setrDownCollision(Rectangle rDownCollision) { + Mario.rDownCollision = rDownCollision; + } + + public void setCenterX(int centerX) { + this.centerX = centerX; + } + + public void setCenterY(int centerY) { + this.centerY = centerY; + } + + public void setMovingLeft(boolean movingLeft) { + this.movingLeft = movingLeft; + } + + public void setMovingRight(boolean movingRight) { + this.movingRight = movingRight; + } + + public void setDucked(boolean ducked) { + this.ducked = ducked; + } + + public void setTurnedRight(boolean turnedRight) { + this.turnedRight = turnedRight; + } + + public void setSpeedX(int speedX) { + this.speedX = speedX; + } + + public void setSpeedY(int speedY) { + this.speedY = speedY; + } + + void setJump(boolean b) { + this.jumped = b; + } + + public void setCantMooveLeft(boolean cantMooveLeft) { + this.cantMooveLeft = cantMooveLeft; + } + + public void setCantMooveRight(boolean cantMooveRight) { + this.cantMooveRight = cantMooveRight; + } + + void enemyHit() { + this.speedY = -this.speedY - 1; + } +} diff --git a/src/suppamario/SuppaMarioApplet.java b/src/suppamario/SuppaMarioApplet.java new file mode 100644 index 0000000..294e748 --- /dev/null +++ b/src/suppamario/SuppaMarioApplet.java @@ -0,0 +1,494 @@ +/** + * *************************************************** + * Autore: Rossi Stefano Nome: SuppaMarioApplet + * *************************************************** + */ +package suppamario; + +import java.applet.Applet; +import java.applet.AudioClip; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; + +/** + * + * @author BBC + */ +public class SuppaMarioApplet extends Applet implements Runnable, KeyListener { + + private Image imgOffScreen, imgMario, imgBg, imgKTwalking, imgKThidden, imgKtCurrent[]; + static Image imgBlock, imgWawes, imgCoinHeavenCloud, imgGround; + private Graphics graphOffScreen; + private Mario mario; + private Thread thAgg = new Thread(this); + private static URL dataPath; + private static Background bg1, bg2; + private KoopaTroopa[] kt; + private Animation marioRunning, marioRunningb, marioDie; + private Tile[][] tilemap = new Tile[2000][15]; + //audio + private AudioClip midiLvl1, midiDead, acJump; + private boolean alreadyDied; + + @Override + public void init() { + this.setSize(800, 480); //grande piu comunce degli schermi android + this.setBackground(Color.BLACK); //imposto lo sfondo del lapplet nera + + //imposto il focus alla finestra cosi non ci devo cliccare + this.setFocusable(true); + this.requestFocus(); + + //doppio buffering + imgOffScreen = createImage(this.getWidth(), this.getHeight()); + graphOffScreen = imgOffScreen.getGraphics(); + + //inizializzo varie variabili + alreadyDied = false; + + //istanzio gli oggetti necessari + bg1 = new Background(2160, 480);//le immagini sono lunghe 216,cosi + bg2 = new Background(2160, 480);//evito errori di sovrapposizione + //poi lo scenerei e composto da 32x32 + //array tilde map 67x25 per immagine + mario = new Mario(300, 300); + + //imposto le immagini + dataPath = getCodeBase(); + imgMario = getImage(dataPath, "img/mario/marioStop.gif"); + imgBg = getImage(dataPath, "img/background/background.png"); + imgBlock = getImage(dataPath, "img/scenery/block.gif"); + imgWawes = getImage(dataPath, "img/scenery/wawes.gif"); + imgCoinHeavenCloud = getImage(dataPath, "img/scenery/coinheavencloud.gif"); + imgGround = getImage(dataPath, "img/scenery/ground.gif"); + + //midi generali + midiDead = getAudioClip(getCodeBase(), "midi/die.wav"); + acJump = getAudioClip(getCodeBase(), "midi/jump.wav"); + + //inizializzo la tilemap in base al file della mappa (carico la mappa) + try { + loadMap("build/classes/mappe/map1.txt"); + + midiLvl1 = getAudioClip(getCodeBase(), "midi/lvl1.mid"); + midiLvl1.loop(); + } catch (IOException e) { + // TODO Auto-generated catch block + System.out.println("IOexception loading map 1"); + } + + //passo le immagini per mario in corsa avanti e indietro + marioRunning = new Animation(); + marioRunning.addFrame(getImage(dataPath, "img/mario/marioRun1.gif"), 50); + marioRunning.addFrame(getImage(dataPath, "img/mario/marioRun2.gif"), 50); + marioRunning.addFrame(getImage(dataPath, "img/mario/marioRun3.gif"), 50); + marioRunning.addFrame(getImage(dataPath, "img/mario/marioRun2.gif"), 50); + + marioRunningb = new Animation(); + marioRunningb.addFrame(getImage(dataPath, "img/mario/marioRun1b.gif"), 50); + marioRunningb.addFrame(getImage(dataPath, "img/mario/marioRun2b.gif"), 50); + marioRunningb.addFrame(getImage(dataPath, "img/mario/marioRun3b.gif"), 50); + marioRunningb.addFrame(getImage(dataPath, "img/mario/marioRun2b.gif"), 50); + + //passo le immagini per la morte di mario + marioDie = new Animation(); + marioDie.addFrame(getImage(dataPath, "img/mario/die1.gif"), 0); + marioDie.addFrame(getImage(dataPath, "img/mario/die2.gif"), 100); + marioDie.addFrame(getImage(dataPath, "img/mario/die3.gif"), 200); + marioDie.addFrame(getImage(dataPath, "img/mario/die4.gif"), 200); + marioDie.addFrame(getImage(dataPath, "img/mario/die5.gif"), 200); + marioDie.addFrame(getImage(dataPath, "img/mario/die6.gif"), 200); + marioDie.addFrame(getImage(dataPath, "img/mario/die7.gif"), 200); + + //attivo il keylistener in questa applet + this.addKeyListener(this); + + thAgg.start(); + } + + @Override + public void start() { + } + + @Override + public void stop() { + } + + @Override + public void destroy() { + } + + //METODI APPLET DI DISEGNO + @Override + public void update(Graphics g) { + //ridisegno la sprite se necessario di mario + if (mario.isDead()) { + imgMario = marioDie.getImage(); + marioDie.update(17); + } else if (mario.isDucked()) { + imgMario = getImage(dataPath, "img/mario/marioDucked.gif"); + } else if (mario.getSpeedY() != 0 || mario.isJumped()) { + if (mario.isTurnedRight()) { + imgMario = getImage(dataPath, "img/mario/marioJump.gif"); + } else { + imgMario = getImage(dataPath, "img/mario/marioJumpb.gif"); + } + } else if (mario.isMoving()) { + marioRunning.update(17); + marioRunningb.update(17); + if (mario.isTurnedRight()) { + imgMario = marioRunning.getImage(); + } else { + imgMario = marioRunningb.getImage(); + } + } else { + if (mario.isTurnedRight()) { + imgMario = getImage(dataPath, "img/mario/marioStop.gif"); + } else { + imgMario = getImage(dataPath, "img/mario/marioStopb.gif"); + } + } + //ridisegno la sprite se necessario dei koopatroopa + for(int i = 0; i < kt.length; i++){ + if(kt[i].getCurrentHealth() == kt[i].getMaxHealth()){ + imgKtCurrent[i] = getImage(dataPath, "img/enemies/koopaTroopa/greenWalking.gif"); + }else{ + imgKtCurrent[i] = getImage(dataPath, "img/enemies/koopaTroopa/greenHidden.gif"); + } + } + + paint(g); + } + + @Override + public void paint(Graphics g) { + //resetto lo scehrmo di buff + graphOffScreen.clearRect(0, 0, imgOffScreen.getWidth(this), imgOffScreen.getWidth(this)); + + //disegno i backdrounds + graphOffScreen.drawImage(imgBg, bg1.getBgX(), 0, this); + graphOffScreen.drawImage(imgBg, bg2.getBgX(), 0, this); + + //stampo la tilemap + for (int i = 0; i < tilemap.length; i++) { + for (int j = 0; j < tilemap[0].length; j++) { + if (tilemap[i][j] != null) { + graphOffScreen.drawImage(tilemap[i][j].getTileImage(), tilemap[i][j].getTileX(), tilemap[i][j].getTileY(), 32, 32, this); + } + } + } + + //disegno mario in base a quanto e grande + graphOffScreen.drawImage(imgMario, mario.getCenterX() - 13, mario.getCenterY() - 16, this); + + //quadrato collisioni sprites// +// graphOffScreen.drawRect((int) Mario.rUpCollision.getLocation().getX(), (int) Mario.rUpCollision.getLocation().getY(), (int) Mario.rUpCollision.getWidth(), (int) Mario.rUpCollision.getHeight()); +// graphOffScreen.drawRect((int) Mario.rDownCollision.getLocation().getX(), (int) Mario.rDownCollision.getLocation().getY(), (int) Mario.rDownCollision.getWidth(), (int) Mario.rDownCollision.getHeight()); +// graphOffScreen.drawRect((int) Mario.rLeftCollision.getLocation().getX(), (int) Mario.rLeftCollision.getLocation().getY(), (int) Mario.rLeftCollision.getWidth(), (int) Mario.rLeftCollision.getHeight()); +// graphOffScreen.drawRect((int) Mario.rRightCollision.getLocation().getX(), (int) Mario.rRightCollision.getLocation().getY(), (int) Mario.rRightCollision.getWidth(), (int) Mario.rRightCollision.getHeight()); +// graphOffScreen.drawRect((int) Mario.rSurroundingMario.getLocation().getX(), (int) Mario.rSurroundingMario.getLocation().getY(), (int) Mario.rSurroundingMario.getWidth(), (int) Mario.rSurroundingMario.getHeight()); + + //disegno i kt + for (int i = 0; i < kt.length; i++) { + if (kt[i].isVisible()) { + //graphOffScreen.drawRect((int) kt[i].getCollision().getLocation().getX(), (int) kt[i].getCollision().getLocation().getY(), (int) kt[i].getCollision().getWidth(),(int) kt[i].getCollision().getHeight()); + graphOffScreen.drawImage(imgKtCurrent[i], kt[i].getCenterX() - 10, kt[i].getCenterY() - ((kt[i].getCurrentHealth() != 2)?0:15), 20, (kt[i].getCurrentHealth() != 2)?15:30, this); + } + } + ///////////////////////////// + + g.drawImage(imgOffScreen, 0, 0, this); + } + + private void loadMap(String mapPath) throws IOException { + //salvo le linee in un arraylist + ArrayList lines = new ArrayList(); + int w = 0, h = 0; + + //in questa variabile carico il file + BufferedReader reader = new BufferedReader(new FileReader(mapPath)); + + //ripeto fino a che tutte le linee sono state lette e le salvo nel arraylist + while (true) { + String line = reader.readLine(); + // no more lines to read + if (line == null) { + reader.close(); + break; + } + + //se la linea non comincia per ! la conteggio + if (!line.startsWith("!")) { + lines.add(line); + //come l unghezza massimo imposto quella della riga piu lunga + w = Math.max(w, line.length()); + } + } + h = lines.size(); + + //ora posso inserire riga per riga i tile nella tilemap + for (int j = 0; j < 15 && j < h; j++) { + String line = (String) lines.get(j); + for (int i = 0; i < w; i++) { + if (i < line.length()) { + char ch = line.charAt(i); + tilemap[i][j] = new Tile(i, j, ch); + } + } + } + + //istanzio i nemici in bse alla mappa + int ktLevel = 4; + + kt = new KoopaTroopa[ktLevel]; + kt[0] = new KoopaTroopa(600, 400); + kt[1] = new KoopaTroopa(800, 400); + kt[2] = new KoopaTroopa(1100, 400); + kt[3] = new KoopaTroopa(1400, 400); + + imgKtCurrent = new Image[ktLevel]; + } + + //GETTER + static Background getBg1() { + return bg1; + } + + static Background getBg2() { + return bg2; + } + + public static URL getDataPath() { + return dataPath; + } + //METODI DEL KEYLISTENER + + @Override + public void keyPressed(KeyEvent e) { + //uso uno switch per il tasto premuto + switch (e.getKeyCode()) { + + case KeyEvent.VK_UP: + if ((mario.getSpeedY() == 0)) { + mario.jump(); + acJump.stop(); + acJump.play(); + } + break; + + case KeyEvent.VK_DOWN: + mario.setDuck(true); + break; + + case KeyEvent.VK_LEFT: + mario.moveLeft(); + break; + + case KeyEvent.VK_RIGHT: + mario.moveRight(); + break; + + case KeyEvent.VK_SPACE: + if ((mario.getSpeedY() == 0)) { + mario.jump(); + acJump.stop(); + acJump.play(); + } + break; + } + } + + @Override + public void keyReleased(KeyEvent e) { + switch (e.getKeyCode()) { + + case KeyEvent.VK_UP: + if (!mario.isDead()) { + mario.stopJumping(); + } + break; + + case KeyEvent.VK_DOWN: + mario.setDuck(false); + break; + + case KeyEvent.VK_LEFT: + mario.stop(); + break; + + case KeyEvent.VK_RIGHT: + mario.stop(); + break; + + case KeyEvent.VK_SPACE: + mario.stopJumping(); + break; + } + } + + @Override + public void keyTyped(KeyEvent e) { + //throw new UnsupportedOperationException("Not supported yet."); + } + + private void checkMarioEnemyCollision() { + for (int i = 0; i < kt.length; i++) { + if (kt[i].isVisible()) { + if (kt[i].isVisible() && kt[i].checkCollision(Mario.rSurroundingMario)) { + if (kt[i].checkCollision(Mario.rDownCollision)) { + mario.enemyHit(); + acJump.stop(); + acJump.play(); + kt[i].hitten(); + } else if (kt[i].checkCollision(Mario.rLeftCollision) || kt[i].checkCollision(Mario.rRightCollision) || kt[i].checkCollision(Mario.rUpCollision)) { + if (!mario.isDead()) { + mario.die(); + kt[i].setVisible(false); + } + } + } + } + } + } + + private synchronized void checkMarioTileCollision() { + //per ogni tile controllo la collisione per fermare il salto + for (int i = 0; i < tilemap.length; i++) { + for (int j = 0; j < tilemap[0].length; j++) { + + //prima controllare ogni singolo rectangle controllo che quello che racchiude tutti collisioni col tipe attuale + if (tilemap[i][j] != null && tilemap[i][j].checkCollision(Mario.rSurroundingMario)) { + //check dalla collisionesuperiore e inferiore + //se questo tile non e vuotoe e non e un blocco che uccide(es: onde) + + if (tilemap[i][j].isSolid() && !tilemap[i][j].isKiller()) { + //System.out.println(tilemap[i][j].getType()); + if (tilemap[i][j].checkCollision(Mario.rUpCollision)) { + mario.upCollisionDetected(); + } else if (tilemap[i][j].checkCollision(Mario.rDownCollision)) { + if (tilemap[i][j].isKiller()) { + if (!mario.isDead()) { + mario.die(); + } + } else if (!mario.isDead()) { + mario.downCollisionDetected(); + Tile.checkpointX = tilemap[0][0].getTileX(); + } + } + } + + //collisioni sx e dx + if (tilemap[i][j].isSolid()) { + //se non e null e non e un carattere vuoto allora controllo la collisione (tab e barra spaziatrice spazio) + if (tilemap[i][j].checkCollision(Mario.rLeftCollision)) { + //se e acqua muore + if (tilemap[i][j].isKiller()) { + if (!mario.isDead()) { + mario.die(); + } + } else { + mario.leftCollisionDetected(); + } + } + + if (tilemap[i][j].checkCollision(Mario.rRightCollision)) { + //se e acqua muore + if (tilemap[i][j].isKiller()) { + if (!mario.isDead()) { + mario.die(); + } + } else { + mario.rightCollisionDetected(); + } + } + } + } + } + } + } + + //ricarico la posizione della tilmap prima di morire + private void loadCheckPointTile() { + for (int i = 0; i < tilemap.length; i++) { + for (int j = 0; j < tilemap[0].length; j++) { + if (tilemap[i][j] != null) { + tilemap[i][j].setTileX(tilemap[i][j].getTileX() + (Math.abs(Tile.absX) - Math.abs(Tile.checkpointX))); + } + } + } + } + + //RUNNABLE + @Override + public void run() { + while (true) { + try { + Thread.sleep((mario.isDead()) ? 50 : 17); + //aggiorno la posizione degli elementi e ridisegno la applet + mario.update(); + bg1.update(); + bg2.update(); + + //questi invece li aggiorno solo se mario non e morto + //collisioni comprese + if (!mario.isDead()) { + for (int i = 0; i < kt.length; i++) { + kt[i].update(); + } + + //agiornamento tilemap + for (int i = 0; i < tilemap.length; i++) { + for (int j = 0; j < tilemap[0].length; j++) { + if (tilemap[i][j] != null) { + tilemap[i][j].update(); + } + } + } + + //eseguo un save di absX della tilemap + Tile.absX = tilemap[0][0].getTileX(); + + //check delle colllisioni tra mario e tilemap + checkMarioTileCollision(); + + //check delle colllisioni tra mario e i nemici + checkMarioEnemyCollision(); + } + + //se dopo queste collisioni mario muore, per una sola volta + if (mario.isDead() && !alreadyDied) { + alreadyDied = true; + midiLvl1.stop(); + midiDead.play(); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + + //controllo la posizione di mario e la resetto, succede se e morto + if (mario.isDead() && mario.getCenterY() > 1000) { + loadCheckPointTile(); + mario.revive(); + alreadyDied = false; + marioDie.reset(); + + midiLvl1.loop(); + } + + repaint(); + //System.out.println("agg"); + } catch (InterruptedException e) { + } + } + } +} \ No newline at end of file diff --git a/src/suppamario/Tile.java b/src/suppamario/Tile.java new file mode 100644 index 0000000..fd467d8 --- /dev/null +++ b/src/suppamario/Tile.java @@ -0,0 +1,191 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package suppamario; + +import java.awt.Image; +import java.awt.Rectangle; + +/** + * + * @author BBC + */ +public class Tile { + // ogni tile sara 32x32 qundi per trovare la posizione + // bastera fare l indice(in cui e posiz nella tilemap) + //e per la posizione 32 * X o Y + + private int tileX, tileY, speedX, type; + //type รจ il tipo (terra, acqua, nuvola, ecc) + //speed e la velocita del pezzo + Image tileImage; + private Rectangle rCollision; + Background bg = SuppaMarioApplet.getBg1(); + private boolean killer = false; // di default false, se questo tile uccide diventa true + private boolean solid = false; //se il blocco e solido + + //variabili statiche per il checkpoint + static int absX = 0; //variabile variata sempre tramite update + static int checkpointX = 0; //variabile per il checkpoint + + static void setCheckPointX(int cpX){ + checkpointX = cpX; + } + static int getCheckPointX(){ + return checkpointX; + } + + public Tile(int X, int Y, char typeInt) { + this.tileX = X * 32; + this.tileY = Y * 32; + this.type = typeInt; + this.rCollision = new Rectangle(tileX, tileY, 32, 32); + //System.out.println(this.tileX + " " + this.tileY); + + this.tileImage = chooseImage(typeInt); + } + + //spostamento del pezzo + public void update() { + + //se mario va a destra e il bg a sx muovo a dx + if (bg.getSpeedX() == bg.SPEEDSTOP - bg.SPEEDMOV) { + speedX = bg.SPEEDMOV * 2; + //se mario va a sx e il bg a dx muovo a sx + } else if (bg.getSpeedX() == bg.SPEEDSTOP + bg.SPEEDMOV) { + speedX = -bg.SPEEDMOV * 2; + //se il bg non si muove + } else { + speedX = 0; + } + // Se il pezzo e una wawes quindi si muove sempre un po (type == 0) + if (this.type == 0) { + speedX -= 1; + } + + tileX += speedX; + + this.rCollision.setBounds(this.tileX, this.tileY, 32, 32); + + //se non e un tile vuoto allora controllo se avviene una collisione + //if(this.type != 9) checkCollision(Mario.rCollision); + } + + //check delle collisioni tra il rettangolo passato e il rettangolo del tile + //se avessi a che fare con piu rectangles potrei creare un rettangolo piu + //grande, che racchiude tutti gli altri e prima verificare se il tile e dentro + //a quello, se non lo e non serve verificare anche tutti gli altri + //cosi facnedo si risparmiano molte operazioni + public boolean checkCollision(Rectangle r) { + if (r.intersects(rCollision)) { + return true; + } else { + return false; + } + } + + //imposto l immagine altile in base al tipo + private Image chooseImage(char typeInt) { + + switch (typeInt) { + case 'w': + this.killer = true; + this.solid = true; + return SuppaMarioApplet.imgWawes; + case 'g': + this.solid = true; + return SuppaMarioApplet.imgGround; + case 'c': + this.solid = false; + return SuppaMarioApplet.imgCoinHeavenCloud; + case 'b': + this.solid = true; + return SuppaMarioApplet.imgBlock; + default: + return null; + } + } + + //GETTER + public int getTileX() { + return tileX; + } + + public int getTileY() { + return tileY; + } + + public int getSpeedX() { + return speedX; + } + + public int getType() { + return type; + } + + public Image getTileImage() { + return tileImage; + } + + public Rectangle getrCollision() { + return rCollision; + } + + public Background getBg() { + return bg; + } + + public boolean isKiller() { + return killer; + } + + public boolean isSolid() { + return solid; + } + + public static int getAbsX() { + return absX; + } + + public static int getCheckpointX() { + return checkpointX; + } + + //setter + public void setTileX(int tileX) { + this.tileX = tileX; + } + + public void setTileY(int tileY) { + this.tileY = tileY; + } + + public void setSpeedX(int speedX) { + this.speedX = speedX; + } + + public void setType(int type) { + this.type = type; + } + + public void setTileImage(Image tileImage) { + this.tileImage = tileImage; + } + + public void setrCollision(Rectangle rCollision) { + this.rCollision = rCollision; + } + + public void setBg(Background bg) { + this.bg = bg; + } + + public static void setAbsX(int absX) { + Tile.absX = absX; + } + + public static void setCheckpointX(int checkpointX) { + Tile.checkpointX = checkpointX; + } +}