Server Bug Fix: Find a path centered on the edge between traversable tiles

Original Source Link

I’m trying to implement a pathfinding system in a simple tower defense game I’m working on. I’ve a 15×8 tilemap where each cell is of size 64×64.

image 1
A is the start point, B is the end point, the green blob is the bad guy, the brown tiles are the route and the green tiles are the “walls”.

So basically I want to auto find a grid-based path from point A to point B for the enemy, similar to this:

image 2

Down below are the scripts I’ve implemented in the game, should be a bit messy…

Main script

func _astar_search(graph, source, target):
    var q =
    var nodes = {}
    nodes[source] =, null, 0)
    q.insert(source, 0)

    while not q.empty():
        var current = q.extract_min()

        if current == target:

        for next in graph.neighbors(nodes[current]):
            if nodes.has(next) == false:
                nodes[next] =

            var new_cost = nodes[current].get_cost() + graph.weight(nodes[current], nodes[next])
            if new_cost < nodes[next].get_cost():

                if q.contains(next) == false:
                    q.insert(next, nodes[next].get_cost() * _heuristic(target, next))

    return nodes

func _find_path(nodes, source, target):
    var path = []
    var current = target

    while current != source:
        current = nodes[current].get_parent()

    return path

func _heuristic(a, b):
    return abs(a.x - b.x) + abs(a.y - b.y)

Graph class

