Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Virtual Screen Problems

This thread is locked; no one can reply to it. rss feed Print
Virtual Screen Problems
Andy S.
Member #2,997
December 2002
avatar

I have a game that uses virtual screen stuff. Everything works fine with the virtual screen, drawing, blitting, but the mouse can NOT go on it! Any and all help is apperciated. Below is my code.

1void NewGameIntro()
2{
3set_clip(screen, 0, 0, VIRTUAL_W, VIRTUAL_H);
4 
5 BITMAP *buffer = create_bitmap(VIRTUAL_W, VIRTUAL_H); //the buffer
6 BITMAP *griz = load_bitmap("gfx/griz.bmp", NULL); //grizwold
7 BITMAP *portal = load_bitmap("gfx/portal.bmp", NULL); //the portal
8 BITMAP *cur = load_bitmap("gfx/cur.bmp", NULL); //the cursor
9 BITMAP *bg = load_bitmap("gfx/bg.bmp", NULL); //the background
10 BITMAP *path = load_bitmap("gfx/path-ri.bmp", NULL); //path right
11 BITMAP *pathu = load_bitmap("gfx/path-up.bmp", NULL); //path up
12 BITMAP *health = load_bitmap("gfx/health.bmp", NULL); //the healthness
13 
14 int bgx=0; //background's current x pos
15 int bgy=0; //back's current y pos
16 int x=mouse_x; //griz's current x pos
17 int y=mouse_y; //griz's current y pos
18 int newx; //the x pos that griz will move to
19 int newy; // y pos he will move to
20 int pany=0; //this makes the screen pan as apposed to jumping from one place to another
21 int panx=0;
22 
23 text_mode(-1); //make the text transparent
24 
25 clear(buffer); //clear excess crap on buffer
26 
27 short int exit = 0; //make exit int (short for memory purpouses)
28 
29 while(exit != 1) //main game loop
30 {
31 while(bgy <= VIRTUAL_H) //make the background
32 {
33 if(bgx >= SCREEN_W/2-pathu->w && bgx <= SCREEN_W/2)
34 draw_sprite(buffer, pathu, bgx, bgy);
35 else
36 draw_sprite(buffer, bg, bgx, bgy); //draw it
37 bgx+=bg->w; //prepare for next
38 if(bgx >= VIRTUAL_W) //move down a row
39 {
40 bgx = 0;
41 bgy+=bg->h;
42 }
43 }
44 bgy=0; //prepare for next draw
45 
46 draw_sprite(buffer, portal, (SCREEN_W/2)+30, 50); //draw portal
47 draw_sprite(buffer, griz, x, y); //draw griz
48 
49 draw_sprite(buffer, health, 0+panx, SCREEN_H-health->h+pany); //draw health
50 
51 
52 if(mouse_x >= SCREEN_W/2+30 && mouse_x <= SCREEN_W/2+portal->w+30 && mouse_y >= 50 && mouse_y <= portal->h+50)
53 textprintf(buffer, font, mouse_x+23, mouse_y, makecol(152,140,100), "Tristram"); //if cursor is on portal display: Tristram
54 
55 if(mouse_b & 1)
56 {
57 newx=mouse_x-griz->w/2; //if the mouse is clicked, set the newx and newy coords so griz will move
58 newy=mouse_y-griz->h/2;
59 }
60 
61 if(x != newx || y != newy)
62 { //move griz if mouse_x and newx (or y) aren't the same
63 if(x < newx)
64 x+=1;
65 else if(x > newx)
66 x-=1;
67 if(y < newy)
68 y+=1;
69 else if(y > newy)
70 y-=1;
71 }
72 
73 //textprintf(buffer, font, 60,60, makecol(100,100,100), "y: %i", SCREEN_W); //debug use
74 textprintf(buffer, font, 7, 7, makecol(200,50,50), "Bug: ");
75 textprintf(buffer, font, 42, 7, makecol(255,255,255),"The legend of the cow level has plauged us all while we played the origional Diablo."); //display the talking text
76 textprintf(buffer, font, 7, 21, makecol(152,140,100), "Grizwold: ");
77 textprintf(buffer, font, 84, 21, makecol(255,255,255), "The cows have invaded Tristram and I am all that is left to defend the fair town!");
78 
79 draw_sprite(buffer, cur, mouse_x, mouse_y); //draw the cursor
80 
81 if(x >= 700)
82 {
83 if(panx < 150)
84 {
85 request_scroll(panx,0); //make the screen pan right
86 panx++;
87 }
88 if(panx >= 151)
89 panx = 0;
90 }
91 if(y >= 500)
92 {
93 if(pany < 150)
94 {
95 request_scroll(0,pany); //make the screen pan down
96 pany++;
97 }
98 if(pany >= 151)
99 pany = 0;
100 }
101 
102 blit(buffer, screen, 0,0,0,0, VIRTUAL_W, VIRTUAL_H); //draw buffer
103 clear(buffer); //clear buffer for re-use
104 
105 if(key[KEY_ESC]) //let esc exit program
106 exit=1;
107 }
108 
109 destroy_bitmap(buffer);
110 destroy_bitmap(cur);
111 destroy_bitmap(portal); //destroy the bitmaps for memory use
112 destroy_bitmap(griz);
113 destroy_bitmap(bg);
114 destroy_bitmap(path);
115 destroy_bitmap(pathu);
116 destroy_bitmap(health);
117}
118 
119int main()
120{
121 
122 allegro_init();
123 install_keyboard();
124 install_mouse();
125 install_timer();
126 set_color_depth(16);
127 set_gfx_mode(GFX_AUTODETECT, 800,600,1600,1200); //1024, 768, 0,0); //kinda wierd, huh
128 
129 begin(); //begin the game, duh!
130}

