It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;)
I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently the map is created using a background image with CSS positioning of team icons on top of that to represent cities. You can see how it looks here: WoA Map
The background image for the map is located here: Map background and created in Omnigraffle. It's not designed to draw maps but I'm hopelessly incompetent with photoshop and this works for my purposes just fine.
The problem comes that I want to perform such fun things as pathfinding and for that I need to have the map somehow stored in code. I have tried using PIL, I have looked at incorporating it with Blender, I tried going "old school" and creating tiles as from many older games and finally I tried to use SVG. I say this so you can see clearly that it's not through lack of trying that I have this problem ;)
I want to be able to store the map layout in code and both create an image from it and use it for things such as pathfinding. I'm using Python but I suspect that most answers will be generic. The cities other such things are stored already and easily drawn on, I want to store the layout of the landmass and features on the landmass.
As for pathfinding, each type of terrain has a movement cost and when the map is stored as just an image I can't access the terrain of a given area. In addition to pathfinding I wish to be able to know the terrain for various things related to the game, cities in mountains produce stone for example.
Is there a good way to do this and what terms should I have used in Google because the terms I tried all came up with unrelated stuff (mapping being something completely different most of the time).
Edit 2:
Armies can be placed anywhere on the map as can cities, well, anywhere but in the water where they'd sink, drown and probably complain (in that order).
After chatting to somebody on MSN who made me go over the really minute details and who has a better understanding of the game (owing to the fact that he's played it) it's occurring to me that tiles are the way to go but not the way I had initially thought. I put the bitmap down as it is now but also have a data layer of tiles, each tile has a given terrain type and thus pathfinding and suchlike can be done on it yet at the same time I still render using Omnigraffle which works pretty well.
I will be making an editor for this as suggested by Adam Smith. I don't know that graphs will be relevant Xynth but I've not had a chance to look into them fully yet.
I really appreciate all those that answered my question, thanks.
I'd store a game map in code as a graph.
Each node would represent a country/city and each edge would represent adjacency. Once you have a map like that, I'm sure you can find many resources on AI (pathfinding, strategy, etc.) online.
If you want to be able to build an image of the map programattically, consider adding an (x, y) coordinate and an image for each node. That way you can display all of the images at the given coordinates to build up a map view.
The key thing to realize here is that you don't have to use just one map. You can use two maps:
The one you already have which is drawn on screen
A hidden map which isn't drawn but which is used for path finding, collision detection etc.
The natural next question then is where does this second map come from? Easy, you create your own tool which can load your first map, and display it. Your tool will then let you draw boundaries around you islands and place markers at your cities. These markers and boundaries (simple polygons e.g.) are stored as your second map and is used in your code to do path finding etc.
In fact you can have your tool emit python code which creates the graphs and polygons so that you don't have to load any data yourself.
I am just basically telling you to make a level editor. It isn't very hard to do. You just need some buttons to click on to define what you are adding. e.g. if you are adding a polygon. Then you can just add each mouse coordinate to an array each time you click on your mouse if you have toggled your add polygon button. You can have another button for adding cities so that each time you click on the map you will record that coordinate for the city and possibly a corresponding name that you can provide in a text box.
You're going to have to translate your map into an abstract representation of some kind. Either a grid (hex or square) or a graph as xynth suggests. That's the only way you're going to be able to apply things like pathfinding algorithms to it.
IMO, the map should be rendered in the first place instead of being a bitmap. What you should be doing is to have separate objects each knowing its dimensions clearly such as a generic Area class and classes like City, Town etc derived from this class. Your objects should have all the information about their location, their terrain etc and should be rendered/painted etc. This way you will have exact knowledge of where everything lies.
Another option is to keep the bitmap as it is and keep this information in your objects as their data. By doing this the objects won't have a draw function but they will have precise information of their placement etc. This is sort of duplicating the data but if you want to go with the bitmap option, I can't think of any other way.
If you just want to do e.g. 2D hit-testing on the map, then storing it yourself is fine. There are a few possibilities for how you can store the information:
A polygon per island
Representing each island as union of a list rectangles (commonly used by windowing systems)
Creating a special (maybe greyscale) bitmap of the map which uses a unique solid colour for each island
Something more complex (perhaps whatever Omnigiraffe's internal representation is)
Asuming the map is fixed (not created on the fly) its "correct" to use a bitmap as graphical representation - you want to make it as pretty as possible.
For any game related features such as pathfinding or whatever fancy stuff you want to add you should add adequate data structures, even if that means some data is redundant.
E.g. describe the boundaries of the isles as polygon splines (either manually or automatically created from the bitmap, thats up to you and how much effort you want to spend and is needed to get the functionality you want).
To sum it up: create data structures matching the problems you have to solve, the bitmap is fine for looks but avoid doing pathfining or other stuff on it.
Related
I'm making a 2D platformer using my own engine in Python/Pygame and have made a good start. I've also made a level designer that exports the level tile map and the game imports it, but I need to associate different things, like switches that open specific doors (or to be more precise, pressure plates that hold a specific door open) but my tile map array currently only holds the tile image index number. What's the best way to include associated tiles (like which switch opens which door etc)?
Do I make an extra file with that data? Or do I have 2 values for each tile? I've tried Googling, but it's not really covered anywhere. I'm sure there's someone with this kind of experience out there... I don't really want to hard-code it in as I want the game to be as versatile as possible.
I would change your file format from storing one tile index per 2D cell to storing some more complex data object. My first thought would be a dictionary per cell for maximum flexibility moving forward, but serializing that and storing it will be quite large. There's a trade-off here between flexibility and storage size.
Another option would be using NamedTuples to store a fixed number of parameters per cell, while preserving a concise serialization. NamedTuples are nice because they let you very concisely represent a data object in a way that both serializes well and can be queried into using named fields.
The questions you need to ask yourself are "what metadata do I need to know about each cell on the map" and "how much do I care about concise file size to represent them".
The answer to my question was posted by #BowlingHawk95 as using NamedTuples for the data object which enabled me to add multiple fields for each cell. I wanted to post a sample to show the resulting code, and a snap shot of how I've implemented it to help anybody else looking for the same thing.
# Initialise the level data array with NamedTuples;
# 'linked_point' is a tuple (x, y) for an associated cell - e.g. switch associated with a door:
Cell = namedtuple('Cell', ['image_id', 'linked_point'])
level_data = [[Cell(image_id=0, linked_point=(0, 0)) for _ in range(grid_width)] for _ in range(grid_height)]
And now that I am able to add coordinates (as the linked_point) I can now reference another cell from the one I'm on. The following image shows a shot of my level designer, with the coords in the title bar, and also showing the image_id name and coords of the linked cell.
Massive thanks to #BowlingHawk95 for the assistance!
I am beginner with NAO programming and I am now working on a project involving arms motion.
I must program a game in which NAO would first stand and point out one among three squares with different colors which would be displayed on the ground.
I think that I can "simply" make Nao move its arm so he would point towards one of three different pre-defined coordinates.
However, animation mode and motion widget do not seem usable for movements with parameters, like one out of the three coordinates.
How do I perform such a move ?
Have you look at the ALMotion.setPositions type of method ?
There are methods working in cartesian space. It means that you just positionnate some end effector (eg the hand) to be at a specific positions compared to the origin of the chest (for instance).
You can see that as a vector pointing to a direction...
The solver used for that could be enhanced, but it's a nice way to achieve what you need to do.
More info there:
http://doc.aldebaran.com/2-1/naoqi/motion/control-cartesian-api.html#ALMotionProxy::setPositions__AL::ALValueCR.AL::ALValueCR.AL::ALValueCR.floatCR.AL::ALValueCR
You could take a look at the pointAt method which takes in parameters the position that you would like to point. If the position of your three objects are known in advance, that would do the job. You can find more here:
http://doc.aldebaran.com/2-1/naoqi/trackers/altracker-api.html#ALTrackerProxy::pointAt__ssCR.std::vector:float:CR.iCR.floatCR
I'm testing an algorithm that finds a shortest path between two certain vertexes in graph and gives a list of vertexes after each turn (actually it gives three paths - one of them is a shortest path in this graph and two others are some kind of extra paths that are also important for us and are used for further shortest path calculations). On each turn the weights of graph edges change somehow so every turn we get a new triple of lists (paths). I would like to visualize the evolving of these paths by drawing a graph (this graph is actually a grid that represents a city, e.g. New York) and each kind of path would be represented with certain colour (so on each turn there would be a grid with three coloured paths). One more time - on every turn the paths will be different so the picture will change. What is the best way to represent it? And one more question - sometimes there would be edges that belong to two or maybe even three of these pathes and I'd like to show it, so it would be nice if there is an opportunity to colour this edge with two/three colours at once. It would be perfect if it was possible to make it look like two/three thinner edges put along together, but I could only find a situation where we draw several lines of different colour that are being put together consecutively (like that: enter image description here). Is there a way to make it the first way?
I'm sorry for being discursive but I've never dealt with graphics in Python and I desperately need help. Thanks!
If you want to show the image in a GUI, it depends on the GUI toolkit that you want to use. In the Tkinter toolkit that comes with most Python distributions you could use the Canvas widget. There are several tutorials online [1], [2]. Most GUI toolkits have a similar functionality, but they can have different names.
If you want to save an image to a file, there are many graphics libraries you could use, depending on what kind of format you want to save it to.
For example the Python bindings to the Cairo library can save a picture as PDF or SVG vector formats.
The Pillow library on the other hand supports many bitmap formats.
There are many others; matplotlib, agg, gd are just some examples.
I'm planning to generate a flower in Maya2016 where the leafs are not flexible, but they are built up by 4-5 segments connected to each other. I already have the python script which gets a segment as an input parameter and generates the leaf. (And also generates multiple leafs in a circle.)
Now the question is, how to animate it. I'm new in maya animation. I've found a few example how to do basic things like rotation or transformation with python. But what I wish to have is a realistic movement where the segments are moving how they should be.
My idea is to generate a "skeleton" bone and joint point for every segment. And then I wish to animate the skeleton.
Do you think it's a good way of animating the leaf?
How can I set up the skeleton?
How can I animate a skeleton?
(For the last two, I expect a good source like a blogpost, but I also wish to know if my entire concept is good or not.)
Thanks!
Background
I have been asked by a client to create a picture of the world which has animated arrows/rays that come from one part of the world to another.
The rays will be randomized, will represent a transaction, will fade out after they happen and will increase in frequency as time goes on. The rays will start in one country's boundary and end in another's. As each animated transaction happens a continuously updating sum of the amounts of all the transactions will be shown at the bottom of the image. The amounts of the individual transactions will be randomized. There will also be a year showing on the image that will increment every n seconds.
The randomization, summation and incrementing are not a problem for me, but I am at a loss as to how to approach the animation of the arrows/rays.
My question is what is the best way to do this? What frameworks/libraries are best suited for this job?
I am most fluent in python so python suggestions are most easy for me, but I am open to any elegant way to do this.
The client will present this as a slide in a presentation in a windows machine.
The client will present this as a slide in a presentation in a windows machine
I think this is the key to your answer. Before going to a 3d implementation and writing all the code in the world to create this feature, you need to look at the presentation software. Chances are, your options will boil down to two things:
Animated Gif
Custom Presentation Scripts
Obviously, an animated gif is not ideal due to the fact that it repeats when it is done rendering, and to make it last a long time would make a large gif.
Custom Presentation Scripts would probably be the other way to allow him to bring it up in a presentation without running any side-programs, or doing anything strange. I'm not sure which presentation application is the target, but this could be valuable information.
He sounds like he's more non-technical and requesting something he doesn't realize will be difficult. I think you should come up with some options, explain the difficulty in implementing them, and suggest another solution that falls into the 'bang for your buck' range.
If you are adventurous use OpenGL :)
You can draw bezier curves in 3d space on top of a textured plane (earth map), you can specify a thickness for them and you can draw a point (small cone) at the end. It's easy and it looks nice, problem is learning the basics of OpenGL if you haven't used it before but that would be fun and probably useful if your in to programing graphics.
You can use OpenGL from python either with pyopengl or pyglet.
If you make the animation this way you can capture it to an avi file (using camtasia or something similar) that can be put onto a presentation slide.
It depends largely on the effort you want to expend on this, but the basic outline of an easy way. Would be to load an image of an arrow, and use a drawing library to color and rotate it in the direction you want to point(or draw it using shapes/curves).
Finally to actually animate it interpolate between the coordinates based on time.
If its just for a presentation though, I would use Macromedia Flash, or a similar animation program.(would do the same as above but you don't need to program anything)