aboutsummaryrefslogtreecommitdiff
path: root/tris
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-09-06 21:47:17 +0200
committerJoop Kiefte <ikojba@gmail.com>2020-09-06 21:47:17 +0200
commitb949c46efbdeb5c76177f643d3082d69987e656e (patch)
tree1b59fadec47b9de2bf5c1db54a4168a88f053246 /tris
parent284ecee1d649fa412a453494e6685e8b556fec60 (diff)
Adding pieces and basic bag mechanics
Diffstat (limited to 'tris')
-rw-r--r--tris/core.go61
1 files changed, 44 insertions, 17 deletions
diff --git a/tris/core.go b/tris/core.go
index 41d1beb..07b4b64 100644
--- a/tris/core.go
+++ b/tris/core.go
@@ -1,30 +1,57 @@
package tris
-type PieceType int
+type Point struct {
+ X, Y int
+}
+
+type Piece [4]uint16
+
+// A table that represents each piece from https://tetris.fandom.com/wiki/SRS
+// in binary starting with 1 top left going per row, here in hexadecimal shorthand.
+var (
+ IPiece = Piece{0x0F00, 0x4444, 0x00F0, 0x2222}
+ JPiece = Piece{0x1700, 0x6220, 0x0740, 0x2230}
+ LPiece = Piece{0x4700, 0x2260, 0x0710, 0x3220}
+ OPiece = Piece{0x6600, 0x6600, 0x6600, 0x6600}
+ SPiece = Piece{0x6300, 0x2640, 0x0630, 0x1320}
+ TPiece = Piece{0x2700, 0x2620, 0x0720, 0x2320}
+ ZPiece = Piece{0x3600, 0x4620, 0x0360, 0x2310}
+)
+
+type Rotation int
const (
- IPiece PieceType = iota
- JPiece
- LPiece
- SPiece
- ZPiece
- TPiece
- OPiece
+ Spawn Rotation = iota
+ Clockwise
+ Flip
+ CounterClockwise
)
-type Point struct {
- X, Y int
+type Placement struct {
+ piece Piece
+ X int
+ Y int
+ Rot Rotation
+ Lock int
}
-type Piece struct {
- Type PieceType
- RelX int
- RelY int
- Layout []Point
- Lock int
+type Bag []Piece
+
+var LockDelay = 30
+
+var ReferenceBag = Bag{IPiece, JPiece, LPiece, OPiece, SPiece, TPiece, ZPiece}
+
+func (b Bag) Randomize() Bag { //TODO: implement randomizer
+ return b
}
-type Bag []Piece
+func (b *Bag) Pick() Placement {
+ if len(*b) == 0 {
+ b = &ReferenceBag.Randomize()
+ }
+ piece := Placement{piece: Bag[0], X: 3, Y: -2, Lock: LockDelay}
+ *b = *b[1:]
+}
type Field [20][10]bool