|
Help a helpless programmer! Unpress() not working. Displaying 1-10 of 10 total.
1
Time_Wizard
|
I'm in the middle of programming my battle system, and can't seem to get my directional keys to Unpress. When I hit the arrow keys to make a selection, the cursor just zips through a bunch of entries, even when I put Unpress() in multiple places throughout the cycle. What's going on here? (note: I'm experiencing no other problems otherwise)
To avoid any need for theorization, I'll just throw down the whole batch of code.
//Here's all the relevant code + additional explanation.
////////////////////////////////
///////// battle.vc
////////////////////////////////
//character[x]=struct array of all the stats of all your characters
//party[x]=array that keeps track of what characters are in your party
void BattleCommands(){ //The idle phase of battle where you enter commands
Menu=0;SubMenu=0;Choice=0;
//Menu= which character's menu is being shown
//SubMenu= which submenu (magic, etc) you're in - 0 is the main menu
//Choice= currently selected choice on the menu
int CommandsDone;CommandsDone=0; //self-explanatory
while (!CommandsDone){
timer=0;
Pulsate++; // the lucency of the little blinking active selection outline
if(Pulsate>100){Pulsate=0;}
Render(); // map is black, just clear the screen
Blit(0,0,BGFull,screen); // draw the battle backdrop
DrawCharacters(); // draw and animate your characters
DrawEnemies(); // draw the enemies
DrawStats(); // draw your HP/MP/Gauges on side of screen
DrawLineup(); // draw the turn order indicator on the other side
UpdateControls();
DrawMenu(); // draw the menu base
Unpress(5);Unpress(6);Unpress(7);Unpress(8);
// unpress all directions (not working?)
ShowPage(); // show all the stuff
while(timer<1){}
//ensures that no more than one cycle is run each tick
//(for those of us with far too fast computers)
}
}
void DrawMenu(){ // draws the graphical base of the menu
SetLucent(50);ScaleBlit(0,180,320,60,Gradient,screen);SetLucent(0);
x=0;
for(a=0;a<5;a++){ // Draw the menu selection character icons
if(Party[a] != 0){
TBlit(x,164,Character[Party[a]].Icon,screen);
if(a=Menu){ // highlight the active menu
SetLucent(Pulsate);
TBlit(x,164,Outline,screen);
SetLucent(0);
}
x+=32;
}
}
Pic=LoadImage('graphics\action_icon.png');
TBlit(x,164,Pic,screen);
FreeImage(Pic);
TBlit(0,180,Character[Party[Menu]].Face,screen);
PrintString(70,180,screen,Font1,Character[Party[Menu]].Name);
//show name of the active character
Rect(68,190,212,234,RGB(128,128,128),screen);
CallMenu(); // Bring up the menu selections
}
/////////////////////////////////////////
////////// battledata.vc
/////////////////////////////////////////
void CallMenu(){ // All the actual command processing is done in here.
switch(Character[Party[Menu]].ID){
case 1: switch(SubMenu){ // Brooke's menu
case 0: PrintString(70,192,screen,Font1,'Attack');
PrintString(70,202,screen,Font1,'Tech');
PrintString(70,212,screen,Font1,'Magic');
PrintString(70,222,screen,Font1,'Item');
PrintString(140,192,screen,Font1,'Ascension');
//PrintString(140,202,screen,Font1,' ');
//PrintString(140,212,screen,Font1,' ');
//PrintString(140,222,screen,Font1,' ');
switch(Choice){
//draws the selection arrow
//and moves it if a direction is pressed
case 0: TBlit(62,190,Arrow,screen);
if(key[SCAN_DOWN]){Choice=1;}
if(key[SCAN_UP]){Choice=3;}
if(key[SCAN_RIGHT]){Choice=4;}
//if(key[SCAN_LEFT]){Choice=_;}
//menu doesn't loop left/right, only up/down
BattleHelp(1);
case 1: TBlit(62,200,Arrow,screen);
if(key[SCAN_DOWN]){Choice=2;}
if(key[SCAN_UP]){Choice=0;}
if(key[SCAN_RIGHT]){Choice=5;}
//if(key[SCAN_LEFT]){Choice=_;}
BattleHelp(2);
case 2: TBlit(62,210,Arrow,screen);
if(key[SCAN_DOWN]){Choice=3;}
if(key[SCAN_UP]){Choice=1;}
if(key[SCAN_RIGHT]){Choice=6;}
//if(key[SCAN_LEFT]){Choice=_;}
BattleHelp(3);
case 3: TBlit(62,220,Arrow,screen);
if(key[SCAN_DOWN]){Choice=0;}
if(key[SCAN_UP]){Choice=2;}
if(key[SCAN_RIGHT]){Choice=7;}
//if(key[SCAN_LEFT]){Choice=_;}
BattleHelp(4);
case 4: TBlit(132,190,Arrow,screen);
if(key[SCAN_DOWN]){Choice=5;}
if(key[SCAN_UP]){Choice=7;}
//if(key[SCAN_RIGHT]){Choice=_;}
if(key[SCAN_LEFT]){Choice=0;}
BattleHelp(5);
case 5: TBlit(132,200,Arrow,screen);
if(key[SCAN_DOWN]){Choice=6;}
if(key[SCAN_UP]){Choice=4;}
//if(key[SCAN_RIGHT]){Choice=_;}
if(key[SCAN_LEFT]){Choice=1;}
case 6: TBlit(132,210,Arrow,screen);
if(key[SCAN_DOWN]){Choice=7;}
if(key[SCAN_UP]){Choice=5;}
//if(key[SCAN_RIGHT]){Choice=_;}
if(key[SCAN_LEFT]){Choice=2;}
case 7: TBlit(132,220,Arrow,screen);
if(key[SCAN_DOWN]){Choice=4;}
if(key[SCAN_UP]){Choice=6;}
//if(key[SCAN_RIGHT]){Choice=_;}
if(key[SCAN_LEFT]){Choice=3;}
}
}
case 2: switch(SubMenu){ // Stuffman's menu
case 0: PrintString(70,192,screen,Font1,'Attack');
PrintString(70,202,screen,Font1,'Tech');
PrintString(70,212,screen,Font1,'');
PrintString(70,222,screen,Font1,'Item');
//PrintString(140,192,screen,Font1,'Grenade');
//PrintString(140,202,screen,Font1,'');
//PrintString(140,212,screen,Font1,'');
//PrintString(140,222,screen,Font1,'');
}
}
}
[Zip Edit: Sorry, the forced width was breaking my brain trying to read this page]
Posted on 2004-09-23 05:39:18 (last edited on 2004-09-24 08:48:22)
|
Zip
|
<edit>Hope the chat on IRC helped a litte, email me (click profile) if you need specific testoring or anything. For future reference, Unpress() affects button values, not key[] values, so check if (up) rather than if (key[SCAN_UP]</edit>
Zip
Posted on 2004-09-23 05:45:36 (last edited on 2004-09-23 07:30:02)
|
resident
|
I dunno if this was all covered in IRC already, but it bears repeating, I think. For controls, whereever possible, use the built in button values than checking the key scan codes, since this means anyone with a joypad plugged in via DirectX will be able to play your game with that. If you use scancodes, they're limited to using the keyboard, which is HORRIBLE.
While there are circumstances where this isn't possible, they're few and far between.
Posted on 2004-09-23 08:07:10
|
zaril
|
Another hint:
void MyUnpress(int k)
{
switch(k)
{
case 0:
key[SCAN_UP] = 0;
key[SCAN_LEFT] = 0;
key[SCAN_RIGHT] = 0;
key[SCAN_DOWN] = 0;
case 1:
key[SCAN_UP] = 0;
case 2:
key[SCAN_LEFT] = 0;
case 3:
key[SCAN_RIGHT] = 0;
case 4:
key[SCAN_DOWN] = 0;
}
// If you want to utilize the code I've written below,
// you should add Unpress(k); here.
// Unpress(k);
}
Additional idea:
If you prefer using key[] and just want to add an optional use for pad users, just add this at the beginning of the big loop (whatever large loop you're in).
UpdateControls();
if (Up) key[SCAN_UP] = 1;
if (Left) key[SCAN_LEFT] = 1;
if (Right) key[SCAN_RIGHT] = 1;
if (Down) key[SCAN_DOWN] = 1;
Hope that helps.
Posted on 2004-09-23 09:06:08
|
mcgrue
|
Quote: Originally posted by resident
I dunno if this was all covered in IRC already, but it bears repeating, I think. For controls, whereever possible, use the built in button values than checking the key scan codes, since this means anyone with a joypad plugged in via DirectX will be able to play your game with that. If you use scancodes, they're limited to using the keyboard, which is HORRIBLE.
While there are circumstances where this isn't possible, they're few and far between.
Optionally, wrap the whole thing!
int my_left()
{
if( !custom_mode )
{
return left;
}
else
{
return KEY[custom_left];
}
}
...Etc...
And remember to have a swank keyconfig screen! ;D
Posted on 2004-09-23 12:17:24 (last edited on 2004-09-23 12:17:38)
|
Time_Wizard
|
Aye, I was planning on setting everything up for configurable keys and gamepads later, right now I just want to get the nerfing thing working.
Thanks to all for suggestions on code optimization.
Posted on 2004-09-24 05:50:24
|
gannon
|
just be carefull on how you do that. I have seen many people destroy there own code just so they could make something work now and not have to wait untill later.
Posted on 2004-09-24 06:19:39
|
mcgrue
|
I've developed the philosophy of late to encapsulte everything in vc from the get-go to make it easy to implement new things later.
Posted on 2004-09-24 07:04:11
|
rpgking
|
Quote:Originally posted by gannon
just be carefull on how you do that. I have seen many people destroy there own code just so they could make something work now and not have to wait untill later.
I've seen myself do this...on more than one occasion. But I think I learned my lesson. ;)
Posted on 2004-09-24 16:08:24
|
aen
|
I do a lot of design work before coding, but I still find I tend to brute something out just to get it working and then worry about prettying it up later. The trick is to not let it pile up to the point of confusion! I tend to get around to clean-up fairly soon after a session of 'sprinting'.
Posted on 2004-09-24 20:42:37
|
Displaying 1-10 of 10 total.
1
|
|