annotate game/Engine.java @ 70:2a7fd02504fa

Disable music again.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 Feb 2011 08:29:22 +0200
parents 163232ec225b
children 855757ab8580
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
2 * Ristipolku Game Engine
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 */
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
5 package game;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
6
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 import java.awt.*;
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 import java.awt.geom.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
9 import java.awt.event.*;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
10 import java.awt.image.*;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
11 import java.awt.event.*;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
12 import java.awt.font.*;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
13 import javax.imageio.*;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
14 import javax.swing.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
15 import java.util.*;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
16 import java.io.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
17 import game.*;
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
18 import javax.sound.sampled.*;
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
19
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
20
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
21 /*
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
22 class AnimatedElement
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
23 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
24 float x, y, stime, value;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
25 Interpolate lerp;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
26 boolean active;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
27
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
28 public AnimatedElement(float x, float y, )
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
29 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
30 stime = 0;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
31 this.x = x;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
32 this.y = y;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
33
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
34 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
35
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
36 public animate(float time)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
37 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
38 if (!active)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
39 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
40 active = true;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
41 stime = time;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
42 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
43
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
44 float t = (time - stime) / 10.0f;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
45 if (t < 100)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
46 value = lerp.getValue(t);
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
47 else
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
48 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
49
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
50 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
51 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
52
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
53 public paint(Graphics2D g, );
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
54 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
55 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
56 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
57 */
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
59 class GameBoard extends IDMWidget
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
61 public static final int boardSize = 9;
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
62 public static final int boardMiddle = 4;
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
63 Piece[][] board;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
64 float pscale;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
65
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
66 public boolean flagGameOver;
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
67 public int gameScore;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
68
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
69 public Piece currPiece, nextPiece;
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
70 int currX, currY, currPoint;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
71
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
72
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
73 SoundManager soundManager;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
74 Sound sndPlaced;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
75
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
76 public GameBoard(IDMPoint pos, SoundManager smgr, float pscale)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
77 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
78 super(pos);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
79 this.pscale = pscale;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
80
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
81 soundManager = smgr;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
82 // sndPlaced = soundManager.getSound("sounds/placed.wav");
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
83
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
84 startNewGame();
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
85 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
86
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
87 public void startNewGame()
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
88 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
89 board = new Piece[boardSize][boardSize];
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
90 board[boardMiddle][boardMiddle] = new Piece(PieceType.START);
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
91
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
92 currX = boardMiddle;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
93 currY = boardMiddle;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
94 currPoint = 0;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
95
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
96 currPiece = null;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
97 nextPiece = new Piece(PieceType.ACTIVE);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
98
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
99 flagGameOver = false;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
100 pieceFinishTurn();
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
101 gameScore = 0;
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
102 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
104 public void paintBackPlate(Graphics2D g)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
105 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
106 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
107 g.setStroke(new BasicStroke(5.0f));
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
108 g.draw(new RoundRectangle2D.Float(getScaledX(), getScaledY(),
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
109 boardSize * pscale, boardSize * pscale,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
110 pscale / 5, pscale / 5));
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
111 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
112
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
113 public void paint(Graphics2D g)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
114 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
115 for (int y = 0; y < boardSize; y++)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
116 for (int x = 0; x < boardSize; x++)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
117 if (board[x][y] != null)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
118 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
119 board[x][y].paint(g,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
120 getScaledX() + (x * pscale),
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
121 getScaledY() + (y * pscale),
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
122 pscale - pscale / 10);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
123 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
124 }
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
125
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
126 public boolean contains(Point where)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
127 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
128 return (where.x >= getScaledX() && where.y >= getScaledY() &&
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
129 where.x < getScaledX() + boardSize * pscale &&
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
130 where.y < getScaledY() + boardSize * pscale);
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
131 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
132
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
133 public void animate(float time)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
134 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
135 for (int y = 0; y < boardSize; y++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
136 for (int x = 0; x < boardSize; x++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
137 if (board[x][y] != null)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
138 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
139 board[x][y].animate(time);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
140 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
141 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
142
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
143 public void pieceRotate(Piece.RotateDir dir)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
144 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
145 if (currPiece != null && !flagGameOver)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
146 {
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
147 currPiece.rotate(dir);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
148 }
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
149 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
150
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
151 private void pieceMoveTo(int point)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
152 {
46
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
153 switch (point)
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
154 {
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
155 case 0: currY--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
156 case 1: currY--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
157
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
158 case 2: currX++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
159 case 3: currX++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
160
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
161 case 4: currY++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
162 case 5: currY++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
163
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
164 case 6: currX--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
165 case 7: currX--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
166 }
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
167 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
168
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
169 public void pieceCreateNew()
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
170 {
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
171 currPiece = nextPiece;
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
172 nextPiece = new Piece(PieceType.ACTIVE);
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
173 }
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
174
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
175 public void pieceSwapCurrent()
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
176 {
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
177 if (!flagGameOver)
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
178 {
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
179 Piece tmp = currPiece;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
180 currPiece = nextPiece;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
181 nextPiece = tmp;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
182 board[currX][currY] = currPiece;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
183 }
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
184 }
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
185
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
186 public boolean pieceCheck(Piece piece)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
187 {
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
188 if (piece == null)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
189 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
190 // Create new piece
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
191 pieceCreateNew();
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
192 board[currX][currY] = currPiece;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
193 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
194 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
195 else
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
196 if (piece.getType() == PieceType.START)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
197 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
198 if (currPiece != null)
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
199 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
200 // Hit center starting piece, game over
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
201 flagGameOver = true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
202 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
203 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
204 else
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
205 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
206 // Start piece as first piece means game is starting
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
207 pieceMoveTo(currPoint);
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
208 pieceCreateNew();
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
209 board[currX][currY] = currPiece;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
210 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
211 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
212 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
213
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
214 // Mark the current piece as locked
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
215 piece.setType(PieceType.LOCKED);
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
216
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
217 // Solve connection (with rotations) through the piece
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
218 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint));
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
219
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
220 // Mark connection as active
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
221 piece.setConnectionState(currPoint, true);
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
222
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
223 // Solve exit point (with rotations)
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
224 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint));
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
225
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
226 // Move to next position accordingly
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
227 pieceMoveTo(currPoint);
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
228 return false;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
229 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
230
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
231 public void pieceFinishTurn()
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
232 {
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
233 boolean finished = false;
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
234 int connections = 0;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
235
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
236 if (currPiece != null)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
237 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
238 soundManager.play(sndPlaced);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
239 }
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
240
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
241 while (!finished)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
242 {
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
243 if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize)
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
244 {
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
245 connections++;
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
246 finished = pieceCheck(board[currX][currY]);
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
247 }
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
248 else
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
249 {
46
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
250 // Outside of the board, game over
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
251 finished = true;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
252 flagGameOver = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
253 }
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
254 }
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
255
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
256 // Compute and add score
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
257 gameScore += connections * connections;
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
258
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
259 // If game over, clear the game
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
260 if (flagGameOver)
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
261 {
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
262 currPiece = null;
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
263 }
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
264 }
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
265
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
266 public boolean mouseWheelMoved(MouseWheelEvent e)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
267 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
268 int notches = e.getWheelRotation();
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
269
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
270 if (notches < 0)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
271 pieceRotate(Piece.RotateDir.LEFT);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
272 else
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
273 pieceRotate(Piece.RotateDir.RIGHT);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
274
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
275 return true;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
276 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
277
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
278 public boolean mouseClicked(MouseEvent e)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
279 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
280 if (flagGameOver)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
281 return false;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
282
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
283 if (contains(e.getPoint()))
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
284 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
285 pieceFinishTurn();
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
286 return true;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
287 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
288 else
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
289 return false;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
290 }
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
291
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
292 public boolean keyPressed(KeyEvent e)
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
293 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
294 if (flagGameOver)
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
295 return false;
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
296
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
297 switch (e.getKeyCode())
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
298 {
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
299 case KeyEvent.VK_LEFT:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
300 case KeyEvent.VK_UP:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
301 pieceRotate(Piece.RotateDir.LEFT);
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
302 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
303
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
304 case KeyEvent.VK_RIGHT:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
305 case KeyEvent.VK_DOWN:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
306 pieceRotate(Piece.RotateDir.RIGHT);
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
307 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
308
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
309 case KeyEvent.VK_ENTER:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
310 pieceFinishTurn();
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
311 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
312 }
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
313 return false;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
314 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
315 }
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
316
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
317
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
318 public class Engine extends JPanel
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
319 implements Runnable, KeyListener,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
320 MouseListener, MouseWheelListener
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
321 {
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
322 long startTime;
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
323 float gameClock, gameFrames;
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
324 Thread animThread;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
325 boolean animEnable = false;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
326
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
327 Font fontMain, font1, font2;
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
328 FontMetrics metrics1, metrics2;
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
329
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
330 GameBoard lauta = null;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
331 BufferedImage lautaBG = null, lautaBGScaled = null;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
332 Dimension lautaDim;
22
afde253ec705 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
333
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
334 static final AudioFormat sfmt = new AudioFormat(22050, 16, 1, true, false);
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
335 SoundManager soundManager;
69
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
336 InputStream musa;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
337
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
338 boolean aboutEnabled = false, aboutSecret = false;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
339 BufferedImage aboutImg = null;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
340
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
341 IDMContainer widgets;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
342
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
343 public Engine()
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
344 {
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
345 // Initialize globals
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
346 System.out.print("Engine() constructor\n");
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
347
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
348 // Sound system
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
349 soundManager = new SoundManager(sfmt, 16);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
350
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
351 // Load resources
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
352 try
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
353 {
24
1be98362e5e9 FPS measurement.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
354 ResourceLoader res = new ResourceLoader("graphics/board.jpg");
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
355 lautaBG = ImageIO.read(res.getStream());
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
356
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
357 res = new ResourceLoader("graphics/lavina.jpg");
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
358 aboutImg = ImageIO.read(res.getStream());
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
359
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
360 try {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
361 res = new ResourceLoader("graphics/font.ttf");
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
362 fontMain = Font.createFont(Font.TRUETYPE_FONT, res.getStream());
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
363
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
364 font1 = fontMain.deriveFont(24f);
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
365 font2 = fontMain.deriveFont(64f);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
366 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
367 catch (FontFormatException e)
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
368 {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
369 System.out.print("Could not initialize fonts.\n");
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
370 }
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
371
69
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
372 res = new ResourceLoader("sounds/gamemusic.wav");
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
373 musa = res.getStream();
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
374 }
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
375 catch (IOException e)
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
376 {
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
377 JOptionPane.showMessageDialog(null,
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
378 e.getMessage(),
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
379 "Initialization error",
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
380 JOptionPane.ERROR_MESSAGE);
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
381
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
382 System.out.print(e.getMessage());
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
383 }
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
384
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
385 // Create IDM GUI widgets
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
386 widgets = new IDMContainer();
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
387
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
388 widgets.add(new BtnSwapPiece(0.75f, 0.60f));
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
389 widgets.add(new BtnAbout(0.75f, 0.75f));
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
390 widgets.add(new BtnNewGame(0.75f, 0.85f));
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
391
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
392 lauta = new GameBoard(new IDMPoint(0.09f, 0.18f), soundManager, 63);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
393 widgets.add(lauta);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
394
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
395 // Game
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
396 aboutEnabled = false;
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
397 startNewGame();
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
398
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
399 // Initialize event listeners
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
400 addKeyListener(this);
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
401 addMouseListener(this);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
402 addMouseWheelListener(this);
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
403
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
404 // Get initial focus
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
405 if (!hasFocus())
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
406 {
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
407 System.out.print("Engine(): requesting focus\n");
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
408 requestFocus();
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
409 }
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
410
70
2a7fd02504fa Disable music again.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
411 // soundManager.play(musa);
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
412 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
413
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
414 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
415 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
416 gameClock = 0;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
417 gameFrames = 0;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
418 startTime = new Date().getTime();
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
419 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
420 }
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
421
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
422 public void paintAbout(Graphics2D g)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
423 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
424 int width = lautaDim.width / 2,
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
425 height = lautaDim.height / 4;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
426
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
427 int x = (lautaDim.width - width) / 2,
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
428 y = (lautaDim.height - height) / 2;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
429
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
430 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f));
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
431 g.fill(new RoundRectangle2D.Float(x, y, width, height, 10, 10));
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
432
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
433
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
434 g.setFont(font1);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
435 g.setPaint(Color.white);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
436
67
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
437 g.drawString("RistiPolku (CrossPaths) v0.5", x + 10, y + 25);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
438 if (aboutSecret)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
439 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
440 g.drawImage(aboutImg, x + 15, y + 35, aboutImg.getWidth(), aboutImg.getHeight(), null);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
441 g.drawString("Dedicated to my", x + 225, y + 55);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
442 g.drawString("favorite woman", x + 225, y + 85);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
443 g.drawString("in the world.", x + 225, y + 115);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
444 g.drawString("- Matti", x + 350, y + 155);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
445 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
446 else
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
447 {
68
52897e3865bf Text color in about box.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
448 g.setPaint(Color.yellow);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
449 g.drawString("(c) Copyright 2011 Matti 'ccr' Hämäläinen", x + 10, y + 55);
67
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
450
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
451 g.setPaint(Color.white);
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
452 g.drawString("Programming project for Java-course", x + 10, y + 105);
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
453 g.drawString("T740306 taught by Kari Laitinen.", x + 10, y + 135);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
454 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
455 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
456
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
457 public void paintComponent(Graphics g)
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
458 {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
459 Graphics2D g2 = (Graphics2D) g;
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
460
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
461 // Use antialiasing when rendering the game elements
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
462 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
463 RenderingHints.VALUE_ANTIALIAS_ON);
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
464
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
465 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
466 RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
467
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
468
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
469 // Rescale if parent component size has changed
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
470 Dimension dim = getSize();
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
471 if (lautaDim == null || !dim.equals(lautaDim))
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
472 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
473 // Rescale IDM GUI widgets
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
474 widgets.setScale(dim.width, dim.height);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
475
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
476 // Rescale background image
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
477 lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
478 Graphics2D gimg = lautaBGScaled.createGraphics();
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
479 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
480 RenderingHints.VALUE_INTERPOLATION_BICUBIC);
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
481
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
482 gimg.drawImage(lautaBG, 0, 0, dim.width, dim.height, null);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
483 lauta.paintBackPlate(gimg);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
484 lautaDim = dim;
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
485
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
486 System.out.print("scale changed\n");
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
487 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
488
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
489 // Get font metrics against current Graphics2D context
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
490 if (metrics1 == null)
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
491 metrics1 = g2.getFontMetrics(font1);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
492
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
493 if (metrics2 == null)
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
494 metrics2 = g2.getFontMetrics(font2);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
495
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
496
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
497 // Draw background image, pieces, widgets
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
498 g2.drawImage(lautaBGScaled, 0, 0, null);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
499 widgets.paint(g2);
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
500
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
501 if (!lauta.flagGameOver)
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
502 {
62
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
503 if (lauta.nextPiece != null)
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
504 {
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
505 // Draw next piece
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
506 AffineTransform save = g2.getTransform();
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
507 lauta.nextPiece.paint(g2, 830, 325, 90);
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
508 g2.setTransform(save);
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
509 }
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
510 }
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
511 else
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
512 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
513 // Game over text
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
514 String text = "Game Over!";
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
515 int textWidth = metrics2.stringWidth(text);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
516 g2.setFont(font2);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
517
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
518 g2.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f));
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
519 g2.drawString(text, (dim.width - textWidth) / 2 + 5, dim.height / 2 + 5);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
520
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
521 double f = Math.sin(gameClock * 0.1) * 4.0;
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
522 g2.setPaint(Color.white);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
523 g2.drawString(text, (dim.width - textWidth) / 2 + (float) f, dim.height / 2 + (float) f);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
524 }
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
525
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
526 // Scores, etc
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
527 g2.setFont(font2);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
528 g2.setPaint(Color.white);
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
529
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
530 g2.drawString(""+ String.format("%05d", lauta.gameScore), dim.width - 230, 220);
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
531
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
532 g2.setFont(font1);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
533 long currTime = new Date().getTime();
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
534 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
535
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
536 if (aboutEnabled)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
537 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
538 paintAbout(g2);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
539 }
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
540 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
541
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
542 public void startThreads()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
543 {
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
544 System.out.print("startThreads()\n");
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
545 if (animThread == null)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
546 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
547 animThread = new Thread(this);
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
548 animEnable = true;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
549 animThread.start();
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
550 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
551 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
552
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
553 public void stopThreads()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
554 {
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
555 System.out.print("stopThreads()\n");
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
556
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
557 // Stop animations
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
558 if (animThread != null)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
559 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
560 animThread.interrupt();
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
561 animEnable = false;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
562 animThread = null;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
563 }
22
afde253ec705 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
564
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
565 // Shut down sound manager
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
566 soundManager.close();
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
567 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
569 public void mouseEntered(MouseEvent e) { }
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
570 public void mouseExited(MouseEvent e) { }
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
571
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
572 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
573 {
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
574 if (!aboutEnabled)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
575 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
576 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
577
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
578 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
579 {
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
580 if (!aboutEnabled)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
581 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
582 }
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
583
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
584 public void mouseClicked(MouseEvent e)
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
585 {
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
586 if (!hasFocus())
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
587 {
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
588 System.out.print("Requesting focus\n");
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
589 requestFocus();
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
590 }
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
591 if (!aboutEnabled)
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
592 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
593 lauta.mouseClicked(e);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
594 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
595 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
596
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
597 public void mouseWheelMoved(MouseWheelEvent e)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
598 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
599 lauta.mouseWheelMoved(e);
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
600 }
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
601
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
602 public void keyTyped(KeyEvent e)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
603 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
604 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
605
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
606 public void keyReleased(KeyEvent e)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
607 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
608 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
609
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
610 public void keyPressed(KeyEvent e)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
611 {
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
612 if (aboutEnabled)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
613 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
614 if (e.getKeyCode() == KeyEvent.VK_L)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
615 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
616 aboutSecret = true;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
617 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
618 else
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
619 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
620 aboutEnabled = false;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
621 aboutSecret = false;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
622 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
623 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
624 else
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
625 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
626 // Handle keyboard input
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
627 if (lauta.keyPressed(e))
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
628 return;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
629
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
630 widgets.keyPressed(e);
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
631 }
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
632 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
633
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
634 public void run()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
635 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
636 while (animEnable)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
637 {
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
638 // Progress game animation clock
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
639 gameClock++;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
640
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
641 // Animate components
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
642 lauta.animate(gameClock);
62
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
643 if (lauta.nextPiece != null)
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
644 lauta.nextPiece.animate(gameClock);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
645
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
646 // Repaint with a frame limiter
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
647 if (gameClock % 4 == 1)
24
1be98362e5e9 FPS measurement.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
648 {
10
4bacc98973f5 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
649 repaint();
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
650 gameFrames++;
24
1be98362e5e9 FPS measurement.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
651 }
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
652
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
653 // Sleep for a moment
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
654 try {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
655 Thread.sleep(10);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
656 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
657 catch (InterruptedException x) {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
658 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
659 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
660 }
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
661
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
662 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
663 {
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
664 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
665 {
67
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
666 super(x, y, KeyEvent.VK_ESCAPE, font1, "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
667 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
668
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
669 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
670 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
671 startNewGame();
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
672 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
673 }
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
674
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
675 class BtnSwapPiece extends IDMButton
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
676 {
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
677 public BtnSwapPiece(float x, float y)
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
678 {
67
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
679 super(x, y, KeyEvent.VK_SPACE, font1, "Swap");
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
680 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
681
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
682 public void clicked()
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
683 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
684 lauta.pieceSwapCurrent();
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
685 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
686 }
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
687
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
688 class BtnAbout extends IDMButton
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
689 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
690 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
691 {
67
b47f874db6be Change language to English.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
692 super(x, y, KeyEvent.VK_A, font1, "About");
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
693 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
694
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
695 public void clicked()
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
696 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
697 aboutEnabled = true;
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
698 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
699 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 }