Shoot

Discussion in 'NDS - Emulation and Homebrew' started by cadw, Apr 25, 2011.

Shoot

by cadw Apr 25, 2011 at 1:32 PM 1,406 Views 12 replies
  1. cadw
    OP

    cadw Member

    Newcomer
    25
    0
    Apr 13, 2011
    Netherlands
    Almere, NL
    Can anyone help me??? I try to make a shooting function. Exactly the same as space invaders. I code in PAlib, but i already have this, but I don't know how to let it shoot:
    CODE
    #include

    #include "all_gfx.h"

    s16 framecount;
    s32 x = 0; s32 y = 166;
    int main(void){
    PA_Init();
    PA_LoadDefaultText(0, 0);
    int bullet.x = 0;
    int bullet.y = 180;
    PA_LoadSpritePal(0, // Screen
    0, // Palette number
    (void*)red_Pal); // Palette name
    PA_CreateSprite(0, 0, (void*)red_Sprite, OBJ_SIZE_32X32, 1, 0, 0, 160);
    while(1){

    PA_SetSpriteXY(0, // screen
    0, // sprite
    x, // x position
    y); // y...
    if(Pad.Held.Left){
    x--;
    }
    if(Pad.Held.Right){
    x++;
    }
    if(Pad.Newpress.A){
    PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
    PA_SetSpriteXY(0, 1, bullet.x, bullet.y++);
    PA_SetSpriteXY(0, 0, x, 160);
    }
    if(Pad.Released.A){
    PA_SetSpriteXY(0, 0, x, 160);
    }
    PA_WaitForVBL();
    }
    return 0;
    }
    BTW, srry for double post, but it was in the wi-fi folder! [​IMG]
     
  2. Sausage Head

    Sausage Head Lord Sausage LXIX

    Member
    1,677
    19
    Oct 28, 2010
    Netherlands
    alanjohn check ur pm
    I can't help you, but I have a few things to say.
    First, don't make duplicate threads. You can use the "Report" button to report the thread to moderators, and they will move it for you.
    Second, use CODE or CODEBOX tags. (with [ in front and ] behind)
     
  3. cadw
    OP

    cadw Member

    Newcomer
    25
    0
    Apr 13, 2011
    Netherlands
    Almere, NL
    I didn't know how to move it, can you also delete it?
     
  4. cadw
    OP

    cadw Member

    Newcomer
    25
    0
    Apr 13, 2011
    Netherlands
    Almere, NL
     
  5. Sausage Head

    Sausage Head Lord Sausage LXIX

    Member
    1,677
    19
    Oct 28, 2010
    Netherlands
    alanjohn check ur pm
    No, regular users (you, me and the rest that have a normal black name color) can't move or delete posts. Using the "report" button we either request our posts to be moved, or report rulebreaking material. If something is rulebreaking, it either gets "snipped" away, or the full post gets deleted. If it's a request, it gets moved.

    You can use the "Edit" button on the bottom of your post to edit it.
     
  6. cadw
    OP

    cadw Member

    Newcomer
    25
    0
    Apr 13, 2011
    Netherlands
    Almere, NL
    I already reported it.
     
  7. YoshiInAVoid

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    337
    Jan 10, 2011
    I know how to make it shoot. Your problem lies here:

    Code:
    if(Pad.Newpress.A){
    PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
    [u][b]PA_SetSpriteXY(0, 1, bullet.x, bullet.y++);[/b][/u]
    PA_SetSpriteXY(0, 0, x, 160);
    }
    First off it's all in a Pad.Newpress event, meaning it will only happen for one frame which is 1/60'th of a second, each time you press A. Secondly what you are saying is to set the bulet to bullet.y variable + 1, this doesn't change the variable at all so it will always just be one more than bullet.y no matter how hard you press A.

    So first of all add a new variable like "ShouldShoot" and it's type needs to be a bool. Next, put it whithin the code quoted above:
    Code:
    if(Pad.Newpress.A){
    PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
    [u][b]ShouldShoot = true;[/b][/u]
    PA_SetSpriteXY(0, 0, x, 160);
    }
    This means that the variable will stay at true until you make it go back to false.

    Now you need to edit the variable bullet.y when the Shoot variable is true:
    Code:
    if(ShouldShoot==true){
    bullet.y++;
    }
    Then at the end of the code, put your set position code for the bullet:
    Code:
    PA_SetSpriteXY(0, 1, bullet.x, bullet.y);



    Hope this helps!
     
  8. cadw
    OP

    cadw Member

    Newcomer
    25
    0
    Apr 13, 2011
    Netherlands
    Almere, NL
     
  9. YoshiInAVoid

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    337
    Jan 10, 2011
    May I ask what that error or "air" message is?
     
  10. cadw
    OP

    cadw Member

    Newcomer
    25
    0
    Apr 13, 2011
    Netherlands
    Almere, NL
     
  11. YoshiInAVoid

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    337
    Jan 10, 2011
    Well, thats a problem with your sound. I can only help if you post your whole project.
     
  12. cadw
    OP

    cadw Member

    Newcomer
    25
    0
    Apr 13, 2011
    Netherlands
    Almere, NL
    I'll PM you with my project... OK?
     
  13. YoshiInAVoid

    YoshiInAVoid GBAtemp Advanced Fan

    Banned
    560
    337
    Jan 10, 2011
    Ok, I completeley re-did it for you. It works perfect now. I sent it to you by email [​IMG]