LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Collision between two sprites

Root / Programming Questions / [.]

AidenCodesCreated:
tilemap
sprites are being used, not bg

tilemap
sprites are being used, not bg
By tilemap I meant something like this:
@lvl1
DATA "111111"
DATA "1    1"
DATA "1    1"
DATA "1   11"
DATA "1   11"
DATA "111111"
That was for how the BG collisions would work for the pac man level.

wow this exploded faster than my schools gas leak I've converted to a map and I'm able to load it into the game, is there a way to get collision with that >.> cant find anything on that that I understand

wow this exploded faster than my schools gas leak I've converted to a map and I'm able to load it into the game, is there a way to get collision with that >.> cant find anything on that that I understand
here's collision for Pac-man (LAY is the Layer that the walls reside on, PACX and PACY are Pac-Man's X and Y positions, DIR is The direction that Pac-Man is moving in, 0=North, 1=South 2=West 3=East and OLDDIR is the state of DIR before the current frame.) (NOTE:the same collision detection would work for the ghosts if you didn't want an authentic Pac-Man experience.)
IF BGGET(LAY,PACX,PACY,1) THEN
 IF DIR==0 THEN
  INC PACY
  DIR=OLDDIR
  ELSEIF DIR==1 THEN
  DEC PACY
  DIR=OLDDIR
  ELSEIF DIR==2 THEN
  DEC PACX
  DIR=OLDDIR
 ELSE
  INC PACX
  DIR=OLDDIR
 ENDIF
ENDIF

wow this exploded faster than my schools gas leak I've converted to a map and I'm able to load it into the game, is there a way to get collision with that >.> cant find anything on that that I understand
here's collision for Pac-man (LAY is the Layer that the walls reside on, PACX and PACY are Pac-Man's X and Y positions, DIR is The direction that Pac-Man is moving in, 0=North, 1=South 2=West 3=East and OLDDIR is the state of DIR before the current frame.) (NOTE:the same collision detection would work for the ghosts if you didn't want an authentic Pac-Man experience.)
IF BGGET(LAY,PACX,PACY,1) THEN
 IF DIR==0 THEN
  INC PACY
  DIR=OLDDIR
  ELSEIF DIR==1 THEN
  DEC PACY
  DIR=OLDDIR
  ELSEIF DIR==2 THEN
  DEC PACX
  DIR=OLDDIR
 ELSE
  INC PACX
  DIR=OLDDIR
 ENDIF
ENDIF
This works ALMOST PERFECTLY!! Thank you @u@! The only problem is due to
SPHOME
being
8,8
, pac-man is staying a few pixels away/inside of walls, and I still do not understand BGGET trust me if I did I would fix this lol , so how do I account for this? Edit: actually I am unsure if SPHOME is the culprit >.> it's not lol, pac-man's just floating like 12 pixels to the right and down for no reason ;--;

@AidenCodes Sphome should be the culprit remove it. Edit: If it isn't then well I don't know. Sorry

wow this exploded faster than my schools gas leak
Really it’s just because you’re the only new user who’s asked an actual question in awhile.

Ok I fixed the floating problem, I was just lazy and used only a few sprites. This time I used one sprite for every different rotation of everything and it worked @U@

Is there a way to remove one tile from a BG layer or should all pills be specified by sprites?

Is there a way to remove one tile from a BG layer or should all pills be specified by sprites?
Replacing a BG tile with tile 0 will remove it.

Is there a way to remove one tile from a BG layer or should all pills be specified by sprites?
Replacing a BG tile with tile 0 will remove it.
OkI did
BGPUT 3,X,Y,0
(3 is the layer pills are on) but it returns the error
Out of range in 0:111 (BGPUT:2)
which means X, right? whats wrong with this? EDIT: I JUST DIVIDED BY 16 AND IT WORKED I'M SMALL BRIAN

Alright, now is there a way to detect when all tiles on a map are tile 0? This is so that when Pill-man (his new copyright-free name) has popped every pill, the game will end.

Alright, now is there a way to detect when all tiles on a map are tile 0? This is so that when Pill-man (his new copyright-free name) has popped every pill, the game will end.
all you can do is just run BGGET a bunch of times. TIP:You can use BG X and Y instead of sprite X and Y by replacing the 1 at the end of BGGET with a 0.

Alright, now is there a way to detect when all tiles on a map are tile 0? This is so that when Pill-man (his new copyright-free name) has popped every pill, the game will end.
all you can do is just run BGGET a bunch of times. TIP:You can use BG X and Y instead of sprite X and Y by replacing the 1 at the end of BGGET with a 0.
The problem was getting PacX and PacY, which I had to divide. I don't see a way around that lol. unless I misunderstand what you're saying

Alright, now is there a way to detect when all tiles on a map are tile 0? This is so that when Pill-man (his new copyright-free name) has popped every pill, the game will end.
all you can do is just run BGGET a bunch of times. TIP:You can use BG X and Y instead of sprite X and Y by replacing the 1 at the end of BGGET with a 0.
The problem was getting PacX and PacY, which I had to divide. I don't see a way around that lol. unless I misunderstand what you're saying
I would judge that they mean how to detect if a game is over with BGGET.

Ok, I have a score, a map, and now I just need ghosts! How can I get the ghosts to move towards specific positions relative to Pill-man while still going through the maze, and not through the walls?

You are going to love pathfinding. Here is A*(a star) tutorial: https://m.youtube.com/watch?v=icZj67PTFhc Also GMTK on how the ghosts act during gameplat(with some dev history) https://m.youtube.com/watch?v=S4RHbnBkyh0 Also I have two questions for coding please help. Thank you. Also message made on mobile so excuse bad grammar.

You are going to love pathfinding. Here is A*(a star) tutorial: https://m.youtube.com/watch?v=icZj67PTFhc Also GMTK on how the ghosts act during gameplat(with some dev history) https://m.youtube.com/watch?v=S4RHbnBkyh0 Also I have two questions for coding please help. Thank you. Also message made on mobile so excuse bad grammar.
I know how the ghosts act, blinky using you as an end point, pinky going ahead of you, inky trying to pincer you with blinky, and clyde being...clyde Anyways, is there a more smilebasic like example? I don't understand this tutorial you provided and my limited research hasn't helped

Ok, I have a score, a map, and now I just need ghosts! How can I get the ghosts to move towards specific positions relative to Pill-man while still going through the maze, and not through the walls?
It won’t be easy. Disclaimer: I don’t know much about path finding and have not watched tutorials on it, but I suspect using sprite functions for ghosts could be a possible solution. Example:
SPSET N,GHOSTSPRITE:SPFUNC N,”GHOST”
'Use spfunc n,”ghost” for all ghost sprites
'n is management number
@LOOP
...
CALL SPRITE
GOTO @LOOP

DEF GHOST
 VAR I=CALLIDX,GX,GY
 SPOFS I OUT GX,GY
 IF GX>PACX AND (BGGET(2,GX-16,GY,1))==0 THEN
  DEC GX
 ELSEIF (BGGET(2,GX-16,GY,1)>0 THEN
  'Code for changing direction and checking bg
  ...'repeat initial if condition for all directions
 ENDIF
'Note you will need additional parameter to limit movement to 1 direction, otherwise ghosts will move diagonally
 SPOFS I,GX,GY
END
Note: I am being lazy not detailing specific ghost movement code. What you see above will need work for things like avoiding diagonal movement, direction change when hitting a wall, and avoiding pill man when the ghosts are vulnerable. However, if fleshed out, this sprite function can handle all of the ghosts movement relevant to pill mans position.

You are going to love pathfinding. Here is A*(a star) tutorial: https://m.youtube.com/watch?v=icZj67PTFhc Also GMTK on how the ghosts act during gameplat(with some dev history) https://m.youtube.com/watch?v=S4RHbnBkyh0 Also I have two questions for coding please help. Thank you. Also message made on mobile so excuse bad grammar.
I know how the ghosts act, blinky using you as an end point, pinky going ahead of you, inky trying to pincer you with blinky, and clyde being...clyde Anyways, is there a more smilebasic like example? I don't understand this tutorial you provided and my limited research hasn't helped
Sorry, but I am not aware of any SB pathfinders. For a simpler pathfinder you could always just run a loop that places invisible blocks in an invisible array each numbered, keep track of the step you're on, and smaller numbers override larger ones, and do that for each ghost until they find pac man's spot. To save memory, you could have only specific tiles where they change direction[i.e. intersection points] Here is a simple pathfinder I wrote in javascript, it was pretty easy, made in about half an hour. No credit needed, but appreciated. NOTE: I created functions for 'fill', 'rect'(these two are basically gfill), and 'text8'(pixelated text, but any works fine. You could use 'locate' and 'print') for ease of acess. Also this was written in JAVASCRIPT, but converting shouldn't be much of a problem.
var level = [
"1111111111111111",
"1S---1---------1",
"1----11111-111-1",
"1----1---------1",
"1----1--111111-1",
"1----1--1------1",
"111--1--1-1111-1",
"1----1--1-1----1",
"1--111-11-1----1",
"1----1-1--111111",
"111--1-1--1---G1",
"1------1--11-111",
"1----111--1----1",
"1----1----1111-1",
"1----1---------1",
"1111111111111111",
];
var paths = [
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
];

for (var j = 0; j < level.length; j++) {
    for (var i = 0; i < level[j].length; i++) {
        if (level[j][i] == "S") {paths[j][i] = 1;}
    }
}

var pathFound = false;
var currentPath = 1;
while (!pathFound) {
for (var j = 0; j < level.length; j++) {
    for (var i = 0; i < level[j].length; i++) {
        if (paths[j][i] == currentPath) {
            if (level[j - 1][i] != "1" && paths[j - 1][i] > currentPath | paths[j - 1][i] == 0 && j - 1 > 0) {paths[j - 1][i] = currentPath + 1;}
            if (level[j + 1][i] != "1" && paths[j + 1][i] > currentPath | paths[j + 1][i] == 0 && j + 1 < level.length - 1) {paths[j + 1][i] = currentPath + 1;}
            if (level[j][i - 1] != "1" && paths[j][i - 1] > currentPath | paths[j][i - 1] == 0 && i - 1 > 0) {paths[j][i - 1] = currentPath + 1;}
            if (level[j][i + 1] != "1" && paths[j][i + 1] > currentPath | paths[j][i + 1] == 0 && i + 1 < level[0].length - 1) {paths[j][i + 1] = currentPath + 1;}
            if (level[j][i] == "G") {pathFound = true;}
        }
    }
}
currentPath++;
}

var run = function() {
try {
fill(255, 255, 255);
rect(0, 0, 455, 256);
for (var j = 0; j < level.length; j++) {
    for (var i = 0; i < level[j].length; i++) {
        if (level[j][i] == "1") {
            fill(0, 0, 0);
            rect(i * 16, j * 16, 16, 16);
        } else if (level[j][i] == "G") {
            fill(0, 0, 255);
            rect(i * 16, j * 16, 16, 16);
        }
    }
}

for (var j = 0; j < paths.length; j++) {
    for (var i = 0; i < paths[j].length; i++) {
        if (paths[j][i] > 0) {
            fill(0, paths[j][i] * 3, 0);
            text8("" + paths[j][i], i * 16, j * 16, 1);
        }
    }
}
} catch(e) {alert(e);}
requestAnimationFrame(run);
};

run();