--- /dev/null
+ METAGUN\r
+\r
+\r
+\r
+ ABOUT \r
+\r
+METAGUN WAS MADE BY MARKUS PERSSON IN\r
+AUGUST 2010 FOR LUDUM DARE 18,\r
+A COMPETITION WHERE YOU MAKE A GAME\r
+DURING A SINGLE WEEKEND.\r
+\r
+\r
+THE THEME OF THE COMPETITION WAS\r
+"ENEMIES AS WEAPONS".\r
+\r
+\r
+\r
+ \r
+ \r
+ THE STORY SO FAR\r
+ \r
+RECENTLY, THE POLITICAL CLIMATE HAS\r
+GROWN WEIRD. SEVERAL COUNTRIES HAVE\r
+DECLARED THEMSELVES ROADLESS, AND\r
+SOMETHING SOMETHING IN THE MONTH OF MAY.\r
+ANYWAY, YOU FIND THIS TOTALLY AWESOME\r
+GUN THAT SHOOTS SMALLER PEOPLE WITH GUNS\r
+WHO IN TURN SHOOT YOU!\r
+\r
+\r
+AWESOME!\r
+\r
+\r
+\r
+\r
+\r
+ CONTROLS\r
+ \r
+USE THE ARROWS KEYS TO MOVE\r
+PRESS Z, A, C OR D TO JUMP\r
+PRESS X OR S TO FIRE\r
+PRESS ESCAPE TO PAUSE THE GAME\r
+\r
+\r
+ONCE YOU GET THE GUN, YOU CAN AIM UP\r
+AND DOWN BY PRESSING UP AND DOWN\r
+\r
+\r
+\r
+\r
+ SELECTED WORDS STARTING WITH F\r
+ \r
+FISH, FREEDOM, FIGURE, FOOT, FORK,\r
+FLOOD, FATAL, FUNGUS, FAX, FILM, FOG,\r
+FATTY, FOOT AGAIN, FELT, GNOME, F'TANG,\r
+\r
+\r
+NO WAIT GNOME STARTS WITH G, I WILL\r
+START OVER!\r
+\r
+ \r
+FISH, FREEDOM, FIGURE, FOOT, FORK,\r
+FLOOD, FATAL, FUNGUS, FAX, FILM, FOG,\r
+FATTY, FOOT AGAIN, FELT, F'TANG,\r
+FONE BONE, FADE, FORCE, FURBISH, FELONY,\r
+FEDORA.\r
+\r
+\r
+\r
+\r
+ THANK YOU\r
+ \r
+ELIN <3\r
+\r
+POV AND THE REST OF THE LD TEAM\r
+\r
+EVERYONE PARTICIPATING IN LD18\r
+\r
+EVERY SINGLE ONE WHO WASTED TIME\r
+WATCHING ME DEVELOP THIS GAME LIVE,\r
+AND EVERYONE WHO CAME WITH FEEDBACK\r
+\r
+DRPETTER FOR SFXR\r
+\r
+VALVE FOR TOTALLY RELEASING EP3 SOON
\ No newline at end of file
-package com.mojang.metagun;\r
-\r
-import java.awt.*;\r
-import java.awt.image.BufferedImage;\r
\r
-import javax.imageio.ImageIO;\r
+package com.mojang.metagun;\r
\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.graphics.Pixmap;\r
+import com.badlogic.gdx.graphics.Texture;\r
import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
\r
public class Art {\r
-// public static BufferedImage[][] guys = split(load("/guys.png"), 6, 6);\r
-// public static BufferedImage[][] player1 = split(load("/player.png"), 16, 32);\r
-// public static BufferedImage[][] player2 = mirrorsplit(load("/player.png"), 16, 32);\r
-// public static BufferedImage[][] walls = split(load("/walls.png"), 10, 10);\r
-// public static BufferedImage[][] gremlins = split(load("/gremlins.png"), 30, 30);\r
- public static TextureRegion bg = scale(load("/background.png"), 8);\r
-// public static TextureRegion level = load("/levels.png");\r
- public static TextureRegion titleScreen = load("/titlescreen.png");\r
-// public static BufferedImage winScreen1 = load("/winscreen1.png");;\r
-// public static BufferedImage winScreen2 = load("/winscreen2.png");;\r
+ public static TextureRegion[][] guys;\r
+ public static TextureRegion[][] player1;\r
+ public static TextureRegion[][] player2;\r
+ public static TextureRegion[][] walls;\r
+ public static TextureRegion[][] gremlins;\r
+ public static TextureRegion bg;\r
+ public static Pixmap level;\r
+ public static TextureRegion titleScreen;\r
+ public static TextureRegion shot;\r
+\r
+ public static TextureRegion winScreen1;\r
+ public static TextureRegion winScreen2;\r
+\r
+ public static void load () {\r
+ bg = load("res/background.png", 320, 240);\r
+ level = new Pixmap(Gdx.files.internal("res/levels.png"));\r
+ titleScreen = load("res/titlescreen.png", 320, 740);\r
+ guys = split("res/guys.png", 6, 6);\r
+ player1 = split("res/player.png", 16, 32);\r
+ player2 = split("res/player.png", 16, 32, true);\r
+ walls = split("res/walls.png", 10, 10);\r
+ gremlins = split("res/gremlins.png", 30, 30);\r
+\r
+ shot = new TextureRegion(guys[0][0].getTexture(), 3, 27, 2, 2);\r
+ winScreen1 = load("res/winscreen1.png", 320, 240);\r
+ winScreen2 = load("res/winscreen2.png", 320, 240);\r
+ }\r
+ \r
+ private static TextureRegion[][] split (String name, int width, int height) {\r
+ return split(name, width, height, false);\r
+ }\r
\r
- public static BufferedImage load(String name) {\r
- try {\r
- BufferedImage org = ImageIO.read(Art.class.getResource(name));\r
- BufferedImage res = new BufferedImage(org.getWidth(), org.getHeight(), BufferedImage.TYPE_INT_ARGB);\r
- Graphics g = res.getGraphics();\r
- g.drawImage(org, 0, 0, null, null);\r
- g.dispose();\r
- return res;\r
- } catch (Exception e) {\r
- throw new RuntimeException(e);\r
- }\r
- }\r
+ private static TextureRegion[][] split (String name, int width, int height, boolean flipX) {\r
+ Texture texture = new Texture(Gdx.files.internal(name));\r
+ int xSlices = texture.getWidth() / width;\r
+ int ySlices = texture.getHeight() / height;\r
+ TextureRegion[][] res = new TextureRegion[xSlices][ySlices];\r
+ for (int x = 0; x < xSlices; x++) {\r
+ for (int y = 0; y < ySlices; y++) {\r
+ res[x][y] = new TextureRegion(texture, x * width, y * height, width, height);\r
+ res[x][y].flip(flipX, true);\r
+ }\r
+ }\r
+ return res;\r
+ }\r
\r
- private static BufferedImage scale(BufferedImage src, int scale) {\r
- int w = src.getWidth() * scale;\r
- int h = src.getHeight() * scale;\r
- BufferedImage res = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);\r
- Graphics g = res.getGraphics();\r
- g.drawImage(src.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING), 0, 0, null);\r
- g.dispose();\r
- return res;\r
- }\r
+ public static TextureRegion load (String name, int width, int height) {\r
+ Texture texture = new Texture(Gdx.files.internal(name));\r
+ TextureRegion region = new TextureRegion(texture, 0, 0, width, height);\r
+ region.flip(false, true);\r
+ return region;\r
+ }\r
\r
- private static BufferedImage[][] mirrorsplit(BufferedImage src, int xs, int ys) {\r
- int xSlices = src.getWidth() / xs;\r
- int ySlices = src.getHeight() / ys;\r
- BufferedImage[][] res = new BufferedImage[xSlices][ySlices];\r
- for (int x = 0; x < xSlices; x++) {\r
- for (int y = 0; y < ySlices; y++) {\r
- res[x][y] = new BufferedImage(xs, ys, BufferedImage.TYPE_INT_ARGB);\r
- Graphics g = res[x][y].getGraphics();\r
- g.drawImage(src, xs, 0, 0, ys, x * xs, y * ys, (x + 1) * xs, (y + 1) * ys, null);\r
- g.dispose();\r
- }\r
- }\r
- return res;\r
- }\r
+// private static BufferedImage scale (BufferedImage src, int scale) {\r
+// int w = src.getWidth() * scale;\r
+// int h = src.getHeight() * scale;\r
+// BufferedImage res = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);\r
+// Graphics g = res.getGraphics();\r
+// g.drawImage(src.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING), 0, 0, null);\r
+// g.dispose();\r
+// return res;\r
+// }\r
+//\r
+// private static BufferedImage[][] mirrorsplit (BufferedImage src, int xs, int ys) {\r
+// int xSlices = src.getWidth() / xs;\r
+// int ySlices = src.getHeight() / ys;\r
+// BufferedImage[][] res = new BufferedImage[xSlices][ySlices];\r
+// for (int x = 0; x < xSlices; x++) {\r
+// for (int y = 0; y < ySlices; y++) {\r
+// res[x][y] = new BufferedImage(xs, ys, BufferedImage.TYPE_INT_ARGB);\r
+// Graphics g = res[x][y].getGraphics();\r
+// g.drawImage(src, xs, 0, 0, ys, x * xs, y * ys, (x + 1) * xs, (y + 1) * ys, null);\r
+// g.dispose();\r
+// }\r
+// }\r
+// return res;\r
+// }\r
\r
- private static BufferedImage[][] split(BufferedImage src, int xs, int ys) {\r
- int xSlices = src.getWidth() / xs;\r
- int ySlices = src.getHeight() / ys;\r
- BufferedImage[][] res = new BufferedImage[xSlices][ySlices];\r
- for (int x = 0; x < xSlices; x++) {\r
- for (int y = 0; y < ySlices; y++) {\r
- res[x][y] = new BufferedImage(xs, ys, BufferedImage.TYPE_INT_ARGB);\r
- Graphics g = res[x][y].getGraphics();\r
- g.drawImage(src, -x * xs, -y * ys, null);\r
- g.dispose();\r
- }\r
- }\r
- return res;\r
- }\r
+// private static BufferedImage[][] split(BufferedImage src, int xs, int ys) {\r
+// int xSlices = src.getWidth() / xs;\r
+// int ySlices = src.getHeight() / ys;\r
+// BufferedImage[][] res = new BufferedImage[xSlices][ySlices];\r
+// for (int x = 0; x < xSlices; x++) {\r
+// for (int y = 0; y < ySlices; y++) {\r
+// res[x][y] = new BufferedImage(xs, ys, BufferedImage.TYPE_INT_ARGB);\r
+// Graphics g = res[x][y].getGraphics();\r
+// g.drawImage(src, -x * xs, -y * ys, null);\r
+// g.dispose();\r
+// }\r
+// }\r
+// return res;\r
+// }\r
}\r
package com.mojang.metagun;\r
\r
-import java.awt.event.KeyEvent;\r
+import com.badlogic.gdx.Input.Keys;\r
+import com.badlogic.gdx.InputAdapter;\r
\r
-public class Input {\r
+public class Input extends InputAdapter {\r
public static final int UP = 0;\r
public static final int DOWN = 1;\r
public static final int LEFT = 2;\r
public void set(int key, boolean down) {\r
int button = -1;\r
\r
- if (key == KeyEvent.VK_UP) button = UP;\r
- if (key == KeyEvent.VK_LEFT) button = LEFT;\r
- if (key == KeyEvent.VK_DOWN) button = DOWN;\r
- if (key == KeyEvent.VK_RIGHT) button = RIGHT;\r
+ if (key == Keys.KEYCODE_DPAD_UP) button = UP;\r
+ if (key == Keys.KEYCODE_DPAD_LEFT) button = LEFT;\r
+ if (key == Keys.KEYCODE_DPAD_DOWN) button = DOWN;\r
+ if (key == Keys.KEYCODE_DPAD_RIGHT) button = RIGHT;\r
\r
- if (key == KeyEvent.VK_NUMPAD8) button = UP;\r
- if (key == KeyEvent.VK_NUMPAD4) button = LEFT;\r
- if (key == KeyEvent.VK_NUMPAD2) button = DOWN;\r
- if (key == KeyEvent.VK_NUMPAD6) button = RIGHT;\r
+ if (key == Keys.KEYCODE_Y) button = JUMP;\r
+ if (key == Keys.KEYCODE_Z) button = JUMP;\r
+ if (key == Keys.KEYCODE_X) button = SHOOT;\r
+ if (key == Keys.KEYCODE_C) button = JUMP;\r
+ if (key == Keys.KEYCODE_A) button = JUMP;\r
+ if (key == Keys.KEYCODE_S) button = SHOOT;\r
+ if (key == Keys.KEYCODE_D) button = JUMP;\r
\r
- if (key == KeyEvent.VK_Z) button = JUMP;\r
- if (key == KeyEvent.VK_X) button = SHOOT;\r
- if (key == KeyEvent.VK_C) button = JUMP;\r
- if (key == KeyEvent.VK_A) button = JUMP;\r
- if (key == KeyEvent.VK_S) button = SHOOT;\r
- if (key == KeyEvent.VK_D) button = JUMP;\r
-\r
- if (key == KeyEvent.VK_ESCAPE) button = ESCAPE;\r
+ if (key == Keys.KEYCODE_ESCAPE) button = ESCAPE;\r
\r
if (button >= 0) {\r
buttons[button] = down;\r
buttons[i] = false;\r
}\r
}\r
+\r
+ @Override public boolean keyDown (int keycode) {\r
+ set(keycode, true);\r
+ return false;\r
+ }\r
+\r
+ @Override public boolean keyUp (int keycode) {\r
+ set(keycode, false);\r
+ return false;\r
+ }\r
+\r
+ @Override public boolean keyTyped (char character) {\r
+ // TODO Auto-generated method stub\r
+ return false;\r
+ } \r
}\r
package com.mojang.metagun;\r
\r
-import java.applet.Applet;\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import java.awt.image.BufferedImage;\r
-import java.io.IOException;\r
-\r
-import javax.imageio.ImageIO;\r
-import javax.swing.JFrame;\r
+import java.awt.event.KeyEvent;\r
\r
import com.badlogic.gdx.ApplicationListener;\r
import com.badlogic.gdx.Gdx;\r
-import com.mojang.metagun.screen.*;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.g2d.BitmapFont;\r
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
+import com.mojang.metagun.screen.GameScreen;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Metagun implements ApplicationListener {\r
public static final int GAME_WIDTH = 320;\r
private Input input = new Input();\r
private boolean started = false;\r
private float accum = 0;\r
+ BitmapFont font;\r
+ SpriteBatch batch;\r
\r
public void create() {\r
+ Art.load();\r
+ Gdx.input.setInputProcessor(input);\r
running = true;\r
- setScreen(new TitleScreen());\r
+// setScreen(new TitleScreen());\r
+ setScreen(new GameScreen());\r
+ font = new BitmapFont(); \r
+ batch = new SpriteBatch();\r
}\r
\r
public void pause() {\r
}\r
\r
public void render() {\r
+ Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
accum += Gdx.graphics.getDeltaTime();\r
while(accum > 1.0f / 60.0f) { \r
screen.tick(input);\r
input.tick();\r
accum -= 1.0f / 60.0f;\r
}\r
- screen.render();\r
+ screen.render(); \r
+ batch.begin();\r
+ font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 30);\r
+ batch.end();\r
}\r
\r
public void keyPressed(KeyEvent ke) {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Sound;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Boss extends BossPart {\r
private static final int MAX_TEMPERATURE = 80 * 5;\r
}\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen screen, Camera camera) {\r
int xp = (int) x - 2;\r
int yp = (int) y - 2;\r
- g.drawImage(Art.gremlins[3][1], xp, yp, null);\r
- g.setColor(Color.BLACK);\r
- yp += 2;\r
- xp -= 7;\r
- g.fillRect(xp + 5, yp - 8, 20, 3);\r
- g.setColor(Color.RED);\r
- g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);\r
+ screen.draw(Art.gremlins[3][1], xp, yp);\r
+ //FIXME\r
+// g.setColor(Color.BLACK);\r
+// yp += 2;\r
+// xp -= 7;\r
+// g.fillRect(xp + 5, yp - 8, 20, 3);\r
+// g.setColor(Color.RED);\r
+// g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);\r
}\r
\r
public void hitSpikes() {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class BossNeck extends BossPart {\r
public int slamTime = 0;\r
baseRot = rot;\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen screen, Camera camera) {\r
int xp = (int) x - 1;\r
int yp = (int) y - 1;\r
- g.drawImage(Art.gremlins[4][1], xp, yp, null);\r
+ screen.draw(Art.gremlins[4][1], xp, yp);\r
}\r
\r
public void hitSpikes() {\r
package com.mojang.metagun.entity;\r
\r
-public class BossPart extends Entity {\r
+\r
+public abstract class BossPart extends Entity {\r
public int dieIn = 0;\r
\r
public void setRot(double rot) {\r
}\r
\r
public void outOfBounds() {\r
- }\r
+ } \r
}
\ No newline at end of file
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
\r
+import com.mojang.metagun.Art;\r
import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Bullet extends Entity {\r
public Entity source;\r
remove();\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
- if (tick % 2 == 0) {\r
- g.setColor(Color.YELLOW);\r
- int x1 = (int) (x + w / 2 - xa * 3);\r
- int y1 = (int) (y + h / 2 - ya * 3);\r
- int x2 = (int) (x + w / 2);\r
- int y2 = (int) (y + h / 2);\r
-\r
- g.drawLine(x1, y1, x2, y2);\r
- g.setColor(Color.WHITE);\r
-\r
- x1 = (int) (x + w / 2 - xa);\r
- y1 = (int) (y + h / 2 - ya);\r
- x2 = (int) (x + w / 2 + xa);\r
- y2 = (int) (y + h / 2 + ya);\r
-\r
- g.drawLine(x1, y1, x2, y2);\r
- } else {\r
- g.setColor(Color.YELLOW);\r
- int x1 = (int) (x + w / 2 - xa);\r
- int y1 = (int) (y + h / 2 - ya);\r
- int x2 = (int) (x + w / 2 + xa);\r
- int y2 = (int) (y + h / 2 + ya);\r
-\r
- g.drawLine(x1, y1, x2, y2);\r
- }\r
+ public void render(Screen g, Camera camera) {\r
+ // FIXME\r
+// if (tick % 2 == 0) {\r
+// g.setColor(Color.YELLOW);\r
+// int x1 = (int) (x + w / 2 - xa * 3);\r
+// int y1 = (int) (y + h / 2 - ya * 3);\r
+// int x2 = (int) (x + w / 2);\r
+// int y2 = (int) (y + h / 2);\r
+//\r
+// g.drawLine(x1, y1, x2, y2);\r
+// g.setColor(Color.WHITE);\r
+//\r
+// x1 = (int) (x + w / 2 - xa);\r
+// y1 = (int) (y + h / 2 - ya);\r
+// x2 = (int) (x + w / 2 + xa);\r
+// y2 = (int) (y + h / 2 + ya);\r
+//\r
+// g.drawLine(x1, y1, x2, y2);\r
+// } else {\r
+// g.setColor(Color.YELLOW);\r
+// int x1 = (int) (x + w / 2 - xa);\r
+// int y1 = (int) (y + h / 2 - ya);\r
+// int x2 = (int) (x + w / 2 + xa);\r
+// int y2 = (int) (y + h / 2 + ya);\r
+//\r
+// g.drawLine(x1, y1, x2, y2);\r
+// }\r
\r
+ g.draw(Art.shot, (int)x, (int)y);\r
// g.fillRect(xp, yp, w, h);\r
}\r
}\r
import java.util.Random;\r
\r
import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.screen.Screen;\r
\r
-public class Entity {\r
+public abstract class Entity {\r
protected boolean onGround = false;\r
protected static Random random = new Random();\r
\r
public void tick() {\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
- }\r
+ public abstract void render(Screen screen, Camera camera); \r
\r
public boolean shot(Bullet bullet) {\r
return false;\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
import com.mojang.metagun.Art;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Explosion extends Entity {\r
private int life, delay, color;\r
this.ya *= 0.4;\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int xp = (int) x;\r
int yp = (int) y;\r
- g.drawImage(Art.guys[(life - 1) * 8 / duration][4 + color], xp - 3, yp - 3, null);\r
+ g.draw(Art.guys[(life - 1) * 8 / duration][4 + color], xp - 3, yp - 3);\r
}\r
}\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
import com.mojang.metagun.Art;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Gore extends Entity {\r
private int life;\r
this.ya *= 0.4;\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int xp = (int) x;\r
int yp = (int) y;\r
- g.drawImage(Art.guys[7][1], xp, yp, null);\r
+ g.draw(Art.guys[7][1], xp, yp);\r
}\r
}\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Sound;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Gremlin extends Entity {\r
private static final int MAX_TEMPERATURE = 80 * 5;\r
}\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int xp = (int) x;\r
int yp = (int) y;\r
if (onGround) {\r
- g.drawImage(Art.gremlins[0][power], xp, yp, null);\r
+ g.draw(Art.gremlins[0][power], xp, yp);\r
} else {\r
- g.drawImage(Art.gremlins[ya > 0 ? 2 : 1][power], xp, yp, null);\r
+ g.draw(Art.gremlins[ya > 0 ? 2 : 1][power], xp, yp);\r
}\r
- g.setColor(Color.BLACK);\r
- g.fillRect(xp + 5, yp - 8, 20, 3);\r
- g.setColor(Color.RED);\r
- g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);\r
+ // FIXME\r
+// g.setColor(Color.BLACK);\r
+// g.fillRect(xp + 5, yp - 8, 20, 3);\r
+// g.setColor(Color.RED);\r
+// g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);\r
}\r
\r
public void hitSpikes() {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Sound;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Gunner extends Entity {\r
public static final int CHARGE_DURATION = 100; \r
}\r
\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
// g.setColor(Color.red);\r
int xp = (int) x;\r
int yp = (int) y;\r
}\r
\r
\r
- g.drawImage(Art.guys[xFrame][yFrame], xp, yp, null);\r
+ g.draw(Art.guys[xFrame][yFrame], xp, yp);\r
\r
java.util.List<Entity> entities = level.getEntities((int) x, (int) y, 1, 1);\r
for (int i = 0; i < entities.size(); i++) {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-import java.awt.image.BufferedImage;\r
-\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Sound;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Hat extends Entity {\r
double time = 0;\r
player.hatCount++;\r
\r
if (xPos >= 0 && yPos >= 0) {\r
- Art.level.setRGB(xPos, yPos, 0);\r
+ Art.level.setColor(0, 0, 0, 0);\r
+ Art.level.drawPixel(xPos, yPos);\r
}\r
Sound.gethat.play();\r
remove();\r
}\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int dir = 1;\r
int xp = (int) x - (16 - w) / 2;\r
int yp = (int) y - 2;\r
- BufferedImage[][] sheet = dir == 1 ? Art.player1 : Art.player2;\r
+ TextureRegion[][] sheet = dir == 1 ? Art.player1 : Art.player2;\r
\r
int xFrame = (int) (xa * 10);\r
if (xFrame < -1) xFrame = -1;\r
if (xFrame > +1) xFrame = +1;\r
- g.drawImage(sheet[1 + xFrame][1], xp, yp, null);\r
+ g.draw(sheet[1 + xFrame][1], xp, yp);\r
}\r
\r
public boolean shot(Bullet bullet) {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
import com.mojang.metagun.Art;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class HeadGore extends Entity {\r
private int life;\r
this.ya *= 0.8;\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int xp = (int) x;\r
int yp = (int) y;\r
- g.drawImage(Art.guys[6][1], xp, yp, null);\r
+ g.draw(Art.guys[6][1], xp, yp);\r
}\r
\r
public void hitSpikes() {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Sound;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Jabberwocky extends Entity {\r
private static final int MAX_TEMPERATURE = 80 * 5;\r
}\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int xp = (int) x;\r
int yp = (int) y-10;\r
- g.drawImage(Art.gremlins[3+(slamTime/10%5==2?1:0)][0], xp, yp, null);\r
- g.setColor(Color.BLACK);\r
- yp+=10;\r
- g.fillRect(xp + 5, yp - 8, 20, 3);\r
- g.setColor(Color.RED);\r
- g.fillRect(xp + 5, yp - 8, (20 * temperature / MAX_TEMPERATURE), 2);\r
+ g.draw(Art.gremlins[3+(slamTime/10%5==2?1:0)][0], xp, yp);\r
+ // FIXME\r
+// g.setColor(Color.BLACK);\r
+// yp+=10;\r
+// g.fillRect(xp + 5, yp - 8, 20, 3);\r
+// g.setColor(Color.RED);\r
+// g.fillRect(xp + 5, yp - 8, (20 * temperature / MAX_TEMPERATURE), 2);\r
}\r
\r
public void hitSpikes() {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-import java.awt.image.BufferedImage;\r
-\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
+import com.mojang.metagun.Sound;\r
+import com.mojang.metagun.Stats;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Player extends Entity {\r
private int dir = 1;\r
public void tick() {\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
// g.setColor(Color.GREEN);\r
int xp = (int) x - (16 - w) / 2;\r
int yp = (int) y - 2;\r
\r
int stepFrame = frame / 4 % 4;\r
\r
- BufferedImage[][] sheet = dir == 1 ? Art.player1 : Art.player2;\r
+ TextureRegion[][] sheet = dir == 1 ? Art.player1 : Art.player2; \r
if (!onGround) {\r
int yya = (int) Math.round(-ya);\r
stepFrame = 4;\r
if (yya < -1) stepFrame = 5;\r
yp += yya;\r
}\r
- g.drawImage(sheet[3 + stepFrame][hatCount > 0 ? 0 : 1], xp, yp, null);\r
+ g.draw(sheet[3 + stepFrame][hatCount > 0 ? 0 : 1], xp, yp);\r
\r
\r
yp += (stepFrame == 3 ? 1 : 0);\r
for (int i = 1; i < hatCount; i++) {\r
- g.drawImage(sheet[0][1], xp, yp - i * 2, null);\r
+ g.draw(sheet[0][1], xp, yp - i * 2);\r
}\r
\r
if (gunLevel > 0) {\r
if (yya > 1) yya = 1;\r
yp += yya;\r
}\r
- g.drawImage(sheet[1 + yAim][(gunLevel - 1) * 2], xp, yp, null);\r
+ g.draw(sheet[1 + yAim][(gunLevel - 1) * 2], xp, yp);\r
}\r
}\r
\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
import com.mojang.metagun.Art;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class PlayerGore extends Entity {\r
private int life;\r
this.ya *= 0.9;\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int xp = (int) x;\r
int yp = (int) y;\r
- g.drawImage(Art.guys[6][1], xp, yp, null);\r
+ g.draw(Art.guys[6][1], xp, yp);\r
}\r
\r
public void hitSpikes() {\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
import com.mojang.metagun.Art;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Sign extends Entity {\r
public int id;\r
}\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
if (id==6 && level.player.gunLevel>=1) return;\r
if (id==15 && level.player.gunLevel>=2) return;\r
if (id==6) {\r
- g.drawImage(Art.walls[5][0], (int)x, (int)y, null);\r
+ g.draw(Art.walls[5][0], (int)x, (int)y);\r
} else if (id==15) {\r
- g.drawImage(Art.walls[6][0], (int)x, (int)y, null);\r
+ g.draw(Art.walls[6][0], (int)x, (int)y);\r
} else {\r
- g.drawImage(Art.walls[4][0], (int)x, (int)y, null);\r
+ g.draw(Art.walls[4][0], (int)x, (int)y);\r
}\r
}\r
}\r
package com.mojang.metagun.entity;\r
\r
-import java.awt.*;\r
-\r
import com.mojang.metagun.Art;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Spark extends Entity {\r
private int life;\r
this.ya *= 0.4;\r
}\r
\r
- public void render(Graphics g, Camera camera) {\r
+ public void render(Screen g, Camera camera) {\r
int xp = (int) x;\r
int yp = (int) y;\r
- g.drawImage(Art.guys[9][1], xp, yp, null);\r
+ g.draw(Art.guys[9][1], xp, yp);\r
}\r
}\r
+\r
package com.mojang.metagun.level;\r
\r
-import java.awt.*;\r
-import java.util.*;\r
+import java.util.ArrayList;\r
import java.util.List;\r
+import java.util.Random;\r
\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.entity.*;\r
+import com.badlogic.gdx.math.Matrix4;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Sound;\r
+import com.mojang.metagun.entity.Boss;\r
+import com.mojang.metagun.entity.BossNeck;\r
+import com.mojang.metagun.entity.BossPart;\r
+import com.mojang.metagun.entity.Entity;\r
+import com.mojang.metagun.entity.Explosion;\r
+import com.mojang.metagun.entity.Gremlin;\r
+import com.mojang.metagun.entity.Gunner;\r
+import com.mojang.metagun.entity.Hat;\r
+import com.mojang.metagun.entity.Jabberwocky;\r
+import com.mojang.metagun.entity.Player;\r
+import com.mojang.metagun.entity.Sign;\r
import com.mojang.metagun.screen.GameScreen;\r
+import com.mojang.metagun.screen.Screen;\r
\r
public class Level {\r
- public static final double FRICTION = 0.99;\r
- public static final double GRAVITY = 0.10;\r
- public List<Entity> entities = new ArrayList<Entity>();\r
- public byte[] walls;\r
- public List<Entity>[] entityMap;\r
- private int width, height;\r
- public Player player;\r
- public int xSpawn, ySpawn;\r
- private Random random = new Random(1000);\r
- private GameScreen screen;\r
- private int respawnTime = 0;\r
- // private int xo, yo;\r
- private int tick;\r
+ public static final double FRICTION = 0.99;\r
+ public static final double GRAVITY = 0.10;\r
+ public List<Entity> entities = new ArrayList<Entity>();\r
+ public byte[] walls;\r
+ public List<Entity>[] entityMap;\r
+ private int width, height;\r
+ public Player player;\r
+ public int xSpawn, ySpawn;\r
+ private Random random = new Random(1000);\r
+ private GameScreen screen;\r
+ private int respawnTime = 0;\r
+ // private int xo, yo;\r
+ private int tick;\r
\r
- @SuppressWarnings("unchecked")\r
- public Level(GameScreen screen, int w, int h, int xo, int yo, int xSpawn, int ySpawn) {\r
- this.screen = screen;\r
- int[] pixels = new int[32 * 24];\r
- this.xSpawn = xSpawn;\r
- this.ySpawn = ySpawn;\r
+ @SuppressWarnings("unchecked") public Level (GameScreen screen, int w, int h, int xo, int yo, int xSpawn, int ySpawn) {\r
+ this.screen = screen;\r
+// int[] pixels = new int[32 * 24];\r
+ this.xSpawn = xSpawn;\r
+ this.ySpawn = ySpawn;\r
\r
- Art.level.getRGB(xo * 31, yo * 23, 32, 24, pixels, 0, 32);\r
+ \r
+// Art.level.getRGB(xo * 31, yo * 23, 32, 24, pixels, 0, 32);\r
\r
- walls = new byte[w * h];\r
- entityMap = new ArrayList[w * h];\r
- this.width = w;\r
- this.height = h;\r
+ walls = new byte[w * h];\r
+ entityMap = new ArrayList[w * h];\r
+ this.width = w;\r
+ this.height = h;\r
\r
- for (int y = 0; y < h; y++) {\r
- for (int x = 0; x < w; x++) {\r
- entityMap[x + y * w] = new ArrayList<Entity>();\r
+ for (int y = 0; y < h; y++) {\r
+ for (int x = 0; x < w; x++) {\r
+ entityMap[x + y * w] = new ArrayList<Entity>();\r
\r
- int col = pixels[x + y * w] & 0xffffff;\r
- byte wall = 0;\r
+// int col = pixels[x + y * w] & 0xffffff;\r
+ int col = (Art.level.getPixel(x + xo * 31, y + yo * 23) & 0xffffff00) >>> 8; \r
+ byte wall = 0;\r
\r
- if (col == 0xffffff) wall = 1;\r
- else if (col == 0xFF00FF) wall = 2;\r
- else if (col == 0xffff00) wall = 3;\r
- else if (col == 0xff0000) wall = 4;\r
- else if (col == 0xB7B7B7) wall = 5;\r
- else if (col == 0xFF5050) wall = 6;\r
- else if (col == 0xFF5051) wall = 7;\r
- else if (col == 0x383838) wall = 8;\r
- else if (col == 0xA3FFFF) wall = 9;\r
- else if (col == 0x83FFFF) {\r
- BossPart prev = new Boss(x * 10 - 2, y * 10 - 2);\r
- int timeOffs = random.nextInt(60);\r
- ((Boss)prev).time = timeOffs;\r
- add(prev);\r
- for (int i = 0; i < 10; i++) {\r
- BossNeck b = new BossNeck(x * 10 - 1, y * 10 - 1, prev);\r
- b.time = i * 10 + timeOffs;\r
- prev = b;\r
- add(prev);\r
- }\r
- } else if (col == 0x80FFFF) {\r
- Gremlin g = new Gremlin(0, x * 10 - 10, y * 10 - 20);\r
- g.jumpDelay = random.nextInt(50);\r
- add(g);\r
- } else if (col == 0x81FFFF) {\r
- Gremlin g = new Gremlin(1, x * 10 - 10, y * 10 - 20);\r
- g.jumpDelay = random.nextInt(50);\r
- add(g);\r
- } else if (col == 0x82FFFF) {\r
- Jabberwocky g = new Jabberwocky(x * 10 - 10, y * 10 - 10);\r
- g.slamTime = random.nextInt(30);\r
- add(g);\r
- } else if (col == 0xFFADF8) {\r
- add(new Hat(x * 10 + 1, y * 10 + 5, xo * 31 + x, yo * 23 + y));\r
- } else if ((col & 0x00ffff) == 0x00ff00 && (col & 0xff0000) > 0) {\r
- add(new Sign(x * 10, y * 10, (col >> 16) & 0xff));\r
- } else if (col == 0x0000ff) {\r
- // if (xSpawn == 0 && ySpawn == 0) {\r
- this.xSpawn = x * 10 + 1;\r
- this.ySpawn = y * 10 - 8;\r
- // }\r
- } else if (col == 0x00FFFF) {\r
- Gunner e = new Gunner(x * 10 + 2, y * 10 + 10 - 6, 0, 0);\r
- e.chargeTime = random.nextInt(Gunner.CHARGE_DURATION / 2);\r
- e.xa = e.ya = 0;\r
+ if (col == 0xffffff)\r
+ wall = 1;\r
+ else if (col == 0xFF00FF)\r
+ wall = 2;\r
+ else if (col == 0xffff00)\r
+ wall = 3;\r
+ else if (col == 0xff0000)\r
+ wall = 4;\r
+ else if (col == 0xB7B7B7)\r
+ wall = 5;\r
+ else if (col == 0xFF5050)\r
+ wall = 6;\r
+ else if (col == 0xFF5051)\r
+ wall = 7;\r
+ else if (col == 0x383838)\r
+ wall = 8;\r
+ else if (col == 0xA3FFFF)\r
+ wall = 9;\r
+ else if (col == 0x83FFFF) {\r
+ BossPart prev = new Boss(x * 10 - 2, y * 10 - 2);\r
+ int timeOffs = random.nextInt(60);\r
+ ((Boss)prev).time = timeOffs;\r
+ add(prev);\r
+ for (int i = 0; i < 10; i++) {\r
+ BossNeck b = new BossNeck(x * 10 - 1, y * 10 - 1, prev);\r
+ b.time = i * 10 + timeOffs;\r
+ prev = b;\r
+ add(prev);\r
+ }\r
+ } else if (col == 0x80FFFF) {\r
+ Gremlin g = new Gremlin(0, x * 10 - 10, y * 10 - 20);\r
+ g.jumpDelay = random.nextInt(50);\r
+ add(g);\r
+ } else if (col == 0x81FFFF) {\r
+ Gremlin g = new Gremlin(1, x * 10 - 10, y * 10 - 20);\r
+ g.jumpDelay = random.nextInt(50);\r
+ add(g);\r
+ } else if (col == 0x82FFFF) {\r
+ Jabberwocky g = new Jabberwocky(x * 10 - 10, y * 10 - 10);\r
+ g.slamTime = random.nextInt(30);\r
+ add(g);\r
+ } else if (col == 0xFFADF8) {\r
+ add(new Hat(x * 10 + 1, y * 10 + 5, xo * 31 + x, yo * 23 + y));\r
+ } else if ((col & 0x00ffff) == 0x00ff00 && (col & 0xff0000) > 0) {\r
+ add(new Sign(x * 10, y * 10, (col >> 16) & 0xff));\r
+ } else if (col == 0x0000ff) {\r
+ // if (xSpawn == 0 && ySpawn == 0) {\r
+ this.xSpawn = x * 10 + 1;\r
+ this.ySpawn = y * 10 - 8;\r
+ // }\r
+ } else if (col == 0x00FFFF) {\r
+ Gunner e = new Gunner(x * 10 + 2, y * 10 + 10 - 6, 0, 0);\r
+ e.chargeTime = random.nextInt(Gunner.CHARGE_DURATION / 2);\r
+ e.xa = e.ya = 0;\r
\r
- add(e);\r
- }\r
- walls[x + y * w] = wall;\r
- }\r
- }\r
+ add(e);\r
+ }\r
+ walls[x + y * w] = wall;\r
+ } \r
+ } \r
+ player = new Player(this.xSpawn, this.ySpawn);\r
+ add(player);\r
+ }\r
\r
- player = new Player(this.xSpawn, this.ySpawn);\r
- add(player);\r
- }\r
+ public void add (Entity e) {\r
+ entities.add(e);\r
+ e.init(this);\r
\r
- public void add(Entity e) {\r
- entities.add(e);\r
- e.init(this);\r
+ e.xSlot = (int)((e.x + e.w / 2.0) / 10);\r
+ e.ySlot = (int)((e.y + e.h / 2.0) / 10);\r
+ if (e.xSlot >= 0 && e.ySlot >= 0 && e.xSlot < width && e.ySlot < height) {\r
+ entityMap[e.xSlot + e.ySlot * width].add(e);\r
+ }\r
+ }\r
\r
- e.xSlot = (int) ((e.x + e.w / 2.0) / 10);\r
- e.ySlot = (int) ((e.y + e.h / 2.0) / 10);\r
- if (e.xSlot >= 0 && e.ySlot >= 0 && e.xSlot < width && e.ySlot < height) {\r
- entityMap[e.xSlot + e.ySlot * width].add(e);\r
- }\r
- }\r
+ public void tick () {\r
+ tick++;\r
+ if (player.removed) {\r
+ respawnTime++;\r
+ if (respawnTime == 20) {\r
+ screen.mayRespawn = true;\r
+ }\r
+ }\r
+ for (int i = 0; i < entities.size(); i++) {\r
+ Entity e = entities.get(i);\r
+ int xSlotOld = e.xSlot;\r
+ int ySlotOld = e.ySlot;\r
+ if (!e.removed) e.tick();\r
+ e.xSlot = (int)((e.x + e.w / 2.0) / 10);\r
+ e.ySlot = (int)((e.y + e.h / 2.0) / 10);\r
+ if (e.removed) {\r
+ if (xSlotOld >= 0 && ySlotOld >= 0 && xSlotOld < width && ySlotOld < height) {\r
+ entityMap[xSlotOld + ySlotOld * width].remove(e);\r
+ }\r
+ entities.remove(i--);\r
+ } else {\r
+ if (e.xSlot != xSlotOld || e.ySlot != ySlotOld) {\r
+ if (xSlotOld >= 0 && ySlotOld >= 0 && xSlotOld < width && ySlotOld < height) {\r
+ entityMap[xSlotOld + ySlotOld * width].remove(e);\r
+ }\r
+ if (e.xSlot >= 0 && e.ySlot >= 0 && e.xSlot < width && e.ySlot < height) {\r
+ entityMap[e.xSlot + e.ySlot * width].add(e);\r
+ } else {\r
+ e.outOfBounds();\r
+ }\r
\r
- public void tick() {\r
- tick++;\r
- if (player.removed) {\r
- respawnTime++;\r
- if (respawnTime == 20) {\r
- screen.mayRespawn = true;\r
- }\r
- }\r
- for (int i = 0; i < entities.size(); i++) {\r
- Entity e = entities.get(i);\r
- int xSlotOld = e.xSlot;\r
- int ySlotOld = e.ySlot;\r
- if (!e.removed) e.tick();\r
- e.xSlot = (int) ((e.x + e.w / 2.0) / 10);\r
- e.ySlot = (int) ((e.y + e.h / 2.0) / 10);\r
- if (e.removed) {\r
- if (xSlotOld >= 0 && ySlotOld >= 0 && xSlotOld < width && ySlotOld < height) {\r
- entityMap[xSlotOld + ySlotOld * width].remove(e);\r
- }\r
- entities.remove(i--);\r
- } else {\r
- if (e.xSlot != xSlotOld || e.ySlot != ySlotOld) {\r
- if (xSlotOld >= 0 && ySlotOld >= 0 && xSlotOld < width && ySlotOld < height) {\r
- entityMap[xSlotOld + ySlotOld * width].remove(e);\r
- }\r
- if (e.xSlot >= 0 && e.ySlot >= 0 && e.xSlot < width && e.ySlot < height) {\r
- entityMap[e.xSlot + e.ySlot * width].add(e);\r
- } else {\r
- e.outOfBounds();\r
- }\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
- }\r
- }\r
- }\r
- }\r
+ private List<Entity> hits = new ArrayList<Entity>();\r
\r
- private List<Entity> hits = new ArrayList<Entity>();\r
+ public List<Entity> getEntities (double xc, double yc, double w, double h) {\r
+ hits.clear();\r
+ int r = 20;\r
+ int x0 = (int)((xc - r) / 10);\r
+ int y0 = (int)((yc - r) / 10);\r
+ int x1 = (int)((xc + w + r) / 10);\r
+ int y1 = (int)((yc + h + r) / 10);\r
+ for (int x = x0; x <= x1; x++)\r
+ for (int y = y0; y <= y1; y++) {\r
+ if (x >= 0 && y >= 0 && x < width && y < height) {\r
+ List<Entity> es = entityMap[x + y * width];\r
+ for (int i = 0; i < es.size(); i++) {\r
+ Entity e = es.get(i);\r
+ double xx0 = e.x;\r
+ double yy0 = e.y;\r
+ double xx1 = e.x + e.w;\r
+ double yy1 = e.y + e.h;\r
+ if (xx0 > xc + w || yy0 > yc + h || xx1 < xc || yy1 < yc) continue;\r
\r
- public List<Entity> getEntities(double xc, double yc, double w, double h) {\r
- hits.clear();\r
- int r = 20;\r
- int x0 = (int) ((xc - r) / 10);\r
- int y0 = (int) ((yc - r) / 10);\r
- int x1 = (int) ((xc + w + r) / 10);\r
- int y1 = (int) ((yc + h + r) / 10);\r
- for (int x = x0; x <= x1; x++)\r
- for (int y = y0; y <= y1; y++) {\r
- if (x >= 0 && y >= 0 && x < width && y < height) {\r
- List<Entity> es = entityMap[x + y * width];\r
- for (int i = 0; i < es.size(); i++) {\r
- Entity e = es.get(i);\r
- double xx0 = e.x;\r
- double yy0 = e.y;\r
- double xx1 = e.x + e.w;\r
- double yy1 = e.y + e.h;\r
- if (xx0 > xc + w || yy0 > yc + h || xx1 < xc || yy1 < yc) continue;\r
+ hits.add(e);\r
+ }\r
+ }\r
+ }\r
+ return hits;\r
+ }\r
\r
- hits.add(e);\r
- }\r
- }\r
- }\r
- return hits;\r
- }\r
+ Matrix4 matrix = new Matrix4();\r
\r
- public void render(Graphics g, Camera camera) {\r
- g.translate(-camera.x, -camera.y);\r
+ public void render (Screen screen, Camera camera) {\r
+ matrix.idt();\r
+ matrix.setToTranslation(camera.x, camera.y, 0);\r
+ screen.spriteBatch.setTransformMatrix(matrix);\r
+ screen.spriteBatch.begin();\r
+ //g.translate(-camera.x, -camera.y);\r
\r
- int xo = camera.x / 10;\r
- int yo = camera.y / 10;\r
- for (int x = xo; x <= xo + camera.width / 10; x++) {\r
- for (int y = yo; y <= yo + camera.height / 10; y++) {\r
- if (x >= 0 && y >= 0 && x < width && y < height) {\r
- int ximg = 0;\r
- int yimg = 0;\r
- byte w = walls[x + y * width];\r
- if (w == 0) yimg = 1;\r
- if (w == 1) ximg = 0;\r
- if (w == 2) ximg = 2;\r
- if (w == 3) ximg = 1;\r
- if (w == 9) ximg = 7;\r
- if (w == 8) {\r
- ximg = 4;\r
- yimg = 1;\r
- }\r
- if (w == 5) {\r
- ximg = 1;\r
- yimg = 1;\r
- }\r
- if (w == 6) {\r
- ximg = (tick / 4 + x * 2) & 3;\r
- yimg = 2;\r
- }\r
- if (w == 7) {\r
- ximg = (-tick / 4 + x * 2) & 3;\r
- yimg = 3;\r
- }\r
- if (w == 4) {\r
- if (walls[x + (y - 1) * width] == 1) {\r
- yimg++;\r
- }\r
- ximg = 3;\r
- }\r
+ int xo = 0;\r
+ int yo = 0;\r
+ for (int x = xo; x <= xo + camera.width / 10; x++) {\r
+ for (int y = yo; y <= yo + camera.height / 10; y++) {\r
+ if (x >= 0 && y >= 0 && x < width && y < height) {\r
+ int ximg = 0;\r
+ int yimg = 0;\r
+ byte w = walls[x + y * width];\r
+ if (w == 0) yimg = 1;\r
+ if (w == 1) ximg = 0;\r
+ if (w == 2) ximg = 2;\r
+ if (w == 3) ximg = 1;\r
+ if (w == 9) ximg = 7;\r
+ if (w == 8) {\r
+ ximg = 4;\r
+ yimg = 1;\r
+ }\r
+ if (w == 5) {\r
+ ximg = 1;\r
+ yimg = 1;\r
+ }\r
+ if (w == 6) {\r
+ ximg = (tick / 4 + x * 2) & 3;\r
+ yimg = 2;\r
+ }\r
+ if (w == 7) {\r
+ ximg = (-tick / 4 + x * 2) & 3;\r
+ yimg = 3;\r
+ }\r
+ if (w == 4) {\r
+ if (walls[x + (y - 1) * width] == 1) {\r
+ yimg++;\r
+ }\r
+ ximg = 3;\r
+ }\r
\r
- g.drawImage(Art.walls[ximg][yimg], x * 10, y * 10, null);\r
- }\r
- }\r
- }\r
- for (int i = entities.size() - 1; i >= 0; i--) {\r
- Entity e = entities.get(i);\r
- e.render(g, camera);\r
- }\r
- }\r
+ if(w == 0)\r
+ continue;\r
+ \r
+ screen.draw(Art.walls[ximg][yimg], x * 10, y * 10);\r
+ }\r
+ }\r
+ }\r
+ for (int i = entities.size() - 1; i >= 0; i--) {\r
+ Entity e = entities.get(i);\r
+ e.render(screen, camera);\r
+ }\r
+ \r
+ screen.spriteBatch.end();\r
+ }\r
\r
- public boolean isFree(Entity ee, double xc, double yc, int w, int h, double xa, double ya) {\r
- if (ee.interactsWithWorld) {\r
- return isBulletFree(ee, xc, yc, w, h);\r
- }\r
- double e = 0.1;\r
- int x0 = (int) (xc / 10);\r
- int y0 = (int) (yc / 10);\r
- int x1 = (int) ((xc + w - e) / 10);\r
- int y1 = (int) ((yc + h - e) / 10);\r
- boolean ok = true;\r
- for (int x = x0; x <= x1; x++)\r
- for (int y = y0; y <= y1; y++) {\r
- if (x >= 0 && y >= 0 && x < width && y < height) {\r
- byte ww = walls[x + y * width];\r
- if (ww != 0) ok = false;\r
- if (ww == 8) ok = true;\r
- if (ww == 4 && ya != 0) ee.hitSpikes();\r
- if (ww == 6) {\r
- ee.xa += 0.12;\r
- }\r
- if (ww == 7) {\r
- ee.xa -= 0.12;\r
- }\r
- }\r
- }\r
+ public boolean isFree (Entity ee, double xc, double yc, int w, int h, double xa, double ya) {\r
+ if (ee.interactsWithWorld) {\r
+ return isBulletFree(ee, xc, yc, w, h);\r
+ }\r
+ double e = 0.1;\r
+ int x0 = (int)(xc / 10);\r
+ int y0 = (int)(yc / 10);\r
+ int x1 = (int)((xc + w - e) / 10);\r
+ int y1 = (int)((yc + h - e) / 10);\r
+ boolean ok = true;\r
+ for (int x = x0; x <= x1; x++)\r
+ for (int y = y0; y <= y1; y++) {\r
+ if (x >= 0 && y >= 0 && x < width && y < height) {\r
+ byte ww = walls[x + y * width];\r
+ if (ww != 0) ok = false;\r
+ if (ww == 8) ok = true;\r
+ if (ww == 4 && ya != 0) ee.hitSpikes();\r
+ if (ww == 6) {\r
+ ee.xa += 0.12;\r
+ }\r
+ if (ww == 7) {\r
+ ee.xa -= 0.12;\r
+ }\r
+ }\r
+ }\r
\r
- return ok;\r
- }\r
+ return ok;\r
+ }\r
\r
- public boolean isBulletFree(Entity bullet, double xc, double yc, int w, int h) {\r
- double e = 0.1;\r
- int x0 = (int) (xc / 10);\r
- int y0 = (int) (yc / 10);\r
- int x1 = (int) ((xc + w - e) / 10);\r
- int y1 = (int) ((yc + h - e) / 10);\r
- boolean ok = true;\r
- for (int x = x0; x <= x1; x++)\r
- for (int y = y0; y <= y1; y++) {\r
- if (x >= 0 && y >= 0 && x < width && y < height) {\r
- byte ww = walls[x + y * width];\r
- if (ww != 0) ok = false;\r
- if (ww == 5) ok = true;\r
- if (ww == 2) {\r
- int xPush = 0;\r
- int yPush = 0;\r
+ public boolean isBulletFree (Entity bullet, double xc, double yc, int w, int h) {\r
+ double e = 0.1;\r
+ int x0 = (int)(xc / 10);\r
+ int y0 = (int)(yc / 10);\r
+ int x1 = (int)((xc + w - e) / 10);\r
+ int y1 = (int)((yc + h - e) / 10);\r
+ boolean ok = true;\r
+ for (int x = x0; x <= x1; x++)\r
+ for (int y = y0; y <= y1; y++) {\r
+ if (x >= 0 && y >= 0 && x < width && y < height) {\r
+ byte ww = walls[x + y * width];\r
+ if (ww != 0) ok = false;\r
+ if (ww == 5) ok = true;\r
+ if (ww == 2) {\r
+ int xPush = 0;\r
+ int yPush = 0;\r
\r
- if (Math.abs(bullet.xa) > Math.abs(bullet.ya)) {\r
- if (bullet.xa < 0) xPush = -1;\r
- if (bullet.xa > 0) xPush = 1;\r
- } else {\r
- if (bullet.ya < 0) yPush = -1;\r
- if (bullet.ya > 0) yPush = 1;\r
- }\r
- double r = 0.5;\r
- if (walls[(x + xPush) + (y + yPush) * width] == 0 && getEntities((x + xPush) * 10 + r, (y + yPush) * 10 + r, 10 - r * 2, 10 - r * 2).size() == 0) {\r
- walls[x + y * width] = 0;\r
- walls[(x + xPush) + (y + yPush) * width] = 2;\r
- }\r
- bullet.remove();\r
- }\r
- if (ww == 3) {\r
- Sound.boom.play();\r
- for (int i = 0; i < 16; i++) {\r
- double dir = i * Math.PI * 2 / 8.0;\r
- double xa = Math.sin(dir);\r
- double ya = Math.cos(dir);\r
- double dist = (i / 8) + 1;\r
- add(new Explosion(1, i * 3, x * 10 + 5 + xa * dist, y * 10 + 5 + ya * dist, xa, ya));\r
- }\r
- bullet.remove();\r
- walls[x + y * width] = 0;\r
- }\r
- if (ww == 9) {\r
- if ((bullet instanceof Explosion) && ((Explosion)bullet).power > 0) {\r
- Sound.boom.play();\r
- for (int i = 0; i < 16; i++) {\r
- double dir = i * Math.PI * 2 / 8.0;\r
- double xa = Math.sin(dir);\r
- double ya = Math.cos(dir);\r
- double dist = (i / 8) + 1;\r
- add(new Explosion(1, i * 3, x * 10 + 5 + xa * dist, y * 10 + 5 + ya * dist, xa, ya));\r
- }\r
- bullet.remove();\r
- walls[x + y * width] = 0;\r
- }\r
- }\r
- }\r
- }\r
+ if (Math.abs(bullet.xa) > Math.abs(bullet.ya)) {\r
+ if (bullet.xa < 0) xPush = -1;\r
+ if (bullet.xa > 0) xPush = 1;\r
+ } else {\r
+ if (bullet.ya < 0) yPush = -1;\r
+ if (bullet.ya > 0) yPush = 1;\r
+ }\r
+ double r = 0.5;\r
+ if (walls[(x + xPush) + (y + yPush) * width] == 0\r
+ && getEntities((x + xPush) * 10 + r, (y + yPush) * 10 + r, 10 - r * 2, 10 - r * 2).size() == 0) {\r
+ walls[x + y * width] = 0;\r
+ walls[(x + xPush) + (y + yPush) * width] = 2;\r
+ }\r
+ bullet.remove();\r
+ }\r
+ if (ww == 3) {\r
+ Sound.boom.play();\r
+ for (int i = 0; i < 16; i++) {\r
+ double dir = i * Math.PI * 2 / 8.0;\r
+ double xa = Math.sin(dir);\r
+ double ya = Math.cos(dir);\r
+ double dist = (i / 8) + 1;\r
+ add(new Explosion(1, i * 3, x * 10 + 5 + xa * dist, y * 10 + 5 + ya * dist, xa, ya));\r
+ }\r
+ bullet.remove();\r
+ walls[x + y * width] = 0;\r
+ }\r
+ if (ww == 9) {\r
+ if ((bullet instanceof Explosion) && ((Explosion)bullet).power > 0) {\r
+ Sound.boom.play();\r
+ for (int i = 0; i < 16; i++) {\r
+ double dir = i * Math.PI * 2 / 8.0;\r
+ double xa = Math.sin(dir);\r
+ double ya = Math.cos(dir);\r
+ double dist = (i / 8) + 1;\r
+ add(new Explosion(1, i * 3, x * 10 + 5 + xa * dist, y * 10 + 5 + ya * dist, xa, ya));\r
+ }\r
+ bullet.remove();\r
+ walls[x + y * width] = 0;\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
- return ok;\r
- }\r
+ return ok;\r
+ }\r
\r
- public void readSign(Sign sign) {\r
- screen.readSign(sign.id - 1);\r
- }\r
+ public void readSign (Sign sign) {\r
+ screen.readSign(sign.id - 1);\r
+ }\r
\r
- public void transition(int x, int y) {\r
- screen.transition(x, y);\r
- }\r
+ public void transition (int x, int y) {\r
+ screen.transition(x, y);\r
+ }\r
\r
- public void getGun(int level) {\r
- screen.getGun(level);\r
- }\r
+ public void getGun (int level) {\r
+ screen.getGun(level);\r
+ }\r
}\r
package com.mojang.metagun.screen;\r
\r
-import java.awt.Graphics;\r
-import java.io.*;\r
-import java.util.*;\r
+import java.io.BufferedReader;\r
+import java.io.InputStreamReader;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
\r
-import com.mojang.metagun.*;\r
+import com.badlogic.gdx.Gdx;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
\r
public class ExpositionScreen extends Screen {\r
private int time = 0;\r
\r
public ExpositionScreen() {\r
try {\r
- BufferedReader br = new BufferedReader(new InputStreamReader(ExpositionScreen.class.getResourceAsStream("exposition.txt")));\r
+ BufferedReader br = new BufferedReader(new InputStreamReader(Gdx.files.internal("res/exposition.txt").read()));\r
\r
String line = "";\r
while ((line = br.readLine()) != null) {\r
\r
}\r
\r
- public void render(Graphics g) {\r
- int w = Art.bg.getHeight();\r
- g.drawImage(Art.bg, 0, -(time / 8 % w), null);\r
- g.drawImage(Art.bg, 0, -(time / 8 % w) + w, null);\r
+ public void render() {\r
+ int w = -Art.bg.getRegionHeight();\r
+ spriteBatch.begin();\r
+ draw(Art.bg, 0, -(time / 8 % w));\r
+ draw(Art.bg, 0, -(time / 8 % w) + w); \r
\r
int yo = time / 4;\r
for (int y = 0; y <= 240 / 6; y++) {\r
int yl = yo / 6 - 240 / 6+y;\r
if (yl >= 0 && yl < lines.size()) {\r
- drawString(lines.get(yl), g, (320 - 40 * 6)/2, y * 6 - yo % 6);\r
+ drawString(lines.get(yl), (320 - 40 * 6)/2, y * 6 - yo % 6);\r
}\r
}\r
+ spriteBatch.end();\r
}\r
\r
public void tick(Input input) {\r
-package com.mojang.metagun.screen;\r
\r
-import java.awt.Graphics;\r
+package com.mojang.metagun.screen;\r
\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
+import com.mojang.metagun.Metagun;\r
+import com.mojang.metagun.Stats;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
\r
public class GameScreen extends Screen {\r
- public static final int MAX_HATS = 7;\r
- \r
- private static final boolean DEBUG_MODE = false;\r
- private int xLevel = DEBUG_MODE?8:0;\r
- private int yLevel = DEBUG_MODE?4:0;\r
+ public static final int MAX_HATS = 7;\r
+\r
+ private static final boolean DEBUG_MODE = false;\r
+ private int xLevel = DEBUG_MODE ? 8 : 0;\r
+ private int yLevel = DEBUG_MODE ? 4 : 0;\r
\r
- Level level = new Level(this, 32, 24, xLevel, yLevel, 0, 0);\r
- private Camera camera = new Camera(Metagun.GAME_WIDTH, Metagun.GAME_HEIGHT);\r
+ Level level = new Level(this, 32, 24, xLevel, yLevel, 0, 0);\r
+ private Camera camera = new Camera(Metagun.GAME_WIDTH, Metagun.GAME_HEIGHT);\r
\r
- public boolean mayRespawn = false;\r
- private int gunLevel = DEBUG_MODE?2:0;\r
- private int hatCount = 1;\r
+ public boolean mayRespawn = false;\r
+ private int gunLevel = DEBUG_MODE ? 2 : 0;\r
+ private int hatCount = 1;\r
\r
- public GameScreen() {\r
- Art.level = Art.load("/levels.png");\r
- Stats.reset();\r
+ public GameScreen () {\r
+ Stats.reset();\r
\r
- level.player.gunLevel = gunLevel;\r
- level.player.hatCount = hatCount;\r
- }\r
+ level.player.gunLevel = gunLevel;\r
+ level.player.hatCount = hatCount;\r
+ }\r
\r
- public void tick(Input input) {\r
- Stats.instance.time++;\r
- if (!input.oldButtons[Input.ESCAPE] && input.buttons[Input.ESCAPE]) {\r
- setScreen(new PauseScreen(this));\r
- return;\r
- }\r
- if (!level.player.removed) level.player.tick(input);\r
- else if (mayRespawn) {\r
- if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {\r
- respawnRoom();\r
- mayRespawn = false;\r
- }\r
- }\r
- level.tick();\r
- Stats.instance.hats = level.player.hatCount;\r
- }\r
+ public void tick (Input input) {\r
+ Stats.instance.time++;\r
+ if (!input.oldButtons[Input.ESCAPE] && input.buttons[Input.ESCAPE]) {\r
+ setScreen(new PauseScreen(this));\r
+ return;\r
+ }\r
+ if (!level.player.removed)\r
+ level.player.tick(input);\r
+ else if (mayRespawn) {\r
+ if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {\r
+ respawnRoom();\r
+ mayRespawn = false;\r
+ }\r
+ }\r
+ level.tick();\r
+ Stats.instance.hats = level.player.hatCount;\r
+ }\r
\r
- public void transition(int xa, int ya) {\r
- Stats.instance.hats = level.player.hatCount;\r
- xLevel += xa;\r
- yLevel += ya;\r
- if (yLevel>10) {\r
- setScreen(new WinScreen());\r
- return;\r
- }\r
- level.player.x -= xa * 300;\r
- level.player.y -= ya * 220;\r
- hatCount = level.player.hatCount;\r
- if (ya != 0) level.player.y -= 10;\r
- Level newLevel = new Level(this, 32, 24, xLevel, yLevel, (int) (level.player.x), (int) (level.player.y + ya * 5));\r
- newLevel.player.remove();\r
- newLevel.player = level.player;\r
- newLevel.add(newLevel.player);\r
- setScreen(new LevelTransitionScreen(this, xLevel-xa, yLevel-ya, level, newLevel, xa, ya));\r
- this.level = newLevel;\r
- level.player.gunLevel = gunLevel;\r
- level.player.hatCount = hatCount;\r
- level.player.damage = 0;\r
- }\r
+ public void transition (int xa, int ya) {\r
+ Stats.instance.hats = level.player.hatCount;\r
+ xLevel += xa;\r
+ yLevel += ya;\r
+ if (yLevel > 10) {\r
+ setScreen(new WinScreen());\r
+ return;\r
+ }\r
+ level.player.x -= xa * 300;\r
+ level.player.y -= ya * 220;\r
+ hatCount = level.player.hatCount;\r
+ if (ya != 0) level.player.y -= 10;\r
+ Level newLevel = new Level(this, 32, 24, xLevel, yLevel, (int)(level.player.x), (int)(level.player.y + ya * 5));\r
+ newLevel.player.remove();\r
+ newLevel.player = level.player;\r
+ newLevel.add(newLevel.player);\r
+ setScreen(new LevelTransitionScreen(this, xLevel - xa, yLevel - ya, level, newLevel, xa, ya));\r
+ this.level = newLevel;\r
+ level.player.gunLevel = gunLevel;\r
+ level.player.hatCount = hatCount;\r
+ level.player.damage = 0;\r
+ }\r
\r
- public void render(Graphics g) {\r
- g.drawImage(Art.bg, -xLevel*160, -yLevel*120, null);\r
- level.render(g, camera);\r
- if (mayRespawn) {\r
- String msg = "PRESS X TO TRY AGAIN";\r
- drawString(msg, g, 160 - msg.length() * 3, 120 - 3);\r
- }\r
- }\r
+ public void render () {\r
+ spriteBatch.begin();\r
+// draw(Art.bg, -xLevel * 160, -yLevel * 120);\r
+ draw(Art.bg, 0, 0);\r
+ spriteBatch.end();\r
+ level.render(this, camera);\r
+ \r
+ spriteBatch.begin();\r
+ if (mayRespawn) {\r
+ String msg = "PRESS X TO TRY AGAIN";\r
+ drawString(msg, 160 - msg.length() * 3, 120 - 3);\r
+ }\r
+ spriteBatch.end();\r
+ }\r
\r
- public void readSign(int id) {\r
- setScreen(new SignReadScreen(this, id));\r
- }\r
+ public void readSign (int id) {\r
+ setScreen(new SignReadScreen(this, id));\r
+ }\r
\r
- public void respawnRoom() {\r
- Level newLevel = new Level(this, 32, 24, xLevel, yLevel, level.xSpawn, level.ySpawn);\r
- this.level = newLevel;\r
- level.player.gunLevel = gunLevel;\r
- if (hatCount<1) hatCount = 1;\r
- level.player.hatCount = hatCount;\r
- level.player.damage = 0;\r
- }\r
+ public void respawnRoom () {\r
+ Level newLevel = new Level(this, 32, 24, xLevel, yLevel, level.xSpawn, level.ySpawn);\r
+ this.level = newLevel;\r
+ level.player.gunLevel = gunLevel;\r
+ if (hatCount < 1) hatCount = 1;\r
+ level.player.hatCount = hatCount;\r
+ level.player.damage = 0;\r
+ }\r
\r
- public void getGun(int level) {\r
- gunLevel = level;\r
- }\r
+ public void getGun (int level) {\r
+ gunLevel = level;\r
+ }\r
}\r
-package com.mojang.metagun.screen;\r
\r
-import java.awt.Graphics;\r
+package com.mojang.metagun.screen;\r
\r
-import com.mojang.metagun.*;\r
-import com.mojang.metagun.level.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
+import com.mojang.metagun.level.Camera;\r
+import com.mojang.metagun.level.Level;\r
\r
public class LevelTransitionScreen extends Screen {\r
- private static final int TRANSITION_DURATION = 20;\r
- private Level level1;\r
- private Level level2;\r
- private int time = 0;\r
- private Screen parent;\r
- private int xa, ya;\r
- private int xLevel, yLevel;\r
-\r
- public LevelTransitionScreen(Screen parent, int xLevel, int yLevel, Level level1, Level level2, int xa, int ya) {\r
- this.level1 = level1;\r
- this.level2 = level2;\r
- this.xLevel = xLevel;\r
- this.yLevel = yLevel;\r
- this.parent = parent;\r
- this.xa = xa;\r
- this.ya = ya;\r
- }\r
+ private static final int TRANSITION_DURATION = 20;\r
+ private Level level1;\r
+ private Level level2;\r
+ private int time = 0;\r
+ private Screen parent;\r
+ private int xa, ya;\r
+ private int xLevel, yLevel;\r
\r
- public void tick(Input input) {\r
- time++;\r
- if (time == TRANSITION_DURATION) {\r
- setScreen(parent);\r
- }\r
- }\r
+ public LevelTransitionScreen (Screen parent, int xLevel, int yLevel, Level level1, Level level2, int xa, int ya) {\r
+ this.level1 = level1;\r
+ this.level2 = level2;\r
+ this.xLevel = xLevel;\r
+ this.yLevel = yLevel;\r
+ this.parent = parent;\r
+ this.xa = xa;\r
+ this.ya = ya;\r
+ }\r
\r
- public void render(Graphics g) {\r
- Camera c = new Camera(320, 240);\r
- double pow = time / (double) TRANSITION_DURATION;\r
- \r
- g.drawImage(Art.bg, -xLevel*160-(int)(xa*160*pow), -yLevel*120-(int)(ya*120*pow), null);\r
- \r
- g.translate((int) (-xa * 310 * pow), (int) (-ya * 230 * pow));\r
- level1.render(g, c);\r
- g.translate(xa * 310, ya * 230);\r
- level2.render(g, c);\r
- }\r
+ public void tick (Input input) {\r
+ time++;\r
+ if (time == TRANSITION_DURATION) {\r
+ setScreen(parent);\r
+ }\r
+ }\r
+ \r
+ Camera c = new Camera(320, 240); \r
+ public void render () { \r
+ double pow = time / (double)TRANSITION_DURATION;\r
+ \r
+ spriteBatch.getTransformMatrix().idt();\r
+ spriteBatch.begin(); \r
+// draw(Art.bg, -xLevel * 160 - (int)(xa * 160 * pow), -yLevel * 120 - (int)(ya * 120 * pow));\r
+ draw(Art.bg, 0, 0);\r
+ spriteBatch.end();\r
+ \r
+ c.x = (int)(-xa * 320 * pow);\r
+ c.y = (int)(-ya * 240 * pow); \r
+ level1.render(this, c); \r
+ \r
+ c.x = (int)(xa * 320 * (1-pow));\r
+ c.y = (int)(ya * 240 * (1-pow)); \r
+ level2.render(this, c); \r
+ }\r
}\r
package com.mojang.metagun.screen;\r
\r
-import java.awt.Graphics;\r
-\r
-import com.mojang.metagun.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
\r
public class PauseScreen extends Screen {\r
private GameScreen parent;\r
this.parent = parent;\r
}\r
\r
- public void render(Graphics g) {\r
- parent.render(g);\r
+ public void render() {\r
+ parent.render();\r
+ \r
+ spriteBatch.begin();\r
int xs = 0;\r
int ys = options.length;\r
for (int y = 0; y < options.length; y++) {\r
if (y < 0) yf--;\r
if (x >= xs) xf++;\r
if (y >= ys) yf++;\r
- g.drawImage(Art.guys[xf][yf], xp + x * 6, yp + y * 6, null);\r
+ draw(Art.guys[xf][yf], xp + x * 6, yp + y * 6);\r
}\r
}\r
for (int y = 0; y < options.length; y++) {\r
if (y == selected) {\r
- drawString("+", g, xp, yp + y * 6);\r
+ drawString("+", xp, yp + y * 6);\r
}\r
- drawString(options[y], g, xp + 6, yp + y * 6);\r
+ drawString(options[y], xp + 6, yp + y * 6);\r
}\r
+ spriteBatch.end();\r
}\r
\r
public void tick(Input input) {\r
+\r
package com.mojang.metagun.screen;\r
\r
-import java.awt.Graphics;\r
import java.util.Random;\r
\r
import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
-import com.mojang.metagun.*;\r
+import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
+import com.badlogic.gdx.math.Matrix4;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
+import com.mojang.metagun.Metagun;\r
\r
public abstract class Screen {\r
- protected static Random random = new Random();\r
- private Metagun metagun;\r
- protected SpriteBatch spriteBatch = new SpriteBatch(100);\r
- \r
- public void removed() { \r
- spriteBatch.dispose();\r
- }\r
-\r
- public final void init(Metagun metagun) {\r
- this.metagun = metagun;\r
- }\r
- \r
- protected void setScreen(Screen screen) {\r
- metagun.setScreen(screen);\r
- }\r
-\r
- String[] chars = {\r
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",\r
- ".,!?:;\"'+-=/\\< "\r
- };\r
- \r
- public void drawString(String string, Graphics g, int x, int y) {\r
- // FIXME\r
-// string = string.toUpperCase();\r
-// for (int i=0; i<string.length(); i++) {\r
-// char ch = string.charAt(i);\r
-// for (int ys=0; ys<chars.length; ys++) {\r
-// int xs = chars[ys].indexOf(ch);\r
-// if (xs>=0) {\r
-// g.drawImage(Art.guys[xs][ys+9], x+i*6, y, null);\r
-// }\r
-// }\r
-// }\r
- }\r
-\r
- public abstract void render(); \r
-\r
- public void tick(Input input) {\r
- }\r
-}
\ No newline at end of file
+ protected static Random random = new Random();\r
+ private Metagun metagun;\r
+ public SpriteBatch spriteBatch;\r
+\r
+ public void removed () {\r
+ spriteBatch.dispose();\r
+ }\r
+\r
+ public final void init (Metagun metagun) {\r
+ this.metagun = metagun;\r
+ Matrix4 projection = new Matrix4();\r
+ projection.setToOrtho(0, 320, 240, 0, -1, 1);\r
+\r
+ spriteBatch = new SpriteBatch(100);\r
+ spriteBatch.setProjectionMatrix(projection);\r
+ }\r
+\r
+ protected void setScreen (Screen screen) {\r
+ metagun.setScreen(screen);\r
+ }\r
+\r
+ String[] chars = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", ".,!?:;\"'+-=/\\< "};\r
+\r
+ public void draw (TextureRegion region, int x, int y) {\r
+ int width = region.getRegionWidth();\r
+ if(width <0) width = -width;\r
+ spriteBatch.draw(region, x, y, width, -region.getRegionHeight());\r
+ }\r
+\r
+ public void drawString (String string, int x, int y) {\r
+ string = string.toUpperCase();\r
+ for (int i = 0; i < string.length(); i++) {\r
+ char ch = string.charAt(i);\r
+ for (int ys = 0; ys < chars.length; ys++) {\r
+ int xs = chars[ys].indexOf(ch);\r
+ if (xs >= 0) {\r
+ draw(Art.guys[xs][ys + 9], x + i * 6, y);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public abstract void render ();\r
+\r
+ public void tick (Input input) {\r
+ }\r
+}\r
package com.mojang.metagun.screen;\r
\r
-import java.awt.Graphics;\r
-\r
-import com.mojang.metagun.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
\r
public class SignReadScreen extends Screen {\r
private Screen parent;\r
\r
public void render() {\r
parent.render();\r
+ spriteBatch.begin();\r
int xs = 0;\r
int ys = signs[id].length+3;\r
for (int y=0; y<signs[id].length; y++) {\r
if (y<0) yf--;\r
if (x>=xs) xf++;\r
if (y>=ys) yf++;\r
- // FIXME\r
- // g.drawImage(Art.guys[xf][yf], xp+x*6, yp+y*6, null);\r
+ draw(Art.guys[xf][yf], xp+x*6, yp+y*6);\r
}\r
}\r
for (int y=0; y<signs[id].length; y++) {\r
- drawString(signs[id][y], null, xp, yp+y*6);\r
+ drawString(signs[id][y], xp, yp+y*6);\r
}\r
if (delay==0)\r
- drawString("PRESS X", null, xp+(xs-8)*6, yp+(signs[id].length+2)*6);\r
+ drawString("PRESS X", xp+(xs-8)*6, yp+(signs[id].length+2)*6);\r
+ spriteBatch.end();\r
}\r
\r
public void tick(Input input) {\r
package com.mojang.metagun.screen;\r
\r
-import java.awt.*;\r
-\r
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
-import com.mojang.metagun.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
+import com.mojang.metagun.Sound;\r
\r
public class TitleScreen extends Screen {\r
private int time = 0; \r
public void render() {\r
int yOffs = 480 - time * 2;\r
if (yOffs < 0) yOffs = 0;\r
- g.drawImage(Art.bg, 0, -yOffs / 2, null);\r
- g.drawImage(Art.titleScreen, 0, -yOffs, null);\r
+ spriteBatch.begin();\r
+ draw(Art.bg, 0, 0);\r
+ draw(Art.titleScreen, 0, -yOffs); \r
if (time > 240) {\r
String msg = "PRESS X TO START";\r
- drawString(msg, g, 160 - msg.length() * 3, 140 - 3 - (int) (Math.abs(Math.sin(time * 0.1) * 10)));\r
+ drawString(msg, 160 - msg.length() * 3, 140 - 3 - (int) (Math.abs(Math.sin(time * 0.1) * 10)));\r
\r
}\r
if (time >=0) {\r
String msg = "COPYRIGHT MOJANG 2010";\r
- drawString(msg, g, 2, 240-6-2);\r
+ drawString(msg, 2, 240-6-2);\r
}\r
+ spriteBatch.end();\r
}\r
\r
public void tick(Input input) {\r
package com.mojang.metagun.screen;\r
\r
-import java.awt.*;\r
-\r
-import com.mojang.metagun.*;\r
+import com.mojang.metagun.Art;\r
+import com.mojang.metagun.Input;\r
+import com.mojang.metagun.Stats;\r
\r
public class WinScreen extends Screen {\r
private int time = 0;\r
\r
- public void render(Graphics g) {\r
- int w = Art.bg.getHeight();\r
- g.drawImage(Art.bg, 0, -(time*2%w), null);\r
- g.drawImage(Art.bg, 0, -(time*2%w)+w, null);\r
+ public void render() {\r
+ spriteBatch.begin();\r
+ int w = 240 * 8; //Art.bg.getHeight();\r
+ draw(Art.bg, 0, -(time*2%w));\r
+ draw(Art.bg, 0, -(time*2%w)+w);\r
\r
int offs0 = 500-time*10;\r
if (offs0<0) offs0=0;\r
int yOffs = 600-time*5;\r
if (yOffs<-120) yOffs = -120;\r
if (yOffs>0) yOffs = 0;\r
- g.drawImage(Art.winScreen1, offs0, yOffs+30, null);\r
- g.drawImage(Art.winScreen2, -offs1, yOffs*2/3+30, null);\r
+ draw(Art.winScreen1, offs0, yOffs+30);\r
+ draw(Art.winScreen2, -offs1, yOffs*2/3+30);\r
\r
int tt = time-(60*2+30);\r
int yo = 130;\r
int xo = 120-8*3;\r
if (tt>=0) {\r
- drawString(" TIME: "+Stats.instance.getTimeString(), g, xo, yo+0*6);\r
- drawString(" DEATHS: "+Stats.instance.deaths, g, xo, yo+1*6);\r
- drawString(" FEDORAS: "+Stats.instance.hats+"/"+7, g, xo, yo+2*6);\r
- drawString("SHOTS FIRED: "+Stats.instance.shots, g, xo, yo+3*6);\r
- drawString("FINAL SCORE: "+timeScale(Stats.instance.getFinalScore(), tt-30*5), g, xo, yo+5*6);\r
+ drawString(" TIME: "+Stats.instance.getTimeString(), xo, yo+0*6);\r
+ drawString(" DEATHS: "+Stats.instance.deaths, xo, yo+1*6);\r
+ drawString(" FEDORAS: "+Stats.instance.hats+"/"+7, xo, yo+2*6);\r
+ drawString("SHOTS FIRED: "+Stats.instance.shots, xo, yo+3*6);\r
+ drawString("FINAL SCORE: "+timeScale(Stats.instance.getFinalScore(), tt-30*5), xo, yo+5*6);\r
\r
- drawString(timeHideScale(Stats.instance.getSpeedScore(), tt-30*1), g, xo+20*6, yo+0*6);\r
- drawString(timeHideScale(Stats.instance.getDeathScore(), tt-30*2), g, xo+20*6, yo+1*6);\r
- drawString(timeHideScale(Stats.instance.getHatScore(), tt-30*3), g, xo+20*6, yo+2*6);\r
- drawString(timeHideScale(Stats.instance.getShotScore(), tt-30*4), g, xo+20*6, yo+3*6);\r
+ drawString(timeHideScale(Stats.instance.getSpeedScore(), tt-30*1), xo+20*6, yo+0*6);\r
+ drawString(timeHideScale(Stats.instance.getDeathScore(), tt-30*2), xo+20*6, yo+1*6);\r
+ drawString(timeHideScale(Stats.instance.getHatScore(), tt-30*3), xo+20*6, yo+2*6);\r
+ drawString(timeHideScale(Stats.instance.getShotScore(), tt-30*4), xo+20*6, yo+3*6);\r
}\r
\r
if (time>60*7 && (time/30%2==0)) {\r
String msg = "PRESS X TO RESET THE GAME"; \r
- drawString(msg, g, 160-msg.length()*3, yo+10*6);\r
+ drawString(msg, 160-msg.length()*3, yo+10*6);\r
}\r
+ spriteBatch.end();\r
}\r
\r
private String timeHideScale(int val, int time) {\r