Juego de Snake en Emu8086
Publicado por eusebio (1 intervención) el 19/05/2017 06:45:58
hola, soy nuevo en esto, me podrían ayudar con el juego de snake, necesito que incremente cuando se tope con algo "comida", ya tengo el gusanito y sus movimientos, pero me falta que incremente al comer algo.
este es mi codigo en Emu8086.
este es mi codigo en Emu8086.
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
name "snake"
org 100h
; jump over data section:
jmp start
; ------ data section ------
s_size equ 7
; the snake coordinates
; (from head to tail)
; low byte is left, high byte
; is top - [top, left]
snake dw s_size dup(0)
tail dw ?
; ENUMS for grow_state
NO_CHANGE = 0
BIGGER = 1
SMALLER = 2
NSEOI_OCW2 = 00100001b
PC_PIC = 20h
; direction constants
; (bios key codes):
left equ 4bh
right equ 4dh
up equ 48h
down equ 50h
cur_dir db right
wait_time dw 0
start:
; variables used for random
food_x DB 1 ; cordinates of the next food
food_y DB 1 ;
attribute DB 13 ; color of next food
char DB 41h ; char of next food
food_type DB 1 ; type of next food,
;0: '-' (makes snake smaller), o.w: ABC char
; variables for current food
cur_food_x DB 0
cur_food_y DB 0
cur_food_type DB 0
cur_food_char DB 0
cur_food_attribute DB 0
grow_state DB NO_CHANGE ; options: NO_CHANGE, BIGGER or SMALLER
ezer_word DW 0
ezer_byte DB 0
ezer_byte2 DB 0
direction_for_next_cycle DB UP ; contains the direction for next
;cycle in main_loop
one_before DB 0 ; flag to use in 'erase_tail' (see there)
.code
mov ax,@data ; ds<-@data
mov ds,ax
;call print_food
;call change_key_stroke_interrupt ; changes the adress of routine resposible to response to key-stroke
; to perform 'update_direction'
;main_loop:
; mov loop_counter,0
;call actions ; performs all tasks for one movement: upadtes snake on screen, checks collision etc
; hide text cursor:
mov ah, 1
mov ch, 2bh
mov cl, 0bh
int 10h
game_loop:
; === select first video page
mov al, 0 ; page number.
mov ah, 05h
int 10h
; === show new head:
mov dx, snake[0]
; set cursor at dl,dh
mov ah, 02h
int 10h
; print '*' at the location:
mov al, '*'
mov ah, 09h
mov bl, 0eh ; attribute.
mov cx, 1 ; single char.
int 10h
; === keep the tail:
mov ax, snake[s_size * 2 - 2]
mov tail, ax
call move_snake
; === hide old tail: solo la cabeza del gusanito cursor
mov dx, tail
; set cursor at dl,dh solo la cabeza del gusanito cursor
mov ah, 02h
int 10h
; print ' ' at the location: necesario para que no se cicle
mov al, ' '
mov ah, 09h
mov bl, 0eh ; attribute.
mov cx, 1 ; single char.
int 10h
check_for_key:
; === check for player commands:
mov ah, 01h
int 16h
jz no_key
mov ah, 00h
int 16h
cmp al, 1bh ; esc - key?
je stop_game ;
mov cur_dir, ah
no_key:
; === wait a few moments here:
; get number of clock ticks
; (about 18 per second)
; since midnight into cx:dx
mov ah, 00h
int 1ah
cmp dx, wait_time
jb check_for_key
add dx, 4
mov wait_time, dx
; === eternal game loop:
jmp game_loop
stop_game:
; show cursor back:
mov ah, 1
mov ch, 0bh
mov cl, 0bh
int 10h
ret
move_snake proc near
; set es to bios info segment:
mov ax, 40h
mov es, ax
; point di to tail
mov di, s_size * 2 - 2
; move all body parts
; (last one simply goes away)
mov cx, s_size-1
move_array:
mov ax, snake[di-2]
mov snake[di], ax
sub di, 2
loop move_array
cmp cur_dir, left
je move_left
cmp cur_dir, right
je move_right
cmp cur_dir, up
je move_up
cmp cur_dir, down
je move_down
jmp stop_move ; no direction.
move_left:
mov al, b.snake[0]
dec al
mov b.snake[0], al
cmp al, -1
jne stop_move
mov al, es:[4ah] ; col number.
dec al
mov b.snake[0], al ; return to right.
jmp stop_move
move_right:
mov al, b.snake[0]
inc al
mov b.snake[0], al
cmp al, es:[4ah] ; col number.
jb stop_move
mov b.snake[0], 0 ; return to left.
jmp stop_move
move_up:
mov al, b.snake[1]
dec al
mov b.snake[1], al
cmp al, -1
jne stop_move
mov al, es:[84h] ; row number -1.
mov b.snake[1], al ; return to bottom.
jmp stop_move
move_down:
mov al, b.snake[1]
inc al
mov b.snake[1], al
cmp al, es:[84h] ; row number -1.
jbe stop_move
mov b.snake[1], 0 ; return to top.
jmp stop_move
;loop_counter,0
stop_move:
ret
move_snake endp
Valora esta pregunta
0