Tag Info

Hot answers tagged

22

Hardcoded constants are fine for small projects, but eventually, as your software grows in size, you will wish you could change those settings without having to recompile everything. Not just that, but many times you will want to change settings while the game is running. You can't do that with hardcoded constants. Once your project grows, you might want to ...


12

This system with all these triggers sounds a bit too complicated and error prone. You could wrap the position of the player using modulo with something like playerPositionX = playerPositionX % mapWidth This way when your player reaches playerPosition == mapWidth the playerPosition will reset back to 0. This solution could be extended with the whole ...


11

Okay, so Assuming that you know what the World Transformation matrix for that object A is, You just need to construct the inverse of that matrix and you will have what you need. Suppose the rotation, scaling and translation matrices of object A used to get it to Global Space are R, S and T respectively. You will multiply these together like S * R * T = W ...


10

The canonical solution is to use portals. In your example, there is only one level, except there is a portal connecting the left and right ends. Anything moving across that portal will have its coordinates translated to the other end of the portal, so that if something is moving left through the portal, it will reappear on the right side of the level and ...


6

Remember that what you display on screen, and what's in memory are two totally different things. Imagine you have a window that you need to fill with data about the world. You fill the window from left to right. While you're parsing your data to fill the world, if you reach the end of the world, simply loop back around to the beginning of your data. Using a ...


5

