? Collision between two sprites (Page 2) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
What's going on?? See: Site Update March 2022

Collision between two sprites

1 2 3 4
  • #21 ✎ 858 IAmRalsei Forum Leader Hidden Achievements Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength
    tilemap
    sprites are being used, not bg
    Posted
  • #22 ✎ 158 Vakore
    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.
    Posted
  • #23 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself 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 Posted
  • #24 ✎ 858 IAmRalsei Forum Leader Hidden Achievements Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength
    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
    Posted
  • #25 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself
    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 @[email protected]! 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 ;--;
    Posted Edited by AidenCodes
  • #26 ✎ 186 Tarudahat QSP Contest 2 Contest Participant I participated in the second SmileBASIC Source QSP Contest! OSP Contest 3 Contest Participant I participated in the third SmileBASIC Source OSP Contest! Avatar Taboo I didn't change my avatar for 180 days Website @AidenCodes Sphome should be the culprit remove it. Edit: If it isn't then well I don't know. Sorry Posted Edited by Tarudahat
  • #27 ✎ 380 ProKuku Pokemon Is Awesome! I love Pokemon! Express Yourself Night Person I like the quiet night and sleep late. Express Yourself QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest!
    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.
    Posted
  • #28 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself 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 @[email protected] Posted
  • #29 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself Is there a way to remove one tile from a BG layer or should all pills be specified by sprites? Posted
  • #30 ✎ 858 IAmRalsei Forum Leader Hidden Achievements Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength
    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.
    Posted
  • #31 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself
    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
    Posted Edited by AidenCodes
  • #32 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself 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. Posted
  • #33 ✎ 858 IAmRalsei Forum Leader Hidden Achievements Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength
    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.
    Posted
  • #34 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself
    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
    Posted
  • #35 ✎ 1580 rando Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Third Year My account is over 3 years old Website Avatar Taboo I didn't change my avatar for 180 days Website
    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.
    Posted
  • #36 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself 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? Posted
  • #37 ✎ 158 Vakore 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. Posted Edited by Vakore
  • #38 ✎ 31 AidenCodes Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Night Person I like the quiet night and sleep late. Express Yourself
    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
    Posted
  • #39 ✎ 127 kitesinpowerlines Avatar Block I didn't change my avatar for 30 days. Website Avatar Embargo I didn't change my avatar for 90 days Website Avatar Taboo I didn't change my avatar for 180 days Website
    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.
    Posted Edited by kitesinpowerlines
  • #40 ✎ 158 Vakore
    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();
    Posted Edited by Vakore
1 2 3 4