Is this possible?

BlitzPlus Forums/BlitzPlus Beginners Area/Is this possible?

Maddog(Posted 2006) [#1]
Hi,

I want to make a game which plays realtime (using timer to refresh the screen) but while all the action happens on the screen, I want to type commands to control the units on the screen. Is this possible without using the Gui part of blitzplus? (so without using a windows-like window and a textbox)?

I know the input command can only be used when the game loop is halted, so that's no alternative.

best regards,
Andrik


CS_TBL(Posted 2006) [#2]
Yep, you can just read out keypresses using events.

To test it make a small eventmonitor, or use the one in the samples directory. You'll get EventID's for keydown, keyrepeat and keyup, and in EventData -iirc- there's the keycode.
Upon those keypresses you can update some onscreen word-displayer orso..


Maddog(Posted 2006) [#3]
I'm sorry,

I probably didn't explain right...what I want to do is enter(type) complete sentences, and after pressing enter, the code must interpret the command. But while entering(typing) an sentence, the game should keep on going.

I know single key-presses can be entered realtime, but what about whole sentences? Without using the blitzplus guilib?


semar(Posted 2006) [#4]
Maddog,
you need a global string variable, let's call it Sentence.

Then you have to update that variable when any key is pressed on your keyboard.
For example:

Global sentence$ = ""
while not keydown(1)

cls
'your game logic here

'show the sentence so far
text 0,0, sentence

flip


if check_keyboard() then
'if enter has been pressed, then perform the action
   do_action()
   'reset the sentence string
   sentence = ""
endif

wend

function check_keyboard()
'this function returns true when enter is pressed.
'otherwise, it appends the last pressed character to the Sentence string variable
'check the scancode for the enter key... I don't have it in mind at the moment, I guess it's 28 :)
if keyhit(28) then 'enter has been pressed
   return true
endif

'Also here, Check the ScanCodes for a complete listing of the scancodes you need.
for n = scancode("a") to scancode("z")
   if keyhit(n) then
      sentence = sentence + str(n)
      exit 'exit for
   endif
end function

function do_action(sentence$)
select sentence
case "patrol"
case "attack"
case "engage"
.
.
and so on...
end select

end function



CS_TBL(Posted 2006) [#5]
Maddog, you're a bit vague in whether your game is event-based or not. Events are a part of the GUI, but GUI isn't part of events perse..

Is this your mainloop?
timer=createtimer(60)
repeat
  waitevent()
  if eventsource()=timer
    gameAI()
    drawgame()
  endif
until gamequit

?

Or is it like the example from semar, the classic blitz 2d/3d stuff?


Maddog(Posted 2006) [#6]
semar,

Thanks for your example, it's clear to me now.

CS_TBL, actually I'm not sure yet if it's gonna be event based, I rather not use the blitzgui lib, but I want the game to respond to mouseclicks on buttons (which probably will be pics) and keypresses.
Right now with the example of semar and your suggestion, I think I can do without eventhandling.

In summary the game has to respond to:
- clicking on the screen(drawm buttons)
- esc key to end the game
- typed sentences, for commands.

So I can do this without eventhandling?

The game is gonna be a startrek-like game, in whicH the player is a ship captain, and commands to the crew have to be typed in on a line (which simulates a captain giving orders).


CS_TBL(Posted 2006) [#7]
I'm convinced one can do whole games (or anything for that matter) with events rather than polling..

For buttons I'd always prefer some kinda canvas which reports me mousemoves etc. rather than running through all your 'graphics' gadgets each run to see whether something changed.
Stuff like mouseenter, mousemove, mouseleave is so easy to use for custom gadgets like buttons, sliders etc..