Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How about low-brow?
#31
Yeah @PhilOfPerth when using the Quote tags you have to paste in the quote and never hurts to say who you are quoting unless quote comes from previous reply (is my rule of thumb anyway). That way you can pinpoint exactly what you are replying to without replaying the whole reply over again.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#32
@PhilOfPerth Is this the sort of thing youre after? Others would make it differently, and i encourage them to add or edit it as they see fit but (and please know it's a very simplified iteration of how i create my engines) but as a base it;s something i think everyone should use a version of...

Code: (Select All)
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////    Low Brow Libs    ///////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

'// ---- Part 1. Basic Type definitions and their Functions -----
'//
'// Using/creating a set of basic UDT's (User Defined Types) is the best way to start.
'// You can use these UDT's in your future programs to make coding obvious and easier.
'// Think of these as the foundations on which you build your programs.

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'// I will be using a Main Function to act as the main loop as i code in C/C++ and this is common practice I think people should
'// Learn from day 1 to make transistioning to modern languages easier later on
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


'// Global shared variables

DIM SHARED Sys_State AS System_State '// This contains our basic program data, screen handle, input and timers
'// Whilst you can define this in your Main function, for other subs and functions to access it without
'// needing to have it passed as a parameter, i find this method more logical.

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Main '// Call the program

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SUB Main
  '// First we set up using the system_state_new function. This creates our screen, initialises the input data and timers
  System_State_New Sys_State, 0, 0, 800, 600, "Low Brow Dev"

  DO
    _LIMIT 144 '// 144 fps is the modern default as most modern screens have this refresh rate
    '// Logic first
    System_State_Update Sys_State '// Update the system data (timers and input) - later we can add screen resizing etc...

    '// Graphics
    CLS '// Clear the screen

    PRINT "Mouse info"
    PRINT
    PRINT "X : " + STR$(Sys_State.Mouse.Position.X)
    PRINT "Y : " + STR$(Sys_State.Mouse.Position.Y)
    PRINT
    PRINT "LB : " + STR$(Sys_State.Mouse.LB)
    PRINT "RB : " + STR$(Sys_State.Mouse.RB)
    PRINT "MB : " + STR$(Sys_State.Mouse.MB)
    PRINT "MW : " + STR$(Sys_State.Mouse.MW)


    _DISPLAY '// Update the display

  LOOP UNTIL _EXIT '// Loop until the eXit button is pressed

  '// Here you would free any memory youve allocated to avoid memory leaks

  SYSTEM '// End the program

END SUB

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SUB Core_UDTS

  '// A position in 2d space
  TYPE Vector_2
    X AS DOUBLE
    Y AS DOUBLE
  END TYPE

  '// A rectangle
  TYPE Rect
    XY AS Vector_2 '// Top left corner
    WH AS Vector_2 '// Width/Height of the rectangle
  END TYPE

  '// With those two UDT's, Screen position and resolution, Buttons, Mouse pointer position and more can be created

  '// Next is the most basic of input devices, the mouse.

  TYPE Mouse_State
    LB AS _BYTE '// Left button
    RB AS _BYTE '// Right Button
    MB AS _BYTE '// Middle button
    MW AS _BYTE '// Mouse wheel value
    Position AS Vector_2 '// Current position
  END TYPE

  '// Next is the core of your program, the System_State. This should hold the resolution settings, input data and what ever else
  '// you decide is a standard requirment

  TYPE System_State
    Screen_Handle AS LONG '// The handle returned by Screen _newimage
    Screen_Rect AS Rect '// The dimensions and position of the screen
    Screen_Title AS STRING * 32 '// the title of your program
    Mouse AS Mouse_State '// Current input data
    Old_Mouse AS Mouse_State '// Last input data - You can then compare the current vs this for just clicked or just released info
    Time AS DOUBLE '// Created at the start of your program
    Delta_Time AS DOUBLE '// The time since the the program was started
  END TYPE

END SUB

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

'// Now we have those defined we can start to use them. For specific things like the mouse and system we make
'// functions to update/create them.

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SUB System_State_New (System_State AS System_State, x#, y#, w#, h#, ScreenTitle$)
  '// Screen dimension and position
  System_State.Screen_Rect.XY.X = x#
  System_State.Screen_Rect.XY.Y = y#
  System_State.Screen_Rect.WH.X = w#
  System_State.Screen_Rect.WH.Y = h#

  '// Now we create the screen, set its position and set the title
  System_State.Screen_Handle = _NEWIMAGE(w#, h#, 32)
  SCREEN System_State.Screen_Handle
  _TITLE ScreenTitle$
  System_State.Screen_Title = ScreenTitle$
  _SCREENMOVE x#, y# '// If you add full screen flag parameter you may wish to add an if clause here

  '// set the system timers
  System_State.Time = TIMER(.001)
  System_State.Delta_Time = System_State.Time

  '// Init input handlers
  Mouse_State_Update System_State.Mouse
  System_State.Old_Mouse = System_State.Mouse

END SUB

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SUB System_State_Update (System_State AS System_State)
  System_State.Old_Mouse = System_State.Mouse '// Copy the old mouse data
  Mouse_State_Update System_State.Mouse '// Get the new mouse data
  '// Update the timers
  System_State.Time = TIMER(.001)
  System_State.Delta_Time = System_State.Time - System_State.Delta_Time
END SUB

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SUB Mouse_State_Update (Mouse_State AS Mouse_State)
  DO WHILE _MOUSEINPUT
    Mouse_State.LB = _MOUSEBUTTON(1)
    Mouse_State.RB = _MOUSEBUTTON(2)
    Mouse_State.MB = _MOUSEBUTTON(3)
    Mouse_State.Position.X = _MOUSEX
    Mouse_State.Position.Y = _MOUSEY
    Mouse_State.MW = Mouse_State.MW + _MOUSEWHEEL
  LOOP
END SUB

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

John
Reply
#33
Thanks John. I think that will be very helpful for me, especially in my bigger programmes. 
Many of my progs are so trivial I won't need this amount of preparation, but it's there when I need it.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#34
I get ya but to me, an please dont take my preference or style as a "Heres how ya do it", once you take that base code (the subs, udts etc...) and then make them as a .bm, your future coding only needs to link to the library. So all you end up with is the main function, i.e your code looks like this

Code: (Select All)
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////    Low Brow Libs    ///////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DIM SHARED Sys_State AS System_State '// This contains our basic program data, screen handle, input and timers

Main '// Call the program

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SUB Main
  '// First we set up using the system_state_new function. This creates our screen, initialises the input data and timers
  System_State_New Sys_State, 0, 0, 800, 600, "Low Brow Dev"

  DO
    _LIMIT 144 '// 144 fps is the modern default as most modern screens have this refresh rate
    '// Logic first
    System_State_Update Sys_State '// Update the system data (timers and input) - later we can add screen resizing etc...

    '// Graphics
    CLS '// Clear the screen

    PRINT "Mouse info"
    PRINT
    PRINT "X : " + STR$(Sys_State.Mouse.Position.X)
    PRINT "Y : " + STR$(Sys_State.Mouse.Position.Y)
    PRINT
    PRINT "LB : " + STR$(Sys_State.Mouse.LB)
    PRINT "RB : " + STR$(Sys_State.Mouse.RB)
    PRINT "MB : " + STR$(Sys_State.Mouse.MB)
    PRINT "MW : " + STR$(Sys_State.Mouse.MW)


    _DISPLAY '// Update the display

  LOOP UNTIL _EXIT '// Loop until the eXit button is pressed

  '// Here you would free any memory youve allocated to avoid memory leaks

  SYSTEM '// End the program

END SUB


'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

REM $INCLUDE:'LBrow.bm'

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Whilst this obscures the underlying functions it allows a user, in two commands to create and update the system state. I can be sure that 90% of the code you make uses a SCREEN command, requires input handlers *you can add kb and gpads to this in the same method as ive shown with the mouse...and further expansion of the underlying UDT's and a couple more params or separate functions will allow the user to write something ONCE and then use it as needed...If this method sits well with you, the same vector and rect basic UDT's can be used for games (Collision detection, animated sprites), GUI's and more without EVER needing to re-write something that is fundamental.

I'm always a BIG FAN of making code accessible and simple (as i know you've inferenced this from my Titan GDK) and teaching is to me the ultimate use of my knowledge so if in anyway i can help YOU create a series of tutorials that fit your ideas then I (and pretty much everyone else who isnt an elitist here) am/are happy to help...we can only give you OUR ideas, we dont all agree, we all code differently so as YOU posed the question it'll be down to YOU to filter through it all and create the "QB64 PE Tutorials for Newbs" that as you say, will help draw in and educate said Newbs!

Next one from me will be using vectors along with a speed and rotation to move objects, SAT for collision detection and then i'll wait until YOU tell us how WE *The old guard? Should proceed...

Glad you liked it though, and think, your booglish with MasterGy's dice code converted to have the letters and not numbers inside a cube would result in a full on 3d representation of the real world thing! (Long road ahead but its entirely possible!)

John
Reply
#35
@John
Quote: Glad you liked it though, and think, your booglish with MasterGy's dice code converted to have the letters and not numbers inside a cube would result in a full on 3d representation of the real world thing! (Long road ahead but its entirely possible!)
Yes, thanks again. Actually, I'm already experimenting with  Googlish Mk2, with MasterGuy's dice with letters. Thanks for the help.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#36
@PhilOfPerth Anytime sir, and anything you need as I say to @Pete , I'm here to help at your request....I look forward to your Mk2! People like YOU are what keep us old guys going!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)