Some of the basic logic is done.
This commit is contained in:
parent
daea9003f6
commit
1883bdcb8a
@ -1,6 +1,7 @@
|
||||
package Classes;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
@ -9,8 +10,8 @@ public class DrawingAircraft
|
||||
public EntityAircraft Plane;
|
||||
private DrawingEngines _engines;
|
||||
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
@ -18,13 +19,12 @@ public class DrawingAircraft
|
||||
protected final int _aircraftWidth = 100;
|
||||
protected final int _aircraftHeight = 120;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawingAircraft(int speed,float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
Plane = new EntityAircraft();
|
||||
Plane.Init(speed,weight,bodyColor);
|
||||
_engines = new DrawingEngines();
|
||||
_engines.setEngines(rnd.nextInt(2,7));
|
||||
Plane = new EntityAircraft(speed,weight,bodyColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x,int y,int width,int height)
|
||||
@ -222,4 +222,9 @@ public class DrawingAircraft
|
||||
_startPosY = _pictureHeight - _aircraftHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectData getCurrentPosition()
|
||||
{
|
||||
return new ObjectData(_startPosX, _startPosY, _startPosX + _aircraftWidth - 1, _startPosY + _aircraftHeight - 1);
|
||||
}
|
||||
}
|
||||
|
96
Classes/DrawingMilitaryAircraft.java
Normal file
96
Classes/DrawingMilitaryAircraft.java
Normal file
@ -0,0 +1,96 @@
|
||||
package Classes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingMilitaryAircraft extends DrawingAircraft
|
||||
{
|
||||
public DrawingMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, boolean rockets, boolean extraWings)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
Plane = new EntityMilitaryAircraft(speed, weight, bodyColor, extraColor, rockets, extraWings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
|
||||
if(!(Plane instanceof EntityMilitaryAircraft))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
super.DrawTransport(g);
|
||||
|
||||
EntityMilitaryAircraft militaryAircraft = (EntityMilitaryAircraft) Plane;
|
||||
|
||||
if(militaryAircraft.ExtraWings)
|
||||
{
|
||||
Polygon pathExtraWing1 = new Polygon();
|
||||
|
||||
Point point1W1 = new Point((int)(_startPosX + 30), (int)(_startPosY + 45));
|
||||
Point point2W1 = new Point(point1W1.x , point1W1.y - 40);
|
||||
Point point3W1 = new Point(point2W1.x + 10,point1W1.y);
|
||||
|
||||
pathExtraWing1.addPoint(point1W1.x,point1W1.y);
|
||||
pathExtraWing1.addPoint(point2W1.x,point2W1.y);
|
||||
pathExtraWing1.addPoint(point3W1.x,point3W1.y);
|
||||
|
||||
g.setColor(Color.black);
|
||||
g.drawPolygon(pathExtraWing1);
|
||||
|
||||
g.setColor(militaryAircraft.ExtraColor);
|
||||
g.fillPolygon(pathExtraWing1);
|
||||
|
||||
Polygon pathExtraWing2 = new Polygon();
|
||||
|
||||
Point point1W2 = new Point((int)(_startPosX + 30),(int)(_startPosY + 60));
|
||||
Point point2W2 = new Point(point1W2.x , point1W2.y + 40);
|
||||
Point point3W2 = new Point(point2W2.x + 10,point1W2.y);
|
||||
|
||||
pathExtraWing1.addPoint(point1W2.x,point1W2.y);
|
||||
pathExtraWing1.addPoint(point2W2.x,point2W2.y);
|
||||
pathExtraWing1.addPoint(point3W2.x,point3W2.y);
|
||||
|
||||
g.setColor(Color.black);
|
||||
g.drawPolygon(pathExtraWing2);
|
||||
|
||||
g.setColor(militaryAircraft.ExtraColor);
|
||||
g.fillPolygon(pathExtraWing2);
|
||||
}
|
||||
|
||||
if(militaryAircraft.Rockets)
|
||||
{
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 50, _startPosY + 30,17,4);
|
||||
|
||||
Polygon pathRocketHead1 = new Polygon();
|
||||
Point point1R1 = new Point((int)(_startPosX + 50),(int)(_startPosY + 30));
|
||||
Point point2R1 = new Point(point1R1.x - 5,point1R1.y + 2);
|
||||
Point point3R1 = new Point(point1R1.x , point1R1.y + 4);
|
||||
|
||||
pathRocketHead1.addPoint(point1R1.x,point1R1.y);
|
||||
pathRocketHead1.addPoint(point2R1.x,point2R1.y);
|
||||
pathRocketHead1.addPoint(point3R1.x,point3R1.y);
|
||||
|
||||
g.drawPolygon(pathRocketHead1);
|
||||
g.setColor(militaryAircraft.ExtraColor);
|
||||
g.fillPolygon(pathRocketHead1);
|
||||
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 50, _startPosY + 70, 17, 4);
|
||||
|
||||
Polygon pathRocketHead2 = new Polygon();
|
||||
Point point1R2 = new Point((int)(_startPosX + 50),(int)(_startPosY + 70));
|
||||
Point point2R2 = new Point(point1R2.x - 5,point1R2.y + 2);
|
||||
Point point3R2 = new Point(point1R2.x, point1R2.y + 4);
|
||||
|
||||
pathRocketHead2.addPoint(point1R2.x,point1R2.y);
|
||||
pathRocketHead2.addPoint(point2R2.x,point2R2.y);
|
||||
pathRocketHead2.addPoint(point2R2.x,point2R2.y);
|
||||
|
||||
g.drawPolygon(pathRocketHead2);
|
||||
g.setColor(militaryAircraft.ExtraColor);
|
||||
g.fillPolygon(pathRocketHead2);
|
||||
}
|
||||
}
|
||||
}
|
40
Classes/DrawingObjectAircraft.java
Normal file
40
Classes/DrawingObjectAircraft.java
Normal file
@ -0,0 +1,40 @@
|
||||
package Classes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingObjectAircraft implements IDrawingObject {
|
||||
private DrawingAircraft _aircraft = null;
|
||||
|
||||
public DrawingObjectAircraft(DrawingAircraft aircraft)
|
||||
{
|
||||
_aircraft = aircraft;
|
||||
}
|
||||
@Override
|
||||
public float getStep()
|
||||
{
|
||||
return _aircraft.Plane.getStep();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_aircraft.SetPosition(x,y,width,height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_aircraft.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawingObject(Graphics g)
|
||||
{
|
||||
_aircraft.DrawTransport(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectData getCurrentPosition() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -10,7 +10,9 @@ public class EntityAircraft
|
||||
public float Step;
|
||||
|
||||
|
||||
public void Init(int speed,float weight,Color bodyColor)
|
||||
|
||||
|
||||
public EntityAircraft(int speed,float weight,Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
|
18
Classes/EntityMilitaryAircraft.java
Normal file
18
Classes/EntityMilitaryAircraft.java
Normal file
@ -0,0 +1,18 @@
|
||||
package Classes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityMilitaryAircraft extends EntityAircraft
|
||||
{
|
||||
public Color ExtraColor;
|
||||
public boolean Rockets;
|
||||
public boolean ExtraWings;
|
||||
|
||||
public EntityMilitaryAircraft(int speed, float weight, Color bodyColor, Color extraColor, boolean rockets, boolean extraWings)
|
||||
{
|
||||
super(speed,weight,bodyColor);
|
||||
this.ExtraColor = extraColor;
|
||||
this.Rockets = rockets;
|
||||
this.ExtraWings = extraWings;
|
||||
}
|
||||
}
|
16
Classes/IDrawingObject.java
Normal file
16
Classes/IDrawingObject.java
Normal file
@ -0,0 +1,16 @@
|
||||
package Classes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingObject
|
||||
{
|
||||
public float getStep();
|
||||
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
void DrawingObject(Graphics g);
|
||||
|
||||
ObjectData getCurrentPosition();
|
||||
}
|
217
Classes/Maps/AbstractMap.java
Normal file
217
Classes/Maps/AbstractMap.java
Normal file
@ -0,0 +1,217 @@
|
||||
package Classes.Maps;
|
||||
|
||||
import Classes.Direction;
|
||||
import Classes.IDrawingObject;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class AbstractMap
|
||||
{
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[][] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected final Random _random = new Random();
|
||||
protected final int _freeRoad = 0;
|
||||
protected final int _barrier = 1;
|
||||
|
||||
public Image CreateMap(int width, int height, IDrawingObject drawingObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawingObject;
|
||||
GenerateMap();
|
||||
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
|
||||
}
|
||||
|
||||
public Image MoveObject(Direction direction)
|
||||
{
|
||||
int CollisionFlag = 0;
|
||||
|
||||
Dimension objSize1 = new Dimension(100,100);
|
||||
|
||||
//COLLISION CHECK
|
||||
if (direction == Direction.Up)
|
||||
{
|
||||
|
||||
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
Point LeftTop = new Point((int)_drawingObject.getCurrentPosition().Left(), (int)(_drawingObject.getCurrentPosition().Top() - _drawingObject.getStep()));
|
||||
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||
|
||||
|
||||
|
||||
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||
|
||||
if (objectRect.intersects(rectBarrier))
|
||||
{
|
||||
CollisionFlag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (direction == Direction.Down)
|
||||
{
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
Point LeftTop = new Point((int)_drawingObject.getCurrentPosition().Left(), (int)(_drawingObject.getCurrentPosition().Top() + _drawingObject.getStep()));
|
||||
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||
|
||||
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y);
|
||||
|
||||
if (objectRect.intersects(rectBarrier))
|
||||
{
|
||||
CollisionFlag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (direction == Direction.Left)
|
||||
{
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
|
||||
Point LeftTop = new Point((int)(_drawingObject.getCurrentPosition().Left() - _drawingObject.getStep()), (int)_drawingObject.getCurrentPosition().Top());
|
||||
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||
|
||||
|
||||
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||
|
||||
if (objectRect.intersects(rectBarrier))
|
||||
{
|
||||
CollisionFlag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (direction == Direction.Right)
|
||||
{
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
Point LeftTop = new Point((int)(_drawingObject.getCurrentPosition().Left() + _drawingObject.getStep()), (int)_drawingObject.getCurrentPosition().Top());
|
||||
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
|
||||
|
||||
|
||||
|
||||
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||
|
||||
|
||||
if (objectRect.intersects(rectBarrier))
|
||||
{
|
||||
CollisionFlag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CollisionFlag != 1)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private boolean SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
int x = _random.nextInt(0,10);
|
||||
int y = _random.nextInt(0,10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
|
||||
Rectangle rectObject = new Rectangle(x, y, 100, 100);
|
||||
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_map[i][j] == _barrier)
|
||||
{
|
||||
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
|
||||
if (rectObject.intersects(rectBarrier))
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private Image DrawMapWithObject()
|
||||
{
|
||||
Image img = new BufferedImage(_width, _height,BufferedImage.TYPE_INT_ARGB);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return img;
|
||||
}
|
||||
Graphics gr = (Graphics2D) img.getGraphics();
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for(int j = 0; j < _map[i].length;j++)
|
||||
{
|
||||
if (_map[i][j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i][j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected abstract void GenerateMap();
|
||||
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
||||
}
|
58
Classes/Maps/NightSkyMap.java
Normal file
58
Classes/Maps/NightSkyMap.java
Normal file
@ -0,0 +1,58 @@
|
||||
package Classes.Maps;
|
||||
|
||||
import org.w3c.dom.css.RGBColor;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class NightSkyMap extends AbstractMap {
|
||||
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map[0].length;
|
||||
_size_y = (float)_height / _map.length;
|
||||
int counter = 0;
|
||||
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
|
||||
_map[i][j] = _freeRoad;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
while (counter < 20)
|
||||
{
|
||||
int x = _random.nextInt(10,90);
|
||||
int y = _random.nextInt(10,90);
|
||||
|
||||
_map[x][ y] = _barrier;
|
||||
_map[x-1][y] = _barrier;
|
||||
_map[x + 1][y] = _barrier;
|
||||
_map[x][y - 1] = _barrier;
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(Color.black);
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
Color ThundercloudColor = new Color(0,0,139);
|
||||
g.setColor(ThundercloudColor);
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
|
||||
}
|
||||
}
|
46
Classes/Maps/SimpleMap.java
Normal file
46
Classes/Maps/SimpleMap.java
Normal file
@ -0,0 +1,46 @@
|
||||
package Classes.Maps;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void GenerateMap()
|
||||
{
|
||||
_map = new int[100][100];
|
||||
_size_x = (float)_width / _map[0].length;
|
||||
_size_y = (float)_height / _map.length;
|
||||
int counter = 0;
|
||||
|
||||
for (int i = 0; i < _map.length; i++)
|
||||
{
|
||||
for (int j = 0; j < _map[i].length; j++)
|
||||
{
|
||||
if (_random.nextInt(0, 90) == 5)
|
||||
{
|
||||
_map[i][j] = _barrier;
|
||||
}
|
||||
else
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1)));
|
||||
}
|
||||
}
|
6
Classes/ObjectData.java
Normal file
6
Classes/ObjectData.java
Normal file
@ -0,0 +1,6 @@
|
||||
package Classes;
|
||||
|
||||
public record ObjectData(float Left, float Top, float Right, float Bottom)
|
||||
{
|
||||
|
||||
}
|
@ -48,16 +48,13 @@ public class FormAirFighter extends JFrame
|
||||
|
||||
private void CreateEntity() {
|
||||
Random random = new Random();
|
||||
_aircraft = new DrawingAircraft();
|
||||
_aircraft.Init(
|
||||
random.nextInt(10, 300),
|
||||
random.nextFloat(1000, 2000),
|
||||
new Color(
|
||||
_aircraft = new DrawingAircraft(random.nextInt(10, 300),
|
||||
random.nextFloat(1000, 2000),new Color(
|
||||
random.nextInt(0,256),
|
||||
random.nextInt(0,256),
|
||||
random.nextInt(0,256)
|
||||
)
|
||||
);
|
||||
));
|
||||
|
||||
_aircraft.SetPosition(
|
||||
random.nextInt(0, 100),
|
||||
random.nextInt(0, 100),
|
||||
|
Loading…
x
Reference in New Issue
Block a user