Mercurial > hg > ristipolku
annotate game/Engine.java @ 183:cf0256f13612
Remove global number of fonts static.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 16 Mar 2017 13:29:22 +0200 |
parents | 2e033eced6e5 |
children | 189cd8fe2304 |
rev | line source |
---|---|
0 | 1 /* |
9 | 2 * Ristipolku Game Engine |
151 | 3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
0 | 4 */ |
9 | 5 package game; |
6 | |
0 | 7 import java.awt.*; |
8 import java.awt.geom.*; | |
1 | 9 import java.awt.event.*; |
7 | 10 import java.awt.image.*; |
11 import java.awt.event.*; | |
25 | 12 import java.awt.font.*; |
9 | 13 import javax.imageio.*; |
7 | 14 import javax.swing.*; |
1 | 15 import java.util.*; |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
16 import java.util.concurrent.locks.Lock; |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
17 import java.util.concurrent.locks.ReentrantReadWriteLock; |
6 | 18 import java.io.*; |
1 | 19 import game.*; |
37 | 20 import javax.sound.sampled.*; |
21 | 21 |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
22 |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
23 class AboutBox extends IDMContainer |
8 | 24 { |
75 | 25 BufferedImage aboutImg; |
26 | |
27 public AboutBox() | |
28 { | |
29 setPos(150f, 150f); | |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
30 setSize(720f, 470f); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
31 setModal(true); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
32 |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
33 add(new BtnOK(500f, 390f)); |
75 | 34 } |
35 | |
36 public void paint(Graphics2D g) | |
37 { | |
115 | 38 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
39 g.fill(new RoundRectangle2D.Float(getScaledX(), getScaledY(), getScaledWidth(), getScaledHeight(), 10, 10)); |
75 | 40 |
76 | 41 setTextFont(G.fonts[3], G.metrics[3]); |
75 | 42 setTextPaint(Color.white); |
173 | 43 setCurrPosScaledRel(20, 35); |
105
75015dfd47ef
Move version number info to G.java.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
44 drawString(g, "RistiPolku (CrossPaths) v"+ G.version +"\n"); |
75 | 45 |
76 | 46 setTextFont(G.fonts[1], G.metrics[1]); |
173 | 47 setTextPaint(Color.yellow); |
48 drawString(g, "(c) Copyright 2011 Tecnic Software productions (TNSP)\n"); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
49 |
173 | 50 setTextPaint(Color.white); |
51 drawString(g, "Programming, graphics and design by " + | |
52 "Matti 'ccr' Hämäläinen.\n" + | |
53 "Audio from archive.org, used non-commercially.\n \n"); | |
75 | 54 |
173 | 55 setTextPaint(Color.red); |
56 drawString(g, "Controls:\n"); | |
57 | |
58 IDMPoint old = textCurrOffs.copy(); | |
81
8932b1300ba1
Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
59 |
173 | 60 setTextPaint(Color.white); |
61 drawString(g, | |
62 "Arrow keys / mouse wheel\n"+ | |
63 "Enter / mouse click\n"+ | |
64 "Space bar\n"); | |
81
8932b1300ba1
Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
65 |
173 | 66 textCurrPos.x += getScaledX(330); |
67 textCurrOffs.y = old.y; | |
68 drawString(g, | |
69 "- Rotate piece\n" + | |
70 "- Place/lock piece\n" + | |
71 "- Swap piece\n"); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
72 |
173 | 73 textCurrPos.x -= getScaledX(330); |
74 setTextPaint(Color.green); | |
75 drawString(g, | |
76 "\nObjective: Create a path long as possible by rotating\n"+ | |
77 "and placing pieces. More points will be awarded for\n"+ | |
78 "advancing the path by several segments per turn." | |
79 ); | |
179 | 80 |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
81 super.paint(g); |
75 | 82 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
83 |
75 | 84 public void clicked() |
8 | 85 { |
75 | 86 parent.remove(this); |
8 | 87 } |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
88 |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
89 class BtnOK extends IDMButton |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
90 { |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
91 public BtnOK(float x, float y) |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
92 { |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
93 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "OK"); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
94 } |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
95 |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
96 public void clicked() |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
97 { |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
98 parent.clicked(); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
99 } |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
100 } |
8 | 101 } |
75 | 102 |
0 | 103 |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
104 class NewGameDialog extends IDMContainer |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
105 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
106 public NewGameDialog() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
107 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
108 setPos(150f, 350f); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
109 setSize(720f, 200f); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
110 setModal(true); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
111 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
112 add(new BtnYes(270f, 120f)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
113 add(new BtnCancel(500f, 120f)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
114 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
115 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
116 public void paint(Graphics2D g) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
117 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
118 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
119 g.fill(new RoundRectangle2D.Float(getScaledX(), getScaledY(), getScaledWidth(), getScaledHeight(), 10, 10)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
120 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
121 setTextFont(G.fonts[3], G.metrics[3]); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
122 setTextPaint(Color.white); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
123 setCurrPosScaledRel(25, 35); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
124 drawString(g, "Really start a new game?\n"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
125 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
126 super.paint(g); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
127 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
128 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
129 public void clicked() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
130 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
131 parent.remove(this); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
132 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
133 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
134 class BtnYes extends IDMButton |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
135 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
136 public BtnYes(float x, float y) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
137 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
138 super(x, y, KeyEvent.VK_Y, G.fonts[1], "Yes"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
139 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
140 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
141 public void clicked() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
142 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
143 sendMessage("NEWGAME"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
144 parent.clicked(); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
145 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
146 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
147 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
148 class BtnCancel extends IDMButton |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
149 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
150 public BtnCancel(float x, float y) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
151 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
152 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "Cancel"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
153 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
154 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
155 public void clicked() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
156 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
157 parent.clicked(); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
158 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
159 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
160 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
161 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
162 |
48 | 163 class GameBoard extends IDMWidget |
0 | 164 { |
75 | 165 static final int boardSize = 9; |
166 static final int boardMiddle = 4; | |
2 | 167 Piece[][] board; |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
168 float pscale, ptime; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
169 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
170 public boolean flagGameOver, flagBoardIsDirty; |
119
52d79502447c
Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
171 int gameScore; |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
172 int moves; |
54 | 173 |
119
52d79502447c
Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
174 Piece currPiece, nextPiece; |
41 | 175 int currX, currY, currPoint; |
9 | 176 |
47 | 177 Sound sndPlaced; |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
178 |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
179 private final ReentrantReadWriteLock pointLock = new ReentrantReadWriteLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
180 private ArrayList<AnimatedPointElement> pointElems; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
181 |
75 | 182 public GameBoard(IDMPoint pos, float ps) |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
183 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
184 super(pos); |
75 | 185 pscale = ps; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
186 |
108
ae66d21d4747
Disable piece placement sound.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
187 // sndPlaced = G.smgr.getSound("sounds/placed.wav"); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
188 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
189 pointElems = new ArrayList<AnimatedPointElement>(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
190 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
191 startNewGame(); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
192 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
193 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
194 public void startNewGame() |
2 | 195 { |
196 board = new Piece[boardSize][boardSize]; | |
197 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); | |
198 | |
41 | 199 currX = boardMiddle; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
200 currY = boardMiddle; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
201 currPoint = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
202 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
203 currPiece = null; |
54 | 204 nextPiece = new Piece(PieceType.ACTIVE); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
205 |
65
dc936dba124e
Set game over-flag correctly, so that we reset everything after a game over
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
206 flagGameOver = false; |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
207 flagBoardIsDirty = true; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
208 pieceFinishTurn(); |
55 | 209 gameScore = 0; |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
210 moves = 0; |
2 | 211 } |
0 | 212 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
213 public void paintBackPlate(Graphics2D g) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
214 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
215 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.2f)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
216 g.setStroke(new BasicStroke(5.0f)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
217 g.draw(new RoundRectangle2D.Float(getScaledX(), getScaledY(), |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
218 boardSize * pscale, boardSize * pscale, |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
219 pscale / 5, pscale / 5)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
220 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
221 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
222 public void paintBoard(Graphics2D g, boolean drawCurrent) |
2 | 223 { |
224 for (int y = 0; y < boardSize; y++) | |
225 for (int x = 0; x < boardSize; x++) | |
226 if (board[x][y] != null) | |
227 { | |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
228 if ((drawCurrent && board[x][y] == currPiece) || |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
229 (!drawCurrent && board[x][y] != currPiece)) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
230 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
231 board[x][y].paint(g, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
232 getScaledX() + (x * pscale), |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
233 getScaledY() + (y * pscale), |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
234 pscale - pscale / 10); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
235 } |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
236 } |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
237 } |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
238 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
239 public void paint(Graphics2D g) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
240 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
241 paintBoard(g, true); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
242 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
243 Lock read = pointLock.readLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
244 read.lock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
245 try |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
246 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
247 for (AnimatedPointElement elem : pointElems) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
248 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
249 elem.paint(g); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
250 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
251 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
252 finally |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
253 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
254 read.unlock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
255 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
256 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
257 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
258 if (!flagGameOver) |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
259 { |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
260 if (nextPiece != null) |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
261 { |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
262 // Draw next piece |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
263 AffineTransform save = g.getTransform(); |
154
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
264 nextPiece.paint(g, G.screenDim.width * 0.85f - 90.0f/2.0f, G.screenDim.height * 0.43f, 90.0f); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
265 g.setTransform(save); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
266 } |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
267 } |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
268 else |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
269 { |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
270 // Game over text |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
271 String text = "Game Over!"; |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
272 int textWidth = G.metrics[2].stringWidth(text); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
273 g.setFont(G.fonts[2]); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
274 |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
275 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f)); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
276 g.drawString(text, (G.screenDim.width - textWidth) / 2 + 5, G.screenDim.height / 2 + 5); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
277 |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
278 double f = Math.sin(ptime * 0.1) * 4.0; |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
279 g.setPaint(Color.white); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
280 g.drawString(text, (G.screenDim.width - textWidth) / 2 + (float) f, G.screenDim.height / 2 + (float) f); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
281 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
282 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
283 // Score |
154
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
284 String text = ""+ String.format("%05d", gameScore); |
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
285 int textWidth = G.metrics[2].stringWidth(text); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
286 g.setFont(G.fonts[2]); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
287 g.setPaint(Color.white); |
154
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
288 g.drawString(text, (G.screenDim.width * 0.85f) - textWidth / 2, G.screenDim.height * 0.3f); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
289 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
290 |
75 | 291 public boolean contains(float x, float y) |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
292 { |
76 | 293 return (x >= getScaledX() && |
75 | 294 y >= getScaledY() && |
295 x < getScaledX() + boardSize * pscale && | |
296 y < getScaledY() + boardSize * pscale); | |
2 | 297 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
298 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
299 public boolean isBoardDirty() |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
300 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
301 if (flagBoardIsDirty) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
302 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
303 flagBoardIsDirty = false; |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
304 return true; |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
305 } |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
306 else |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
307 return false; |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
308 } |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
309 |
9 | 310 public void animate(float time) |
311 { | |
148
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
312 if (nextPiece != null) |
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
313 { |
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
314 nextPiece.animate(time); |
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
315 } |
179 | 316 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
317 ptime = time; |
9 | 318 for (int y = 0; y < boardSize; y++) |
319 for (int x = 0; x < boardSize; x++) | |
320 if (board[x][y] != null) | |
321 { | |
322 board[x][y].animate(time); | |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
323 if (board[x][y] != currPiece && board[x][y].active) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
324 flagBoardIsDirty = true; |
9 | 325 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
326 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
327 Lock write = pointLock.writeLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
328 write.lock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
329 try |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
330 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
331 ArrayList<AnimatedPointElement> tmp = new ArrayList<AnimatedPointElement>(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
332 |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
333 for (AnimatedPointElement elem : pointElems) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
334 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
335 elem.animate(time); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
336 if (elem.active) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
337 tmp.add(elem); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
338 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
339 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
340 pointElems = tmp; |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
341 |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
342 if (time % 32 == 1) |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
343 { |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
344 Random rnd = new Random(); |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
345 pointElems.add(new AnimatedPointElement( |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
346 new IDMPoint(10 + rnd.nextInt(400), 10 + rnd.nextInt(100)), ".")); |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
347 } |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
348 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
349 finally |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
350 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
351 write.unlock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
352 } |
9 | 353 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
354 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
355 public void pieceRotate(Piece.RotateDir dir) |
2 | 356 { |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
357 if (currPiece != null && !flagGameOver) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
358 { |
41 | 359 currPiece.rotate(dir); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
360 } |
2 | 361 } |
1 | 362 |
75 | 363 // Change coordinates based on the "outgoing" |
364 // piece connection point. | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
365 private void pieceMoveTo(int point) |
7 | 366 { |
46 | 367 switch (point) |
368 { | |
369 case 0: currY--; break; | |
370 case 1: currY--; break; | |
371 | |
372 case 2: currX++; break; | |
373 case 3: currX++; break; | |
374 | |
375 case 4: currY++; break; | |
376 case 5: currY++; break; | |
377 | |
378 case 6: currX--; break; | |
379 case 7: currX--; break; | |
380 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
381 } |
9 | 382 |
54 | 383 public void pieceCreateNew() |
384 { | |
385 currPiece = nextPiece; | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
386 currPiece.changed(); |
54 | 387 nextPiece = new Piece(PieceType.ACTIVE); |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
388 flagBoardIsDirty = true; |
54 | 389 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
390 |
54 | 391 public void pieceSwapCurrent() |
392 { | |
56 | 393 if (!flagGameOver) |
394 { | |
395 Piece tmp = currPiece; | |
396 currPiece = nextPiece; | |
397 nextPiece = tmp; | |
398 board[currX][currY] = currPiece; | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
399 currPiece.changed(); |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
400 nextPiece.changed(); |
139
be9cc2ee3c16
Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
401 flagBoardIsDirty = true; |
56 | 402 } |
54 | 403 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
404 |
75 | 405 // Check one piece, set connections, find the new placement |
406 // based on piece rotations etc. | |
407 private boolean pieceCheck(Piece piece) | |
48 | 408 { |
53 | 409 if (piece == null) |
48 | 410 { |
411 // Create new piece | |
56 | 412 pieceCreateNew(); |
48 | 413 board[currX][currY] = currPiece; |
414 return true; | |
415 } | |
416 else | |
53 | 417 if (piece.getType() == PieceType.START) |
48 | 418 { |
419 if (currPiece != null) | |
420 { | |
421 // Hit center starting piece, game over | |
422 flagGameOver = true; | |
423 return true; | |
424 } | |
425 else | |
426 { | |
427 // Start piece as first piece means game is starting | |
428 pieceMoveTo(currPoint); | |
54 | 429 pieceCreateNew(); |
48 | 430 board[currX][currY] = currPiece; |
431 return true; | |
432 } | |
433 } | |
434 | |
435 // Mark the current piece as locked | |
53 | 436 piece.setType(PieceType.LOCKED); |
48 | 437 |
438 // Solve connection (with rotations) through the piece | |
53 | 439 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint)); |
48 | 440 |
441 // Mark connection as active | |
53 | 442 piece.setConnectionState(currPoint, true); |
48 | 443 |
444 // Solve exit point (with rotations) | |
53 | 445 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint)); |
48 | 446 |
447 // Move to next position accordingly | |
448 pieceMoveTo(currPoint); | |
449 return false; | |
450 } | |
451 | |
75 | 452 // Finish one move/turn of the game, resolve path and find placement |
453 // of the next piece, or set "game over" state if required. | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
454 public void pieceFinishTurn() |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
455 { |
48 | 456 boolean finished = false; |
55 | 457 int connections = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
458 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
459 if (currPiece != null) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
460 { |
75 | 461 G.smgr.play(sndPlaced); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
462 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
463 |
48 | 464 while (!finished) |
7 | 465 { |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
466 if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize) |
27 | 467 { |
135
a33fdb1de11c
Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
468 int oldX = currX, oldY = currY; |
55 | 469 connections++; |
48 | 470 finished = pieceCheck(board[currX][currY]); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
471 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
472 if (!finished) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
473 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
474 Lock write = pointLock.writeLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
475 write.lock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
476 try |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
477 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
478 pointElems.add(new AnimatedPointElement( |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
479 new IDMPoint( |
135
a33fdb1de11c
Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
480 getScaledX() + ((oldX + 0.5f) * pscale), |
a33fdb1de11c
Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
481 getScaledY() + ((oldY + 0.5f) * pscale)), |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
482 "" + connections)); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
483 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
484 finally |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
485 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
486 write.unlock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
487 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
488 } |
135
a33fdb1de11c
Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
489 |
27 | 490 } |
491 else | |
492 { | |
46 | 493 // Outside of the board, game over |
48 | 494 finished = true; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
495 flagGameOver = true; |
7 | 496 } |
497 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
498 |
66 | 499 // Compute and add score |
55 | 500 gameScore += connections * connections; |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
501 moves++; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
502 |
66 | 503 // If game over, clear the game |
53 | 504 if (flagGameOver) |
505 { | |
506 currPiece = null; | |
507 } | |
139
be9cc2ee3c16
Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
508 |
be9cc2ee3c16
Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
509 flagBoardIsDirty = true; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
510 } |
66 | 511 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
512 public boolean mouseWheelMoved(MouseWheelEvent e) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
513 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
514 int notches = e.getWheelRotation(); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
515 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
516 if (notches < 0) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
517 pieceRotate(Piece.RotateDir.LEFT); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
518 else |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
519 pieceRotate(Piece.RotateDir.RIGHT); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
520 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
521 return true; |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
522 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
523 |
75 | 524 public void clicked() |
525 { | |
77
d17db72ac770
Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
526 if (!flagGameOver) |
d17db72ac770
Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
527 pieceFinishTurn(); |
75 | 528 } |
47 | 529 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
530 public boolean keyPressed(KeyEvent e) |
47 | 531 { |
54 | 532 if (flagGameOver) |
533 return false; | |
534 | |
47 | 535 switch (e.getKeyCode()) |
536 { | |
537 case KeyEvent.VK_LEFT: | |
538 case KeyEvent.VK_UP: | |
539 pieceRotate(Piece.RotateDir.LEFT); | |
540 return true; | |
541 | |
542 case KeyEvent.VK_RIGHT: | |
543 case KeyEvent.VK_DOWN: | |
544 pieceRotate(Piece.RotateDir.RIGHT); | |
545 return true; | |
546 | |
547 case KeyEvent.VK_ENTER: | |
548 pieceFinishTurn(); | |
549 return true; | |
550 } | |
551 return false; | |
552 } | |
1 | 553 } |
554 | |
555 | |
9 | 556 public class Engine extends JPanel |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
557 implements Runnable, KeyListener, |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
558 MouseListener, MouseWheelListener |
1 | 559 { |
164 | 560 double startTime; |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
561 float gameUpdates, gameFrames; |
75 | 562 |
8 | 563 Thread animThread; |
564 boolean animEnable = false; | |
25 | 565 |
4 | 566 GameBoard lauta = null; |
69
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
567 InputStream musa; |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
568 IDMWindow widgets; |
75 | 569 AboutBox aboutBox; |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
570 NewGameDialog newGameDialog; |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
571 |
147 | 572 public void dbg(String msg) |
573 { | |
574 System.out.print("Engine: " + msg); | |
575 } | |
576 | |
9 | 577 public Engine() |
2 | 578 { |
25 | 579 // Initialize globals |
580 System.out.print("Engine() constructor\n"); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
581 |
37 | 582 // Sound system |
133
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
583 G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 1); |
9 | 584 |
25 | 585 // Load resources |
4 | 586 try |
587 { | |
24 | 588 ResourceLoader res = new ResourceLoader("graphics/board.jpg"); |
75 | 589 G.lautaBG = ImageIO.read(res.getStream()); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
590 |
25 | 591 try { |
592 res = new ResourceLoader("graphics/font.ttf"); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
593 |
183
cf0256f13612
Remove global number of fonts static.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
594 G.fonts = new Font[4]; |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
595 G.baseFont = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); |
179 | 596 |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
597 setupDerivedFonts(1.0f); |
25 | 598 } |
599 catch (FontFormatException e) | |
600 { | |
147 | 601 dbg("Could not initialize fonts.\n"); |
25 | 602 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
603 |
69
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
604 res = new ResourceLoader("sounds/gamemusic.wav"); |
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
605 musa = res.getStream(); |
4 | 606 } |
607 catch (IOException e) | |
608 { | |
609 JOptionPane.showMessageDialog(null, | |
21 | 610 e.getMessage(), |
4 | 611 "Initialization error", |
612 JOptionPane.ERROR_MESSAGE); | |
37 | 613 |
147 | 614 dbg(e.getMessage()); |
18 | 615 } |
616 | |
52 | 617 // Create IDM GUI widgets |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
618 widgets = new IDMWindow(); |
52 | 619 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
620 lauta = new GameBoard(new IDMPoint(95, 130), 63); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
621 widgets.add(lauta); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
622 |
75 | 623 widgets.add(new BtnSwapPiece(767f, 450f)); |
124
fa1b86b632aa
Slight changes in UI buttons placement to match the graphics changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
119
diff
changeset
|
624 widgets.add(new BtnAbout (767f, 550f)); |
fa1b86b632aa
Slight changes in UI buttons placement to match the graphics changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
119
diff
changeset
|
625 widgets.add(new BtnNewGame (767f, 630f)); |
50 | 626 |
75 | 627 aboutBox = new AboutBox(); |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
628 newGameDialog = new NewGameDialog(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
629 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
630 // Game |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
631 startNewGame(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
632 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
633 // Initialize event listeners |
18 | 634 addKeyListener(this); |
635 addMouseListener(this); | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
636 addMouseWheelListener(this); |
18 | 637 |
93 | 638 // Start playing background music |
639 G.smgr.play(musa); | |
640 | |
18 | 641 // Get initial focus |
642 if (!hasFocus()) | |
643 { | |
147 | 644 dbg("Requesting focus.\n"); |
18 | 645 requestFocus(); |
4 | 646 } |
93 | 647 |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
648 gameUpdates = 0; |
164 | 649 startTime = System.currentTimeMillis(); |
8 | 650 } |
651 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
652 public void startNewGame() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
653 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
654 gameFrames = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
655 lauta.startNewGame(); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
656 } |
25 | 657 |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
658 public void setupDerivedFonts(float scale) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
659 { |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
660 G.fonts[0] = G.baseFont.deriveFont(16f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
661 G.fonts[1] = G.baseFont.deriveFont(22f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
662 G.fonts[2] = G.baseFont.deriveFont(62f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
663 G.fonts[3] = G.baseFont.deriveFont(32f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
664 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
665 |
25 | 666 public void paintComponent(Graphics g) |
667 { | |
668 Graphics2D g2 = (Graphics2D) g; | |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
669 boolean scaleChanged = false, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
670 updateBoard = lauta.isBoardDirty(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
671 |
52 | 672 // Rescale if parent component size has changed |
25 | 673 Dimension dim = getSize(); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
674 if (G.screenDim == null || !dim.equals(G.screenDim) || G.metrics == null) |
25 | 675 { |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
676 dbg("Scale changed.\n"); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
677 scaleChanged = true; |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
678 updateBoard = true; |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
679 |
133
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
680 float dw = dim.width / 1024.0f, |
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
681 dh = dim.height / 768.0f; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
682 |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
683 G.screenDim = dim; |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
684 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
685 // Rescale fonts |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
686 setupDerivedFonts(dw); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
687 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
688 // Get font metrics against current Graphics2D context |
183
cf0256f13612
Remove global number of fonts static.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
689 G.metrics = new FontMetrics[G.fonts.length]; |
cf0256f13612
Remove global number of fonts static.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
690 for (int i = 0; i < G.fonts.length; i++) |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
691 G.metrics[i] = g2.getFontMetrics(G.fonts[i]); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
692 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
693 // Rescale IDM GUI widgets |
133
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
694 widgets.setScale(dw, dh); |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
695 } |
179 | 696 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
697 if (updateBoard) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
698 { |
147 | 699 // dbg("updateBoard()\n"); |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
700 G.lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
701 Graphics2D gimg = G.lautaBGScaled.createGraphics(); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
702 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
703 RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
704 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
705 gimg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
706 RenderingHints.VALUE_ANTIALIAS_ON); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
707 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
708 gimg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
709 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
710 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
711 gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
712 lauta.paintBackPlate(gimg); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
713 lauta.paintBoard(gimg, false); |
25 | 714 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
715 |
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
716 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
717 // Draw background image, pieces, widgets |
75 | 718 g2.drawImage(G.lautaBGScaled, 0, 0, null); |
86
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
719 |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
720 // Use antialiasing when rendering the game elements |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
721 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
722 RenderingHints.VALUE_ANTIALIAS_ON); |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
723 |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
724 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
725 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
726 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
727 widgets.paint(g2); |
55 | 728 |
75 | 729 |
730 // Frames per second counter | |
155
1ba6f56203f2
Disable FPS counter for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
731 /* |
75 | 732 g2.setFont(G.fonts[1]); |
25 | 733 long currTime = new Date().getTime(); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
734 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20); |
155
1ba6f56203f2
Disable FPS counter for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
735 */ |
168 | 736 |
737 Toolkit.getDefaultToolkit().sync(); | |
75 | 738 gameFrames++; |
25 | 739 } |
740 | |
8 | 741 public void startThreads() |
742 { | |
147 | 743 dbg("startThreads()\n"); |
8 | 744 if (animThread == null) |
745 { | |
746 animThread = new Thread(this); | |
747 animEnable = true; | |
748 animThread.start(); | |
749 } | |
750 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
751 |
8 | 752 public void stopThreads() |
753 { | |
147 | 754 dbg("stopThreads()\n"); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
755 |
37 | 756 // Stop animations |
8 | 757 if (animThread != null) |
758 { | |
759 animThread.interrupt(); | |
760 animEnable = false; | |
761 animThread = null; | |
762 } | |
22 | 763 |
37 | 764 // Shut down sound manager |
75 | 765 G.smgr.close(); |
2 | 766 } |
0 | 767 |
75 | 768 public void mouseEntered(MouseEvent e) |
769 { | |
770 widgets.mouseEntered(e); | |
771 } | |
772 public void mouseExited(MouseEvent e) | |
773 { | |
774 widgets.mouseExited(e); | |
775 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
776 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
777 public void mousePressed(MouseEvent e) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
778 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
779 widgets.mousePressed(e); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
780 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
781 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
782 public void mouseReleased(MouseEvent e) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
783 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
784 widgets.mouseReleased(e); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
785 } |
18 | 786 |
787 public void mouseClicked(MouseEvent e) | |
788 { | |
789 if (!hasFocus()) | |
790 { | |
147 | 791 dbg("Requesting focus.\n"); |
18 | 792 requestFocus(); |
793 } | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
794 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
795 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
796 public void mouseWheelMoved(MouseWheelEvent e) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
797 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
798 if (widgets.getActiveModalWidget() == null) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
799 lauta.mouseWheelMoved(e); |
18 | 800 } |
801 | |
75 | 802 public void keyTyped(KeyEvent e) { } |
803 public void keyReleased(KeyEvent e) { } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
804 |
9 | 805 public void keyPressed(KeyEvent e) |
2 | 806 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
807 widgets.keyPressed(e); |
2 | 808 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
809 |
8 | 810 public void run() |
811 { | |
812 while (animEnable) | |
813 { | |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
814 // Progress game animation clock |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
815 gameUpdates++; |
9 | 816 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
817 // Animate components |
164 | 818 int tmp = (int) ((System.currentTimeMillis() - startTime) / 10f); |
819 lauta.animate(tmp); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
820 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
821 // Repaint with a frame limiter |
168 | 822 if (gameUpdates % 2 == 1) |
10 | 823 repaint(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
824 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
825 // Sleep for a moment |
9 | 826 try { |
168 | 827 Thread.sleep(15); |
9 | 828 } |
829 catch (InterruptedException x) { | |
830 } | |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
831 |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
832 String msg; |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
833 do { |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
834 msg = widgets.getMessage(); |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
835 if (msg != null && msg == "NEWGAME") |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
836 startNewGame(); |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
837 } while (msg != null); |
8 | 838 } |
839 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
840 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
841 class BtnNewGame extends IDMButton |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
842 { |
51 | 843 public BtnNewGame(float x, float y) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
844 { |
75 | 845 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "New Game"); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
846 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
847 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
848 public void clicked() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
849 { |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
850 if (!lauta.flagGameOver && lauta.moves > 0) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
851 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
852 if (!widgets.containsObject(newGameDialog)) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
853 widgets.add(newGameDialog); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
854 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
855 else |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
856 sendMessage("NEWGAME"); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
857 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
858 } |
50 | 859 |
860 class BtnSwapPiece extends IDMButton | |
861 { | |
51 | 862 public BtnSwapPiece(float x, float y) |
50 | 863 { |
75 | 864 super(x, y, KeyEvent.VK_SPACE, G.fonts[1], "Swap"); |
50 | 865 } |
866 | |
867 public void clicked() | |
868 { | |
54 | 869 lauta.pieceSwapCurrent(); |
50 | 870 } |
871 } | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
872 |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
873 class BtnAbout extends IDMButton |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
874 { |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
875 public BtnAbout(float x, float y) |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
876 { |
75 | 877 super(x, y, KeyEvent.VK_A, G.fonts[1], "About"); |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
878 } |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
879 |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
880 public void clicked() |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
881 { |
75 | 882 if (!widgets.containsObject(aboutBox)) |
883 widgets.add(aboutBox); | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
884 } |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
885 } |
0 | 886 } |