move with rawdraw [edit!]

Started by , Tue 19/02/2008 13:56:47

Previous topic - Next topic

bicilotti

I'm working on some kind of tile-block game and I've got a problem with "walkbehinds": my main character won't "disappear" under room-blocks, as they're drawn using rawdraw.

I couldn't use objects or characters becuase the things to draw are many.

I tried to add some "dummy characters" which follows closely the main character, but even that solution wasn't ok, because then the dummy blocks themselves behaved in the same way and with the same problems of the main character.

Finally I've thought that i can use an invisible main character AND use rawdraw to picture the board as I feel right to, BUT:

1) I need to make the rawdrawed hero to follow the invisible character;

So I need to set up a sort of "walk" with rawdraw. Is there any code/module I can peek? Thank you in advance.

Ghost

MAybe you can set up the whole game board as a struct, without even using characters- KrisMuc gave some nice tips here:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=33748.0

bicilotti

Quote from: Ghost on Tue 19/02/2008 14:46:45
MAybe you can set up the whole game board as a struct, without even using characters- KrisMuc gave some nice tips here:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=33748.0

Actually I *did* set up my game as a struct. I'll check Khris code, it is sure worthy.

GarageGothic

#3
RawDrawing a character following an invisible character is quite easy. Assuming a full screen DrawingSurface called "background":

Code: ags

Viewframe *playerframe = Game.GetViewFrame(player.View, player.Loop, player.Frame);
//if you need to scale or tint the character, we create a DynamicSprite of him, otherwise skip this and use playerframe.Graphic instead of herosprite.Graphic later on  
DynamicSprite *herosprite = DynamicSprite.CreateFromExistingSprite(playerframe.Graphic);
herosprite.Resize((herosprite.Width*player.Scaling)/100, (herosprite.Height*player.Scaling)/100));
Region *playerregion = Region.GetAtRoomXY(player.x, player.y);
if (playerregion.TintEnabled == true) {
   herosprite.Tint(playerregion.TintRed, playerregion.TintGreen, playerregion.TintBlue, playerregion.TintSaturation, 100);
   }
else if (playerregion.LightLevel < 0) herosprite.Tint(0, 0, 0, 0, 100+playerregion.LightLevel); //not sure about the saturation setting here
//now to RawDraw the character
background.DrawImage(player.x-(herosprite.Width/2), player.y - herosprite.Height, herosprite.Graphic); // you can also wait to resize the sprite until drawing it by using optional parameters


However, I'm wondering how you handle background collision detection and pathfinding on a RawDrawn background? Presumably the character can't walk everywhere, so how does the invisible character know where to walk and where not to go?

Radiant

If you're doing rawdraws rather than characters, you'd have to do your own collision and pathfinding as well, which is not really recommended.

What exactly are you trying to accomplish?

Khris

#5
As far as I understand it, bicilotti wants to use an invisible standard character that's "followed" by a raw drawn one. This way, he can take advantage of the built-in pathfinding and collision detection but the visual representation can follow his own rules, as in, the char can be obscured by other raw drawn objects.

Edit (after reading GG's post):
Right, sorry.
I assume bicilotti won't need pathfinding and will do his own collision detection based on the tile data.
That's what I'd do.

GarageGothic

I think both I and Radiant understand that part, KhrisMUC, but the question is how the built-in pathfinding can deal with obstacles in the background when the background consists of RawDrawn tiles rather than objects or pre-set walkable areas.

bicilotti

#7
First of all thank you all: I briefly viewed GG code and I think it'll help me quite a lot.

Quote from: KhrisMUC on Tue 19/02/2008 18:56:54
As far as I understand it, bicilotti wants to use an invisible standard character that's "followed" by a raw drawn one. This way, he can take advantage of the built-in pathfinding and collision detection but the visual representation can follow his own rules, as in, the char can be obscured by other raw drawn objects.

KhrisMUC got it perfectly and with a more polished language than my own post.

Quote
However, I'm wondering how you handle background collision detection and pathfinding on a RawDrawn background? Presumably the character can't walk everywhere, so how does the invisible character know where to walk and where not to go?

My game has few, very simple mechanics, which allowed me to takle this quite easily. And, moreover, no pain, no gain. Again thank you!

edit (after 20 mins): the code won't do what I thought it should.

Let's see if I did that right:
-I've put it in repex (slightly modifying it to my needs);
-I've run the game;

Now, when I asked the question *that* was the solution I had in mind. The problem is that rawdraw does not mop up what it has previously drawn. With a fresh mind I see I can use CreateCopy to sneak around the problem, but before trying that I want to hear if I did something wrong to mess up GG code

[/edit]

bicilotti


GarageGothic

#9
I assumed that you were RawDrawing everything to the screen every game cycle and were therefore already clearing the screen in-between game cycles. Since that doesn't seem to be the case, yes, you must use CreateCopy() and restore the background at the beginning of a cycle. Alternately, to optimize it a bit, you could simply redraw the tiles surrounding the player character before drawing the character.

Edit: Perhaps a better solution would be to stick with the regular character, and instead draw the "walkbehind areas" onto a full-screen sprite with a clear background. This sprite could then be displayed as an Overlay. That way you could avoid RawDrawing and restoring background every cycle, since this is pretty slow in the new Direct3D mode.

bicilotti

Quote from: GarageGothic on Tue 19/02/2008 23:13:42
Alternately, to optimize it a bit, you could simply redraw the tiles surrounding the player character before drawing the character.

That's what I'm scripting right now. Thanks again.

GarageGothic

That was a very quick reply :). Please also check my edit.

bicilotti

#12
Quote from: GarageGothic on Tue 19/02/2008 23:13:42
Edit: Perhaps a better solution would be to stick with the regular character, and instead draw the "walkbehind areas" onto a full-screen sprite with a clear background. This sprite could then be displayed as an Overlay. That way you could avoid RawDrawing and restoring background every cycle, since this is pretty slow in the new Direct3D mode.

Didn't thought about that...  :o Let's - a - try!

edit: I have once again to correct myself. Walkbehinds in my (convoluted) little game change and move. If I cannot move them and I got only 15 of them this path will lead to damnation. What a pity.

Now then, I'm working on rawdraw walk again.

Khris

A screen shot would be really helpful :=

Maybe you can use a second character as mobile walkbehind. Using ViewFrame, you can change the char's standing / face down frame to a graphic holding the part of the "background" in front of the player, then move the char to player.x, player.y, keeping its baseline at player.y+1.
This has to be done every loop but should be fast enough.

bicilotti

Quote from: KhrisMUC on Wed 20/02/2008 00:25:34
A screen shot would be really helpful :=

The least I can do :) Here's the prototype:



White block is "hero", others block are "furniture". I've tried the "dummy characters" solution, but, for reasons which the image make obvious, wasn't the right path.

Anyway, I'm 50% of the walk scripting. Thank you again and be assured you'll have your place in the "many thanks" readme section. :)

Radiant

Ah.

If that was the idea, I'd go with no characters at all, but simply building the screen with rawdraws.

Since the playing area appears to be a simple matrix, doing your own pathfinding isn't going to be all that hard.

Looks interesting, btw. I like puzzle games.

SMF spam blocked by CleanTalk