Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] mouseclick menu technique

Author
Message
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 20th Jul 2009 07:52 Edited at: 20th Jul 2009 13:52
In a game I'm working on right now, I have a lot of "hot spots" on the screen that the player can click on, making various things happen. So I put in a bunch of if/then tests for the mousex and mousey locations at the time of the click. Wow, not very pretty.

Then I thought of this, and maybe it's already been done, but it's new to me.

I made a graphic of the main screen, but with a mask of different levels of color red, and put it in bitmap 4. Then this code



gets the red value of the mask bitmap. I'm using red values that match scankey codes, and trapping keypresses at the same time. On the area of the screen where the player can click to move forward, I've painted rgb(17,0,0), on the area to move backward I've painted rgb(31,0,0), and so on. Then I can use a select case like this...



With a 24 bit mask, I can have 255 different hot spots on a black background. Plus, I can have very irregularly shaped hotspots, all designed visually on my main screen.

Rich
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 23rd Jul 2009 10:50
Brilliant Rich. This is very similar to our Statics mapping we used for our RPG demo project. The concept was in 3D, but basically the same. Where the player is on the 3D map (x & z) pointed to coordinates on an image map (x & y), and the resulting pixel colors told the code which objects to load for grass, sand, dirt, rocks, flowers, and so on. It was also used for sounds as the player "walked" on the various terrain types.

IMHO, Images hold a lot of data, and I believe that all that data is way under used. This is one more example of how image data can be used beyond just pretty pictures.

Anyway, I am ashamed that I did not think of this as an extension of statics. So, here is me playing around with it (image is the attachment). There are more things I want to do, but this is just a start.

Oh, and you might find the image-memblock functions useful. Saves having to swap bitmaps to pull the pixel.




Open MMORPG: It's your game!

Attachments

Login to view attachments
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Jul 2009 11:02
Genius!
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 24th Jul 2009 15:37
Thanks for the responses!

RiiDii, I have not done anything with memblocks as of yet, but I do plan to learn about them as I get deeper into DarkBASIC.

Since I was just using the red value to check mouse clicks, I was thinking that an 8 bit depth might save on memory overhead, instead of 24 bits. I suppose a 256 color grey-scale image would load into a memblock?

Rich
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Oct 2009 04:55 Edited at: 31st Oct 2009 04:59
I see RiDii has already recommended the use of memblocks. Point is quite a slow command so I'd say memblocks are the way to go.
I've seen this done before but kudos for coming up with the same idea on your own

PS shades of blue are easier to check because they're simply 0-255, using the rgbr command does n*65536, which eats up power when checking thousands of pixels.

TGC Forum - converting error messages into sarcasm since 2002.

Login to post a reply

Server time is: 2024-05-05 01:54:24
Your offset time is: 2024-05-05 01:54:24