Friday 15 February 2013

java - My Enemy wont draw -



java - My Enemy wont draw -

i making -very- simple 1v1 game , enemy won't draw. code game:

the main class:

package generic; import org.lwjgl.opengl.display; import org.lwjgl.opengl.displaymode; import static org.lwjgl.opengl.gl11.*; public class main { public static player player; public static enemy enemy; public static void main(string[] args) throws exception { display.setdisplaymode(new displaymode (640, 480)); display.create(); player = new player(); //game while(!display.iscloserequested()) { setcamera(); drawbackground(); player.draw(); enemy.draw(); display.sync(60); display.update(); } display.destroy(); } public static void setcamera(){ glclear(gl_color_buffer_bit); //clear screen glmatrixmode(gl_projection); //projection matrix glloadidentity(); glortho(0, 640, 0, 480, -1, 1); //modify modelview matrix glmatrixmode(gl_modelview); glloadidentity(); } public static void drawbackground() { glbegin(gl_quads); //draw sky glcolor3d(0.7, 0.8, 0.9); glvertex2d(0, 0); glvertex2d(640, 0); glcolor3d(0.5, 0.6, 0.9); glvertex2d(640, 480); glvertex2d(0, 480); glend(); //draw ground glbegin(gl_quads); glcolor3d(0.5, 0.25, 0.1); glvertex2d(0, 0); glvertex2d(640, 0); glvertex2d(640, 32); glvertex2d(0, 32); glend(); //draw grass glbegin(gl_quads); glcolor3d(0, 0.7, 0.1); glvertex2d(0, 25); glvertex2d(640, 25); glvertex2d(640, 32); glvertex2d(0, 32); glend(); } }

the player class:

package generic; import static org.lwjgl.opengl.gl11.*; public class player { public double x, y, xspeed, yspeed; public player() { x=100; y=100; } public void draw() { glpushmatrix(); gltranslated(x, y, 0); glbegin(gl_quads); glcolor3d(1, 0, 0); glvertex2d(-8, 0); glcolor3d(0, 1, 0); glvertex2d(8, 0); glcolor3d(0, 0, 1); glvertex2d(8, 16); glcolor3d(1, 1, 0); glvertex2d(-8, 16); glend(); glpopmatrix(); } }

the enemy class:

package generic; import static org.lwjgl.opengl.gl11.*; public class enemy { public double x, y; public enemy() { x=200; y=32; } public void logic() { x+=1; if(x<=640+10) x = -10; } public void draw() { logic(); glpushmatrix(); gltranslated(x, y, 0); glbegin(gl_quads); glcolor3d(1, 0, 0); glvertex2d(-8, 0); glcolor3d(0, 1, 0); glvertex2d(8, 0); glcolor3d(0, 0, 1); glvertex2d(8, 16); glcolor3d(1, 1, 0); glvertex2d(-8, 16); glend(); glpopmatrix(); } }

the enemy (which should cube) not beingness drawn on screen. please help new java/lwjgl , don't know how solve on own

it looks calling drawbackground after drawing enemy, covering enemy?

remember when drawing things screen, computer going draw them in order phone call them regardless of beingness background or kind of object.

java eclipse rendering lwjgl

No comments:

Post a Comment