Anubiss

Members
  • Content count

    10
  • Joined

  • Last visited

Community Reputation

100 Neutral

About Anubiss

  • Rank
    Member
  1. Animation - shakingProblem

    hey guys. following problem: I want to let my startbutton shake if it is not touched within 10 seconds. this lecture is out of a book i baught for starting with Android programing. But although i am thinking of havin done everything correct, the button does not shake. [b]buttonID = button1[/b] [b]res/anim/wackeln.xml[/b] [code] <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="-40" android:toDegrees="40" android:duration="1000" android:repeatCount="20" /> [/code] and in my main activity: [code] private Animation animationWackeln; private Button startButton; private Handler handler = new Handler(); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(this); animationWackeln = AnimationUtils.loadAnimation(this, R.anim.wackeln); startButton = (Button)findViewById(R.id.button1); } private class WackleButton implements Runnable { public void run() { startButton.startAnimation(animationWackeln); } } @Override protected void onResume(){ super.onResume(); handler.postDelayed(new WackleButton(), 1000*10); } [/code] i hope someone will help. thank you
  2. Creating A New Object Ingame

    what do you mean with that i "dont take keypad input in my menu loop"? they´re in each loop as i see. in the first Menu it´s even working, but if i´m pressing the A-Button the new menu appears but with each klick on up or down the "o" will put out on each y-value EDIT: Allright, I understood what you mean. made it now so: [code]//Handelsbildschirm: ///////////////////////////////////////////////// void handelsbildschirm(void){ PA_OutputText(1,0,1,"++++++++++++++++"); PA_OutputText(1,0,2," Station: %02d", stations[istationen].id); PA_OutputText(1,0,3,"++++++++++++++++"); PA_OutputText(1,2,5,"Handelsbildschirm"); PA_OutputText(1,0,6,"++++++++++++++++"); PA_OutputText(1,0,optionskursor,"o"); if(Pad.Newpress.Down)optionskursor++; if(Pad.Newpress.Up)optionskursor--; } //Stations-Menü: ///////////////////////////////////////////////// void stationsmenu(void){ PA_OutputText(1,0,1,"++++++++++++++++"); PA_OutputText(1,0,2," Station: %02d", stations[istationen].id); PA_OutputText(1,0,3,"++++++++++++++++"); PA_OutputText(1,2,5,"Handelsbildschirm"); PA_OutputText(1,2,6,"Stationsinformationen"); PA_OutputText(1,2,7,"Schiffsinformationen"); PA_OutputText(1,0,optionskursor,"o"); if(Pad.Newpress.Down)optionskursor++; if(Pad.Newpress.Up)optionskursor--; }[/code] and to call the menu: [code] while ((stations[istationen].entfx<30)&&(stations[istationen].entfy<30)){ //PA_OutputText(1,2,9,"'X' zum kaufen"); // //menu(); if(optionsflag==0)stationsmenu(); if(Pad.Newpress.A)optionsflag=1; if(optionsflag==1)handelsbildschirm(); break; }[/code] I´m of course not ready with it, but seeing that it´s working, is bringing me forward. Have much thanks!
  3. Creating A New Object Ingame

    But i only have to use free() if i really want to destroy an "object"? So i can create, create and create and only for "n"- 1 (for example) i need to free the memory then? EDIT: btw, there´s a new question i have. i made an option-menu [code]//Handelsbildschirm: ///////////////////////////////////////////////// void handelsbildschirm(void){ while(1){ PA_OutputText(1,0,1,"++++++++++++++++"); PA_OutputText(1,0,2," Station: %02d", stations[istationen].id); PA_OutputText(1,0,3,"++++++++++++++++"); PA_OutputText(1,2,5,"Handelsbildschirm"); PA_OutputText(1,0,6,"++++++++++++++++"); PA_OutputText(1,0,optionskursor,"o"); if(Pad.Newpress.Down)optionskursor++; if(Pad.Newpress.Up)optionskursor--; if(Pad.Newpress.B)break; } } //Stations-Menü: ///////////////////////////////////////////////// void stationsmenu(void){ PA_OutputText(1,0,1,"++++++++++++++++"); PA_OutputText(1,0,2," Station: %02d", stations[istationen].id); PA_OutputText(1,0,3,"++++++++++++++++"); PA_OutputText(1,2,5,"Handelsbildschirm"); PA_OutputText(1,2,6,"Stationsinformationen"); PA_OutputText(1,2,7,"Schiffsinformationen"); PA_OutputText(1,0,optionskursor,"o"); if(Pad.Newpress.Down)optionskursor++; if(Pad.Newpress.Up)optionskursor--; if(Pad.Newpress.A){ PA_ClearTextBg(1); switch(optionskursor){ case 5: handelsbildschirm(); } } }[/code] I choose with my cursor the option "Handelsbildschirm" an it leads me to the new menu, but there the cursor does not move. is it because of the "while()" ?
  4. Creating A New Object Ingame

    glorious! have much thanks. it´s working very fine. but for understanding. realloc is reserving memory as malloc is doing. But realloc keeps the given values and new values are simply added behind the already excisting values?
  5. Creating A New Object Ingame

    i´m calling it in each frame. should i make some kind of counter or something like that? but i don´t think it can be a lack of mem, because a few minutes ago i was able to load about 30 new stations, with 30 sprites. but they just where created on the same coordinates.. and didn´t move
  6. Creating A New Object Ingame

    thank you. now i have one problem more. my function is now looking like that: [code]oid ladestationen(void){ stations = (ownstation*) malloc(n*sizeof(ownstation)); istationen=0; while (istationen<n){ if (stations[istationen].flag!=1){ stations[istationen].x=330; stations[istationen].y=120; PA_CreateSprite(0, istationen,(void*)station01_Sprite, OBJ_SIZE_64X64,1, 1, stations[istationen].x-16, stations[istationen].y-16); stations[istationen].flag=1; } PA_SetSpriteXY(0, istationen, ((stations[istationen].x-16)+(-scrollx>>8))-16, ((stations[istationen].y-16)+(scrolly>>8))-16); istationen++; } }[/code] It works everything so far, but when i create a new station the game freezes. it does not freeze, when it looks like so: [code]void ladestationen(void){ stations = (ownstation*) malloc(n*sizeof(ownstation)); while (istationen<n){ if (stations[istationen].flag!=1){ stations[istationen].x=330; stations[istationen].y=120; PA_CreateSprite(0, istationen,(void*)station01_Sprite, OBJ_SIZE_64X64,1, 1, stations[istationen].x-16, stations[istationen].y-16); stations[istationen].flag=1; } PA_SetSpriteXY(0, istationen, ((stations[istationen].x-16)+(-scrollx>>8))-16, ((stations[istationen].y-16)+(scrolly>>8))-16); istationen++; } }[/code] but now the x and y values of the station do not change..
  7. Creating A New Object Ingame

    Alright. It´s working so far. I can add a new station. But after making one station the game freezes. [code] void ladestationen(void){ while (istationen<n){ stations[istationen].x=210; stations[istationen].y=100; if (stations[istationen].flag!=1){ PA_CreateSprite(0, istationen,(void*)station01_Sprite, OBJ_SIZE_64X64,1, 1, stations[istationen].x-16, stations[istationen].y-16); stations[istationen].flag=1; } PA_SetSpriteXY(0, 3, ((stations[istationen].x-16)+(-scrollx>>8))-16, ((stations[istationen].y-16)+(scrolly>>8))-16); } } [/code] I almost think, that this is correct. But following I wrote out of a function and out of the main-function: [code]ownstation* stations; stations = (ownstation*) malloc(n*sizeof(ownstation));[/code] And how does it work with resizing? I don´t really understand where exactly this has to be written. EDIT: That´s wrong, aye? void ladestationen(void){ stations = (ownstation*) malloc(n*sizeof(ownstation)); while (istationen<n){ stations[istationen].x=210; stations[istationen].y=100; if (stations[istationen].flag!=1){ PA_CreateSprite(0, istationen,(void*)station01_Sprite, OBJ_SIZE_64X64,1, 1, stations[istationen].x-16, stations[istationen].y-16); stations[istationen].flag=1; } PA_SetSpriteXY(0, 3, ((stations[istationen].x-16)+(-scrollx>>8))-16, ((stations[istationen].y-16)+(scrolly>>8))-16); } temp = (ownstation*) malloc(newlen*sizeof(ownstation)); memcpy(temp, stations, oldlen*sizeof(ownstation)); free(stations); stations=temp; }
  8. Creating A New Object Ingame

    allright. the 1st part i checked. now i do following: [code] void menu(void){ if (Pad.Newpress.X) n++; } [/code] and [code] if ((rs.entfx<30)&&(rs.entfy<30)){ PA_OutputText(1,0,2,"'X' zum kaufen-"); menu(); } [/code] So i add "1" to n, when the X-Button is pressed. And how are the stations looking like? I mean, if n=2, do i have stations[0] and stations[1] then?
  9. Creating A New Object Ingame

    this malloc function sounds very good, but it seems like i need to understand a bit more about this and also pointers. So i made now a struct for the stations i want to buy: [code] typedef struct{ int id; int x; int y; int flag; int entfx; int entfy; }ownstation; ownstation neu[10]; [/code] Is it correct to make an array now if i for example don´t want to have more than 10 stations? then i have found following for this malloc: [code] char * String; String = (char *) malloc(1000); [/code] so if the code would be: if (klicking on "buy"){ do what? } EDIT: ownstation* neu(neu[10](int id[10])); something like this maybe? (i know that it is not correct, but maybe i am on the right way)
  10. Creating A New Object Ingame

    Hey friends. I hope you can help me with my lil game what i´m writing in C with the PaLib library for my nintendo ds. I have a ship what´s flying through the orbit. when the ship is landing in the space-station i want to have the option "buy new station". But how do i code the creation of a new station. i just need the idea of how doing that. Will be happy about any help. Here´s the code till now: [code] // Includes #include <PA9.h> #include "gfx/all_gfx.c" #include "gfx/all_gfx.h" int main(int argc, char ** argv) { PA_Init(); PA_InitVBL(); PA_EasyBgLoad(0, 1, aa); PA_InitText(1,0); PA_LoadSpritePal(0, 0, (void*)vaisseau_Pal); PA_LoadSpritePal(0, 1, (void*)station01_Pal); PA_CreateSprite(0, 0,(void*)vaisseau_Sprite, OBJ_SIZE_32X32,1, 0, 128-16, 96-16); // Das SChiff auf Mitte des unteren Screens setzen PA_SetSpriteRotEnable(0,0,0); u16 angle = 0; int x = (128) << 8; int y = (96) << 8; int sx; int sy; typedef struct{ int x; int xmax; int schalter; }pflanze; pflanze buche; buche.xmax=1000; buche.schalter=0; int scrollx = 0; int scrolly = 0; //Raumstation: ///////////////////////////////////////////////// typedef struct{ int x; int y; int flag; int entfx; int entfy; }station; station rs; //station fremd[10];//0-9 rs.x=200; rs.y=96; rs.flag=0; rs.entfx; rs.entfy; void station01test(void){ rs.entfx=(sx>>8)-(rs.x);//Entfernung zwischen Station und Raumschiff messen if (rs.entfx<0){rs.entfx=-rs.entfx;}//Betrag, falls Entfernung negativ! rs.entfy=(sy>>8)-(rs.y); if (rs.entfy<0){rs.entfy=-rs.entfy;} if (rs.flag==0){ PA_CreateSprite(0, 2,(void*)station01_Sprite, OBJ_SIZE_64X64,1, 1, rs.x-16, rs.y-16); rs.flag=1; } if ((rs.entfx>100)&&rs.flag==1){ PA_DeleteSprite (0, 2); rs.flag=0; } if ((rs.entfy>100)&&rs.flag==1){ PA_DeleteSprite (0, 2); rs.flag=0; } if ((rs.entfx<30)&&(rs.entfy<30)){ PA_OutputText(1,0,2,"'START' zum Landen-"); } if ((rs.entfx>30)||(rs.entfy>30)){ PA_OutputText(1,0,2," "); } } //Einfacher test: ///////////////////////////////////////////////// void wachse(void){ if (buche.schalter==1) if(buche.x<buche.xmax) buche.x++; if(buche.x==buche.xmax) buche.x=buche.xmax; } //STATUSBILDSCHIRM ////////////////////////////////////////////////////////////////// void statusscreen(void){ //Ausgabe von Informationen auf oberen Screen: //////////////////////////////////////////////////////////////////////////////// PA_OutputText(1,0,12,"Map-x: %02d", scrollx>>8); PA_OutputText(1,0,13,"Map-y: %02d", scrolly>>8); PA_OutputText(1,0,14,"-------------------"); PA_OutputText(1,0,15,"Schiff-x: %02d", sx>>8); PA_OutputText(1,0,16,"Schiff-y: %02d", sy>>8); PA_OutputText(1,0,17,"-------------------"); PA_OutputText(1,0,18,"x von Station entfernt: %02d", rs.entfx); PA_OutputText(1,0,19,"y von Station entfernt: %02d", rs.entfy); PA_OutputText(1,0,20,"Winkel des Schiffes: %02d", angle); } //MAIN: //////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// while (1) { //Test-Buche: zählt von 0 bis 1000, wenn "A" gedrückt wird if (Pad.Newpress.A) buche.schalter=1; wachse(); PA_OutputText(1,0,0,"%02d", buche.x); //Winkelberechnung-Flugschiff: /////////////////////////////////////////////////////////////////////////////// angle = PA_GetAngle(x>>8, y>>8, Stylus.X, Stylus.Y); // PA_SetRotsetNoZoom(0, 0, angle); // Änderung des Schiffswinkels // //Flugschiff-Koordinaten AUSSERHALB DER ENGINE: sx=(scrollx+x); sy=(scrolly+y); //Hintergrund-Scrolling: ////////////////////////////////////////////////////////////////////////////// if(Pad.Held.B){ // scrollx += PA_Cos(angle); // scrolly += PA_Sin(angle); }; //Map-Grenzen: // if((scrollx>>8)>(2560-255)){ scrollx=590080; }; if((scrollx>>8)<0){ scrollx=0; }; if((-scrolly>>8)>(1600-191)){ scrolly=-360704; }; if((-scrolly>>8)<0){ scrolly=0; }; //Set-Map: PA_LargeScrollXY(0, 1, scrollx>>8, -scrolly>>8); statusscreen(); PA_SetSpriteXY(0, 0, (x>>8)-16, (y>>8)-16); PA_SetSpriteXY(0, 2, ((rs.x-16)+(-scrollx>>8))-16, ((rs.y-16)+(scrolly>>8))-16); station01test(); PA_WaitForVBL(); } return 0; } [/code]