-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathengine.e
More file actions
187 lines (145 loc) · 4.74 KB
/
Copy pathengine.e
File metadata and controls
187 lines (145 loc) · 4.74 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
note
description: "Summary description for {ENGINE}."
author: "Guillaume Hamel-Gagné"
date: "16 mai 2016"
revision: "1.1"
deferred class
ENGINE
inherit
GAME_LIBRARY_SHARED -- To use `game_library'
IMG_LIBRARY_SHARED -- To use `image_file_library'
AUDIO_LIBRARY_SHARED -- To use `audio_library'
TEXT_LIBRARY_SHARED -- To use `text_library'
feature {NONE}
make
do
window.maximize
create font.make("./ressource/font/font.ttf",24)
font.open
create last_x.make_from_reference (0)
create last_y.make_from_reference (0)
create music_menu.make
create keyboard.make
create command
input_buffer:=""
end
display_mode:GAME_DISPLAY_MODE
-- Permet d'avoir le mode de d'affichage de l'écran principale.
local
l_display_info:GAME_DISPLAY
once
create l_display_info.make (0)
Result:=l_display_info.current_mode
end
window:GAME_WINDOW_SURFACED
-- Dit au programme ou aller chercher l'emplacement de l'image `image_location'.
local
l_window_builder:GAME_WINDOW_SURFACED_BUILDER
once
l_window_builder.set_dimension ((display_mode.width * 0.9).rounded,(display_mode.height * 0.9).rounded)
l_window_builder.enable_border
l_window_builder.set_title("BattleShip")
Result:=l_window_builder.generate_window
end
feature -- Run
run_game
-- Cette routine ajoute des events au controler de la librarie et de la fenêtre, puis lance la librairie.
do
game_library.quit_signal_actions.extend(agent on_quit(?))
game_library.iteration_actions.extend (agent cycle(?))
window.mouse_motion_actions.extend (agent on_mouse_move(?, ?, ?, ?)) -- Lorsque l'utilisateur bouge son curseur sur l'écran
window.mouse_button_pressed_actions.extend (agent on_mouse_click(?,?,?))
window.key_pressed_actions.extend (agent on_key_pressed(?,?))
window.start_text_input
window.text_input_actions.extend (agent on_text_input)
game_library.launch
end
feature -- Implementation
cycle(a_timestamp: NATURAL_32)
-- Routine qui fait les mises à jours de l'écran et des sons.
do
manage_cycle(a_timestamp)
window.update
audio_library.update
end
manage_cycle(a_timestamp: NATURAL_32)
do
end
on_mouse_move(a_timestamp: NATURAL_32;a_mouse_state: GAME_MOUSE_MOTION_STATE; a_delta_x, a_delta_y: INTEGER_32)
-- Routine qui garde en mémoire l'emplacement du curseur lors de ses mouvements.
do
last_x:=a_mouse_state.x
last_y:=a_mouse_state.y
manage_mouse_move(a_timestamp,a_mouse_state,a_delta_x, a_delta_y)
window.update
audio_library.update
end
manage_mouse_move(a_timestamp: NATURAL_32;a_mouse_state: GAME_MOUSE_MOTION_STATE; a_delta_x, a_delta_y: INTEGER_32)
do
end
on_mouse_click(a_timestamp: NATURAL_32;a_mouse_state: GAME_MOUSE_BUTTON_PRESSED_STATE; click_count: NATURAL_8)
-- Routine qui garde en mémoire les actions du curseur lorsqu'un click est effectué.
do
last_x:=a_mouse_state.x
last_y:=a_mouse_state.y
manage_mouse_click(a_timestamp,a_mouse_state,click_count)
window.update
audio_library.update
end
manage_mouse_click(a_timestamp: NATURAL_32;a_mouse_state: GAME_MOUSE_BUTTON_PRESSED_STATE; click_count: NATURAL_8)
do
end
on_key_pressed(a_timestamp: NATURAL_32; a_key_state: GAME_KEY_STATE)
-- Routine qui est lancé lorsqu'un touche du clavier à été appuyé.
-- Elle gère certaine touche et fait quelque chose dépendament quelle à été appuyé.
local
l_input:STRING
do
l_input:=keyboard.get_key (a_key_state)
if l_input.is_equal ("backspace") and (input_buffer.count > 0) then
input_buffer:=input_buffer.substring (1, input_buffer.count-1)
elseif l_input.is_equal ("return") and (input_buffer.count > 0) then
manage_command
end
manage_input(l_input)
window.update
audio_library.update
end
on_text_input(a_timestamp:NATURAL_32; a_text:STRING_32)
-- When the user write a character on the keyboard (does not handle special key like backspace, return, etc.
do
if input_buffer.count < 81 then
input_buffer:= input_buffer + a_text.to_string_8
manage_input(a_text.to_string_8)
end
window.update
audio_library.update
end
manage_input(a_input:STRING)
do
end
manage_command
do
end
feature -- Access
--texts:LINKED_LIST[TUPLE[x, y:INTEGER; text:STRING_32]]
on_quit(a_timestamp: NATURAL_32)
-- Cette routine ferme la librairie, lorsque le bouton X ou la touche escape ont été appuyés.
do
--window.stop_text_input
window.clear_events
game_library.clear_all_events
music_menu.environement_audio.source.stop
game_library.stop -- Arrête le controller en boucle.
end
feature
font:TEXT_FONT
music_menu:SPEAKER
command:COMMAND
last_x, last_y:INTEGER
-- Les dernières positions (x,y) de la sourie.
quit:BOOLEAN
stop:BOOLEAN
keyboard:KEYBOARD
input_buffer:STRING
end