It works perfectly.
Code: Select all
# game field
default gf = [
#0 1 2 3 4 5 6 7 8 9
[1,1,1,1,1,1,1,1,1,1], #0
[1,0,0,0,0,0,0,0,0,1], #1
[1,0,0,0,0,0,0,0,0,1], #2
[1,0,0,0,0,0,0,0,0,1], #3
[1,0,0,0,0,0,0,0,0,1], #4
[1,0,0,0,0,0,0,0,0,1], #5
[1,1,1,1,1,1,1,1,1,1] ]
# player's positions
default x = 0
default y = 0
default x_win = 9
default y_win = 6
# game field position and transform
default gf_align = (0.5, -0.4)
transform my_tr():
zoom 1.2
rotate 0
# images
image tile_1:
Solid("#888")
size(50, 50)
image tile_0:
Solid("#000")
size(50, 50)
image token:
Solid("#333")
size(50, 50)
# game screen
screen game_field():
key "focus_left" action SetVariable("x", max(x-1, 0))
key "focus_right" action SetVariable("x", min(x+1, 9))
key "focus_up" action SetVariable("y", max(y-1, 0))
key "focus_down" action SetVariable("y", min(y+1, 6))
# if player at the winning position
if x == x_win and y == y_win:
timer 0.01 action Jump("win_label") repeat False
# for moving left
if x>0: # check if player is not at the left side of field
if gf[y][x-1] != 0: # check if tile at left is not 0
key "focus_left" action SetVariable("x", max(x-1, 0))
else:
key "focus_left" action NullAction()
# for moving right
if x<9: # check if player is not at the right side of field
if gf[y][x+1] != 0: # check if tile at right is not 0
key "focus_right" action SetVariable("x", min(x+1, 9))
else:
key "focus_right" action NullAction()
# for moving up
if y>0: # check if player is not at the top side of field
if gf[y-1][x] != 0: # check if tile above is not 0
key "focus_up" action SetVariable("y", max(y-1, 0))
else:
key "focus_up" action NullAction()
# for moving down
if y<6: # check if player is not at the bottom side of field
if gf[y+1][x] != 0: # check if tile under is not 0
key "focus_down" action SetVariable("y", min(y+1, 6))
else:
key "focus_down" action NullAction()
####################################################################
# DELETED AND ADDING THE KEYS IN THE TOP OF SCREEN (WITHOUT "ELSE")
#------------------------------------------------------------------
# if not yet - let him/her move the token
#else:
# key "focus_left" action SetVariable("x", max(x-1, 0))
# key "focus_right" action SetVariable("x", min(x+1, 9))
# key "focus_up" action SetVariable("y", max(y-1, 0))
# key "focus_down" action SetVariable("y", min(y+1, 6))
# disallow further progress in game
#key "dismiss" action NullAction()
#####################################################################
# game field
grid 10 7 spacing 1:
align gf_align
at my_tr
for row in gf:
for tile in row:
if tile == 1:
add "tile_1"
else:
null
# player's token
grid 10 7 spacing 1:
align gf_align
at my_tr
for py in range(7):
for px in range(10):
if py == y and px == x:
add "token"
else:
null
######################################
# The game starts here.
label start:
"..."
show screen game_field with dissolve
"Use arrow keys to move."
"?!"
label win_label:
"Well done!"
hide screen game_field with dissolve
"... ..."
return
Just add the dice and this minigame will be ready. However, that will remain a task for me.
When I incorporate the dice, I'll put it on this topic and take it for "solved".
I am very happy because I will be able to add this code to my game.
I heartily thank you for what you did for me, Alex.