there is a begin sub, but it has no virtual screen use in it, therefore, no problems.
If you would like to see what you are working on please click here

------------------------------------------------------
Sometimes you find yourself in the middle of nowhere, and somewhere, in the middle of nowhere, you find yourself.

Ultio
Member #1,336
April 2001

So, are you saying that you don't want the mouse to go into the area of the virtual screen? I can't really tell what you're asking. I took a quick look at your code.

If I'm reading your problem correctly, you don't want the mouse to scroll off the visible bounds of the screen. Well, it's quite simple. You already know the coordinates of the mouse, and the size of your (visible) screen. Just store the width and height of the screen and check if the mouse coordinates go over. If it does, just reset the values to those stored width and height of your screen.

IE: If the mouse scrolls right and goes out of bounds of the screen, just do a test, like so:

if(mouse_x < 0)
    mouse_x = 0;
if(mouse_y < 0)
    mouse_y = 0;
if(mouse_x > VISIBLE_W)
    mouse_x = VISIBLE_W;
if(mouse_y > VISIBLE_H)
    mouse_y = VISIBLE_H)

Did that make sense? I hope this answers the question you were asking.

---
"It's nice knowing that someday, the software I write will just be pirated by millions of people." :-/
http://loomsoft.net | Zep's Dreamland | Allegro Newbie Tutorials

Andy S.
Member #2,997
December 2002
avatar

nono, the oppisite. I want it to go on the virtual screen and it wont!

------------------------------------------------------
Sometimes you find yourself in the middle of nowhere, and somewhere, in the middle of nowhere, you find yourself.

Ultio
Member #1,336
April 2001

Aha. Then, I have no idea how to help you. Have you tried tracking the coordinates to the screen? Does it just stop at the edge? Hm. What do you need it to go into the virtual zone for, anyways? I mean, you can't see it... :/

---
"It's nice knowing that someday, the software I write will just be pirated by millions of people." :-/
http://loomsoft.net | Zep's Dreamland | Allegro Newbie Tutorials

Andy S.
Member #2,997
December 2002
avatar

you can see it. I have scroll screen so that you can see the virtual screen. And yes, it stoppes at the edge. I dont understand what the rest of your message says, Sorry.

