class JumpNRun { double x, y, sprung, gx, gy, grx, gry; String screen, unterUns, ueberUns, beiUns; JButton bStart; JLabel lGewonnen,lVerloren; void onStart( ) { bStart = new JButton( "Spiel starten", 50, 30, 50, 10 ); bStart.setStyle( "background", "red" ); lGewonnen = new JLabel( "Du hast gewonnen", 50, 50, 60, 30 ); lGewonnen.setStyle( "fontSize", "20pt" ); lGewonnen.setVisible( false ); lVerloren = new JLabel( "Du hast verloren", 50, 50, 60, 30 ); lVerloren.setStyle( "fontSize", "20pt" ); lVerloren.setVisible( false ); App.world.addRow( "F " ); App.world.addRow( "BBBBBB " ); App.world.addRow( " " ); App.world.addRow( " BBB " ); App.world.addRow( " " ); App.world.addRow( "BBBBB BBB" ); App.world.addRow( " " ); App.world.addRow( " BBBB " ); App.world.addRow( " " ); App.world.addRow( "BBBBBBBBBBBB" ); App.gamepad.show( ); x = 4; y = 2; gx = 7; gy = 4; grx = 0; gry = 0.1; sprung = 0; screen = "start"; } void onTileDraw( double x, double y, String type, String info ) { if ( type == "B" ) { App.world.drawImage( "ground", x, y, 1, 1, 0, false ); } if ( type == "F" ) { App.world.drawImage( "flag", x, y, 0.7, 0.8, 0, false ); } } void onAction( JComponent trigger ) { if ( trigger == bStart ) { screen = "spiel"; bStart.setVisible( false ); } } void onGamepadDown( String button ) { if ( button == "A" && unterUns == "B" ) { sprung = 0.4; } } void bienensteuerung( ) { if ( App.gamepad.left ) { x = x - 0.1; } if ( App.gamepad.right ) { x = x + 0.1; } y = y + sprung; sprung = sprung - 0.03; beiUns = App.world.getType( x, y ); ueberUns = App.world.getType( x, y + 0.5 ); unterUns = App.world.getType( x, y - 0.5 ); if ( sprung < 0 ) { if ( unterUns == "B" ) { sprung = 0; } } if ( sprung > 0 ) { if ( ueberUns == "B" ) { sprung = 0; } } if ( beiUns == "F" ) { screen = "gewonnen"; lGewonnen.setVisible( true ); } App.setFontsize( 8 ); App.world.write( "🐝", x, y, "center" ); } void geistbewegung( ) { gx = gx + grx; gy = gy + gry; if ( gy >= 10 ) { gry = -gry; } if ( gry < 0 ) { String unterGeist = App.world.getType( gx, gy - 0.5 ); if ( unterGeist == "B" ) { gry = -gry; } } double abstand=App.distance(gx, gy, x, y); if(abstand<0.6){ screen="verloren"; lVerloren.setVisible(true); } App.world.drawImage( "geist", gx, gy, 1, 1, 0, false ); } void onNextFrame( ) { App.clear( ); if ( screen == "start" ) { App.setColor( "black" ); App.fillRect( 50, 50, 80, 20 ); App.setColor( "gold" ); App.setFontsize( 8 ); App.write( "Super Jump & Run", 50, 50, "center" ); } if ( screen == "gewonnen" ) { } if(screen=="verloren"){ } if ( screen == "spiel" ) { App.world.draw( ); bienensteuerung( ); geistbewegung( ); } } public static void main( String[ ] args ) { App.loadAsset( "https://thomaskl.uber.space/Webapps/Assets/graphics/misc/sensed_monster_nasty.png", "monster" ); App.loadAsset( "https://thomaskl.uber.space/Webapps/Assets/graphics/gui/spells/monster/summon_undead.png", "geist" ); App.loadAsset( "https://thomaskl.uber.space/Webapps/Assets/graphics/platformer/ground.png", "ground" ); App.loadAsset( "https://thomaskl.uber.space/Webapps/Assets/graphics/platformer/water.png", "water" ); App.loadAsset( "https://thomaskl.uber.space/Webapps/Assets/graphics/platformer/coin_gold.png", "coin_gold" ); App.loadAsset( "https://thomaskl.uber.space/Webapps/Assets/graphics/overworld/flag.png", "flag" ); App.setupApp( "JumpNRun", "🐝", 100, 100, "lightblue" ); new JumpNRun( ); } }