i have tried converting lwjgl game applet can't load images, when delete code images throws null pointer exception, give me walkthrough on how convert code applet:
package com.kgt.platform.name; import java.io.file; import java.io.ioexception; import java.util.arraylist; import kuusisto.tinysound.sound; import kuusisto.tinysound.music; import kuusisto.tinysound.tinysound; import org.lwjgl.input.keyboard; import org.lwjgl.opengl.display; import org.lwjgl.opengl.displaymode; import org.lwjgl.opengl.gl11; import org.newdawn.slick.color; import org.newdawn.slick.opengl.texture; import org.newdawn.slick.opengl.textureloader; import org.newdawn.slick.util.resourceloader; import static org.lwjgl.opengl.gl11.*; public class game { public static player player; public static enemy enemy; public static exitbutton exitbutton; public static menubutton menubutton; public static arraylist<coin> coinlist; public static arraylist<bullet> bulletlist; public static arraylist<bullet2> bulletlist2; public static arraylist<platform> platformlist; public static arraylist<onewayplatform> onewayplatformlist; public static int score; public static boolean p1on; public static boolean p2on; static state state = state.game; public int curlvl = 1; private static texture logo; private static texture pause; public enum state { pause, game, main_menu, intro; } public static void init() { try { // load texture png file logo = textureloader.gettexture("png", resourceloader.getresourceasstream("res/logo.png")); system.out.println("texture 'logo' loaded. format: png"); pause = textureloader.gettexture("png", resourceloader.getresourceasstream("res/paused.png")); system.out.println("texture 'pause' loaded. format: png"); } catch (ioexception e) { e.printstacktrace(); } } public static void logo() { color.white.bind(); logo.bind(); // or gl11.glbind(texture.gettextureid()); gl11.glbegin(gl11.gl_quads); gl11.gltexcoord2f(0,0); gl11.glvertex2f(192,468); gl11.gltexcoord2f(1,0); gl11.glvertex2f(192+logo.gettexturewidth(),468); gl11.gltexcoord2f(1,1); gl11.glvertex2f(192+logo.gettexturewidth(),468- logo.gettextureheight()); gl11.gltexcoord2f(0,1); gl11.glvertex2f(192,468-logo.gettextureheight()); gl11.glend(); } public static void pause() { color.white.bind(); pause.bind(); // or gl11.glbind(texture.gettextureid()); gl11.glbegin(gl11.gl_quads); gl11.gltexcoord2f(0,0); gl11.glvertex2f(256,440); gl11.gltexcoord2f(1,0); gl11.glvertex2f(256+pause.gettexturewidth(),440); gl11.gltexcoord2f(1,1); gl11.glvertex2f(256+pause.gettexturewidth(),440- pause.gettextureheight()); gl11.gltexcoord2f(0,1); gl11.glvertex2f(256,440-pause.gettextureheight()); gl11.glend(); } public static void main(string[] args) throws exception { system.setproperty("org.lwjgl.librarypath", new file("natives").getabsolutepath()); system.out.println("native path: " + system.getproperty("org.lwjgl.librarypath")); display.setdisplaymode(new displaymode(640, 480)); display.create(); init(); score = 0; player = new player(); exitbutton = new exitbutton(320, 61); menubutton = new menubutton(320, 95); enemy = new enemy(); coinlist = new arraylist<coin>(0); bulletlist = new arraylist<bullet>(0); bulletlist2 = new arraylist<bullet2>(0); platformlist = new arraylist<platform>(0); onewayplatformlist = new arraylist<onewayplatform>(0); level1(); while(!display.iscloserequested()) { setcamera(); drawbackground1(); for(coin c: coinlist) c.draw(); for(bullet b: bulletlist) b.draw(); for(bullet2 b: bulletlist2) b.draw(); for(platform b: platformlist) b.draw(); for(onewayplatform b: onewayplatformlist) b.draw(); enemy.draw(); player.draw(); states(); stateinput(); exitbutton.draw(); menubutton.draw(); display.update(); display.sync(60); } display.destroy(); } public static void stopsound(){ tinysound.shutdown(); } public static void states(){ switch (state) { case intro: gl11.glbindtexture(gl11.gl_texture_2d, 0); glcolor3f(1.0f, 0.0f, 0.0f); glrectf(0, 0, 640, 480); break; case game: gl11.glbindtexture(gl11.gl_texture_2d, 0); break; case main_menu: gl11.glbindtexture(gl11.gl_texture_2d, 0); glcolor3f(0.0f, 0.0f, 1.0f); glrectf(0, 0, 640, 480); gl11.glbindtexture(gl11.gl_texture_2d, logo.gettextureid()); logo(); break; case pause: gl11.glbindtexture(gl11.gl_texture_2d, 0); glenable(gl_color_array); glbegin(gl_quads); glcolor4d(0.5f, 0.5f, 0.5, 0.7); glvertex2d(224, 40); glvertex2d(416, 40); glcolor4d(0.7f, 0.7f, 0.7, 0.7); glvertex2d(416, 440); glvertex2d(224, 440); glend(); gldisable(gl_color_array); glcolor3f(0f, 0f, 0f); glrectf(224, 40, 226, 440); glrectf(416, 40, 414, 440); glrectf(224, 40, 416, 42); glrectf(224, 438, 416, 440); gl11.glbindtexture(gl11.gl_texture_2d, pause.gettextureid()); pause(); break; } } public static void stateinput(){ while (keyboard.next()) { if(keyboard.iskeydown(keyboard.key_escape)) { if(state == state.game) state = state.pause; else if(state == state.pause) state = state.game; } } } public static void jumpsound(){ tinysound.init(); sound jump = tinysound.loadsound("/sound/jump6.wav"); jump.play(); } public static void shootsound(){ tinysound.init(); sound shoot = tinysound.loadsound("/sound/shoot1.wav"); shoot.play(); } public static void selectsound(){ tinysound.init(); sound select = tinysound.loadsound("/sound/select.wav"); select.play(); } public static void hurtsound(){ tinysound.init(); sound hurt = tinysound.loadsound("/sound/hurt1.wav"); hurt.play(); } public static void music(int track){ tinysound.init(); music ocean = tinysound.loadmusic("/music/ocean.wav"); music menu1 = tinysound.loadmusic("/music/menu1.wav"); if(track == 1){ ocean.play(true); } else if (track == 0){ menu1.play(true); } } public static void setcamera(){ gl11.glenable(gl11.gl_texture_2d); gl11.glenable(gl_color_array); gl11.glshademodel(gl11.gl_smooth); gl11.gldisable(gl11.gl_depth_test); gl11.gldisable(gl11.gl_lighting); gl11.glenable( gl11.gl_texture ); gl11.glclearcolor(0.0f, 0.0f, 0.0f, 0.0f); gl11.glcleardepth(1); gl11.glenable(gl11.gl_blend); gl11.glblendfunc(gl11.gl_src_alpha, gl11.gl_one_minus_src_alpha); gl11.glviewport(0,0,640,480); gl11.glmatrixmode(gl11.gl_modelview); gl11.glmatrixmode(gl11.gl_projection); gl11.glloadidentity(); gl11.glortho(0, 640, 0, 480, 1, -1); gl11.glmatrixmode(gl11.gl_modelview); } public static void level1(){ game.platformlist.add(new platform(16, 120)); game.platformlist.add(new platform(48, 120)); game.platformlist.add(new platform(624, 120)); game.platformlist.add(new platform(592, 120)); game.onewayplatformlist.add(new onewayplatform(128, 200)); game.onewayplatformlist.add(new onewayplatform(160, 200)); music(1); } public static void drawbackground1(){ gl11.glbindtexture(gl11.gl_texture_2d, 0); glbegin(gl_quads); glcolor3d(0.4, 0.5, 0.7); glvertex2d(640, 480); glvertex2d(0, 480); glcolor3d(0.7, 0.8, 0.9); glvertex2d(0, 0); glvertex2d(640, 0); glend(); glbegin(gl_quads); glcolor3d(0.3, 0.2, 0.1); glvertex2d(0, 0); glvertex2d(640, 0); glcolor3d(0.5, 0.2, 0.1); glvertex2d(640, 32); glvertex2d(0, 32); glend(); glbegin(gl_quads); glcolor3d(0.5, 0.2, 0.1); glvertex2d(0, 32); glvertex2d(640, 32); glcolor3d(0.2, 0.5, 0.1); glvertex2d(640, 47); glvertex2d(0, 47); glcolor3d(1, 1, 1); glend(); } }
Comments
Post a Comment