diff --git a/Project2D.ahk b/Project2D.ahk new file mode 100644 index 0000000..0105dd2 --- /dev/null +++ b/Project2D.ahk @@ -0,0 +1,351 @@ +; Script Information =========================================================== +; Name: Project 2D +; Description: Example of a tile-based game engine using AutoHotkey +; AHK Version: AHK_L 1.1.25.01 (Unicode 32-bit) - March 5, 2017 +; OS Version: Windows 2000+ +; Language: English - United States (en-US) +; Author: Weston Campbell +; Website: https://autohotkey.com/boards/viewtopic.php?f=6&t=7348 +; ============================================================================== + +; Revision History ============================================================= +; Revision 2 (March 13, 2017) +; * Complete rewrite +; ------------------------------------------------------------------------------ +; Revision 1 (June 08, 2016) +; * Initial Release +; ============================================================================== + +; Auto-Execute ================================================================= +#SingleInstance, Force ; Allow only one running instance of script +#Persistent ; Keep the script permanently running until terminated +#NoEnv ; Avoid checking empty variables for environment variables +#Warn ; Enable warnings to assist with detecting common errors +#NoTrayIcon ; Disable the tray icon of the script +SendMode, Input ; The method for sending keystrokes and mouse clicks +SetWorkingDir, %A_ScriptDir% ; Set the working directory of the script +SetBatchLines, -1 ; The speed at which the lines of the script are executed +SetWinDelay, -1 ; The delay to occur after modifying a window +SetControlDelay, -1 ; The delay to occur after modifying a control +OnExit("OnUnload") ; Run a subroutine or function when exiting the script + +return ; End automatic execution +; ============================================================================== + +; Labels ======================================================================= +;GuiEscape: +GuiClose: +ExitSub: + ExitApp ; Terminate the script unconditionally +return +; ============================================================================== + +; Functions ==================================================================== +OnLoad() { + Global ; Assume-global mode + Static Init := OnLoad() ; Call function + + OnMessage(0x0100, "WM_KEYDOWN") +} + +OnUnload(ExitReason, ExitCode) { + Global ; Assume-global mode +} + +WM_KEYDOWN(wParam, lParam, Msg, Hwnd) { + Global ; Assume-global mode + Static VK_UP := 26, VK_LEFT := 25, VK_DOWN := 28, VK_RIGHT := 27, + VK_KEY_W := 57, VK_KEY_A := 41, VK_KEY_S := 53, VK_KEY_D := 44, + VK_F1 := 70, VK_RETURN := "D", VK_ESCAPE := "1B" + + If (lParam & 0x40000000) { + return ; Disable auto-repeat + } + + VK := Format("{:x}", wParam) + + If (VK = VK_UP) || (VK = VK_KEY_W) { + Hero.Move(0, -1, true) + } + + If (VK = VK_LEFT) || (VK = VK_KEY_A) { + Hero.Move(-1, 0, true) + } + + If (VK = VK_DOWN) || (VK = VK_KEY_S) { + Hero.Move(0, 1, true) + } + + If (VK = VK_RIGHT) || (VK = VK_KEY_D) { + Hero.Move(1, 0, true) + } + + If (VK = VK_RETURN) { + GridAction("VK_RETURN") + } + + If (VK = VK_F1) { + GuiControlGet, DebugVisible, Visible, Debug + GuiControl, % (!DebugVisible ? "Show" : "Hide"), Debug + } + + If (VK = VK_ESCAPE) { + GoSub, ExitSub + } +} + +GuiCreate() { + Global ; Assume-global mode + Static Init := GuiCreate() ; Call function + + Menu, Tray, Icon, resources\images\icon.ico + Gui, +LastFound -Resize +HWNDhProject2D + Gui, Color, 000000 + Gui, Margin, 10, 10 + Gui, Add, Edit, x0 y0 w0 h0 0x800 ; Focus + Gui, Add, Picture, x0 y0 w640 h640 vStage + Gui, Add, Picture, x0 y0 w32 h32 vHero BackgroundTrans + Gui, Add, Text, x10 y10 w620 r3 cFFFFFF vDebug BackgroundTrans + Gui, Show, w640 h640, Project 2D + + Stage := new Stage("Stage") + Stage.Color("000000") + Stage.Background("bg_title.png") + Stage.Map("map_0000.map") + + Hero := new Player("Hero") + Hero.Move(-1, -1, false) +} + +GridAction(Action := "") { + Global ; Assume-global mode + + If (GridType = 1) { + Hero.Move(PX, PY, false) + return + } + + If (Map = "map_0000.map") { + If (Action = "VK_RETURN") { + Stage.Background("bg_0001.png") + Stage.Map("map_0001.map") + Hero.Move(9, 11, false) + return + } + } + + If (Map = "map_0001.map") { + If (GridType = 2) { ; Go to next map + Stage.Background("bg_0002.png") + Stage.Map("map_0002.map") + Hero.Move(PX, 19, false) + return + } + } + + If (Map = "map_0002.map") { + If (GridType = 2) { ; Go to previous map + Stage.Background("bg_0001.png") + Stage.Map("map_0001.map") + Hero.Move(PX, 0, false) + return + } + + If (GridType = 3) { ; Go to next map + Stage.Background("bg_0003.png") + Stage.Map("map_0003.map") + Hero.Move(PX, 19, false) + return + } + } + + If (Map = "map_0003.map") { + If (GridType = 2) { ; Go to previous map + Stage.Background("bg_0002.png") + Stage.Map("map_0002.map") + Hero.Move(PX, 0, false) + return + } + + If (GridType = 3) { ; Fell in hole + Hero.Move(10, 19, false) + return + } + + If (GridType = 4) { ; Go to next map + Stage.Background("bg_0004.png") + Stage.Map("map_0004.map") + Hero.Move(16, 15, false) + return + } + } + + If (Map = "map_0004.map") { + If (GridType = 2) { ; Go to previous map + Stage.Background("bg_0003.png") + Stage.Map("map_0003.map") + Hero.Move(8, 10, false) + return + } + + If (GridType = 3) { ; AutoHotkey "A" icon + Stage.Background("bg_0004_2.png") + Stage.Map("map_0004_2.map") + return + } + } + + If (Map = "map_0004_2.map") { + If (GridType = 2) { ; Go to next map + Stage.Background("bg_0005.png") + Stage.Map("map_0005.map") + Hero.Move(19, PY, false) + return + } + } + + If (Map = "map_0005.map") { + If (GridType = 2) { ; Go to previous map + Stage.Background("bg_0004_2.png") + Stage.Map("map_0004_2.map") + Hero.Move(0, PY, false) + return + } + + If (GridType = 3) { ; Key item + Stage.Background("bg_0005_2.png") + Stage.Map("map_0005_2.map") + return + } + } + + If (Map = "map_0005_2.map") { + If (GridType = 2) { ; AutoHotkey "H" icon + Stage.Background("bg_0005_3.png") + Stage.Map("map_0005_3.map") + return + } + } + + If (Map = "map_0005_3.map") { + If (GridType = 2) { ; Go to next map + Stage.Background("bg_0006.png") + Stage.Map("map_0006.map") + Hero.Move(PX, 0, false) + return + } + } + + If (Map = "map_0006.map") { + If (GridType = 2) { ; Go to previous map + Stage.Background("bg_0005_3.png") + Stage.Map("map_0005_3.map") + Hero.Move(PX, 19, false) + return + } + + If (GridType = 3) { ; Key item + Stage.Background("bg_0006_2.png") + Stage.Map("map_0006_2.map") + return + } + } + + If (Map = "map_0006_2.map") { + If (GridType = 2) { ; AutoHotkey "K" icon + Stage.Background("bg_0006_3.png") + Stage.Map("map_0006_3.map") + return + } + } + + If (Map = "map_0006_3.map") { + If (GridType = 2) { ; Go to next map + Stage.Background("bg_0007.png") + Stage.Map("map_0007.map") + Hero.Move(9, 13, false) + return + } + } + + If (Map = "map_0007.map") { + If (GridType = 2) { ; AutoHotkey icon + Stage.Background("bg_0008.png") + Stage.Map("map_0008.map") + Hero.Move(-1, -1, false) + return + } + } +} + +Class Stage { + __New(Hwnd) { + this.Stage := Hwnd + } + + Background(File) { + Global ; Assume-global mode + + GuiControl,, % this.Stage, % "resources\images\" (Background := File) + } + + Color(Hex) { + Gui, Color, % Hex + } + + Map(File) { + Global ; Assume-global mode + + GridMap := [] + + FileRead, MapData, % "resources\maps\" (Map := File) + + For Each, Line In StrSplit(MapData, "`n", "`r") { + GridMap.Push(StrSplit(Line)) + } + } +} + +Class Player { + __New(Hwnd) { + this.Player := Hwnd + } + + Visible(Show := true) { + GuiControl, % (Show ? "Show" : "Hide"), % this.Player + } + + Image(File) { + GuiControl,, % this.Player, % "resources\images\" File + } + + Move(X, Y, Relative := 0) { + Global ; Assume-global mode + + GuiControlGet, Player, Pos, % this.Player + PX := (PlayerX // 32), PY := (PlayerY // 32) + X := (Relative ? PX + X : X), Y := (Relative ? PY + Y : Y) + GridType := GridMap[Y + 2, X + 2] + GuiControl,, Debug, %X%, %Y%`n%Background%`n%Map% ; Debug info + + If (Y < PY) { + this.Image("player_up.png") + } + + If (X < PX) { + this.Image("player_left.png") + } + + If (Y > PY) { + this.Image("player_down.png") + } + + If (X > PX) { + this.Image("player_right.png") + } + + GuiControl, Move, % this.Player, % " x" X * 32 " y" Y * 32 + GridAction("Move") + } +} +; ============================================================================== \ No newline at end of file diff --git a/resources/images/bg_0001.png b/resources/images/bg_0001.png new file mode 100644 index 0000000..9bea77a Binary files /dev/null and b/resources/images/bg_0001.png differ diff --git a/resources/images/bg_0002.png b/resources/images/bg_0002.png new file mode 100644 index 0000000..7733d67 Binary files /dev/null and b/resources/images/bg_0002.png differ diff --git a/resources/images/bg_0003.png b/resources/images/bg_0003.png new file mode 100644 index 0000000..6e07c2c Binary files /dev/null and b/resources/images/bg_0003.png differ diff --git a/resources/images/bg_0004.png b/resources/images/bg_0004.png new file mode 100644 index 0000000..e9ac53d Binary files /dev/null and b/resources/images/bg_0004.png differ diff --git a/resources/images/bg_0004_2.png b/resources/images/bg_0004_2.png new file mode 100644 index 0000000..2673946 Binary files /dev/null and b/resources/images/bg_0004_2.png differ diff --git a/resources/images/bg_0005.png b/resources/images/bg_0005.png new file mode 100644 index 0000000..a4a6992 Binary files /dev/null and b/resources/images/bg_0005.png differ diff --git a/resources/images/bg_0005_2.png b/resources/images/bg_0005_2.png new file mode 100644 index 0000000..f5a6d8a Binary files /dev/null and b/resources/images/bg_0005_2.png differ diff --git a/resources/images/bg_0005_3.png b/resources/images/bg_0005_3.png new file mode 100644 index 0000000..b410eb9 Binary files /dev/null and b/resources/images/bg_0005_3.png differ diff --git a/resources/images/bg_0006.png b/resources/images/bg_0006.png new file mode 100644 index 0000000..6e08a5f Binary files /dev/null and b/resources/images/bg_0006.png differ diff --git a/resources/images/bg_0006_2.png b/resources/images/bg_0006_2.png new file mode 100644 index 0000000..ba88174 Binary files /dev/null and b/resources/images/bg_0006_2.png differ diff --git a/resources/images/bg_0006_3.png b/resources/images/bg_0006_3.png new file mode 100644 index 0000000..f37650f Binary files /dev/null and b/resources/images/bg_0006_3.png differ diff --git a/resources/images/bg_0007.png b/resources/images/bg_0007.png new file mode 100644 index 0000000..b44925e Binary files /dev/null and b/resources/images/bg_0007.png differ diff --git a/resources/images/bg_0008.png b/resources/images/bg_0008.png new file mode 100644 index 0000000..b32cd15 Binary files /dev/null and b/resources/images/bg_0008.png differ diff --git a/resources/images/bg_title.png b/resources/images/bg_title.png new file mode 100644 index 0000000..9373cb2 Binary files /dev/null and b/resources/images/bg_title.png differ diff --git a/resources/images/icon.ico b/resources/images/icon.ico new file mode 100644 index 0000000..957cdd3 Binary files /dev/null and b/resources/images/icon.ico differ diff --git a/resources/images/player_down.png b/resources/images/player_down.png new file mode 100644 index 0000000..7f5d4e4 Binary files /dev/null and b/resources/images/player_down.png differ diff --git a/resources/images/player_left.png b/resources/images/player_left.png new file mode 100644 index 0000000..047b27d Binary files /dev/null and b/resources/images/player_left.png differ diff --git a/resources/images/player_right.png b/resources/images/player_right.png new file mode 100644 index 0000000..7a3de9d Binary files /dev/null and b/resources/images/player_right.png differ diff --git a/resources/images/player_up.png b/resources/images/player_up.png new file mode 100644 index 0000000..1a46f16 Binary files /dev/null and b/resources/images/player_up.png differ diff --git a/resources/maps/map_0000.map b/resources/maps/map_0000.map new file mode 100644 index 0000000..4b8a5fe --- /dev/null +++ b/resources/maps/map_0000.map @@ -0,0 +1,22 @@ +0000000000000000000000 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0000000000000000000000 \ No newline at end of file diff --git a/resources/maps/map_0001.map b/resources/maps/map_0001.map new file mode 100644 index 0000000..e78ab1e --- /dev/null +++ b/resources/maps/map_0001.map @@ -0,0 +1,22 @@ +1111111111221111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111100000011111111 +1111111100000011111111 +1111111100000011111111 +1111111100000011111111 +1111111100000011111111 +1111111100000011111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0002.map b/resources/maps/map_0002.map new file mode 100644 index 0000000..9a43da9 --- /dev/null +++ b/resources/maps/map_0002.map @@ -0,0 +1,22 @@ +1111111111331111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111011111111111 +1111111111001111111111 +1111111111001111111111 +1111111111101111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111101111111111 +1111111111001111111111 +1111111111001111111111 +1111111111011111111111 +1111111111001111111111 +1111111111101111111111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111221111111111 \ No newline at end of file diff --git a/resources/maps/map_0003.map b/resources/maps/map_0003.map new file mode 100644 index 0000000..d1f1e71 --- /dev/null +++ b/resources/maps/map_0003.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111300000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111001111001111001111 +1111001111001111001111 +1111001100030011001111 +1111001140000011001111 +1111001111111111001111 +1111001111111111001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000330000000001111 +1111111111001111111111 +1111111111001111111111 +1111111111001111111111 +1111111111221111111111 \ No newline at end of file diff --git a/resources/maps/map_0004.map b/resources/maps/map_0004.map new file mode 100644 index 0000000..dfe5915 --- /dev/null +++ b/resources/maps/map_0004.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111000003100010001111 +1111000000101010101111 +1111011111101010101111 +1100010000001010101111 +1100000000001010101111 +1111000000001010101111 +1111100000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010101111 +1111100000001000121111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0004_2.map b/resources/maps/map_0004_2.map new file mode 100644 index 0000000..ab128d4 --- /dev/null +++ b/resources/maps/map_0004_2.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111000000100010001111 +1111000000101010101111 +1111011111101010101111 +2000010000001010101111 +2000000000001010101111 +1111000000001010101111 +1111100000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010101111 +1111000000001010111111 +1111100000001000111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0005.map b/resources/maps/map_0005.map new file mode 100644 index 0000000..dd0bdab --- /dev/null +++ b/resources/maps/map_0005.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111000000000111111 +1111111000000000011111 +1111100000000000000002 +1111100000000000000002 +1111100000000000011111 +1111100000000000111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111130000011111111111 +1111100000011111111111 +1111100000011111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0005_2.map b/resources/maps/map_0005_2.map new file mode 100644 index 0000000..0e2a739 --- /dev/null +++ b/resources/maps/map_0005_2.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111120000000000111111 +1111100000000000011111 +1111100000000000000011 +1111100000000000000011 +1111100000000000011111 +1111100000000000111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0005_3.map b/resources/maps/map_0005_3.map new file mode 100644 index 0000000..1ac9569 --- /dev/null +++ b/resources/maps/map_0005_3.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111100000000000111111 +1111100000000000011111 +1111100000000000000011 +1111100000000000000011 +1111100000000000011111 +1111100000000000111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111122222211111111111 \ No newline at end of file diff --git a/resources/maps/map_0006.map b/resources/maps/map_0006.map new file mode 100644 index 0000000..9773235 --- /dev/null +++ b/resources/maps/map_0006.map @@ -0,0 +1,22 @@ +1111122222211111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000000000011111 +1111100000000000011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111101111011110011111 +1111101001011110011111 +1111101001011110311111 +1111101111011111111111 +1111100000011111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0006_2.map b/resources/maps/map_0006_2.map new file mode 100644 index 0000000..49d317a --- /dev/null +++ b/resources/maps/map_0006_2.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000000000011111 +1111100000000000011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100200011110011111 +1111100000011111111111 +1111100000011111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0006_3.map b/resources/maps/map_0006_3.map new file mode 100644 index 0000000..8a60ad6 --- /dev/null +++ b/resources/maps/map_0006_3.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111100000011111111111 +1111100000011111111111 +1111100000011111111111 +1111100000000000211111 +1111100000000000011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011110011111 +1111100000011111111111 +1111100000011111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0007.map b/resources/maps/map_0007.map new file mode 100644 index 0000000..3defbe2 --- /dev/null +++ b/resources/maps/map_0007.map @@ -0,0 +1,22 @@ +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000200000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111000000000000001111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 +1111111111111111111111 \ No newline at end of file diff --git a/resources/maps/map_0008.map b/resources/maps/map_0008.map new file mode 100644 index 0000000..4b8a5fe --- /dev/null +++ b/resources/maps/map_0008.map @@ -0,0 +1,22 @@ +0000000000000000000000 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0111111111111111111110 +0000000000000000000000 \ No newline at end of file