Rather than rotating the projectile about its own centre, then translating it to the end of the cannon, you could translate it first and then rotate the projectile using the origin of the tank (the tank's centre, in this case) by the tank's rotation. Here is how to rotate a point around another point in c++. (C# version) Following that: ...


5

I've done this with trigonometry rather than matrixes in the past (I am a matrix noob). Ashes999's answer is halfway there, get the relative vector, then rotate that by the inverse of EntityA's angle. relativeX = B.x - A.x relativeY = B.y - A.y rotatedX = Cos(-Angle) * relativeX - Sin(-Angle) * relativeY rotatedY = Cos(-Angle) * relativeY + ...


4

Well first off an enum defines what the values can be, not what the values are. Thus you still need to declare another variable after you've declared the enum. For example: public enum Sound { ON, QUIET, OFF } public Sound soundValue; In this example, you can now set soundValue to ON, QUIET, or OFF. Then you still need to structure your ...


4

Short answer: no. Long answer: Game Maker's performance are really bad. If you are a good programmer, you will find yourself hitting the performance wall more than once or pay for the YYC (Yoyo COmpiler) which unlocks decent performances at a price. Libraries like libGDX, slick2D, LWJGL or any other will beat GameMaker by a lot. Object oriented patterns in ...


4

Let me try to give you something somewhere between The Light Spark's answer and Elliot's answer, because from what I read, you're really looking for an algorithm to follow and not just math tossed at you. Problem Statement: Given that you have a location A (50, 50) and a heading (since you didn't provide one, I'll assert it as y = 2 * x + 25), find where B ...


4

I would instantiate the Projectile at the (x,y) location of the Entity and then move it in the direction of the Entity by radius distance. In code, that would go: projectileX = entity.x + cos(entity.angle) * radius; projectileY = entity.y + sin(entity.angle) * radius; Then add your projectile to the game world and send it off!


3

I assume you will be using some modern rendering API to draw to the screen, such as OpenGL or D3D. You will certainly want to batch sprites as much as possible and use sprite sheets to reduce the number of textures. A sprite sheet is nothing more than a Texture Atlas (also read this). Once you have a Texture Atlas up and running, it will be up to you how you ...


3

Create an invisible box in front of the fan. Then check if some object is inside that box. Apply movement to that object. This can be done in unity quite easily. Create Empty gameobject Select the new gameobject Add Component-> Mesh -> Mesh filter Select from inspector -> Mesh filter -> mesh and set it to "cube" ( or what ever shape you want ) Add ...


2

It really depends on the geometry that your world consists of and how you set your orthographic projection and camera up relative to that world. Most of the time, when people make 2D games with orthographic projections, they don't bother actually creating 3D geometry. Usually everything is a quad with a texture applied, or simple 3D geometry without much ...


2

Take a look at this. It's common to have a single image for all your tiles and draw a different part of it at rendering. You can then draw your tiles like this : int mx = tileId % numberOfTileCols; int my = tileId / numberOfTileRows; graphics.drawImage(image, x, y, x + tileWidth, y + tileHeight, mx * tileWidth, my * tileHeight, mx * ...


2

Just go really simple. Add a flag to the player that tells the camera when they're jumping. If they're jumping, don't follow them up. The other situation you need to handle is when the player jumps up or down to different levels. In this case it would be pretty simple to start tracking again when the player touches down, or if the player goes below the ...


2

If the engine is using the 3D graphics hardware under the hood, then it still has vertices, even if it's a 2D game. The models might be very simpleā€”a rectangle for each sprite, for instance. But the matrices would still apply to the vertices, just as they do in a 3D game. If the engine doesn't use 3D graphics hardware under the hood, but does all its own ...


2

Disconnect the rendering from the world and you can do wraparound and correct rendering without resorting to any cloning or teleporting artifacts. First, in your world you have a fixed size world, from 0 to Width. Anytime an object goes below 0 you wrap it to the end, and anytime an object is over Width wrap it to the start. This means that all logical ...


2

The solution can be pretty simple - just add a field or flag and dont release until n bullets of your burst have been fired. in weapon: int burst = 0; when hadling event: void onFireButtonPress() { //previously simple fire(); burst = burst > 0 ? BULLETS_PER_BURST : burst; //or some other behavoiur like burst += 3 etc. } in game loop: ...


1

While it might not be ideal or the most performant option depending on your actual use case, you could just create a single "3d tile" that is actually bigger than your real tile (due to having the 3d part attached): While the tile size would be 32 × 32 pixels, this tile image is actually 40 × 40 pixels big (the fake depth is 8 pixels in every ...


1

glampert solution is very complete, but I will add my personal experience. I ran into this same problem, and my solution was to use an static Variables class. The Variables class internally keeps a map from string to string (so far all my variables are only strings) and is accessed via getters and setters. The point is that getting access to global ...


1

Simply use shapes and AABB collisions. Keep a tiled map. Create an approximation of a circle using tiles and create a rectangle for each of the unwalkable tiles. Next, when you create a player or any movable entity, simply create a Rectangle around them too. Before moving, look whether or not the player's rectangle would collide with any of the wall's ...


1

I'm assuming you're either using some sort of entity-component system, or else you have in-game classes that represent your objects. Either way, you have some reference to your in-game objects (players, walls, enemies, etc.) At a minimum, these objects should have: A position A sprite (display) A collision primitive (axis-aligned bounding box?) All you ...


1

Your car is slipping for the same reason that a car hanging up-side down, riding the ceiling, with 100% friction would slip. 100% friction roughly means that 100% of the force exerted via the wheels on the terrain is used to counter movement perpendicular along the normal of the terrain. But this force still isn't enough to counter the force of gravity. This ...


1

Size and fit can be taken care of the heuristic that declares whether a move is valid during the path finding. Once the path itself is generated it's then up to a localized movement function to handle not bumping into things on the way, called path smoothing. Maybe paths with smoothing will help generate some ideas that work for you. The last time I did ...


1

I suspect that there are several tricks in play. It is entirely possible that the game camera or view is a 3D perspective camera and all the sprites are placed in a 3D environment just at different heights. there could also be some clever parallax effects going on here. I would most likely suspect that this is in fact either a 3D or "2.5D" game or it is a ...


1

Essentially a series of flood fills - one for each cell in the grid, but skipping over any you've already visited, and dropping out early if you find a cell not connected to a group you've already flood-filled/gathered but of the same type as that group. Written blind, so please excuse any code typos or holes; highlight them in a comment and I will amend. ...


1

The way I might approach it is to create a list of all possible hex center locations during the initialization stage before the game loop starts. Then during the game loop, if there is a mouse click within 1.5 tile radius (or whatever dist you think is approp) of a white tile, simply iterate the list and find the closest list Point to the click point. If the ...


1

Sorry for late answer - I originally jumped on the love IRC where I was pointed towards love.graphics's Coordinate Functions which allows you to modify love's coordinate system to do exactly what I wanted. Credit also to NauticaMile for suggesting hump.camera, which uses this as the underlying implementation. This example replaces my original hardcoded ...


1

By computing the velocity as some factor of the difference between the start and end position, you can achieve the association you want: var velocity = (endPosition - startPosition) * scale; The hard part be will choosing a value for scale. You can initially try constants -- such as 1.0f or 0.5f. This makes the velocity directly proportional to the start ...



Only top voted, non community-wiki answers of a minimum length are eligible