-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgame.gd
67 lines (59 loc) · 1.84 KB
/
game.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
extends Control
# member variables here, example:
# var a=2
# var b="textvar"
const max_width=90
const max_height=60
const min_width=10
const min_height=10
func _ready():
# Called every time the node is added to the scene.
# Initialization here
var node=get_node("vertical/header/new_game")
node.connect("pressed", self, "new_game_pressed")
new_game_pressed()
set_process(true)
func _process(delta):
var board=get_node("vertical/Board")
var new_game=get_node("vertical/header/new_game")
var win=preload("res://images/32x32/facewin.png")
var loose=preload("res://images/32x32/facedie.png")
if board.game_win:
new_game.set_normal_texture(win)
if board.game_over:
new_game.set_normal_texture(loose)
func number_tile_pressed():
var animation=get_node("vertical/header/new_game/new_game_player")
animation.play("surprise")
pass
func new_game_pressed():
var board=get_node("vertical/Board")
var width_node=get_node("vertical/header/cols")
var height_node=get_node("vertical/header/rows")
var bombs_node=get_node("vertical/header/bombs")
var width=int(width_node.get_value())
var height=int(height_node.get_value())
var bombs=int(bombs_node.get_value())
width=check_size(width, max_width, min_width)
height=check_size(height, max_height, min_height)
bombs=check_bombs(bombs, width, height)
board.new_game(width, height, bombs)
var new_game=get_node("vertical/header/new_game")
var smile=preload("res://images/32x32/smile.png")
new_game.set_normal_texture(smile)
var board_width_pixels=width*32 ## TODO avoid this hack
var board_height_pixels=height*32 ## TODO avoid this hack
set_size(Vector2(board_width_pixels, board_height_pixels))
func check_size(s, max_s, min_s):
if s<min_s:
s=min_s
if s>max_s:
s=max_s
return s
func check_bombs(b, w, h):
var localb=b
if b<=0:
localb=10
if b>int(w*h/3.0):
localb=int(w*h/3.0)
return localb