[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-games-devel
Subject:    RE: [Kde-games-devel] Tiled canvas
From:       Philippe FREMY <P.FREMY () OBERTHURCS ! com>
Date:       2001-04-30 8:37:13
[Download RAW message or body]



	Hi, 

It is nice to see that some people have big games in mind.

Given your description, QCanvas is exactly the thing you need.

And it is more high-level that you think. 

QCanvas is optimized to show only the interesting part of a Canvas. So you
can define a QCanvas of 12000x12000, if your QCanvasView is 30x30, only a
30x30 view will be calculated. This allow to show complex background with
lot of objects moving quite efficiently. Since only the ojects actually
visible are shown, it is quite fast.

For your game, define a QCAnvas of 12000x12000, place all your sprites and
background, then move them and animate them. You don't have to worry about
scrollbars, about optimizing the update and the view, this is already done
internally by the QCanvas.

The QCanvasView is the window through which you view your canvas. If the
canvas is bigger than the QCanvasView, scrollbars are automatically added to
the QCanvasView and the automatically scroll the area being viewed. And you
can have multiple views, isn't that fun ?

You don't have to redefine the paint() function of anything, just put your
sprites and move them.

Now, regarding the function setTiles(). The function is used to draw a
static and relatively simple background. If for example you want to draw a
background of 400x400 with pixmaps of size 100x100, you must create one big
pixmap of size 1600x100 that will feed the function setTiles. That would be
something like that:
big_horizontal_pixmap = 
------------------------------------------------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
------------------------------------------------------------------------

setTiles( big_horizontal_pixmap, 4, 4, 100, 100 )

to get a background map like that:
---------------------
| 1  | 2  | 3  | 4  |
---------------------
| 5  | 6  | 7  | 8  |
---------------------
| 9  | 10 | 11 | 12 |
---------------------
| 13 | 14 | 15 | 16 |
---------------------

Obviously in your case, you don't want a 12000x12000 pixmap. So this is not
the function to use, simply use sprites with a height of 0, it will work
just the same.

Before you start coding your map, I strongly suggest you look at other
projects. Instead of wasting your time trying to achieve a complex map, use
what other have done. You will have less bug and more time to work on you
particular aspects of your game.

Check:
- boson at www.boson.eu.org
Boson is a StarCraft-like Kde/Qt game. The game is playable and it features
a big map, a mini-map plus a map-editor. I know the code to handle the map
is in a separate directory, so you can probably take a lot of things from
here. There are also a lot of ideas in the sprites moving and message
exchanging. I am pretty sure you can use at least 50% of the code of boson
in your game.

- freeciv at www.freeciv.org
Freeciv is turn-based game that uses a map and a mini-map. It doesn't have a
Qt client but one might be being written, ask them. Freeciv has a gtk client
though, and it is easy to convert a program from gtk to Qt (I am a
specialist of this). Freeciv now also have a iso view so you might like it
very much for your game. Again, consider to reuse as much as you can of
their code.

- Evas by Raster at http://australia.internet.com/r/article/jsp/sid/415317
Evas is a powerful Canvas, just like QCanvas. It features the same
accelerations tricks of QCAnvas in 2d and some very impressive acceleration
tricks in 3D. It also features anti-aliasing, alpha-transparency and a lot
of cool stuff. Of course, this is Raster and Gnome...


Do not hesitate to ask other question and talk about your game, I think we
are all very interested. What is the goal and the plot ?


	regards,

	Philippe







> 
> Hi
> 


> Thanks for the reply, I will supply you with more
> information.
> 
> I want to create a very large map made of tiles, where
> each tile is 300x300 pixels. Instead of showing the
> whole map I was going to show only a 3x3 grid of the
> specific part of the map that the play is currently
> on. The map is made up of roads running through the
> countryside and the game is designed to be a turn
> based game involving vehicles. So I will require the
> drawing of cars, and items on the road although they
> will not have to move very quickly since it is turn
> based. In order to make the map generation as simple
> as possible I envisaged using a text file that
> contained the names of the tiles required to make a
> 40x40 map (or any size really) in some sort of order.
> The game would then read that file for that area and
> then update the 3x3 (possibly 5x5 with scrollbars) as
> the player moved across the map, redisplaying the
> tiles to place the player in the centre tile at the
> start of a new turn (if he leaves the centre tile he
> was on). That way I can have very large maps without
> having to create massive 12000x12000 pixel images
> which would be impossible to handle in Gimp and also
> take huge memory requirements. This is all intended to
> be viewed top-down but alternatively I could try
> OpenGL and do it in 3D I suppose. However my artistic
> skills are not great and I only have limited
> experience of OpenGL, although I am probably better at
> it than I am at KDE at the moment :-)
> 
> Since I am going to be moving sprites around I require
> some kind of collision detection for ramming and
> running over landmines etc. Also what is on the tiles
> affects the vehicles too, for example whether they are
> on grass or tarmac.
> 
> So at the moment I am working on the game board and
> the engine to handle all the movement so I need to get
> this tiled map thing set up so I can see whether my
> ideas would work or whether I am just being stupid.
> 
> Thanks again,
> 
> Giles
> 
> --- Burkhard Lehner <Burkhard.Lehner@gmx.de> wrote: >
> Hi, Giles!
> > 
> > I'm not sure if QCanvas is really the thing you
> > want. What do you need the 
> > widget for? What do you want to show?
> > 
> > If you think of "tiles" as fields of a board game,
> > then you most probably 
> > will be better off using QTableView. With this class
> > you can have a widget 
> > with cells. By default all the cells have the same
> > height and width, but you 
> > can also assign an individual width to a column, or
> > an individual height to a 
> > row.
> > 
> > In almost any case you will have to create your own
> > subclass of QTableView, 
> > and overwrite the method paintCell. This method is
> > called for each cell that 
> > has to be repainted for some reason. 
> > 
> > QTableView can also create scrollbars if the
> > widget's size is reduced to be 
> > smaller than the contents.
> > 
> > QCanvas is intended to be used for an area where
> > objects can sit on arbitrary 
> > positions, especially if they are moving. (QCanvas
> > avoids flickering there.)
> > 
> > If you need an example how to use QTableView, just
> > ask me again and I will 
> > look for a small example I once wrote.
> > 
> > Bye,
> >  Burkhard
> > 
> >
> ----------------------------------------------------------------
> > Burkhard Lehner                        
> > Burkhard.Lehner@gmx.de
> > Pfaffenbergstraße 101                      Tel:
> > (0631) 1 03 63
> > 67663 Kaiserslautern                    Fax: (0631)
> > 3 10 52 15
> >                http://www.burkhardlehner.de/
> > _______________________________________________
> > Kde-games-devel mailing list
> > Kde-games-devel@master.kde.org
> > http://master.kde.org/mailman/listinfo/kde-games-devel
> 
> =====
> --------------------------------
> Giles Turner
> School of Chemistry
> The University of Birmingham, UK
> Registered Linux User: 190440
> 
> ____________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
> or your free @yahoo.ie address at http://mail.yahoo.ie
> _______________________________________________
> Kde-games-devel mailing list
> Kde-games-devel@master.kde.org
> http://master.kde.org/mailman/listinfo/kde-games-devel
> 
_______________________________________________
Kde-games-devel mailing list
Kde-games-devel@master.kde.org
http://master.kde.org/mailman/listinfo/kde-games-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic