Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Platformer Demo (OpenGL)


  • Please log in to reply
29 replies to this topic
Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
A 3D version of Platformer - Platform Game in AHK. First person version, only intended to be a demo. Controls, lighting, and navigation implemented.

Screenshot:

Posted Image

Controls:

W - Move forward
S - Move backward
D - Jump
D + W / D + S - Wall climb
Tab - Toggle slow motion


Code:

AutoHotkey.net

Creating levels:

Levels are simple to create, with the help of SmartGUI Creator. Use a Button control to represent the character, use Edit controls to represent the level, use ListBox controls to represent item blocks, and use a Progress control to represent the goal:

Posted Image

Then, after creating your level, feed it into this script:

GUICode = ;put your generated GUI below
(
Gui, Add, Button, x742 y500 w30 h40 , Button
Gui, Add, Edit, x312 y560 w480 h30 , Edit
Gui, Add, Edit, x42 y420 w350 h40 , Edit
Gui, Add, Edit, x172 y160 w40 h260 , Edit
Gui, Add, Edit, x72 y160 w100 h30 , Edit
Gui, Add, Edit, x162 y60 w280 h20 , Edit
Gui, Add, Edit, x442 y110 w100 h20 , Edit
Gui, Add, Edit, x562 y60 w100 h30 , Edit
Gui, Add, Edit, x702 y220 w100 h30 , Edit
Gui, Add, Edit, x512 y230 w100 h30 , Edit
Gui, Add, Progress, x532 y170 w60 h60 , 25
Gui, Add, ListBox, x272 y310 w40 h30 , ListBox
Gui, Add, ListBox, x472 y70 w40 h30 , ListBox
; Generated using SmartGUI Creator 4.0
Gui, Show, w827 h614, Untitled GUI
Return

GuiClose:
ExitApp
)

MsgBox % Clipboard := LoadGUI(GUICode)

LoadGUI(GUICode)
{
 global Rectangles, ItemBlocks, CurrentRectX, CurrentRectY, CurrentRectW, CurrentRectH, GoalRectX, GoalRectY, GoalRectW, GoalRectH, Width, Height
 Loop, Parse, GUICode, `n, `r%A_Space%%A_Tab%
 {
  If Not RegExMatch(A_LoopField,"iS)Gui,? *Add, *(Edit|ListBox), *x(\d+) *y(\d+) *w(\d+) *h(\d+)",Match)
   Continue
  If Match1 = Edit
   Rectangles .= Match2 . ","Match3 . ","Match4 . ","Match5 . "`n"
  Else
   ItemBlocks .= Match2 . ","Match3 . ","Match4 . ","Match5 . "`n"
 }
 Rectangles := SubStr(Rectangles,1,-1), ItemBlocks := SubStr(ItemBlocks,1,-1)
 If RegExMatch(GUICode,"iS)Gui,? *Add, *Button, *x(\d+) *y(\d+) *w(\d+) *h(\d+)",Match)
  CurrentRectX := Match1, CurrentRectY := Match2, CurrentRectW := Match3, CurrentRectH := Match4
 If RegExMatch(GUICode,"iS)Gui,? *Add, *Progress, *x(\d+) *y(\d+) *w(\d+) *h(\d+)",Match)
  GoalRectX := Match1, GoalRectY := Match2, GoalRectW := Match3, GoalRectH := Match4
 If RegExMatch(GUICode,"iS)Gui,? *Show, *(?:x\d+ *y\d+ *)?w(\d+) *h(\d+)",Match)
  Width := Match1, Height := Match2
 Return, "Width = " . Width . "`n" . "Height = " . Height . "`n`nCurrentRect = " . CurrentRectX . "," . CurrentRectY . "," . CurrentRectW . "," . CurrentRectH . "`nGoalRect = " . GoalRectX . "," . GoalRectY . "," . GoalRectW . "," . GoalRectH . "`n`nRectangles = `n(`n" . Rectangles . "`n)`n`nItemBlocks = `n(`n" . ItemBlocks . "`n)"
}

Which will copy it to the Clipboard and display it. Replace the current level with the generated level, and start playing!

LiquidGravity
  • Members
  • 156 posts
  • Last active: Oct 11 2014 04:11 PM
  • Joined: 26 Jan 2009
Looks interesting but I can't find the include OpenGL/Box.ahk anywhere on the forums.

Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
Whoops, forgot the #Include...

It's now bundled with the script (just a wrapper around a whole bunch of OpenGL calls).

RaptorOne
  • Members
  • 43 posts
  • Last active: Apr 07 2012 08:44 PM
  • Joined: 07 Apr 2010
Perhaps yout take a look at:
New German OpenGl Library and Wrapper
Bentschies OpenGl Tutorials (German)
Ahk_Ide_v3
Sry for my english.
Its very Bad! :lol:

Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
Thanks for the links, RaptorOne! I haven't noticed the new OGL wrapper yet.

I think I'll keep the current implementation of the demo for now, as it does not depend on any external scripts. However, these libraries provide valuable insight into better ways of doing certain tasks, and I am sure there is a lot to learn from studying them.

Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
Update: Fixed lighting errors (had a negative Height being passed to Box()), added ability to wall jump, and modularized the code further. Also has less globals.

LiquidGravity
  • Members
  • 156 posts
  • Last active: Oct 11 2014 04:11 PM
  • Joined: 26 Jan 2009
Its interesting and has lots of potential.

Here are some suggestions:

Using the mouse to look and the arrow keys and space to jump is kind of awkward. I'd suggest using the standard shooter keys of WASD instead of the arrow keys.

The forward and backward keys are more like north and south since they aren't relative to the view angle of the player. Any chance it could be made relative or at least a north south component or relative to the view?

Add escape key as an exit.

Add an out of bounds check to reset.

Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
Updated. I found using A and D to turn on the Y axis was a bit awkward, and so I have kept mouselook for now. The W and S keys move it back and forth, though, and the Jump key is now D (so the player places one hand on the keyboard, the other on the mouse).

Controls have been modified to follow the direction the player is currently facing (except when wall climbing).

Escape key exits.

When the bounds are left, the game is lost.

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Very nice!

Surprisingly short code and smooth working, even on a low-end pc.

8)

Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
More updates!

[*:7a96cueo]Item blocks now supported, although your score is not displayed yet
[*:7a96cueo]Goal block is now visible
[*:7a96cueo]Performance improvements

Lucid_Method
  • Members
  • 147 posts
  • Last active: Dec 06 2014 08:39 AM
  • Joined: 19 Apr 2010
Uberi: Very cool :-) Would it be possible to incorporate buttons/controls into that environment to launch subroutines? This concept could turn into some really cool interfaces if so.. keep up the good work!

Also - how hard would it be to set it up to incorporate images into that "3d world" ? I'm currently working on a slideshow/problem recorder tool that uses a lot of screen shots. It would be awesome to setup an interface like that to be able to zoom through collections of images to get to specific areas in the time line, especially if double clicking on that image could launch something..
Posted Image
Macro Everything
Lucid_Method Index

IsNull
  • Moderators
  • 990 posts
  • Last active: May 15 2014 11:56 AM
  • Joined: 10 May 2007

Also - how hard would it be to set it up to incorporate images into that "3d world" ?

You have to load Textures.

As RaptorOne mentioned before, we have a little OpenGL Master in the German Forum, look at this basic examples for Demos with textures <!-- m -->http://de.autohotkey...opic.php?t=7619<!-- m -->

The included Example in his new OpenGL Library also includes simple image loading: <!-- m -->http://de.autohotkey...opic.php?t=8320<!-- m -->

Btw: Uberi, very amazing work!

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Just reporting: if I move the mouse quickly, I'm able to get off the game's screen.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Lucid_Method
  • Members
  • 147 posts
  • Last active: Dec 06 2014 08:39 AM
  • Joined: 19 Apr 2010
Thanks IsNull, I just looked through the examples, looks really nice
Posted Image
Macro Everything
Lucid_Method Index

Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
Update: Added texture support! Looks much better now, IMO. Screenshot updated as well (refresh this page if changes are not seen).

NOTE: The script will download the needed textures from my AHK.net account. Make sure you have an internet connection, or else you will not be able to see the textures.

Lucid_Method: I saw a tutorial somewhere about selection masks, but it was pretty complicated (and written in C++ :(). I'll have a look at it soon, though.

IsNull: Those tutorials were a great resource. Would you know where I could find an english version?

MasterFocus: Yeah, that's something I've been trying to get rid of, but then you wouldn't be able to use the mouse properly after Alt + Tabbing to another window.