Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Tile slicing again

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Tile slicing again
Thc-03_Berserk
Member #10,980
May 2009

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.
.
;D

William Labbett
Member #4,486
March 2004
avatar

Not quite sure if you want to

create a bitmap the size you need for mygamegrid.

something like this perhaps :-

#SelectExpand
1BITMAP *grid; 2 3 4 5grid = create_bitmap(TILE_LENGTH * GRID_WIDTH_IN_TILES, TILE_HEIGHT * GRID_HEIGHT_IN_TILES); 6 7 8/* then */ 9 10for(x = 0; x < 7; ++x) 11{ 12 for(y = 0; y < 23; ++y) 13 { 14 blit(image[y][x], grid, 0, 0, x * TILE_LENGTH, y * TILE_HEIGHT, TILE_LENGTH, TILE_HEIGHT); 15 16 } 17}

Sorry if that's a headache ;)

Thc-03_Berserk
Member #10,980
May 2009

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.
.

William Labbett
Member #4,486
March 2004
avatar

sorry chap. I'm not sure what that code is doing.

LennyLen
Member #5,313
December 2004
avatar

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).

Thc-03_Berserk
Member #10,980
May 2009

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.

LennyLen
Member #5,313
December 2004
avatar

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.

Quote:

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.

Thc-03_Berserk
Member #10,980
May 2009

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.
.

BlackShark
Member #9,796
May 2008

well, if you press the esc key, is done == true?

-BlackShark

Thc-03_Berserk
Member #10,980
May 2009

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.
.

Tobias Dammers
Member #2,604
August 2002
avatar

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.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Thc-03_Berserk
Member #10,980
May 2009

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.

LennyLen
Member #5,313
December 2004
avatar

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.

Arthur Kalliokoski
Second in Command
February 2005
avatar

In addition to reading the friendly manual, you might try altering the example programs in small ways to see what happens.

They all watch too much MSNBC... they get ideas.

GullRaDriel
Member #3,861
September 2003
avatar

There is also the wiki link in the main page of a.cc.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Thc-03_Berserk
Member #10,980
May 2009

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.

LennyLen
Member #5,313
December 2004
avatar

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.

William Labbett
Member #4,486
March 2004
avatar

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.

Schyfis
Member #9,752
May 2008
avatar

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.

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

Thc-03_Berserk
Member #10,980
May 2009

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.
.

Arthur Kalliokoski
Second in Command
February 2005
avatar

And no, I'm not gonna leave.

Persistence is a virtue for programmers. :)

They all watch too much MSNBC... they get ideas.

LennyLen
Member #5,313
December 2004
avatar

Persistence is a virtue for programmers.

So is the ability to think for yourself.

Tobias Dammers
Member #2,604
August 2002
avatar

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.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Thc-03_Berserk
Member #10,980
May 2009

[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.
.

count
Member #5,401
January 2005

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]

 1   2 


Go to: