Commit 36ee6d79 authored by 9731301's avatar 9731301

add bullet class and add some classes

parent a8b5f416
......@@ -2,12 +2,21 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="0b3d586d-9f0f-4ca4-b09d-03a200e1e684" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/UI/GameState/BulletState.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/GameState/TankState.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/GameState/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/UI/GameFrame.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameFrame.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameLoop.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameLoop.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState$KeyHandler.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState$MouseHandler.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/WallState$WallData.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/WallState.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameFrame.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/SettingPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/SettingPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameLoop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/WallState.java" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -18,6 +27,7 @@
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
<option value="Enum" />
</list>
</option>
</component>
......@@ -105,6 +115,10 @@
<workItem from="1595766182905" duration="14490000" />
<workItem from="1595787964241" duration="8776000" />
<workItem from="1595807570766" duration="19718000" />
<workItem from="1595889331611" duration="71000" />
<workItem from="1596026842920" duration="4069000" />
<workItem from="1596042670145" duration="24545000" />
<workItem from="1596134290663" duration="1190000" />
</task>
<servers />
</component>
......@@ -116,42 +130,46 @@
<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="1595827412140">
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596080698011">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1595827412140" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1595774990960">
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596080698011" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1596028833005">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes/0.0.1536.824@0.0.1536.824" timestamp="1595774990960" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes/0.0.1536.824@0.0.1536.824" timestamp="1596028833005" />
<state x="611" y="310" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.packages" timestamp="1596028822408">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="611" y="310" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.packages/0.0.1536.824@0.0.1536.824" timestamp="1596028822408" />
<state x="593" y="0" key="CommitChangelistDialog2" timestamp="1595639194593">
<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="1595639194593" />
<state width="1493" height="168" key="GridCell.Tab.0.bottom" timestamp="1595828869703">
<state width="1493" height="134" key="GridCell.Tab.0.bottom" timestamp="1596135091697">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="168" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<state width="1493" height="168" key="GridCell.Tab.0.center" timestamp="1595828869703">
<state width="1493" height="134" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596135091697" />
<state width="1493" height="134" key="GridCell.Tab.0.center" timestamp="1596135091697">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="168" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<state width="1493" height="168" key="GridCell.Tab.0.left" timestamp="1595828869703">
<state width="1493" height="134" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596135091697" />
<state width="1493" height="134" key="GridCell.Tab.0.left" timestamp="1596135091697">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="168" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<state width="1493" height="168" key="GridCell.Tab.0.right" timestamp="1595828869703">
<state width="1493" height="134" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596135091697" />
<state width="1493" height="134" key="GridCell.Tab.0.right" timestamp="1596135091697">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="168" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<state width="1493" height="134" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596135091697" />
<state x="589" y="114" key="RollbackChangesDialog" timestamp="1595702094731">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="589" y="114" key="RollbackChangesDialog/0.0.1536.824@0.0.1536.824" timestamp="1595702094731" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1595807634287">
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596134473346">
<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="1595807634287" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596134473346" />
<state x="209" y="33" key="new project wizard" timestamp="1593723788909">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
package UI;
import UI.GameState.BulletState;
import UI.GameState.TankState;
import UI.GameState.WallState;
import UI.LogIn.Setting;
import javax.imageio.ImageIO;
......@@ -51,7 +54,7 @@ public class GameFrame extends JFrame {
* Game rendering with triple-buffering using BufferStrategy.
*/
public void render(GameState state) {
public void render(TankState tankState , BulletState bulletState) {
do {
// The following loop ensures that the contents of the drawing buffer
......@@ -63,7 +66,7 @@ public class GameFrame extends JFrame {
Graphics2D graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
try {
doRendering(graphics, state);
doRendering(graphics, tankState , bulletState);
} finally {
// Dispose the graphics
graphics.dispose();
......@@ -86,7 +89,7 @@ public class GameFrame extends JFrame {
*/
// Draw all game elements according
// to the game 'state' using 'g2d' ...
private void doRendering(Graphics2D g2d, GameState state) {
private void doRendering(Graphics2D g2d, TankState tankState , BulletState bulletState) {
// Draw background
wallState.paintComponent(g2d);
......@@ -98,19 +101,21 @@ public class GameFrame extends JFrame {
} catch (IOException e) {
System.out.println(e);
}
// Rotation information
double rotationRequired = Math.toRadians (state.rotate);
double rotationRequired = Math.toRadians (tankState.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.drawImage(op.filter( image11, null),tankState.locX , tankState.locY , null);
// g2d.drawImage(image2 , state.locX+30 , state.locY+30 , null);
//Draw bullet
g2d.setColor(Color.GRAY);
g2d.fillOval(bulletState.locX, bulletState.locY, bulletState.diam, bulletState.diam);
// Print FPS info
long currentRender = System.currentTimeMillis();
......@@ -140,7 +145,7 @@ public class GameFrame extends JFrame {
g2d.setFont(g2d.getFont().deriveFont(18.0f));
g2d.drawString(userGuide, 10, GAME_HEIGHT - 10);
// Draw GAME OVER
if (state.gameOver) {
if (tankState.gameOver) {
String str = "GAME OVER";
g2d.setColor(Color.WHITE);
g2d.setFont(g2d.getFont().deriveFont(Font.BOLD).deriveFont(64.0f));
......
......@@ -2,6 +2,9 @@ package UI;
/*** In The Name of Allah ***/
import UI.GameState.BulletState;
import UI.GameState.TankState;
/**
* A very simple structure for the main game loop.
* THIS IS NOT PERFECT, but works for most situations.
......@@ -14,7 +17,7 @@ package UI;
* patterns is available in the following link:
* http://gameprogrammingpatterns.com/game-loop.html
*
* @author Seyed Mohammad Ghaffarian
* @author Seyede zahra seyed fatehi
*/
public class GameLoop implements Runnable {
......@@ -25,7 +28,8 @@ public class GameLoop implements Runnable {
public static final int FPS = 30;
private GameFrame canvas;
private GameState state;
private TankState tankState;
private BulletState bulletState ;
public GameLoop(GameFrame frame) {
canvas = frame;
......@@ -36,10 +40,11 @@ public class GameLoop implements Runnable {
*/
public void init() {
// Perform all initializations ...
state = new GameState(canvas.wallState);
canvas.addKeyListener(state.getKeyListener());
canvas.addMouseListener(state.getMouseListener());
canvas.addMouseMotionListener(state.getMouseMotionListener());
tankState = new TankState(canvas.wallState);
bulletState = new BulletState(canvas.wallState , tankState);
canvas.addKeyListener(tankState.getKeyListener());
canvas.addMouseListener(tankState.getMouseListener());
canvas.addMouseMotionListener(tankState.getMouseMotionListener());
}
@Override
......@@ -49,8 +54,8 @@ public class GameLoop implements Runnable {
try {
long start = System.currentTimeMillis();
//
state.update();
canvas.render(state);
tankState.update();
canvas.render(tankState , bulletState);
//
long delay = (1000 / FPS) - (System.currentTimeMillis() - start);
if (delay > 0)
......
package UI.GameState;
import UI.GameFrame;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class BulletState {
public static int locX, locY, diam , angle;
private WallState wallState;
public BulletState(WallState wallState , TankState tankState){
this.wallState = wallState ;
// Initialize the game state and all elements ...
locX = tankState.locX;
locY = tankState.locY;
angle = tankState.rotate;
diam = 10;
}
}
package UI;
package UI.GameState;
/*** In The Name of Allah ***/
import javax.imageio.ImageIO;
import java.awt.*;
import UI.GameFrame;
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.
* This class also handles user inputs, which affect the game state.
*
* @author Seyed Mohammad Ghaffarian
* @author Seyede zahra seyed fatehi
*/
public class GameState {
public class TankState {
public int locX, locY, diam, rotate;
public boolean gameOver;
private boolean keyUP, keyDOWN, keyRIGHT, keyLEFT;
private boolean keyUP, keyDOWN, keyRIGHT, keyLEFT , keySpace;
private boolean mousePress;
private int mouseX, mouseY;
private KeyHandler keyHandler;
private MouseHandler mouseHandler;
private WallState walls;
BulletState bulletState = new BulletState(walls , TankState.this);
public TankState(){
}
public GameState(WallState walls) {
public TankState(WallState walls) {
this.walls = walls;
// Initialize the game state and all elements ...
locX = 100;
locY = 100;
rotate = 4;
rotate = 0;
diam = 32;
gameOver = false;
......@@ -39,6 +42,7 @@ public class GameState {
keyDOWN = false;
keyRIGHT = false;
keyLEFT = false;
keySpace = false;
mousePress = false;
mouseX = 0;
......@@ -94,7 +98,7 @@ public class GameState {
rotate -=10;
else
rotate = 90;
}
}
if (keyRIGHT ) {
rotate = rotate % 360;
locX += 8;
......@@ -105,6 +109,18 @@ public class GameState {
else
rotate =270;
}
if (keySpace) {
// for (int i = 0; i < 100; i++) {
bulletState.locY += 5*Math.sin(rotate) ;
System.out.println(bulletState.locY );
bulletState.locX += 5*Math.cos(rotate) ;
System.out.println("preeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeesssssssssssssedddddddddddddd");
// }
// bulletState.locX = locX;
// bulletState.locY = locY;
}
if (walls.isWall(locX,locY)){
locX = lastx;
......@@ -139,8 +155,7 @@ public class GameState {
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode())
{
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
keyUP = true;
break;
......@@ -153,6 +168,10 @@ public class GameState {
case KeyEvent.VK_RIGHT:
keyRIGHT = true;
break;
case KeyEvent.VK_SPACE: {
keySpace = true;
break;
}
case KeyEvent.VK_ESCAPE:
gameOver = true;
break;
......@@ -172,6 +191,10 @@ public class GameState {
case KeyEvent.VK_LEFT:
keyLEFT = false;
break;
case KeyEvent.VK_SPACE: {
keySpace = false;
break;
}
case KeyEvent.VK_RIGHT:
keyRIGHT = false;
break;
......@@ -180,6 +203,10 @@ public class GameState {
}
public void setWalls(WallState walls) {
this.walls = walls;
}
/**
* The mouse handler.
*/
......
package UI;
package UI.GameState;
import java.awt.*;
import java.io.IOException;
......@@ -79,7 +79,7 @@ public class WallState {
x = (w*c)+(w/2)+start;
if (r==numRows-1 && c>0)
x -=w/2;
draw(g,x,y,w,wallWidth);
draw(g,x,y,w,wallWidth);
}
if ((r>0 && lines[r-1].charAt(c)=='1') || (r>0 && r<numRows-1 && lines[r+1].charAt(c)=='1')) { //vertical
......
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