-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShop
87 lines (66 loc) · 2.3 KB
/
Shop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package playerObjects;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.Graphics;
import grid.Grid;
//makes a shop with icons separate from the grid to render during game
//literally copying grid a little bit
public class Shop {
//size of the shop in pixels
private Vector2f size;
//location in relation to the page
private Vector2f location;
//makes the actual buying thing
private Icon[][] store;
private Turret[][] storeTurrets;
public Shop (Vector2f l, Vector2f s){
size = s;
location = l;
//I assume the shop will be comprised of two basic turrets, then three colours, then the two additional
//upgrades per color
storeTurrets = new Turret[1][3];
store = new Icon [1][3];//changed to acclimate grid
}
public Icon[][] getStore() {
return store;
}
public void addTurret(int x, int y, Turret t) {
storeTurrets[x][y] = t;
}
public Turret getTurret(int x, int y) {
return storeTurrets[x][y];
}
public void addIcon(int r, int c, Icon i) {
store[r][c] = i;
}
public Vector2f getSize() {
return size;
}
public Vector2f getLoc() {
return location;
}
public Vector2f[] iconHitbox(int x, int y) {
Vector2f[] tlbr= new Vector2f[2];
tlbr[0] = new Vector2f(location.x + x*size.x/store.length, location.y+y*size.y/store[0].length);
tlbr[1] = new Vector2f(tlbr[0].x+size.x/store.length, tlbr[0].y+size.y/store[0].length);
return tlbr;
}
public void render (Graphics g){
Grid shopGrid = new Grid (location, size, store.length, store[0].length);
shopGrid.render(g);
for(int i = 0; i<store.length; i++) {
for(int j = 0; j<store[0].length; j++) {
//This prints out the icon image inside the grid boxes (Needs testing)
if(!store[i][j].getDesign().equals(null)) {
//Changing size breaks it, TODO Make that not happen!
//g.scale(store[i][j].getSize().x/store.length, store[i][j].getSize().y/store[i].length);
g.translate(location.x+i*shopGrid.getSize().x/shopGrid.getGrid().length, location.y+j*shopGrid.getSize().y/shopGrid.getGrid()[0].length);
store[i][j].getDesign().draw(0, 0);
g.translate(5, size.x/shopGrid.getGrid().length/2);
//TODO add turret test data to test this.
//g.drawString("$"+storeTurrets[i][j].getCost(), 0, 0);
g.resetTransform();
}
}
}
}
}