------------------------------------------------------
Sometimes you find yourself in the middle of nowhere, and somewhere, in the middle of nowhere, you find yourself.

Ultio
Member #1,336
April 2001

Hm. So, it scrolls the screen into the virtual zone, and then the mouse stops at the non-virtual bounds?

---
"It's nice knowing that someday, the software I write will just be pirated by millions of people." :-/
http://loomsoft.net | Zep's Dreamland | Allegro Newbie Tutorials

Andy S.
Member #2,997
December 2002
avatar

yes

------------------------------------------------------
Sometimes you find yourself in the middle of nowhere, and somewhere, in the middle of nowhere, you find yourself.

Ultio
Member #1,336
April 2001

I found it. It's in the docs.

void set_mouse_range(int x1, int y1, int x2, int y2);

Sets the area of the screen within which the mouse can move. Pass the top left corner and the bottom right corner (inclusive). If you dont call this function the range defaults to (0, 0, SCREEN_W-1, SCREEN_H-1).

Hope that does the trick :)

---
"It's nice knowing that someday, the software I write will just be pirated by millions of people." :-/
http://loomsoft.net | Zep's Dreamland | Allegro Newbie Tutorials

Andy S.
Member #2,997
December 2002
avatar

EXCELLENT! THANK YOU THANK YOU THANK YOU! But now, on to the next problem! When the screen has scrolled right, it can not scroll down. And when it has scrolled down, it can scroll right, but when it does, the viewable screen will go back to the origional screen. Does that make sense? If you wait about 2 mins after posting this I should be able to upload a newer example here. Thanks In Advance!

------------------------------------------------------
Sometimes you find yourself in the middle of nowhere, and somewhere, in the middle of nowhere, you find yourself.

Ultio
Member #1,336
April 2001

You should be doing it like this:
request_scroll(panx,pany);
on both of the lines that do the virtual scrolling stuff. The other way you're doing it -- you are always setting either the Y or X value to Zero and only scrolling one way or another. That's why you're getting that weird problem.

---
"It's nice knowing that someday, the software I write will just be pirated by millions of people." :-/
http://loomsoft.net | Zep's Dreamland | Allegro Newbie Tutorials

Synapse Jumps
Member #3,073
December 2002

I too am having a problem that relates to this. I have a game much like Will, here. But, I clip the rest of the area that isn't visable. Here's my code for scrolling, but when you scoll right some of the visable area get's cut off. Also, when it does scroll, it looks TOO fluid, does that make sense??? When you scroll the only thing that looks like it's moving is the mouse.

Here is my code:

1if(x >= (visablelimitx-150))
2 {
3 if(movescreenx+150 < VIRTUAL_W)
4 {
5 scroll_screen(movescreenx,movescreeny); //make the screen pan right
6 visablelimitx++; //move the visable area over
7 beginvisablelimity++;
8 movescreenx++;
9 }
10 }
11 if(y >= (visablelimity-150))
12 {
13 if(movescreeny+150 < VIRTUAL_H)
14 {
15 scroll_screen(movescreenx,movescreeny); //make the screen pan down
16 visablelimity++; //move the visable area down
17 beginvisablelimity++;
18 movescreeny++;
19 }
20 }
21 if(x <= (beginvisablelimitx+150))
22 {
23 if(movescreenx-150 > 0)
24 {
25 scroll_screen(movescreenx,movescreeny); //make the screen pan right
26 visablelimitx--; //move the visable area over
27 beginvisablelimitx--;
28 movescreenx--;
29 }
30 }
31 if(y <= (beginvisablelimity+150))
32 {
33 if(movescreeny-150 > 0)
34 {
35 screen_scroll(movescreenx,movescreeny); //make the screen pan right
36 visablelimity--; //move the visable area over
37 beginvisablelimity--;
38 movescreeny--;
39 }
40 }

P.S. How do you make it into a box like Will's?

Edit: [url http://www.allegro.cc/mockup.html]

Go to: