Question

I am trying to change the code of the android sample snake app, that when I press on the right triangle and the snake turns right, the .png file (I think it's called 'yellowstar.png') rotates by 90 degrees and Vice Versa. I replaced the yellowstar.png with the image of a real snakehead but the current situation is , that when the snake turns right, the snakehead stays in the same 'North-faced' direction. Sorry for the unspecific Question..I tried to specify them so you know what I mean..

I updated the PNG's of the Snakehead and now I have 4 PNG's. (head left; head up; head right; head down) Which PNG is used for the head is depending on which direction the snake is mooving. There are 4 Classes (Backgroundview,Snake,SnakeView,TileView) and I'm not sure where to load my 4 new PNG's.

Questions:

1.is it possible to realize the suggestion of arkocal with the setTile() command?

2.If Q#1 is correct: is this the right place to put it??:

//Figure out which way the snake is going, see if he's run into anything (the
//walls,himself, or an apple). If he's not going to die, we then add to the front 
//and subtract from the rear in order to simulate motion. If we want to grow him, we 
//don't subtract from the rear.

private void updateSnake() {
    boolean growSnake = false;

    // Grab the snake by the head
    Coordinate head = mSnakeTrail.get(0);
    Coordinate newHead = new Coordinate(1, 1);

    mDirection = mNextDirection;

    switch (mDirection) {
        case EAST: {
            newHead = new Coordinate(head.x + 1, head.y);
            break;
        }
        case WEST: {
            newHead = new Coordinate(head.x - 1, head.y);
            break;
        }
        case NORTH: {
            newHead = new Coordinate(head.x, head.y - 1);
            break;
        }
        case SOUTH: {
            newHead = new Coordinate(head.x, head.y + 1);
            break;
        }
    }

3.If this is the wrong place, please show me where to put it

Thank you for answers,

Julien

Was it helpful?

Solution

The simplest solution would be manually rotating (copying it 4 times and rotating them with any image editing program) the image, as there are only infinite (4) rotations are needed. Then you can load these images instead of doing some graphics work in java.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top