|
|
| Having problem scrolling my mappy map in A5 |
|
ISDcaptain
Member #15,087
May 2013
|
Okay So Im trying to draw a map/level made in mappy nd trying to scroll it. I had no problem doing this in A4 using mappyal.h and mappyal.c. Now im doing it in A5 using mappy_A5.h and mappy_A5.c. Okay heres the code any ways First my display dimensions 1#define WIDTH 800
2#define HEIGHT 600
Now here are my map scrolling variables 1//Camera variables
2int mapxoff = 0, mapyoff = 0;
Okay so now I want my scrolling variables to lock onto my player, so I make a function for it: 1//Set the camera up and keep it updates
2void UpdateCamera()
3{
4 //Sync the camera with the player position
5 mapxoff = link->x + link->width/2 - WIDTH/2 + 10;
6 mapyoff = link->y + link->height/2 - HEIGHT/2 + 10;
7
8 //avoid making the camera go off screen.
9 //x axis
10 if(mapxoff < 0)
11 mapxoff = 0;
12 if(mapxoff > (mapwidth * mapblockwidth) - WIDTH)
13 mapxoff = (mapwidth * mapblockwidth) - WIDTH;
14 //y axis
15 if(mapyoff < 0)
16 mapyoff = 0;
17 if(mapyoff > (mapheight * mapblockheight) - HEIGHT)
18 mapyoff = (mapheight * mapblockheight) - HEIGHT;
19}
So everything seems so good so far right? K lets get into the main function and load up the map: 1//Load in the map
2MapLoad("Zelda1.fmp", 1);
Okay now I need to call that function from above in my game loop and get it locked with my character so I do that here inside my "game loop" 1else if(state == playing)
2 {
3 //Play the music
4 al_stop_sample_instance(introInstance);
5 playSounds();
6
7 //Life check (test)
8 checkLife();
9
10 //Update the camera
11 UpdateCamera();
12 //Check if the player pressed a key
13 //and act accordingly
14 getInput();
15
16
17 }
K now finally I render the map onto screen in the redering area of the game loop: 1//What to draw during the playing state
2 else if(state == playing)
3 {
4
5 //Draw the map background
6 MapDrawBG(mapxoff, mapyoff, 0, 150, 800-1, 448-1);
7 //Draw the map foreground
8 MapDrawFG(mapxoff, mapyoff, 0, 150, 800-1, 448-1, 0);
9
10 //Draw Link
11 drawLINK();
12
13 //Draw the status bar
14 drawGUI();
15
16 }
THe problem is that the game immediately crashes right after I enter the playing state and takes me to this area of the mappyA5.h file: 1
2/* draw the background graphics on the current layer to the target bitmap, usually backbuffer */
3void MapDrawBG (int mapxo, int mapyo, int mapx, int mapy,int mapw, int maph)
4{
5 int i, j, mycl, mycr, myct, mycb, mapvclip, maphclip;
6 int mbgx, mbgy;
7 short int *mymappt;
8 short int *mymap2pt;
9 BLKSTR *blkdatapt;
10 ANISTR *myanpt;
11 ALLEGRO_BITMAP* mapdestpt;
12
13 mapdestpt=PushTargetDisplayAndBitmap(NULL);
14 al_get_clipping_rectangle(&mycl,&mycr,&myct,&mycb);
15 al_set_clipping_rectangle(mapx,mapy,mapw,maph);// set_clip (mapdestpt, mapx, mapy, mapx+mapw-1, mapy+maph-1);
16
17 mapxo -= mapblockstaggerx;
18 mapyo -= mapblockstaggery;
19 mymappt = (short int *) mappt;
20 if (mapblockstaggerx || mapblockstaggery)
21 {
22 mymappt += (mapxo/mapblockgapx)+((mapyo/mapblockgapy)*mapwidth*2);
23 mbgx = mapblockgapx;
24 mbgy = mapblockgapy;
25 }
26 else
27 {
28 mymappt += (mapxo/mapblockgapx)+((mapyo/mapblockgapy)*mapwidth);
29 mbgx = 0;
30 mbgy = 0;
31 }
32 mapvclip = mapyo%mapblockgapy;
33 maphclip = mapxo%mapblockgapx;
34
35 mymap2pt = mymappt;
36 for (j=((mapy-mapvclip)-mbgy);j<((mapy+maph));j+=mapblockgapy)
37 {
38 for (i=((mapx-maphclip)-mbgx);i<((mapx+mapw));i+=mapblockgapx)
39 {
40 if (*mymappt>=0)
41 blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
42 else
43 {
44 myanpt = mapanimstrendpt + *mymappt;
45 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff];
46 }
47 if (mapblockstaggerx || mapblockstaggery)
48 {
49 if (abmTiles[0] != (ALLEGRO_BITMAP *) blkdatapt->bgoff)
50 //masked_blit ((ALLEGRO_BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j, mapblockwidth, mapblockheight);
51 al_draw_bitmap((ALLEGRO_BITMAP *) blkdatapt->bgoff,i,j,0); //size should be the same
52 }
53 else
54 {
55 al_draw_bitmap_region((ALLEGRO_BITMAP *) blkdatapt->bgoff,0,0,mapblockwidth,mapblockheight,i,j,0); //blit ((BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j, mapblockwidth, mapblockheight);
56 }
57 mymappt++;
58 }
59 if (mapblockstaggerx || mapblockstaggery)
60 {
61 mymap2pt += mapwidth;
62 mymappt = mymap2pt;
63 for (i=(((mapx-maphclip)-mbgx)+mapblockstaggerx);i<((mapx+mapw));i+=mapblockgapx)
64 {
65 if (*mymappt>=0)
66 blkdatapt = ((BLKSTR*) mapblockstrpt) + *mymappt;
67 else
68 {
69 myanpt = mapanimstrendpt + *mymappt;
70 blkdatapt = ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff];
71 }
72 if (abmTiles[0] != (ALLEGRO_BITMAP *) blkdatapt->bgoff)
73 //masked_blit ((ALLEGRO_BITMAP *) blkdatapt->bgoff, mapdestpt, 0, 0, i, j+mapblockstaggery, mapblockwidth, mapblockheight);
74 al_draw_bitmap((ALLEGRO_BITMAP *) blkdatapt->bgoff,i,j+mapblockstaggery,0); //size should be the same
75
76 mymappt++;
77 }
78 }
79 mymap2pt += mapwidth;
80 mymappt = mymap2pt;
81 }
82 al_set_clipping_rectangle(mycl,mycr,myct,mycb);
83 PopTargetDisplayAndBitmap();
84}
If anyone could help me out that would be wonderful. Im looking at you Neil Walker since you made the mappya5.h/.c files. |
|
Dizzy Egg
Member #10,824
March 2009
|
I'm not 100% sure about that BLKSTR* being used as an ALLEGRO_BITMAP* ... could you try commenting out the lines with al_draw_bitmap etc that use blkdatapt...obviously it wont draw anything then, but it's my only idea so far!!
---------------------------------------------------- |
|
Listopad
Member #15,486
February 2014
|
When the program will crash on the mappy function, read all args from function and compare it with dimension of map. If You don't understand what iam talking about, paste it here. |
|
|