Commit e4e29e50 authored by 9731301's avatar 9731301

add rotate to tank and a calss for walls

parent 770fa7be
......@@ -2,15 +2,20 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="0b3d586d-9f0f-4ca4-b09d-03a200e1e684" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/Server_Client/Client.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/Server_Client/Server.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/WallState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Server.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Server.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState$KeyHandler.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState$KeyHandler.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState$MouseHandler.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState$MouseHandler.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Main.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainFrame.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainFrame.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$3.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$3.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pics/tankBody_blue_outline.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/MainInitialPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/MainInitialPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/MainFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/MainFrame.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -85,6 +90,9 @@
<workItem from="1595496830549" duration="1042000" />
<workItem from="1595500392081" duration="9357000" />
<workItem from="1595519390600" duration="8731000" />
<workItem from="1595580635762" duration="18427000" />
<workItem from="1595610264637" duration="6164000" />
<workItem from="1595631601242" duration="3984000" />
</task>
<servers />
</component>
......@@ -92,6 +100,10 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1595580808418">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1595580808418" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1595424907485">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -104,26 +116,26 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="593" y="0" key="CommitChangelistDialog2/0.0.1536.824@0.0.1536.824" timestamp="1595526973946" />
<state width="1078" height="121" key="GridCell.Tab.0.bottom" timestamp="1595527014303">
<state width="1493" height="120" key="GridCell.Tab.0.bottom" timestamp="1595635273015">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1078" height="121" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1595527014303" />
<state width="1078" height="121" key="GridCell.Tab.0.center" timestamp="1595527014303">
<state width="1493" height="120" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1595635273014" />
<state width="1493" height="120" key="GridCell.Tab.0.center" timestamp="1595635273013">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1078" height="121" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1595527014303" />
<state width="1078" height="121" key="GridCell.Tab.0.left" timestamp="1595527014303">
<state width="1493" height="120" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1595635273013" />
<state width="1493" height="120" key="GridCell.Tab.0.left" timestamp="1595635273013">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1078" height="121" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1595527014303" />
<state width="1078" height="121" key="GridCell.Tab.0.right" timestamp="1595527014303">
<state width="1493" height="120" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1595635273013" />
<state width="1493" height="120" key="GridCell.Tab.0.right" timestamp="1595635273014">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1078" height="121" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1595527014303" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1595519582789">
<state width="1493" height="120" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1595635273014" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1595611936192">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1595519582789" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1595611936192" />
<state x="209" y="33" key="new project wizard" timestamp="1593723788909">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -132,13 +144,13 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1595279815795" />
<state x="425" y="187" key="run.anything.popup" timestamp="1595509733410">
<state x="426" y="187" key="run.anything.popup" timestamp="1595584056607">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="425" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1595509733410" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1595522974558">
<state x="426" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1595584056607" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1595612989869">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup/0.0.1536.824@0.0.1536.824" timestamp="1595522974558" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup/0.0.1536.824@0.0.1536.824" timestamp="1595612989869" />
</component>
</project>
\ No newline at end of file
111111111111111111111
101001001001010100001
100000000001000110001
100111000111011100001
101100000000000100111
100000111100111100001
111111111111111111111
\ No newline at end of file
package UI;
/*** In The Name of Allah ***/
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
/**
* This class holds the state of the game and all of its elements.
......@@ -11,7 +15,7 @@ import java.awt.event.*;
*/
public class GameState {
public int locX, locY, diam;
public int locX, locY, diam, rotate;
public boolean gameOver;
private boolean keyUP, keyDOWN, keyRIGHT, keyLEFT;
......@@ -25,6 +29,8 @@ public class GameState {
// Initialize the game state and all elements ...
locX = 100;
locY = 100;
rotate = 4;
diam = 32;
gameOver = false;
......@@ -55,19 +61,53 @@ public class GameState {
locY = mouseY - diam / 2;
locX = mouseX - diam / 2;
}
if (keyUP)
if (keyUP) {
rotate = rotate % 360;
locY -= 8;
if (keyDOWN)
if ( (rotate> 90 && rotate <180) || rotate== 90 )
rotate +=10;
else if ( (rotate >180 && rotate < 270) || rotate ==270 )
rotate -=10;
else
rotate =180;
}
if (keyDOWN) {
rotate = rotate % 360;
locY += 8;
if (keyLEFT)
if ( (rotate > 270 && rotate < 360) || rotate ==270 )
rotate +=10;
else if ( (rotate < 90 && rotate > 0) || rotate == 90 )
rotate -=10;
else
rotate = 0;
}
if (keyLEFT ){
rotate = rotate % 360;
locX -= 8;
if (keyRIGHT)
if ( (rotate > 0 && rotate < 90 )|| rotate == 0)
rotate +=10;
else if ( (rotate > 90 && rotate <180 )|| rotate == 180 )
rotate -=10;
else
rotate = 90;
}
if (keyRIGHT ) {
rotate = rotate % 360;
locX += 8;
if ((rotate > 180 && rotate < 270)|| rotate ==180 )
rotate +=10;
else if ( (rotate > 270 && rotate < 360) || rotate == 360)
rotate -=10;
else
rotate =270;
}
locX = Math.max(locX, 0);
locX = Math.min(locX, MainFrame.GAME_WIDTH - diam);
locY = Math.max(locY, 0);
locY = Math.min(locY, MainFrame.GAME_HEIGHT - diam);
}
......@@ -90,6 +130,7 @@ public class GameState {
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode())
{
case KeyEvent.VK_UP:
......
......@@ -16,9 +16,9 @@ public class Main {
ThreadPool.init();
// Show the game menu ...
InitialFrame initialFrame = new InitialFrame("Trouble Tank");
// InitialFrame initialFrame = new InitialFrame("Trouble Tank");
System.out.println("yes");
if (initialFrame.isClickOnPlay()) {
// if (initialFrame.isClickOnPlay()) {
// After the player clicks 'PLAY' ...
EventQueue.invokeLater(new Runnable() {
......@@ -37,6 +37,6 @@ public class Main {
}
});
}
// }
}
}
......@@ -3,10 +3,14 @@ package UI;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
public class MainFrame extends JFrame {
......@@ -14,24 +18,19 @@ public class MainFrame extends JFrame {
private BufferStrategy bufferStrategy;
private ArrayList<Float> fpsHistory;
private Image image1;
private Image image2;
public static final int GAME_HEIGHT = 720; // 720p game resolution
public static final int GAME_WIDTH = 16 * GAME_HEIGHT / 9; // wide aspect ratio
public MainFrame (String gameName){
public MainFrame(String gameName) {
lastRender = -1;
setTitle(gameName);
pack();
setSize(GAME_WIDTH , GAME_HEIGHT);
setSize(GAME_WIDTH, GAME_HEIGHT);
setResizable(false);
int lastRender = -1;
fpsHistory = new ArrayList<>(100);
try{
image1 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tankBody_blue_outline.png"));
}
catch(IOException e){
System.out.println(e);
}
}
/**
......@@ -81,15 +80,33 @@ public class MainFrame extends JFrame {
*/
// Draw all game elements according
// to the game 'state' using 'g2d' ...
private void doRendering(Graphics2D g2d, GameState state) {
// Draw background
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, GAME_WIDTH , GAME_HEIGHT);
// Draw ball
g2d.setColor(Color.BLACK);
g2d.fillOval(state.locX, state.locY, state.diam, state.diam);
g2d.drawImage(image1 , state.locX , state.locY , null);
WallState wallState = new WallState();
//wallState.paintComponent(g2d);
g2d.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
// Draw tank;
try {
image1 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_blue.png"));
// image2 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_sand.png"));
} catch (IOException e) {
System.out.println(e);
}
// Rotation information
double rotationRequired = Math.toRadians (state.rotate);
BufferedImage image11 = (BufferedImage)image1;
double locationX = image11.getWidth() / 2;
double locationY = image11.getHeight() / 2;
AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
// Drawing the rotated image at the required drawing locations
g2d.drawImage(op.filter( image11, null),state.locX , state.locY , null);
// g2d.rotate(state.rotateR);
// g2d.fillOval(state.locX, state.locY, state.diam, state.diam);
// g2d.drawImage(image1, state.locX, state.locY, null);
// g2d.drawImage(image2 , state.locX+30 , state.locY+30 , null);
// Print FPS info
......@@ -110,7 +127,7 @@ public class MainFrame extends JFrame {
g2d.setFont(g2d.getFont().deriveFont(18.0f));
int strWidth = g2d.getFontMetrics().stringWidth(str);
int strHeight = g2d.getFontMetrics().getHeight();
g2d.drawString(str, (GAME_WIDTH - strWidth) / 2, strHeight+50);
g2d.drawString(str, (GAME_WIDTH - strWidth) / 2, strHeight + 50);
}
lastRender = currentRender;
// Print user guide
......@@ -128,4 +145,8 @@ public class MainFrame extends JFrame {
g2d.drawString(str, (GAME_WIDTH - strWidth) / 2, GAME_HEIGHT / 2);
}
}
}
package UI;
import java.awt.*;
import java.io.BufferedReader;
import java.io.FileReader;
public class WallState {
public void paintComponent(Graphics g)
{
try{
paintComponent(g);
FileReader fr = new FileReader("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\maps\\map1.txt");
BufferedReader br=new BufferedReader(fr);
g.setColor(Color.black); //colour of the walls
String s;
s=br.readLine();
int numFilas= Integer.parseInt(s); //number of rows
s=br.readLine();
int numColumnas= Integer.parseInt(s); //number of columns
int ladoFilas=650/numFilas; //sideY
int ladoColumnas=400/numColumnas; //sideX
int grosor=5; //width of the wall
int y=0;
for(int i=0;i<numFilas;i++){
int x=0;
for(int j=0;j<numColumnas;j++){
int lectura=br.read();
char b= (char) lectura; //char from File
//here I create rectangles with different position, width, etc depending on the read value from the file. These rectangles are the walls. I use fillRect(x,y,width,height)
if(b=='1'){
g.fillRect(x, y, ladoColumnas, grosor);
}
lectura=br.read();
b= (char) lectura;
if(b=='1'){
g.fillRect(x+(ladoColumnas-grosor), y, grosor, ladoFilas);
}
lectura=br.read();
b= (char) lectura;
if(b=='1'){
g.fillRect(x, y+(ladoFilas-grosor),ladoColumnas, grosor);
}
lectura=br.read();
b= (char) lectura;
if(b=='1'){
g.fillRect(x, y, grosor, ladoFilas);
}
x+=ladoColumnas;
}
br.readLine();
y+=ladoFilas;
}
//exit position, which is the last two lines of the the file
s=br.readLine();
int filaSalida=Integer.parseInt(s); //exit row
s=br.readLine();
int columnaSalida=Integer.parseInt(s); //exit column
g.setColor(Color.green);
g.fillRect((ladoColumnas*columnaSalida)-ladoColumnas,ladoFilas*filaSalida, ladoFilas, ladoColumnas); //I paint a square in the exit
br.close();
}
catch(Exception e){
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment