Skip to content
Snippets Groups Projects
Commit d80e861a authored by Sabvente's avatar Sabvente
Browse files

ablak átméretezve; board kép; map; range upgrade köd alatt FIX

parent 649bf1c8
Branches
No related tags found
No related merge requests found
......@@ -81,7 +81,7 @@ public class Engine
gameWindow = new JFrame("The Two Towers Defense");
gameWindow.setResizable(false);
gameWindow.setVisible(true);
gameWindow.setSize(1000, 830);
gameWindow.setSize(1200, 770);
gameWindow.setLocationRelativeTo(null);
gameWindow.setContentPane(new GamePanel(world));
gameWindow.addWindowListener(new WindowAdapter()
......
--------------------
--------------S-----
---------S----R-----
-----S---R----R-----
-S---R---R----R-----
-R---R---R----R-----
-R---R---R----R-----
-RRRRRRRRRRRRRM-----
-R---R---R----R-----
-R---R---R----R-----
-S---R---R----R-----
-----S---R----R-----
---------S----R-----
--------------S-----
--------------------
src/resources/board.png

40.9 KiB

......@@ -7,13 +7,17 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.MouseInputListener;
......@@ -26,9 +30,18 @@ import world.World;
public class GamePanel extends JPanel {
private World world;
private static final int marginTop = 50;
private static final int marginLeft = 200;
private Font font, fontGameEnd;
private Field clickedField;
private static Image board;
static{
try {
board = ImageIO.read(new File("src\\resources\\board.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public GamePanel(World world) {
this.world = world;
......@@ -43,12 +56,12 @@ public class GamePanel extends JPanel {
public void paint(Graphics g) {
Point towerRangePoint = null;
g.setColor(Color.black);
g.fillRect(0, 0, g.getClipBounds().width, marginTop);
g.drawImage(board, 0, 0, null);
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 20; j++) {
Field f = world.getField(i, j);
int x = j * 50;
int y = i * 50 + marginTop;
int x = j * 50 + marginLeft;
int y = i * 50;
FieldView.Draw(f, x, y, g);
......@@ -80,29 +93,29 @@ public class GamePanel extends JPanel {
g.setFont(font);
g.setColor(Color.white);
PlayerView.Draw(world.getPlayer(), 30, 30, g);
PlayerView.Draw(world.getPlayer(), 10, 50, g);
SpawnManagerView.Draw(world.getSpawnManager(), 750, 30, g);
SpawnManagerView.Draw(world.getSpawnManager(), 10, 110, g);
g.setFont(fontGameEnd);
Engine e = world.getEngine();
if (!e.isGameRunning()) {
if (!e.isVictory()) {
g.setColor(Color.red);
g.drawString("DEFEAT!", 300, 400);
g.drawString("DEFEAT!", 400, 400);
} else {
g.setColor(Color.green);
g.drawString("VICTORY!", 300, 400);
g.drawString("VICTORY!", 400, 400);
}
}
}
private Point getFieldAt(Point screenCoord) {
if (screenCoord.y < marginTop) {
if (screenCoord.x < marginLeft) {
return null;
}
int fieldY = screenCoord.x / 50;
int fieldX = (screenCoord.y - marginTop) / 50;
int fieldY = (screenCoord.x-marginLeft) / 50;
int fieldX = (screenCoord.y) / 50;
return new Point(fieldX, fieldY);
}
......
......@@ -148,6 +148,9 @@ public class Tower extends Placeable implements ITickable, IEnemyObserver,
}
public void setRange(int range) {
if (fogDescends) {
range += 1;
}
if (range > 4)
return;
this.range = range;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment