Skip to content

Commit eb9fb34

Browse files
committed
fix main issues
1 parent c2cf147 commit eb9fb34

File tree

11 files changed

+230
-41
lines changed

11 files changed

+230
-41
lines changed
5.06 KB
Loading
8.34 KB
Loading
8.12 KB
Loading
5.39 KB
Loading
8.96 KB
Loading

source/core/src/main/com/deco2800/game/areas/ForestGameArea.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ public void create() {
171171
spawnBobo();
172172
spawnTimeConsumeableItem();
173173
spawnClueItem();
174-
spawnSwitchItems();
175174
playMusic();
176175
spawnCoralItems();
177176
spawnZoe();
@@ -180,6 +179,8 @@ public void create() {
180179
spawnHeph();
181180
spawnOrpheus();
182181
spawnNereus();
182+
183+
spawnSwitchItems();
183184
}
184185

185186
private void loadLevel(String name){
@@ -439,16 +440,16 @@ private void spawnClueItem() {
439440
}
440441

441442
private void spawnCoralItems() {
442-
GridPoint2 minPos = new GridPoint2(5, 5);
443+
GridPoint2 minPos = new GridPoint2(5, 10);
443444
GridPoint2 maxPos = terrain.getMapBounds(0).sub(15, 15);
444445

445-
if (NpcInteractionDisplay.chapterNum == 2) {
446-
spawnEntityAt(ItemFactory.createItem(4), RandomUtils.random(minPos, maxPos), true, false);
447-
spawnEntityAt(ItemFactory.createItem(5), RandomUtils.random(minPos, maxPos), true, false);
448-
spawnEntityAt(ItemFactory.createItem(6), RandomUtils.random(minPos, maxPos), true, false);
449-
spawnEntityAt(ItemFactory.createItem(7), RandomUtils.random(minPos, maxPos), true, false);
450-
spawnEntityAt(ItemFactory.createItem(8), RandomUtils.random(minPos, maxPos), true, false);
451-
}
446+
// if (NpcInteractionDisplay.chapterNum == 2) {
447+
spawnEntityAt(ItemFactory.createItem(4), new GridPoint2(20, 10), true, false);
448+
spawnEntityAt(ItemFactory.createItem(5), new GridPoint2(20, 14), true, false);
449+
spawnEntityAt(ItemFactory.createItem(6), new GridPoint2(20, 18), true, false);
450+
spawnEntityAt(ItemFactory.createItem(7), new GridPoint2(20, 20), true, false);
451+
spawnEntityAt(ItemFactory.createItem(8), new GridPoint2(20, 23), true, false);
452+
// }
452453

453454
if (NpcInteractionDisplay.chapterNum == 3) {
454455
spawnEntityAt(ItemFactory.createItem(4), RandomUtils.random(minPos, maxPos), true, false);
@@ -459,25 +460,28 @@ private void spawnCoralItems() {
459460

460461
private void spawnSwitchItems() {
461462
if (NpcInteractionDisplay.chapterNum <= 1) {
462-
Entity switchItem = SwitchFactory.createSwitch();
463+
Entity switchItem = SwitchFactory.createSwitch(player, game);
463464
spawnEntityAt(switchItem, new GridPoint2(20, 10), true, true);
464465

465466
Entity tool = SwitchFactory.createTool();
466467
spawnEntityAt(tool, new GridPoint2(25, 10), true, true);
467468

468-
GridPoint2 minPos = new GridPoint2(5, 5);
469-
GridPoint2 maxPos = terrain.getMapBounds(0).sub(15, 15);
470-
471-
for (int i = 0; i < NUM_BATTERIES; i++) {
472-
GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
473-
Entity battery = ItemFactory.createItem(3);
474-
spawnEntityAt(battery, randomPos, true, false);
475-
}
469+
// GridPoint2 minPos = new GridPoint2(10, 10);
470+
// GridPoint2 maxPos = terrain.getMapBounds(0).sub(25, 25);
471+
472+
// for (int i = 0; i < NUM_BATTERIES; i++) {
473+
// GridPoint2 randomPos = RandomUtils.random(minPos, maxPos);
474+
// Entity battery = ItemFactory.createItem(3);
475+
// spawnEntityAt(battery, randomPos, true, false);
476+
spawnEntityAt(ItemFactory.createItem(3), new GridPoint2(15, 10), true, false);
477+
spawnEntityAt(ItemFactory.createItem(3), new GridPoint2(15, 13), true, false);
478+
spawnEntityAt(ItemFactory.createItem(3), new GridPoint2(15, 16), true, false);
479+
// }
476480
}
477481

478482
// if (NpcInteractionDisplay.chapterNum == 2) {
479-
var en = SwitchFactory.createPodium(player);
480-
spawnEntityAt(en, new GridPoint2(20, 12), true, true);
483+
var en = SwitchFactory.createPodium(player, game);
484+
spawnEntityAt(en, new GridPoint2(20, 25), true, true);
481485
// }
482486
//
483487
// if (NpcInteractionDisplay.chapterNum == 3) {
@@ -557,10 +561,11 @@ private void spawnGhostKing() {
557561
Entity ghostKing = NPCFactory.createGhostKing(player);
558562
spawnEntityAt(ghostKing, randomPos, true, true);
559563
}
564+
private Entity zoe;
560565

561566
private void spawnZoe() {
562567
GridPoint2 pos = new GridPoint2(10, 10);
563-
Entity zoe = NPCFactory.createZoe(player.getComponent(NpcInteractionDisplay.class));
568+
zoe = NPCFactory.createZoe(player.getComponent(NpcInteractionDisplay.class));
564569
spawnEntityAt(zoe, pos, true, true);
565570
}
566571

source/core/src/main/com/deco2800/game/components/countDownClock/PausedWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
8989
MusicStuff.playMusic(buttonPath, false);
9090
logger.debug("resume button clicked");
9191
// stop = false;
92-
game.theGameScreen.changeStatus2();
92+
//game.theGameScreen.changeStatus2();
9393
resumeGame();
9494
}
9595
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.deco2800.game.components.countDownClock;
2+
3+
import com.badlogic.gdx.Gdx;
4+
import com.badlogic.gdx.graphics.Texture;
5+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
6+
import com.badlogic.gdx.scenes.scene2d.InputEvent;
7+
import com.badlogic.gdx.scenes.scene2d.ui.*;
8+
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
9+
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
10+
import com.deco2800.game.GdxGame;
11+
import com.deco2800.game.components.player.PlayerProfileDisplay;
12+
import com.deco2800.game.ui.UIComponent;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
16+
public class TaskWindow extends UIComponent {
17+
18+
private static final int bgWidth = 700;
19+
private static final int bgHeight = 350;
20+
private static final Logger logger = LoggerFactory.getLogger(PlayerProfileDisplay.class);
21+
22+
23+
GdxGame game;
24+
25+
Table background;
26+
Table buttons;
27+
Stack stack;
28+
29+
private String imageName;
30+
31+
public TaskWindow(GdxGame game, String imageName) {
32+
super();
33+
this.game = game;
34+
this.imageName = imageName;
35+
}
36+
37+
@Override
38+
public void create(){
39+
super.create();
40+
addActors();
41+
}
42+
43+
@Override
44+
protected void draw(SpriteBatch batch) {
45+
46+
}
47+
48+
49+
private void addActors() {
50+
Texture pauseWindowTexture = new Texture(Gdx.files.internal(this.imageName));
51+
TextureRegionDrawable pausedWindow = new TextureRegionDrawable(pauseWindowTexture);
52+
53+
Texture resumeBtnTexture = new Texture(Gdx.files.internal("images/countdown_clock/resume.png"));
54+
TextureRegionDrawable resumeBtnDrawable = new TextureRegionDrawable(resumeBtnTexture);
55+
56+
// Texture restartBtnTexture = new Texture(Gdx.files.internal("images/countdown_clock/replay1.png"));
57+
// TextureRegionDrawable restartBtnDrawable = new TextureRegionDrawable(restartBtnTexture);
58+
59+
Button resumeButton = new ImageButton(resumeBtnDrawable);
60+
// Button restartButton = new ImageButton(restartBtnDrawable);
61+
62+
Image pausedWindowImage = new Image(pausedWindow);
63+
64+
background = new Table();
65+
background.setFillParent(true);
66+
background.add(pausedWindowImage).width(bgWidth).height(bgHeight);
67+
68+
// buttons = new Table();
69+
// buttons.add(resumeButton).expandY().width(40).height(40);
70+
// buttons.add(restartButton).expandY().width(100).height(100);
71+
72+
stack = new Stack();
73+
stack.add(background);
74+
// stack.add(buttons);
75+
76+
stack.setFillParent(true);
77+
78+
stage.addActor(stack);
79+
80+
background.addListener(
81+
new ClickListener() {
82+
@Override
83+
public void clicked(InputEvent event, float x, float y) {
84+
logger.info("Clicked on background");
85+
dispose();
86+
}
87+
});
88+
}
89+
90+
public void dispose() {
91+
super.dispose();
92+
stack.remove();
93+
}
94+
95+
}

source/core/src/main/com/deco2800/game/components/tasks/DistanceTask.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
package com.deco2800.game.components.tasks;
22

3-
import com.badlogic.gdx.Gdx;
43
import com.badlogic.gdx.math.Vector2;
54
import com.deco2800.game.GdxGame;
65
import com.deco2800.game.ai.tasks.DefaultTask;
76
import com.deco2800.game.ai.tasks.PriorityTask;
8-
import com.deco2800.game.ai.tasks.Task;
7+
import com.deco2800.game.components.countDownClock.TaskWindow;
98
import com.deco2800.game.components.npc.NpcInteractionDisplay;
109
import com.deco2800.game.components.player.InventoryComponent;
11-
import com.deco2800.game.components.player.InventoryDisplayComponent;
1210
import com.deco2800.game.components.player.entity.ClueItem;
1311
import com.deco2800.game.entities.Entity;
1412
import com.deco2800.game.entities.factories.SwitchFactory;
15-
import com.deco2800.game.rendering.DebugRenderer;
16-
import com.deco2800.game.services.GameTime;
17-
import com.deco2800.game.services.ServiceLocator;
1813

1914
public class DistanceTask extends DefaultTask implements PriorityTask {
2015
private final Entity target;
2116
private Entity owner;
17+
private TaskWindow pausedWindow;
18+
private GdxGame game;
2219

23-
public DistanceTask(Entity target) {
20+
public DistanceTask(Entity target, GdxGame game) {
2421
this.target = target;
22+
this.game = game;
2523
}
2624

2725
public void setOwner(Entity owner) {
@@ -41,7 +39,13 @@ public void update() {
4139
Vector2 from = owner.getCenterPosition();
4240
float distance = to.dst(from);
4341

44-
if (NpcInteractionDisplay.chapterNum == 2 && distance <= 0.5f && !SwitchFactory.isCollected) {
42+
if (distance <= 1f && !SwitchFactory.isCollected && !SwitchFactory.isMermaidProcessing) {
43+
SwitchFactory.isMermaidProcessing = true;
44+
pausedWindow = new TaskWindow(game, "images/test1.png");
45+
pausedWindow.create();
46+
}
47+
48+
if (distance <= 1f && !SwitchFactory.isCollected && SwitchFactory.isMermaidProcessing) {
4549
var playerInventory = target.getComponent(InventoryComponent.class);
4650
if (playerInventory.contains(ClueItem.MERMAID_SCALE1) &
4751
playerInventory.contains(ClueItem.MERMAID_SCALE2) &
@@ -56,6 +60,11 @@ public void update() {
5660
playerInventory.remove(ClueItem.MERMAID_SCALE5);
5761

5862
playerInventory.add(ClueItem.LACK);
63+
64+
pausedWindow = new TaskWindow(game, "images/test2.png");
65+
pausedWindow.create();
66+
67+
5968
SwitchFactory.isCollected = true;
6069
status = Status.FINISHED;
6170
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.deco2800.game.components.tasks;
2+
3+
import com.badlogic.gdx.math.Vector2;
4+
import com.deco2800.game.GdxGame;
5+
import com.deco2800.game.ai.tasks.DefaultTask;
6+
import com.deco2800.game.ai.tasks.PriorityTask;
7+
import com.deco2800.game.components.countDownClock.TaskWindow;
8+
import com.deco2800.game.components.npc.NpcInteractionDisplay;
9+
import com.deco2800.game.components.player.InventoryComponent;
10+
import com.deco2800.game.entities.Entity;
11+
import com.deco2800.game.entities.factories.SwitchFactory;
12+
13+
public class SwitchTask extends DefaultTask implements PriorityTask {
14+
private final Entity target;
15+
private Entity owner;
16+
private GdxGame game;
17+
private TaskWindow pausedWindow;
18+
19+
public SwitchTask(Entity target, GdxGame game) {
20+
this.target = target;
21+
this.game = game;
22+
}
23+
24+
public void setOwner(Entity owner) {
25+
this.owner = owner;
26+
}
27+
28+
@Override
29+
public void start() {
30+
super.start();
31+
}
32+
33+
@Override
34+
public void update() {
35+
Vector2 to = target.getCenterPosition();
36+
Vector2 from = owner.getCenterPosition();
37+
float distance = to.dst(from);
38+
39+
if (NpcInteractionDisplay.chapterNum == 1 && distance <= 1f && !SwitchFactory.isWorking
40+
&& !SwitchFactory.isSwitchProcessing) {
41+
SwitchFactory.isSwitchProcessing = true;
42+
pausedWindow = new TaskWindow(game, "images/test4.png");
43+
pausedWindow.create();
44+
}
45+
46+
if (SwitchFactory.isSwitchProcessing && NpcInteractionDisplay.chapterNum == 1 && distance <= 1f) {
47+
var playerInventory = target.getComponent(InventoryComponent.class);
48+
49+
if (playerInventory.contains(SwitchFactory.BATTERY_ID)
50+
&& playerInventory.count(SwitchFactory.BATTERY_ID) == 3
51+
&& playerInventory.contains(SwitchFactory.TOOL_ID)){
52+
playerInventory.remove(SwitchFactory.TOOL_ID);
53+
playerInventory.remove(SwitchFactory.BATTERY_ID, 3);
54+
SwitchFactory.isWorking = true;
55+
SwitchFactory.isSwitchProcessing = false;
56+
57+
pausedWindow = new TaskWindow(game, "images/test5.png");
58+
pausedWindow.create();
59+
}
60+
}
61+
}
62+
63+
@Override
64+
public int getPriority() {
65+
return 0;
66+
}
67+
}

0 commit comments

Comments
 (0)