File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 55
55
best HighScore
56
56
snake []Pos
57
57
dir Direction
58
+ last_dir Direction
58
59
food Pos
59
60
start_time i64
60
61
last_tick i64
@@ -70,6 +71,7 @@ fn (mut app App) reset_game() {
70
71
Pos{0 , 8 },
71
72
]
72
73
app.dir = .right
74
+ app.last_dir = app.dir
73
75
app.food = Pos{10 , 8 }
74
76
app.start_time = time.ticks ()
75
77
app.last_tick = time.ticks ()
@@ -91,22 +93,22 @@ fn (mut app App) move_food() {
91
93
fn on_keydown (key gg.KeyCode, mod gg.Modifier, mut app App) {
92
94
match key {
93
95
.w, .up {
94
- if app.dir != .down {
96
+ if app.last_dir != .down {
95
97
app.dir = .up
96
98
}
97
99
}
98
100
.s, .down {
99
- if app.dir != .up {
101
+ if app.last_dir != .up {
100
102
app.dir = .down
101
103
}
102
104
}
103
105
.a, .left {
104
- if app.dir != .right {
106
+ if app.last_dir != .right {
105
107
app.dir = .left
106
108
}
107
109
}
108
110
.d, .right {
109
- if app.dir != .left {
111
+ if app.last_dir != .left {
110
112
app.dir = .right
111
113
}
112
114
}
@@ -150,6 +152,8 @@ fn on_frame(mut app App) {
150
152
}
151
153
app.snake << app.snake.last () + app.snake.last () - app.snake[app.snake.len - 2 ]
152
154
}
155
+
156
+ app.last_dir = app.dir
153
157
}
154
158
// drawing snake
155
159
for pos in app.snake {
You can’t perform that action at this time.
0 commit comments