func neighbors(vertex):
    var cell = vertex.get_cell()
    var result = PoolVector2Array([
        cell + Vector2.UP,
        cell + Vector2.LEFT,
        cell + Vector2.DOWN,
        cell + Vector2.RIGHT,

    #if fmod(cell.x + cell.y, 2) == 0:
    #   result.invert()

    result = _filter("_in_bounds", result)
    result = _filter("_walkable", result)
    return result

func _in_bounds(cell):
    return cell.x >= 0 and cell.x < size.x and cell.y >= 0 and cell.y < size.y

func _walkable(cell):
    return obstacles.has(cell) == false

It’s not working properly. I need the path to be centralized in between the two “roads” just like the image 2, but what I’ve now is:

image 3

The blue line is the path generated by the algorithm and the red dots are the same path but centered at tile’s position

Do you have any suggestions on how could I center the path?

Your problem lies in generating the graph, before any actual pathfinding takes place. It looks like you want the intersections of tiles to be considered the nodes of your graph, and only want intersections where all four adjacent tiles are ground.

If you do it correctly, the pathfinder in your example will have only one valid path to choose from.

If I understand correctly, you want the algorithm to return a path that touches the center of each grid (the red dots, in your last image) rather than one that goes along the grid lines (the blue line, in your last image).

To accomplish this, you need only to add the half-size of your node to the node’s world position. For example: Given a node whose grid position is at (0, 0) in grid that is centered at world position (10, 10), and your nodes are 3 world units wide, then the center of the given node would be at (11.5, 11.5).

Note that you may need to subtract the half-size from one or both axes instead of adding depending on the pivot position of your nodes. If your nodes pivot from the bottom-left, you would do it the same as in my example. However, if the pivot position were to be top-left, you would add to the x-axis and subtract from the y-axis instead.

However, a much easier solution, as noted by one of the other answers, is to simply offset your terrain tiles so that the grid lines touch the center of each tile instead. This way no math is necessary and the apparent result is the same.

So after much effort I finally get it working, although I’m not sure if I did it the best way. Tried to do what Agent Tatsu suggested but it didn’t work. I did something based on what I understood from the BlueRaja’s answer.

Basically I took every walkable tile of the map and “packed” each with its three adjacent tiles to form a “bigger tile”. Each of these big tiles became a node in the graph, which I positioned at the center between the 4 small tiles.

That’s it, took like 30 hours but easy right

Joking aside, thank you all for the help, stay safe
EDIT: I can’t upvote right now but will once I’ve 15 reputation

Tagged : / / /

Code Bug Fix: In Java, how would I initialize an array in which elements in an even column or row are 0, and in odd columns or rows, the elements are 1?

Original Source Link

I am working on an assignment where I needed to have two 1d arrays, send them to another method, and make a 2d array. I would then have to pass the array back to the main method (all of which I have completed). I now have to print out this 2d array by using for loops in a way that would make all of the elements in even rows or columns 0, and all of the elements in odd rows or columns 1. My code prints all 0s. My code and output is below.

numRows and numColumns were the arrays that I used to make oddEven.

for(int j = 0; j < numColumns.length; j++)

        for(int i = 0; i < numRows.length; i++)
            for(int a = 0; a < numColumns.length; a++) //tests for even number column
                if(a % 2 == 0)  
                    oddEven[j][i] = 0;
                }else {
                    oddEven[j][i] = 1;
            for(int b = 0; b < numRows.length; b++) //tests for even number row
                if( b % 2 == 0)
                    oddEven[j][i] = 0;
                }else {
                    oddEven[j][i] = 1;
            System.out.print(oddEven[j][i] + " ");


0 0 0 0 0 
0 0 0 0 0 
0 0 0 0 0 
0 0 0 0 0

I know how to print out a 2d array, but I have no idea how to do what I just described above.

Here is what the output should be.

0 0 0 0 0
0 1 0 1 0
0 0 0 0 0 
0 1 0 1 0

Write oddEven[j][i] = (i%2)*(j%2)

You are unnecessarily iterating through both indices inside the existing loop which is causing every value to be set to zero since you are updating each index with the last value.

You only need the two outermost loops. You can simplify your code as such:

for(int j = 0; j < numColumns.length; j++)

        for(int i = 0; i < numRows.length; i++)

            oddEven[j][i] = (j%2!=0&&i%2!=0)?1:0;

            System.out.print(oddEven[j][i] + " ");


To provide further explanation, your a loop is pointless as the following b loop sets the same values. The value of oddEven[j][i] for any j and i in the range will be set based on numRows.length - 1 since that will be the last value in your b for loop.

Using an if instead of a ternary operator

for(int j = 0; j < numColumns.length; j++)

        for(int i = 0; i < numRows.length; i++)

            System.out.print(oddEven[j][i] + " ");


Tagged : / /

Code Bug Fix: how can I check for bounties from a saved position to the current position of the player

Original Source Link

  * Updates saveX and saveY to the current player position.
  def save(): Unit = {
  saveX = playerX
  saveY = playerY

 * Returns the current save position as a tuple, in (x,y) order.
def getSavePos(): (Int, Int) =  {
return (saveX, saveY);

def checkBounty() {
if(bounties (playerX)(playerY) != null){
  var bounty: Int => Int = bounties(playerX)(playerY)
  score = bounty(score)
  bounties(playerX)(playerY) == null

The checkBounty() function checks for bounties in the current position of the player which is (playerX, playerY) if there is a bounty it is collected and the bounty is then removed hence bounties(playerX)(playerY) == null

  * Checks if the rectangle defined by the current position and saved position 
  * covers nine or more positions. If yes, it collects bounties in it, increases the 
  * score, and erases the bounties.
  def checkBounties() {
  if(((playerX - saveX)+1).abs * ((playerY - saveY) + 1).abs >= 9){

  for(x <-  saveX to playerX; y <- saveY to playerY){

  saveX = -1
  saveY = -1

the checkBounties() function does what it says in the comment and also if 9 or more positions are covered sets the save position back to (-1,-1).
I tried the for loop to check for any bounties that are within the saved position and current position after it moves from the saved position, I then delegated the checkBounty() function so it does that for each cell moved between the saved and current position.
But this code doesnt exactly work as I expected it to the saveX and saveY in the for loop isnt representing the saved X and Y positions and instead its saveX is -1 and saveY is -1, so it is checking for bounties from -1 to playerX but I need it to check form the last saved position to playerX

I think problem that you are don’t use x and y from for loop in checkBounty(). Maybe passing them as arguments will solve your issue:

def checkBounty(x: Int, y: Int): Int = {
  if(bounties (x)(y) != null){
    val bounty: Int => Int = bounties(x)(y)
    score += bounty(score)
    bounties(x)(y) == null

def checkBounties() {
  if (((playerX - saveX) + 1).abs * ((playerY - saveY) + 1).abs >= 9) {

    for (x <- saveX to playerX; y <- saveY to playerY) {

      checkBounty(x, y);
    saveX = -1
    saveY = -1


Also, using mutable statements is bad practise in scala. If you want to use mutable variables I would advise you using Ref or you can rewrite you code using immutable structures.

Tagged : / / /

Steam Game: Resolutiion

Source Link

An old killer escorts a curious AI through chaotic combat, puzzling secrets, and unsettling calm. Explore a fractured future, collecting weird weapons and stories, to piece together the past.

About This Game

An old killer escorts a curious AI through chaotic combat, puzzling secrets, and unsettling calm in a dreamscape of madmen and sane animals.

Resolutiion is a fast-paced action-adventure created by two angry German brothers leading a band of vagrants who loaded it with lovely pixels, dirty jokes, deep ideas and badassemotional tunes for 20 hours of punishing combat, rewarding exploration, and layered storytelling. Will you be the player or will you be played? In the Infinite Empire nothing is as it seems.

Explore a fractured future, gathering weird weapons and stories, to piece together the past: a friend betrayed, a family broken, worlds at war.

To solve the mystery of the Cradles take on a multi-cultural-mashup of cynical gods, emotional machines, zealots, luddites, and furry critters in a world that doesn’t care if it confuses or kills you — oh hey, a kitty!


  • 20 hour playtime
  • Explore a grim cyberpunk world where nothing is as it seems
  • Experience a dark story where you might be the hero – or the villian
  • Unlock new abilities to defeat your enemies
  • Survive in brutal fights and crush gruesome bosses
  • Listen to a badassemotional cyberpunk Soundtrack

Here kitty-kitty…

Tagged : / / / / / / / / / / / / / / / / / / / /

Steam Game: The Banner Saga

Source Link

Live through an epic role-playing Viking saga where your strategic choices directly affect your personal journey. Make allies as you travel with your caravan across this stunning yet harsh landscape. Carefully choose those who will help fight a new threat that jeopardizes an entire civilization.

About This Game

Live through an epic role-playing Viking saga where your strategic choices directly affect your personal journey. Make allies as you travel with your caravan across this stunning yet harsh landscape. Carefully choose those who will help fight a new threat that jeopardizes an entire civilization. Every decision you make in travel, conversation and combat has a meaningful effect on the outcome as your story unfolds. Not everyone will survive, but they will be remembered.

Key Features

  • Player choice that drives your own narrative – every decision you make in travel, conversation and combat has a meaningful effect on the outcome as your story unfolds.
  • Over 25 playable characters from 2 different races, human and varl, the horned giants – embark on your epic journey with a variety of characters from 7 different classes, each with unique abilities and upgrade options to fit your play style.
  • Strategic combat with consequences – victory or defeat and even the permanent loss of a character depends on which characters you choose to take into battle and what decisions you make afterwards.
  • The journey is as important as battle – your role in building and managing your caravan as you travel the vast frozen landscape is critical to not only your own survival but the survival of an entire civilization.
  • An epic Viking saga brought to life in 2D glory – beautifully hand drawn combat sequences and animations, accompanied by an evocative score from Grammy-nominated composer Austin Wintory, will immerse you into a fantasy realm inspired by Norse mythology.
  • Multiplayer Combat Enhanced – sharpen your combat skills in the free multiplayer game “Factions”. Compete against other players with many of the character classes you see in The Banner Saga.

The Banner Saga is the first part of a planned trilogy. If you complete this game, your unique progress and storyline will carry over to the next part of the story.

Tagged : / / / / / / / / / / / / / / / / / / / /

Steam Game: Banners of Ruin

Source Link

Assemble your party. Answer the call. Win the war. Build a deck and fight a series of turn-based combats with up to 6 party characters through the city of Dawn’s Point. Each character can unlock a set of unique cards and abilities that can augment your deck in powerful, exciting ways.

About This Game

The Blackfoots have been dealt a mighty blow by the fearsome House Ender – you must infiltrate their defences and cut out the rot.

Build your deck and fight your way through the city of Dawn’s Point with card based combat and up to 6 members in your party. Characters loyal to your cause have a set of unique cards and abilities that may augment your deck in powerful, exciting ways. Defeat each of the elite opponents in your path to the city’s Guard Captain and cripple the Enders at their core. You and your brethren may fall at this attempt, but there will always be others to carry the torch. House Blackfoot will remember, and they will never relent. Encounter a series of scenarios as you travel through the city which may help you, but at the expense of some moral ground.

  • Build your deck by looting, buying and unlocking a myriad of cards.
  • Beavers and Bears? Or Wolves and Weasels? Build a party of up to 6 throughout your run to battle your foes.
  • 6 Races to explore with unique racial card pools and passives to choose from.
  • Ding! Level up your characters to unlock talent cards and powerful passives that can drastically impact your strategy.
  • Loot! Collect weapons and armour to bolster your ranks with interesting effects and abilities.
  • Which way? Navigate the streets in a dynamic card driven campaign.
  • Decisions. Reveal and engage in varying encounters on your journey which can have positive and negative outcomes.
  • Fight an increasingly challenging array of enemies with exciting AI behaviours.
  • Another failed attempt? Earn tokens after every run to unlock new cards and passives into the game to help you achieve victory.

We think Banners of Ruin is in a really enjoyable place right now. There’s plenty to expand upon, balance and polish – a lot of the artwork needs a rendering pass (the game requires a huge amount!) – but we think there’s plenty of depth to explore. As long-standing fans of deckbuilders like Dominion, we think the game offers a deeper, more unique flavour of deckbuilding while introducing new mechanics like positions, characters, equipment and races!

The game is designed to be re-played, with at least 4-6 hours of content, a fun core gameplay loop and an unlock system that increases the pool of cards you want to see over the course of successive runs. We want you to know that content is our biggest priority going forward, but also that it’s all being created by a tiny core team of two, with an extremely talented composer.

There’s so many exciting things we want to do with Banners of Ruin, and we know it might not come as quickly as you’d like, but nevertheless we hope you’ll choose to support us and most importantly – love the game! We’ve got plenty of ideas in mind and we’d like nothing more than a vibrant community to join us in exploring them.

Don’t hesitate to contact us if you’re having issues, want to provide some feedback, or just tell us which animal you think is the best 🙂

(P.S. it’s Bears.)

Tagged : / / / / / / / / / / / / / / / / / / / /

Steam Game: Helltaker: Artbook + Pancake Recipe

Source Link

About This Content

The Helltaker’s Artbook. If you liked the game, consider buying this little bag of goodies.


  • Concept Art – see how the characters evolved during game’s developement
  • Artist’s Notes – discover pointless facts about your favourite demon girl
  • Pancake Recipe – learn how to make Helltaker’s signature dish

Please Note:

Everything in this artbook can also be unlocked for free in the game. But if you end up buying it anyway – thanks a lot!


After download, you’ll find the Artbook in your game’s directory folder, accessible through: Helltaker->Properties->Browse Local Files

Tagged : / / / / / / / / / /

Steam Game: Iconoclasts

Source Link

Join renegade mechanic Robin and uncover the secrets of a dying planet. Explore a big world filled with intricate puzzles, interesting characters and menacing bosses in a beautiful platform adventure that tells a personal story about faith, purpose and the challenge of helping people.

About This Game

Robin just wants to be a mechanic and help people, but without a license she’s a sinner in Mother’s eyes. Ever since picking up her wrench, the world has been going nuts and she’s wanted to bolt it back together. Now Penance is raining down on everyone she loves and One Concern agents are after her.

But something big is going on – bigger than droughts of Ivory fuel and personal conflicts – and Robin’s in the thick of it.

  • Hours of nut-twisting platform action-adventure
  • Numerous densely detailed locations filled with fine-tuned action and puzzles
  • 20+ gear-grinding, screen-filling boss battles stand in your way
  • Three game-changing difficulty settings supported by a unique tweak system
  • A heart-wrenching epic – can one mechanic fix the whole world?

Iconoclasts is the masterwork of indie developer Joakim Sandberg, seven long years in the making. Iconoclasts delivers awesome action, hilarious hijinks and an emotional rollercoaster of deeply personal storytelling.

Tagged : / / / / / / / / / / / / / / / / / /

Steam Game: Project Highrise

Source Link

Project Highrise is a skyscraper construction and management sim…

About This Game

Your job as the architect and developer is to build world-famous skyscrapers that will be the envy of the entire city, masterpieces of art and engineering. But a skyscraper is more than just steel and glass, it’s an intricate ecosystem, full of people that live and work in the building. They become a complex machine that needs your steady hand to keep it running smoothly and efficiently.

From the moment you break ground, every decision rests with you. As the architect you must coordinate the construction of everything – every wall and wire, every office and apartment. As the building owner you must keep your tenants happy – and paying rent on time. As a savvy developer you must keep an eye on the bottom line and invest in the future. Succeed and you will reap the rewards of a prestigious address where everyone will clamor to live and work. Fail and you will watch tenants leave in disgust, taking their business elsewhere and leaving your reputation in tatters.

Will you create an exclusive office highrise that attracts business leaders from around the world? Will you construct luxury apartments in the sky, penthouses for the elite and playgrounds for the famous? Perhaps greed will get the better of you and you’ll build a tenement building that trades tenant happiness for loads of cash? All these choices and more are yours. Success is entirely in your hands.


  • Deep and complex simulation of a modern skyscraper.
  • Huge variety of tenants with their own unique characteristics, from restaurants, to offices, retail stores, or residential apartments.
  • Open sandbox play with several difficulty levels and starting conditions allowing you to build your dream skyscraper towering above the surrounding city.
  • Campaign mode that tests your skill at building a successful highrise in challenging scenarios.
  • Test your management mettle by keeping up with your buildings diverse population and their ever-increasing demands.
  • Hire specialized consultants to increase your building’s curb appeal, operational efficiency, and pull with city hall.

Tagged : / / / / / / / / / / /

Steam Game: GUNBIRD

Source Link

“Marion” the little great wizard in the steampunk world. The masterpiece of the “Psikyo Shooting”! Online rankings are available.

About This Game

“Marion” the little great wizard in the steampunk world.
The masterpiece of the “Psikyo Shooting”!

GUNBIRD is a vertical-scrolling shooter game that first appeared in arcades in 1994.

A comical story about the “magical mirror” that makes wishes come true.
You can see the dialogue demos that unfold during the intermission and when the boss appears,
and the dialogue between the characters that changes when the 2 players mode.

You can set the difficulty level, life, number of continues,
controls, screen orientation, and more.

In addition, now we have online rankings!
Be the world’s best GUNBIRD!


  • You like it, don’t you? – “Marion” The Little Great Wizard
  • One strike, one kill, one rocket punch! – “Barnas” The Flying Robot Warrior
  • The offensive and defensive ruyi stick! – “Yang Nyan” The Chinese Magician Girl
  • Power is No. 1! – “Tetsu “The Lovely Carpenter
  • Speed is No. 1! – “Ash” The Sky Explorer


  • Power up with “P” items, with sub-weapons also added.
  • Get bombs with the “B” item to wipe out enemy bullets and evade your foes!
  • Unleash the charge shot to take down your enemies!

Arcade mode:

  • 7 levels of difficulty can be selected for beginners.
  • Now players can really test out their skills with a “HARD” and “VERY HARD” mode. We’re looking for recruits who are up for the test.
  • Local rankings will support all difficulty levels and your own planes.


  • The vertical screen mode that allows you to play in arcade style like back in the day.
  • Select the screen filter from the normal +2 version.
  • You can set the number of lives from 1 to 9 and the number of continues from 0 to unlimited.
  • Assign “Shot”, “Auto Shot” and “Bomb” in the key configuration.
  • The vertical screen mode can be operated in the horizontal mode as well! Now enjoy a completely different gameplay.

Score Attack:

  • This is a new feature that has a very severe mode with a fixed difficulty level and number of lives.
  • Compete in high scores and score attacks against players from all over the world!
  • Online rankings can be viewed from the options menu.

Tagged : / / / / / / /