Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
JTankTrouble
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9831111
JTankTrouble
Commits
bb466c9a
Commit
bb466c9a
authored
Aug 03, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add enemy tank.
parent
660d635a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
11 deletions
+12
-11
GameFrame.java
src/GameFrame.java
+12
-11
No files found.
src/GameFrame.java
View file @
bb466c9a
...
@@ -119,7 +119,7 @@ public class GameFrame extends JFrame {
...
@@ -119,7 +119,7 @@ public class GameFrame extends JFrame {
/**
/**
* Game rendering with triple-buffering using BufferStrategy.
* Game rendering with triple-buffering using BufferStrategy.
*/
*/
public
void
render
(
GameState
state
1
,
GameState
state
,
GameState
state2
)
throws
IOException
{
public
void
render
(
GameState
state
)
throws
IOException
{
// Render single frame
// Render single frame
do
{
do
{
// The following loop ensures that the contents of the drawing buffer
// The following loop ensures that the contents of the drawing buffer
...
@@ -129,7 +129,7 @@ public class GameFrame extends JFrame {
...
@@ -129,7 +129,7 @@ public class GameFrame extends JFrame {
// to make sure the strategy is validated
// to make sure the strategy is validated
Graphics2D
graphics
=
(
Graphics2D
)
bufferStrategy
.
getDrawGraphics
();
Graphics2D
graphics
=
(
Graphics2D
)
bufferStrategy
.
getDrawGraphics
();
try
{
try
{
doRendering
(
graphics
,
state
1
,
state
,
state2
);
doRendering
(
graphics
,
state
);
}
finally
{
}
finally
{
// Dispose the graphics
// Dispose the graphics
...
@@ -179,7 +179,7 @@ public class GameFrame extends JFrame {
...
@@ -179,7 +179,7 @@ public class GameFrame extends JFrame {
/**
/**
* Rendering all game elements based on the game state.
* Rendering all game elements based on the game state.
*/
*/
private
void
doRendering
(
Graphics2D
g2d
,
GameState
state
,
GameState
state1
,
GameState
state2
)
throws
IOException
{
private
void
doRendering
(
Graphics2D
g2d
,
GameState
state
)
throws
IOException
{
renderCount
++;
renderCount
++;
// Draw background
// Draw background
g2d
.
setColor
(
Color
.
white
);
g2d
.
setColor
(
Color
.
white
);
...
@@ -192,8 +192,8 @@ public class GameFrame extends JFrame {
...
@@ -192,8 +192,8 @@ public class GameFrame extends JFrame {
// g2d.drawImage(image1,state.locX,state.locY,null);
// g2d.drawImage(image1,state.locX,state.locY,null);
g2d
.
setColor
(
Color
.
black
);
g2d
.
setColor
(
Color
.
black
);
//g2d.drawImage(rotate(image1, state1.rotateAmount), state1.locX, state1.locY, null);
//g2d.drawImage(rotate(image1, state1.rotateAmount), state1.locX, state1.locY, null);
setTanks
(
3
,
g2d
,
state
,
state1
,
state2
);
setTanks
(
3
,
g2d
,
state
);
setEnemy
(
g2d
);
setEnemy
(
g2d
,
state
);
setName
(
g2d
,
"narges"
,
"sara"
,
"bardia"
);
setName
(
g2d
,
"narges"
,
"sara"
,
"bardia"
);
setMap
(
g2d
,
new
File
(
"map3.txt"
));
setMap
(
g2d
,
new
File
(
"map3.txt"
));
drawMap
(
g2d
);
drawMap
(
g2d
);
...
@@ -240,13 +240,14 @@ public class GameFrame extends JFrame {
...
@@ -240,13 +240,14 @@ public class GameFrame extends JFrame {
// g2d.drawImage(image5, 1050, 750, null);
// g2d.drawImage(image5, 1050, 750, null);
}
}
public
void
setEnemy
(
Graphics2D
g2d
){
public
void
setEnemy
(
Graphics2D
g2d
,
GameState
state
){
Tank
tank
=
new
Tank
(
"enemy.png"
);
Tank
tank
=
new
Tank
(
"enemy.png"
);
taken
=
tank
.
getIcon
();
taken
=
tank
.
getIcon
();
tanks
.
add
(
tank
);
tanks
.
add
(
tank
);
g2d
.
drawImage
(
tank
.
getIcon
(),
200
,
200
,
null
);
g2d
.
drawImage
(
rotate
(
tank
.
getIcon
(),
state
.
rotateAmountPC
),
state
.
pcX
,
state
.
pcY
,
null
);
// System.out.println(pcState.pcX+" "+pcState.pcY);
}
}
public
void
setTanks
(
int
numOfPlayer
,
Graphics2D
g2d
,
GameState
state
,
GameState
state1
,
GameState
state2
)
{
public
void
setTanks
(
int
numOfPlayer
,
Graphics2D
g2d
,
GameState
state
)
{
//g2d.drawImage(background, 0, 0, null);
//g2d.drawImage(background, 0, 0, null);
if
(
numOfPlayer
>
0
)
{
if
(
numOfPlayer
>
0
)
{
Tank
tank
=
new
Tank
(
"tank_blue_RS.png"
);
Tank
tank
=
new
Tank
(
"tank_blue_RS.png"
);
...
@@ -254,7 +255,7 @@ public class GameFrame extends JFrame {
...
@@ -254,7 +255,7 @@ public class GameFrame extends JFrame {
tanks
.
add
(
tank
);
tanks
.
add
(
tank
);
g2d
.
drawImage
(
rotate
(
tank
.
getIcon
(),
state
.
rotateAmount
),
state
.
locX
,
state
.
locY
,
null
);
g2d
.
drawImage
(
rotate
(
tank
.
getIcon
(),
state
.
rotateAmount
),
state
.
locX
,
state
.
locY
,
null
);
// numOfPlayer--;
// numOfPlayer--;
//
// if (numOfPlayer > 0) {
// if (numOfPlayer > 0) {
// Tank tank1 = new Tank("tank_green_RS.png");
// Tank tank1 = new Tank("tank_green_RS.png");
// g2d.drawImage(rotate(tank1.getIcon(), state1.rotateAmount), state1.locX, state1.locY, null);
// g2d.drawImage(rotate(tank1.getIcon(), state1.rotateAmount), state1.locX, state1.locY, null);
...
@@ -372,7 +373,7 @@ public class GameFrame extends JFrame {
...
@@ -372,7 +373,7 @@ public class GameFrame extends JFrame {
firstPrize
=
false
;
firstPrize
=
false
;
lastX
=
prizeLoc
.
get
(
randomLoc
);
lastX
=
prizeLoc
.
get
(
randomLoc
);
lastY
=
prizeLoc
.
get
(
randomLoc
+
1
);
lastY
=
prizeLoc
.
get
(
randomLoc
+
1
);
renderCountLimit
=
renderCount
+
18
0
;
renderCountLimit
=
renderCount
+
30
0
;
lastPrize
=
bullet2
;
lastPrize
=
bullet2
;
}
else
if
(
renderCount
!=
renderCountLimit
&&
!
Controller
.
getPrize
)
{
}
else
if
(
renderCount
!=
renderCountLimit
&&
!
Controller
.
getPrize
)
{
g2d
.
drawImage
(
lastPrize
,
lastX
,
lastY
,
null
);
g2d
.
drawImage
(
lastPrize
,
lastX
,
lastY
,
null
);
...
@@ -406,7 +407,7 @@ public class GameFrame extends JFrame {
...
@@ -406,7 +407,7 @@ public class GameFrame extends JFrame {
}
}
lastX
=
prizeLoc
.
get
(
randomLoc
);
lastX
=
prizeLoc
.
get
(
randomLoc
);
lastY
=
prizeLoc
.
get
(
randomLoc
+
1
);
lastY
=
prizeLoc
.
get
(
randomLoc
+
1
);
renderCountLimit
=
renderCount
+
18
0
;
renderCountLimit
=
renderCount
+
30
0
;
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment