refactor(all)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ru.dmitriymx.game;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import ru.dmitriymx.game.engine.Sprite;
|
||||
|
||||
public class Foxy {
|
||||
private Sprite tex_idle, tex_run;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.dmitriymx.game;
|
||||
package ru.dmitriymx.game.engine;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
28
src/ru/dmitriymx/game/engine/Sprite2.java
Normal file
28
src/ru/dmitriymx/game/engine/Sprite2.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package ru.dmitriymx.game.engine;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Sprite2 extends Texture {
|
||||
private int width_frame, height_frame;
|
||||
private int count_frames;
|
||||
private int[][] frames_coords;
|
||||
|
||||
private void prepare_sprite(int width, int height){
|
||||
width_frame = width;
|
||||
height_frame = height;
|
||||
|
||||
count_frames = (int)(Math.floor(this.getWidth() / width_frame) * Math.floor(this.getHeight() / height_frame));
|
||||
frames_coords = new int[4][count_frames];
|
||||
}
|
||||
|
||||
public Sprite2(BufferedImage image, int width, int height) {
|
||||
super(image);
|
||||
prepare_sprite(width, height);
|
||||
}
|
||||
|
||||
public Sprite2(InputStream stream, int width, int height) {
|
||||
super(stream);
|
||||
prepare_sprite(width, height);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.dmitriymx.game;
|
||||
package ru.dmitriymx.game.engine;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
@@ -3,7 +3,7 @@ package ru.dmitriymx.game.mw;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import ru.dmitriymx.game.Sprite;
|
||||
import ru.dmitriymx.game.engine.Sprite;
|
||||
|
||||
public class Prometheus {
|
||||
private Sprite body, gun;
|
||||
@@ -96,21 +96,6 @@ public class Prometheus {
|
||||
render_body(bodyFrame);
|
||||
render_gun(gunFrame);
|
||||
|
||||
/*int _x;
|
||||
int _y;
|
||||
if(!inverse) {
|
||||
_x = (x + (19 * K));
|
||||
_y = (y + (5 * K));
|
||||
} else {
|
||||
_x = (x + (29 * K));
|
||||
_y = (y + (5 * K));
|
||||
}
|
||||
int mX = Mouse.getX();
|
||||
int mY = Display.getHeight() - Mouse.getY();
|
||||
float _a = (float)(Math.atan2(mY - _y, mX - _x) * 180/Math.PI);
|
||||
draw_target(_x, _y, 0);
|
||||
draw_quad(_x,_y,_a);*/
|
||||
|
||||
if(state == 1){
|
||||
if(!inverse){
|
||||
if(!rigth){
|
||||
|
||||
105
src/ru/dmitriymx/game/mw/Prometheus2.java
Normal file
105
src/ru/dmitriymx/game/mw/Prometheus2.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package ru.dmitriymx.game.mw;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import ru.dmitriymx.game.engine.Sprite;
|
||||
|
||||
public class Prometheus2 implements TexturedObject {
|
||||
private final double _180_DIV_PI = 180/Math.PI;
|
||||
private final int WIDTH, HEIGHT;
|
||||
private int x, y = 0;
|
||||
private Sprite body, gun;
|
||||
|
||||
public Prometheus2(){
|
||||
WIDTH = 48;
|
||||
HEIGHT = 32;
|
||||
body = new Sprite(Prometheus2.class.getResourceAsStream("/ru/dmitriymx/game/mw-prometheus-01.png"), WIDTH, HEIGHT);
|
||||
gun = new Sprite(Prometheus2.class.getResourceAsStream("/ru/dmitriymx/game/mw-prometheus-gun.png"), 48, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setX(int value) {
|
||||
this.x = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setY(int value) {
|
||||
this.y = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
GL11.glColor3f(1f, 1f, 1f);
|
||||
|
||||
render_body(body.getFrame());
|
||||
render_gun(body.getFrame());
|
||||
}
|
||||
|
||||
private void render_body(Sprite.Coords frame){
|
||||
body.bind();
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x, y, 0);
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glTexCoord2f(body.floatX(frame.x1), body.floatY(frame.y1));
|
||||
GL11.glVertex2f(0, 0);
|
||||
GL11.glTexCoord2f(body.floatX(frame.x2), body.floatY(frame.y1));
|
||||
GL11.glVertex2f(body.getWidthSprite(), 0);
|
||||
GL11.glTexCoord2f(body.floatX(frame.x2), body.floatY(frame.y2));
|
||||
GL11.glVertex2f(body.getWidthSprite(), body.getHeightSprite());
|
||||
GL11.glTexCoord2f(body.floatX(frame.x1), body.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, body.getHeightSprite());
|
||||
GL11.glEnd();
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private void render_gun(Sprite.Coords frame){
|
||||
int _x = x + 19;
|
||||
int _y = y + 5;
|
||||
int offcetX = -16;
|
||||
int offcetY = -10;
|
||||
int mX = Mouse.getX();
|
||||
int mY = Display.getHeight() - Mouse.getY();
|
||||
float angle = (float)(Math.atan2(mY - _y, mX - _x) * _180_DIV_PI);
|
||||
|
||||
gun.bind();
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(_x, _y, 0);
|
||||
GL11.glRotatef(angle, 0, 0, 1);
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glTexCoord2f(gun.floatX(frame.x1), gun.floatY(frame.y1));
|
||||
GL11.glVertex2f(offcetX, offcetY);
|
||||
GL11.glTexCoord2f(gun.floatX(frame.x2), gun.floatY(frame.y1));
|
||||
GL11.glVertex2f(offcetX + gun.getWidthSprite(), offcetY);
|
||||
GL11.glTexCoord2f(gun.floatX(frame.x2), gun.floatY(frame.y2));
|
||||
GL11.glVertex2f(offcetX + gun.getWidthSprite(), offcetY + gun.getHeightSprite());
|
||||
GL11.glTexCoord2f(gun.floatX(frame.x1), gun.floatY(frame.y2));
|
||||
GL11.glVertex2f(offcetX, offcetY + gun.getHeightSprite());
|
||||
GL11.glEnd();
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
13
src/ru/dmitriymx/game/mw/TexturedObject.java
Normal file
13
src/ru/dmitriymx/game/mw/TexturedObject.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.dmitriymx.game.mw;
|
||||
|
||||
public interface TexturedObject {
|
||||
public int getX();
|
||||
public int getY();
|
||||
public int getWidth();
|
||||
public int getHeight();
|
||||
|
||||
public void setX(int value);
|
||||
public void setY(int value);
|
||||
|
||||
public void render();
|
||||
}
|
||||
Reference in New Issue
Block a user