Ok, I gave credits to those helping me out in tile slicing.
Now I have a little problem yet: what do I do in order to blit the bitmaps I sliced?
I mean, how do I split a 4x2 tile bitmap in a 8 element array is a clear task. But how do I blit a tile in the array? Please note, I will have to paste the same image more than once.
In Darkbasic Professional I would do something like:
load image, 1
for x = 1 to 4
for y = 1 to 2
get image y*x
next y
next x
for x = 1 to 7
for y = 1 to 23
paste image, myGameGrid[x, y]
next y
next x
The code will probably not run in DarkBasic professional as I done it on the fly.
But I gave the idea no?
How do I do to do something like this?
Thanks everybody in advance.
Bye, Berserk.
.
Not quite sure if you want to
create a bitmap the size you need for mygamegrid.
something like this perhaps :-
Sorry if that's a headache
No, sorry. My problem is another.
I have a bitmap containing the tiles, so I would do
Rem Project: example
Rem Created: 23/05/2009 17.05.59
Rem ***** Main Source File *****
set display mode 800, 600, 32
set window on
hide mouse
sync on
dim grid(7, 23)
load image "blocks.bmp", 1
paste image 1, 0, 0
for x = 1 to 4
for y = 1 to 2
get image (x + (y - 1) * 4), 32 * (x - 1), 32 * (y - 1), 32 * x, 32 * y
next y
next x
for x = 1 to 7
for y = 1 to 23
grid(x, y) = rnd(7) + 1
next y
next x
do
cls
for x = 1 to 7
for y = 1 to 23
paste image grid(x, y), x * 32, (y - 1) * 32
next y
next x
sync
loop
Please note DarkBasic Professional uses 1 based arrays indexes, while C++ uses 0 based.
The grid contains values going 1 to 8 (0 to 7 in C++).
Thanks in advance for any help.
Bye, Berserk.
.
sorry chap. I'm not sure what that code is doing.
I'm assuming you have an array of BITMAPs for your tiles like this: BITMAP *tiles[8];?
If you wanted, for example, to blit the 4th tile 60 times to a buffer, in a 10x6 grid, starting from the point 100, 100, you would do this:
startx = 100; starty = 100; width = tiles[3]->w; height = tiles[3]->h; for (y = 0; y < 6; y++) { for (x = 0; x < 10; x++) { blit(tiles[3], buffer, 0, 0, startx + x * width, starty + y * height, width, height); } }
You should be able to modify that to do whatever it is you want (I'm not sure what that is, to be honest).
The code above takes a bitmap and loads it onto the screen.
Then it splits the contents of the screen in tiles wich are loaded in an array.
Then it loads random values in my game grid, and finally shows the content of the game grid. The do ... loop statement clears the screen, pastes the images from the grid and flips the screen buffer.
How would I do the same with C++ and Allegro?
Bye, Berserk.
.
P.S.: Try the posted code with a trial of darkbasic professional and the attached blocks.bmp.
How would I do the same with C++ and Allegro?
The code you were given in your last thread (which takes a bitmap, and splits it into tiles) and the code I just gave you (which takes one of those tiles and blits it onto a grid) does almost all of what you want. If you can't figure out how to modify them to suit your needs, then you have absolutely no future as a programmer and should just give up now.
If you're just too lazy, and expect everyone to do it fro you, then you're also out of luck.
P.S.: Try the posted code with a trial of darkbasic professional and the attached blocks.bmp.
I really doubt that anyone here is going to do that.
I just don't know allegro, I also tryed with SDL with a little more luck.
I would like someone converting the code as I don't have a clue of what the posted code does.
Plus I have another problem, I have while (!key[KEY_ESC] && !done) { as the main loop but the program wont quit hitting the esc key. why?
Bye, Berserk.
.
well, if you press the esc key, is done == true?
No, done is not == true.
But if false and true should return false, so the loop should quit.
Please help me with the tile slicing code as this is my first allegro project.
Thanks.
Bye, Berserk.
.
I would like someone converting the code as I don't have a clue of what the posted code does.
This is the <strong>allegro</strong>.cc forum. Allegro is a programming library for <strong>C</strong>, and although it can be used with a lot of other programming languages, either directly as with C++, or through a wrapper or other glue, as with C# or Pascal, your chances of getting useful help here are practically zero unless you communicate in C or C++.
So either learn a bit of C (it's hard, but not THAT hard), or try a Darkbasic forum.
Please don't misunderstand me. I wrote an entyre gameplay in C++ and I know the C++ language.
The only thing I don't know is the Allegro programming library, so I'm in front of a wall trying to develop my first real game (by real I mean a C++ game).
I programmed other games before, either in darkbasic professional or in C++ console mode.
The game is ready, it just misses the graphics, sound and input management in order to be playable.
I explained what the code I wish to do, just post a code wich does it please.
Thanks in advance.
Bye, Berserk.
.
P.S.: However, here is a C++ + pseudocode snippet to work on.
[code]
// Project: example
// Created: 23/05/2009 17.05.59
// ***** Main Source File *****
set display mode 800, 600, 32 // this is clear, sets the display mode to 800x600 32 bits
set window on // this sets windowed mode
hide mouse // this hides the mouse cursor
sync on // this is dbpro only: sets manual syncing of the screen
dim grid(7, 23) // this would be equivalent to int grid[7][23];
load image "blocks.bmp", 1 // loads an image
paste image 1, 0, 0 // paste such image onto the screen. please note the next operations are done on the screen and not on the image
for (int x = 1; x <= 4; x++) {
for (int y = 1; y <= 2; y++) {
get image (x + (y - 1) * 4), 32 * (x - 1), 32 * (y - 1), 32 * x, 32 * y
// this will get an image from the screen, the parameters are:
// get image (image number), (x left), (y top), (x right), (y bottom)
}
}
for (int x = 1; x <= 7; x++) {
for (int y = 1; y <= 23; y++) {
grid[x][y] = rand() % 7 + 1
}
}
while(!(escape_key)) {
cls // clear the screen
for (int x = 1; x <= 7; x++) {
for (int y = 1; y <= 23; y++) {
paste image grid(x, y), x * 32, (y - 1) * 32
// this will paste the tile on the screen. parameters are
// paste image (image number), (x coordinate), (y coordinate)
}
}
sync // update the screen
}
[/code]
Thanks.
The only thing I don't know is the Allegro programming library, so I'm in front of a wall trying to develop my first real game (by real I mean a C++ game).
There's an expression that gets used quite a bit that's quite applicable in this situation, it goes like this: read the fucking manual.
In addition to reading the friendly manual, you might try altering the example programs in small ways to see what happens.
There is also the wiki link in the main page of a.cc.
There should be a reason if I have not read the fucking manual as you sayd.
In fact I'm limited to 1 hour PC using a day, that's why I'm asking here instead of completing he "step by step guide on programming a game with allegro" book, wich I downloaded in my main language (italian) and I still have no time to read.
Thanks for your fucking help, fucking community.
Thanks for your fucking help, fucking community.
You were given help, but we're not going to do everything for you. I'm guessing you're leaving then? Good riddance.
Seems to me that it's a question of being realistic. If you want to write a game using allegro but you've got severely limited time with a PC then you've got a problem because you won't get anywhere if you can't learn (which means practice) some C programming.
People don't want to write your game for you because they know it won't help you in the long run.
My advice is spend the time you've got learning C and look at the examples and it'll become clear what you need to do.
Why not take a look at some of the Allegro example programs?
I've attached exsprite, which is an example of all the sprite-drawing functions. It should help you figure out how to load images from datafiles as well.
Messing around with the examples is often the best way to learn things.
Ok, I solved on another forum. Thanks for the exsprite but I already have it and I already gave it a look. Unfortunately I wasn't able to recognize ho to do a sub texture. Now, all I asked was simply create_sub_bitmap( function explanation, but I wasn't knowing that function. Nevermind, I solved on another forum. And no, I'm not gonna leave.
Bye, Berserk.
.
And no, I'm not gonna leave.
Persistence is a virtue for programmers.
Persistence is a virtue for programmers.
So is the ability to think for yourself.
Now, all I asked was simply create_sub_bitmap( function explanation, but I wasn't knowing that function
No, that was not all. You pretty much asked for an entire game to be written for you:
The game is ready, it just misses the graphics, sound and input management in order to be playable.
I explained what the code I wish to do, just post a code wich does it please.
[code]
BITMAP *buf, *tiles[7], *blocks; // this is at the beginning of my main function
newGrid.redraw(tiles, buf); // this is in my main loop
void grid::redraw(BITMAP ** tiles, BITMAP * screen) {
for (int x = 0; x < 7; x++) {
for (int y = 0; y < 19; y++) {
blit(tiles[playground[x][y]], screen, 0, 0, (this->x + x) * 32, (this->y + y) * 32, tiles[playground[x][y]]->w, tiles[playground[x][y]]->h);
}
}
}
this code is where I split my image in tiles
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 2; y++) {
tiles[x + y * 4] = create_sub_bitmap(blocks, x * 32, y * 32, 32, 32);
}
}
[/code]
I also added a vsync but all I get is a black screen. Why?
Bye, Berserk.
.
Not enough code
Where and when do you load what into this variables?
BITMAP *buf, *tiles[7], *blocks; // this is at the beginning of my main function
What is buf? A buffer? If so why do you blit directly to the screen and not to the buffer?
And please note that it is:
<code> your code </code>
NOT
[code]
[/code]
Even writing on screen (wich someone told me is a global variable) I still get a black screen.
Check the return values of your function calls, especially those of set_gfx_mode and load_bitmap. Also note that the documentation of create_sub_bitmap clearly states "Remember to free the sub bitmap before freeing the parent bitmap to avoid memory leaks and potential crashes accessing memory which has been freed."
You do it exactly the other way 'round.
Edit: Oh, and we need more source code. What's grid::redraw doing, for example?
If you need more, just ask. Thanks in advance for any help.
Bye, Berserk.
.
I certainly won't solve this issue for you, I can't find anything obviously wrong with the snippet (apart from a few unclear things, like what values this->x and this->y can take in grid::redraw). Here are some pointers to find the error yourself (in no way do I claim that this list is complete or guarantees success):
Verify the graphics mode is set correctly
Verify that "blocks.bmp" is loaded correctly and contains the scenery you want
Verify (for each of the blocks) that it contains the graphics it should
Verify grid::redraw uses correct positions (e.g., by placing a putpixel or similar at strategic points)
Verify that playground contains the correct values (and thus, point to valid block tiles)
You should be able to do most of these tasks simply by outputting something to the screen, and probably wait for user input, thus allowing you to "step through" the program flow.
What also can help is removing things until it works again (like, modifying the grid in any way). If it then magically appears to be working, you probably could reduce the domain of the error (it may not always be that simple, though).
Thanks very much.
Bye, Berserk.
.
EDIT: Now it works flawlessly. Why? Because I was executing the game from visual studio using the play icn on the toolbar. Executing the game by double-clicking it shows me the game grid. Shame on me.