Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn), 581 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Player input discussion #55863
09/22/05 10:20
09/22/05 10:20
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Hi!
One job in programming can be done with many ways. And all be right, but one is simpler, second is smaller, third is faster...
Let's talk about another way to control yout game. Conitec in 3dgs give to you some usefull variables: key_force, mouse_force, joy_force. These vars gives smoothed and calibrated user input.
They are great for simplifying your code and you can pick up this technique for your needs. Technique, I'm talking about separating user input functions and you 'reactor' functions, not about using these vars in any project.
Imagine your game:
You have a player on a board, he can move in four directions step by step. He can select and use something from inventory and can view the map.
Yes, you can:
Code:

on_ctrl=use_item;
on_alt=select_item;
...


Ok, second try:
Code:

...
while (lives > 0){ // as long as I'm alive
while (key_any == 0){ // as long as I haven't walked
...
wait (1);
}
if (key_cuu == 1){ // if we press the "up" arrow
...
}
if (key_cud == 1){
...
}
...


Better, but not perfect. Try this (not perfect too):
Code:

var move_forw_scan = 72; //CursorUp
var move_back_scan = 80; //CursorDown
var move_left_scan = 75; //CursorLeft
var move_right_scan = 77; //CursorRight
var select_scan = 56; //Alt
var use_scan = 29; //Ctrl
var map_scan = 15; //Tab
var player_input_mask=0; //bitmask for player movement

define player_move_none, 0;
define player_move_forw, 1;
define player_move_back, 2;
define player_move_left, 4;
define player_move_right, 8;
define player_move_any, 15;
define player_select, 16;
define player_use, 32;
define player_map, 64;

function update_player_input(){ //react for keypressing
while(player==null){wait(1);}
while(player!=null){
player_input_mask=player_move_none;
if(enable_key==on){
// check for keyboard/mouse_button/joy_button input
if(Key_Pressed(move_forw_scan)==on&&
Key_Pressed(move_back_scan)==off&&
Key_Pressed(move_left_scan)==off&&
Key_Pressed(move_right_scan)==off){
player_input_mask=player_move_forw;
}else{
if(Key_Pressed(move_forw_scan)==off&&
Key_Pressed(move_back_scan)==on&&
Key_Pressed(move_left_scan)==off&&
Key_Pressed(move_right_scan)==off){
player_input_mask=player_move_back;
}else{
if(Key_Pressed(move_forw_scan)==off&&
Key_Pressed(move_back_scan)==off&&
Key_Pressed(move_left_scan)==on&&
Key_Pressed(move_right_scan)==off){
player_input_mask=player_move_left;
}else{
if(Key_Pressed(move_forw_scan)==off&&
Key_Pressed(move_back_scan)==off&&
Key_Pressed(move_left_scan)==off&&
Key_Pressed(move_right_scan)==on){
player_input_mask=player_move_right;
}}}}
if(Key_Pressed(select_scan)==on&&
Key_Pressed(use_scan)==off){
player_input_mask|=player_select;
}else{
if(Key_Pressed(select_scan)==off&&
Key_Pressed(use_scan)==on){
player_input_mask|=player_use;
}}
if(Key_Pressed(map_scan)==on){
player_input_mask|=player_map;
}
}
wait(1);
}
}


Somewhere in your code:
Code:

action player{
update_player_input();
player = me;
...
if ((player_input_mask & player_move_any) > 0 ){
if ((player_input_mask & player_move_forw) > 0){ //forward
...
}
if ((player_input_mask & player_move_back) > 0){ //backward
...
}
if ((player_input_mask & player_move_right) > 0){ //right
...
}
if ((player_input_mask & player_move_left) > 0){ //left
...
}
...
}
...
if ((player_input_mask & player_use)!=0){ //use
use_inventory();
}else{
if ((player_input_mask & player_select)!=0){ //select
select_inventory();
}
}
if ((player_input_mask & player_map)>0){ //toggle map
toggle_map_camera();
}
wait(1);
}


Yes this is only a pattern, you have to change this for your needs.
What we can get with this ?
Player input served in one easy managable function, we can reassign input keys with user menu and can easily implement 'key 2 logic' technique.
That's all, may be this usefull for noobs like me...

Re: Player input discussion [Re: Lion_Ts] #55864
09/23/05 18:21
09/23/05 18:21
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
yeah, no discussion...
i'm sorry

Re: Player input discussion [Re: Lion_Ts] #55865
10/05/06 05:26
10/05/06 05:26
Joined: Jul 2005
Posts: 366
eleroux Offline
Senior Member
eleroux  Offline
Senior Member

Joined: Jul 2005
Posts: 366
I wrote a script to manage Actors, which can be human or not. So I wanted to separate the user input from it.

What I do is to use a skill for something called 'ActorCommand', used to pass input commands to an actor. This way, if the actor is driven by some AI code, it will also pass 'commands' to the Actor movement script.

Commands are for instance: "COMMAND_JUMP".

and there is a value skill - ActorCommand_Val

for instance the command may be "COMMAND_TURN" and ActorCommand_Val be "-5" or "8"

So far I have managed to keep the keyboard and mouse Input completely out of my Actor pseudo-physics (movement) and from my animation codes.


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1