1 | package g0803.bindingofshiba.view.game; | |
2 | ||
3 | import g0803.bindingofshiba.App; | |
4 | import g0803.bindingofshiba.bundles.Bundle; | |
5 | import g0803.bindingofshiba.events.IEventManager; | |
6 | import g0803.bindingofshiba.events.Observer; | |
7 | import g0803.bindingofshiba.events.game.PlayerEnterDoorEvent; | |
8 | import g0803.bindingofshiba.gui.GUI; | |
9 | import g0803.bindingofshiba.math.Vec2D; | |
10 | import g0803.bindingofshiba.model.game.Game; | |
11 | import g0803.bindingofshiba.model.game.elements.Player; | |
12 | import g0803.bindingofshiba.model.game.room.Room; | |
13 | import g0803.bindingofshiba.textures.ITexture; | |
14 | import g0803.bindingofshiba.textures.TextTextureBuilder; | |
15 | import g0803.bindingofshiba.view.View; | |
16 | import g0803.bindingofshiba.view.ViewFactory; | |
17 | import java.awt.*; | |
18 | ||
19 | public class GameView extends View<Game> implements Observer { | |
20 | ||
21 | private final ViewFactory<Room> roomViewFactory; | |
22 | ||
23 | private final View<Player> playerView; | |
24 | private View<Room> roomView; | |
25 | ||
26 | public GameView(Game model, IEventManager eventManager) { | |
27 | this(model, eventManager, PlayerView::new, RoomView::new); | |
28 | } | |
29 | ||
30 | public GameView( | |
31 | Game model, | |
32 | IEventManager eventManager, | |
33 | ViewFactory<Player> playerViewFactory, | |
34 | ViewFactory<Room> roomViewFactory) { | |
35 | super(model, eventManager); | |
36 | ||
37 | this.roomViewFactory = roomViewFactory; | |
38 | this.playerView = playerViewFactory.create(getModel().getPlayer(), getEventManager()); | |
39 | ||
40 |
1
1. <init> : removed call to g0803/bindingofshiba/view/game/GameView::createViews → KILLED |
createViews(getModel().getCurrentRoom()); |
41 |
1
1. <init> : removed call to g0803/bindingofshiba/events/IEventManager::addObserver → SURVIVED |
getEventManager().addObserver(this); |
42 | } | |
43 | ||
44 | private void createViews(Room room) { | |
45 | this.roomView = roomViewFactory.create(room, getEventManager()); | |
46 | } | |
47 | ||
48 | private void drawPlayer(App app, GUI gui, Vec2D offset) { | |
49 |
1
1. drawPlayer : removed call to g0803/bindingofshiba/view/View::draw → KILLED |
playerView.draw(app, gui, offset); |
50 | } | |
51 | ||
52 | private void drawRoom(App app, GUI gui, Vec2D offset) { | |
53 |
1
1. drawRoom : removed call to g0803/bindingofshiba/view/View::draw → KILLED |
roomView.draw(app, gui, offset); |
54 | } | |
55 | ||
56 | private void drawHud(App app, GUI gui, Vec2D offset) { | |
57 |
1
1. drawHud : removed call to g0803/bindingofshiba/view/game/GameView::drawHealthBar → KILLED |
drawHealthBar(app, gui, offset); |
58 |
1
1. drawHud : removed call to g0803/bindingofshiba/view/game/GameView::drawOverlay → KILLED |
drawOverlay(app, gui, offset); |
59 |
1
1. drawHud : removed call to g0803/bindingofshiba/view/game/GameView::drawKeys → KILLED |
drawKeys(app, gui, offset); |
60 | } | |
61 | ||
62 | private void drawHealthBar(App app, GUI gui, Vec2D offset) { | |
63 | Bundle<ITexture> textures = app.getTextures(); | |
64 | ITexture texture = textures.get("health.idle"); | |
65 | ||
66 | int currentHp = getModel().getPlayer().getHp(); | |
67 | int maxHp = getModel().getPlayer().getMaxHp(); | |
68 |
1
1. drawHealthBar : Replaced double division with multiplication → KILLED |
double percentage = (double) currentHp / maxHp; |
69 |
2
1. drawHealthBar : Replaced double multiplication with division → KILLED 2. drawHealthBar : Replaced double multiplication with division → KILLED |
double x = 0.5 * percentage * texture.getWidth(); |
70 | ||
71 | Vec2D position = new Vec2D(x, 0).add(offset).round(); | |
72 |
1
1. drawHealthBar : removed call to g0803/bindingofshiba/gui/GUI::blit → KILLED |
gui.blit((int) position.getX(), (int) position.getY(), texture); |
73 | } | |
74 | ||
75 | private void drawOverlay(App app, GUI gui, Vec2D offset) { | |
76 | Bundle<ITexture> textures = app.getTextures(); | |
77 | ITexture texture = textures.get("hud"); | |
78 | ||
79 | Vec2D position = offset.round(); | |
80 |
1
1. drawOverlay : removed call to g0803/bindingofshiba/gui/GUI::blit → KILLED |
gui.blit((int) position.getX(), (int) position.getY(), texture); |
81 | } | |
82 | ||
83 | private void drawKeys(App app, GUI gui, Vec2D offset) { | |
84 | Bundle<Font> fonts = app.getFonts(); | |
85 | Font font = fonts.get("text"); | |
86 | ||
87 | String keys = String.valueOf(getModel().getPlayer().getNumberOfKeys()); | |
88 | ITexture texture = | |
89 | new TextTextureBuilder(font).setText(keys).setColor(Color.lightGray).build(); | |
90 | ||
91 | Vec2D position = new Vec2D(9, 6).add(offset).round(); | |
92 | ||
93 |
1
1. drawKeys : removed call to g0803/bindingofshiba/gui/GUI::blit → KILLED |
gui.blit((int) position.getX(), (int) position.getY(), texture); |
94 | } | |
95 | ||
96 | @Override | |
97 | public void draw(App app, GUI gui, Vec2D offset) { | |
98 |
1
1. draw : removed call to g0803/bindingofshiba/gui/GUI::fill → KILLED |
gui.fill(new Color(90, 72, 53)); |
99 | ||
100 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/GameView::drawRoom → KILLED |
drawRoom(app, gui, offset.add(new Vec2D(0, 9))); |
101 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/GameView::drawPlayer → KILLED |
drawPlayer(app, gui, offset.add(new Vec2D(0, 9))); |
102 |
1
1. draw : removed call to g0803/bindingofshiba/view/game/GameView::drawHud → KILLED |
drawHud(app, gui, offset); |
103 | } | |
104 | ||
105 | @Override | |
106 | public void onPlayerEnterDoor(PlayerEnterDoorEvent event) { | |
107 | Room room = event.getDoor().getOtherRoom(getModel().getCurrentRoom()); | |
108 |
1
1. onPlayerEnterDoor : removed call to g0803/bindingofshiba/view/game/GameView::createViews → KILLED |
createViews(room); |
109 | } | |
110 | } | |
Mutations | ||
40 |
1.1 |
|
41 |
1.1 |
|
49 |
1.1 |
|
53 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
59 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 2.2 |
|
72 |
1.1 |
|
80 |
1.1 |
|
93 |
1.1 |
|
98 |
1.1 |
|
100 |
1.1 |
|
101 |
1.1 |
|
102 |
1.1 |
|
108 |
1.1 |