:: PlayerAdvance.org ::  

Précédent   :: PlayerAdvance.org :: > :: Forums Hébergés :: > OldSchool Library > Aide au développement

Aide au développement Aide sur l'utilisation d'OSLib

Publicité

Réponse
 
Outils de la discussion Modes d'affichage
Vieux 09/09/2007, 20h46   #1
Netaro
Membre
 
Date d'inscription: 04/09/2007
Messages: 15
Par défaut Problem with pad.release function

Hello (or Bonjour, as you wish )
Well, i'm having some problems with pad system of OSL, with osl_pad.released one to be precise (althought i think it's all because of my poor programming skills...).

I'm trying to make a moving arrow that will move on itself and will stop moving after releasing the cross.

The function looks like this:
Code:
void BouncyImage::moveBump(){
if(osl_pad.released.cross){
    if(isBumping == false){
        isBumping =true;
        }
    else{
        isBumping = false;
        } 
    }

//the (quite long) rest is about moving and all...
}
http://rapidshare.com/files/54517913/main.cpp.html
there is the whole main.cpp source.
So, althought i think one of possibilities of this error is because the rest of function is quite long... Yet, it's not possible to make some more checks in the function.
So, is there any way to get rid if this problem?

And quite an offtopic question that i'd like to know the anwser: how does the library know if the button has been held, pushed or just released?

I'm still new to programming, so please forgive me those little mistakes
Netaro est déconnecté   Réponse avec citation

Publicité

Vieux 09/09/2007, 21h30   #2
Yodajr
Administrateur
 
Date d'inscription: 09/11/2005
Messages: 3 738
Par défaut

But what is your problem ?
Sorry I don't understand...

If you want : "make a moving arrow that will move on itself and will stop moving after releasing the cross", use osl_pad.held :

Code PHP:
if (osl_pad.held.cross)  isBumping true;
else 
isBumping false
Yodajr est déconnecté   Réponse avec citation
Vieux 09/09/2007, 22h22   #3
Netaro
Membre
 
Date d'inscription: 04/09/2007
Messages: 15
Par défaut

Oh god, i forgot to say what the problem is! Well, the thing is, that pressing X works only sometimes, usually nothing happens
Netaro est déconnecté   Réponse avec citation
Vieux 05/10/2007, 19h17   #4
Netaro
Membre
 
Date d'inscription: 04/09/2007
Messages: 15
Par défaut

Well, there is still a big problem with pad.released and pad.pressed. I'm actually "trying" to make a galaga-like game. And so, i made a function that makes ship shoot a bullet when X button is...
Well, it only works when X is checked with osl_pad.held.cross.
When i'm trying to check if the button is pressed or released, it looks like it doesn't work! The ship shoots the bullet only if X is held. So, what is the problem and how to solve it?
Netaro est déconnecté   Réponse avec citation
Vieux 05/10/2007, 22h02   #5
Brunni
Super Modérateur
 
Date d'inscription: 10/11/2005
Localisation: Un pays avec beaucoup de banques
Messages: 3 188
Par défaut

The problem is probably in your code because if the X key didn't work properly, a lot of other people (including me) would have noticed it
What does it look like?
Brunni est déconnecté   Réponse avec citation
Vieux 05/10/2007, 22h25   #6
Yodajr
Administrateur
 
Date d'inscription: 09/11/2005
Messages: 3 738
Par défaut

Citation:
Envoyé par Netaro Voir le message
So, what is the problem and how to solve it?
I think that the problem is in your code, not with oslib
Yodajr est déconnecté   Réponse avec citation
Vieux 06/10/2007, 18h17   #7
Netaro
Membre
 
Date d'inscription: 04/09/2007
Messages: 15
Par défaut

http://rapidshare.com/files/60694391/Ast.rar.html
Well, there's the source, and tehgame itself... Crappy, but somewhat works... 'cept that problem

And the code looks like that:

In main.c the engine is initialized, and the SetKeyAutorepeat looks like:
Code:
    oslSetKeyAutorepeatInit(40);
    oslSetKeyAutorepeatInterval(10);
And then, the gameScreen class is initialized, which creates the ships 'n stuff...

Them in the main loop, the gameScreen.createScreen(); is called.
Within this function, lies:
Code:
void gameScreen::createScreen(){
    itsShip.checkMovement();
    itsEnemyArray.moveArray();
    itsShip.moveBullet(-1);
}
itsShip.checkMovement() calls oslReadKey(); then checks if the left or right is held, and that part works ok. Then, the itsEnemyArray.moveArray(); moves the array of enemies (mr. obvious to the rescue ). Then, within itsShip.moveBullet(-1); lies the problematic part.
Code:
void ship::moveBullet(int Vector){
    oslReadKeys();
    bool breaker = false;
if(osl_pad.released.cross){
        for(int iCounter = 0; iCounter < 3;iCounter++){
            if(itsBullet[iCounter].retMovement() == false){
                itsBullet[iCounter].createBullet("bullet.png",itsX + 3,itsY);
                breaker = true;
                }
            if(breaker == true)
            break;
               
            }
  }
    for(int i = 0; i < 3; i++){
    itsBullet[i].move(Vector);
    }
}
that function checks if the button has been released, and then, checks if there any free bullet slots (i designed the ship to be able to shoot max. 3 bullets). If there are any, then bullet is shot. It works only if i change the "released" to "held", which is very, very undesireable .
And that's all...

To be frank, same problem appeared in the previous, much simpler project
Netaro est déconnecté   Réponse avec citation
Vieux 06/10/2007, 20h30   #8
Yodajr
Administrateur
 
Date d'inscription: 09/11/2005
Messages: 3 738
Par défaut

It's hard to understand this damn C++ syntax

But try to delete the 2nd "oslReadKeys();" at l.126...
oslReadKeys must be called only once.
I didn't tested it, but try a look.

And this will do not work :
Citation:
itsBullet[iCounter].createBullet("rocket.png",itsX + 3,itsY);
because no file called "rocket.png" in your game files
Yodajr est déconnecté   Réponse avec citation
Vieux 06/10/2007, 22h00   #9
Netaro
Membre
 
Date d'inscription: 04/09/2007
Messages: 15
Par défaut

Deleting the second call of function helped a lot Thank you, Yodajr!

And also, a question -> was that syntax illegilible because you are more fluent with c or was my messy style of writing the reason?
Netaro est déconnecté   Réponse avec citation
Vieux 06/10/2007, 23h19   #10
Yodajr
Administrateur
 
Date d'inscription: 09/11/2005
Messages: 3 738
Par défaut

You're welcome
And don't worry, it's because I learned only C
Yodajr est déconnecté   Réponse avec citation
Réponse

Liens sociaux

Publicité



Utilisateurs regardant la discussion actuelle : 1 (0 membre(s) et 1 invité(s))
 
Outils de la discussion
Modes d'affichage

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 23h56.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. Tous droits réservés.
Version française #16 par l'association vBulletin francophone
Design par Ass-Itch, DJP et Dr.Vince