The purpose is to show how easy programming in Hollywood can be, so this first code is stripped down to just what is needed to make it run.
I might add more features to in in follow up posts later.
Prerparations: You should make an image at 640x480 pixels, with a black background representing the maze. The maze in the example is made so that the start position will be at position 225, 235, and the exit close to the upper left corner. Apart from this, you can design the maze walls at your own wish. Just make sure that there is enaugh room between the maze walls for the character to move freely.
You must also draw an image for the character, which can be of the size of your choice, but in the example below the character image is 15x17 pixels.
Save these two images as bg_maze_1.png and character.png, in the same folder as you choose to save the script,
I did add the rest of the explaining as comments in the code, so I hope it will be self explaining.
Code: Select all
LoadBrush(1, "bg_maze_1.png", {Transparency = #BLACK}) ; Maze backgrund image to be loaded as brush id1
DisplayBrush(1, 1, 1) ; display the maze background
LoadSprite(1, "character.png") ; the character image is loaded as sprite id1
;initial character position x and y are set to fixed value to match the center of the maze
startposition_x = 225
startposition_y = 235
; dynamic variables are set and used to display the sprite at the starting position
position_x = startposition_x ; this variable will
position_y = startposition_y
DisplaySprite(1, position_x, position_y)
StartTimer(1) ; starts the timer to be used for movement speed later
;program main loop
Repeat
mouse_pressed = IsLeftMouse() ; check if left mouse button is pressed
t1 = GetTimer(1) ; gets the timer value in milliseconds
If t1 > 10 ; this number will affect the movement speed, the lower number the faster the character will move.
If mouse_pressed
;target position x and y are the set to the mouse pointer position, so that the character will always move towards the mouse
; the -7 and -8 are offsets to make the target position to match the center of the characer of 15x17 pixels
target_x = MouseX()-7
target_y = MouseY()-8
If target_x > position_x ; if the mouse pointer is at the right side of the character
position_x = position_x+1
Else
If target_x < position_x Then position_x = position_x-1 ; if the mouse pointer is at the left side of the character
EndIf
If target_y > position_y ; if the mouse pointer is lower than the character
position_y = position_y+1
Else
If target_y < position_y Then position_y = position_y-1 ; if the mouse pointer is higher than the character
EndIf
DisplaySprite(1, position_x, position_y) ; will move the character to its new position
If Collision(#SPRITE_VS_BRUSH, 1, 1, 1, 1) ; will check if the character touches any of the non-transparent parts of the brush
; reset the character position if it collides with the maze walls
position_x = startposition_x
position_y = startposition_y
DisplaySprite(1, position_x , position_y)
EndIf
ResetTimer(1) ; the timer will be reset to zero after each character movement
EndIf
EndIf
Forever