Nalcwap Pubblicato: 24 Novembre 2011 Segnalazione Share Pubblicato: 24 Novembre 2011 Sorry i want know how make 2 squares 10x10cm collide and collide in all 4 positions up,down,right,left use graph block='block.png' block2='block2.png' x=10 y=50 l=30 m=50 function objects() graph.put(.x,.y,.block) graph.put(.l,.m,.block2) end function collide_sq1_sq2() if .x=.l and .y=.m then .x=.x-10; esif ... end end ui.keys(false); while true do g.clear(); objects(); ke=ui.cmd(1); if ke=ui.rightkey then x=x+10; elsif ke=ui.leftkey then x=x-10; elsif ke=ui.upkey then y=y-10; elsif ke=ui.downkey then y=y+10; end; collide_sq1_sq2() g.show(); end ho collide the 2 squares in all faces up.down,left,right? Thanks for any help Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 25 Novembre 2011 Segnalazione Share Pubblicato: 25 Novembre 2011 Sorry i want know how make 2 squares 10x10cm collide and collide in all 4 positions up,down,right,left.. the squares overlap? Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 26 Novembre 2011 Autore Segnalazione Share Pubblicato: 26 Novembre 2011 No i do not want the squares overlap ,i want the squares hit in all sides and collide example [x][l] collide but not overlap or [y] [m] Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 26 Novembre 2011 Segnalazione Share Pubblicato: 26 Novembre 2011 (modificato) Questo è quello che so fare, vedi se ti può andar bene,(non sono un programmatore ) 1) Considero due quadrati di lato 10x10. 2) Considero che i movimenti dei quadrati portino sempre a sovrapporre il perimeto mai oltre. (quindi devi spostarti sempre di 10 pixel per volta.) 3) diamo per scontato che il lato destro di block.png può sovrapporsi solo al lato sinistro di block2.png cosi pure lato alto di block.png si sovrappone solo a lato basso di block2.png. Per semplicità verifico se il lato di un quadrato si sovrappone all'altro. (.x+10=.l) e per essere una collisione la distanza assoluta di (.y-.m) deve essere minore del lato del quadrato. Per permetterti di verificare il tutto ho trasformato il tuo codice in un mini giochino dove ti puoi divertire a respingere il quadratino come fossero due magneti di stessa polarità. // 26/11/2011 Ore 15.00 use graph as g, ui, math; //--Variable global----- block=g.icon('block.png'); block2=g.icon('block2.png'); // x x+10 // ! ! // y ---+-----+ // ! ! // ! ! // y+10--+-----+ x=10; y=50; l=30; m=50; // -----Function---------- function objects() graph.put(.x,.y,.block); graph.put(.l,.m,.block2); end function collide_sq1_sq2() if (.x+10=.l) and (math.abs(.y-.m)<10) then .l=.l+10; elsif (.x=.l+10) and (math.abs(.y-.m)<10) then .l=.l-10; elsif (.y+10=.m) and (math.abs(.x-.l)<10) then .m=.m+10; elsif (.y=.m+10) and (math.abs(.x-.l)<10) then .m=.m-10; end; end //============MAIN============= ui.keys(false); while true do g.clear(); objects(); ke=ui.cmd(1); if ke=ui.rightkey then x=x+10; elsif ke=ui.leftkey then x=x-10; elsif ke=ui.upkey then y=y-10; elsif ke=ui.downkey then y=y+10; end; collide_sq1_sq2(); g.show(); end //==========END MAIN============ sqGame.txt Modificato 26 Novembre 2011 da lento Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 26 Novembre 2011 Autore Segnalazione Share Pubblicato: 26 Novembre 2011 Thanks lento you are genius in making games without you this board is more dead ,1 question if square l,m is fixed not move what i have to modified the code to stop and collide fixed? Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 27 Novembre 2011 Segnalazione Share Pubblicato: 27 Novembre 2011 1 question if square l,m is fixed not move what i have to modified the code to stop and collide fixed? Questo programma utilizza il metodo di rilevazione contenuto in questo post: https://www.nokioteca.net/home/forum/index.php/topic/150216-mshell-far-rotolare-il-barile/page__view__findpost__p__1719803 Ti ho lasciato anche la funzione collide_sq1_sq2() se oltre la collisione ti servisse sapere su che lato è avvenuta. // 27/11/2011 Ore 08.00 use graph as g, ui, math; //--Variable global----- block=g.icon('block.png'); block2=g.icon('block2.png'); // x x+10 // ! ! // y ---+-----+ // ! ! // ! ! // y+10--+-----+ x=10; y=50; l=30; m=50; // -----Function---------- function objects() graph.put(.x,.y,.block); graph.put(.l,.m,.block2); end function collisione(x1,y1) if (math.abs((.l+5)-(.x+x1+5))< 10) and (math.abs((.m+5)-(.y+y1+5))< 10) then return true; end; return false; end; // alternativa rende il lato colpito--------------+ function collide_sq1_sq2() // if (.x+10=.l) and (math.abs(.y-.m)<10) then // return "right"; //.l=.l+10; // elsif (.x=.l+10) and (math.abs(.y-.m)<10) then // return "left"; //.l=.l-10; // elsif (.y+10=.m) and (math.abs(.x-.l)<10) then // return "down"; //.m=.m+10; // elsif (.y=.m+10) and (math.abs(.x-.l)<10) then // return "up"; //.m=.m-10; // end; // return ""; // end // //------------------------------------------------+ //============MAIN============= ui.keys(false); while true do g.clear(); objects(); ke=ui.cmd(1); if ke=ui.rightkey then if collisione(10,0)=false then x=x+10 end; elsif ke=ui.leftkey then if collisione(-10,0)=false then x=x-10 end; elsif ke=ui.upkey then if collisione(0,-10)=false then y=y-10 end; elsif ke=ui.downkey then if collisione(0,10)=false then y=y+10 end; end; // collide_sq1_sq2(); g.show(); end //==========END MAIN============ sqGame1.txt Dato che i quadrati si spostano sempre di 10 pixel e in caso di collisione il quadrato1 si sovrappone esattamente sul quadrato2 potresti utilizzare questa soluzione più semplice e veloce: // 27/11/2011 Ore 08.15 // very simple and fast use graph as g, ui; //--Variable global----- block=g.icon('block.png'); block2=g.icon('block2.png'); x=10; y=50; l=30; m=50; // -----Function---------- function objects() graph.put(.x,.y,.block); graph.put(.l,.m,.block2); end function collisione(x1,y1) if (.l=.x+x1) and (.m=.y+y1) then return true; end; return false; end; //============MAIN============= ui.keys(false); while true do g.clear(); objects(); ke=ui.cmd(1); if ke=ui.rightkey then if collisione(10,0)=false then x=x+10 end; elsif ke=ui.leftkey then if collisione(-10,0)=false then x=x-10 end; elsif ke=ui.upkey then if collisione(0,-10)=false then y=y-10 end; elsif ke=ui.downkey then if collisione(0,10)=false then y=y+10 end; end; g.show(); end //==========END MAIN============ sqGame2.txt Spero di aver capito cosa volevi... Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 27 Novembre 2011 Autore Segnalazione Share Pubblicato: 27 Novembre 2011 Thanks buddy for your help the sqgame2 is more ease and small and fast if i have doubts i call you ,very thanks Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 27 Novembre 2011 Autore Segnalazione Share Pubblicato: 27 Novembre 2011 Sorry this question in the use graph as g, ui; block=g.icon('block.png'); block2=g.icon('block2.png'); x=10; y=50; l=30; m=50; function objects() graph.put(.x,.y,.block); graph.put(.l,.m,.block2); end function collisione(x1,y1) if (.l=.x+x1) and (.m=.y+y1) then return true; end; return false; end; ui.keys(false); while true do g.clear(); objects(); ke=ui.cmd(1); if ke=ui.rightkey then if collisione(10,0)=false then x=x+10 end; elsif ke=ui.leftkey then if collisione(-10,0)=false then x=x-10 end; elsif ke=ui.upkey then if collisione(0,-10)=false then y=y-10 end; elsif ke=ui.downkey then if collisione(0,10)=false then y=y+10 end; end; g.show(); end i want implement the array(i try make the game step by step for easy understand) now the objects(squares) i try put into a array example: blocks=[[1,0,0,2,2,0,0,0,0,0], [0,0,0,0,0,0,0,0,2,0], [0,0,0,0,0,0,0,0,2,0], [0,0,0,0,0,0,0,0,0,0]] 0=null 1=block 2=block2 but now with the script sqgame2 i not have a clue how implement the collision you make for all squares can you explain if the example sqgame2.txt what i have to do for the collision work in all squares if ease best im very bad understand complicated formulas and thanks for the trouble Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 28 Novembre 2011 Segnalazione Share Pubblicato: 28 Novembre 2011 Quanto spiegato per le collisioni, non serve se utilizzi il sistema "Tile" per disegnare lo scenario e far muovere i personaggi.As explained for the collision, the system is not needed if you use "Tile" to paint the scenery and the characters to move. Collisioni in "Tile" sono già state spiegate ed usate in: Snake: https://www.nokioteca.net/home/forum/index.php/topic/153386-mshell-snake/page__view__findpost__p__1308015 Pacman: https://www.nokioteca.net/home/forum/index.php/topic/172833-divertiamoci-a-creare-pacman/page__view__findpost__p__1447308 Comunque per riassumere se vuoi muovere il personaggio in un "Tile" prima leggi nella matrice dello scenario cosa contiene quel "Tile" e poi decidi se vi può accedere oppure no. Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 4 Dicembre 2011 Autore Segnalazione Share Pubblicato: 4 Dicembre 2011 Sorry lento i read the sneake and the packman but not understand the basis for in my example sqgame2 put square1 walking and collide in array can you explain please easy the base for this level=[[2,0,0,2,2], [0,0,0,0,0], [0,2,0,2,0], [0,0,2,0,0], [0,0,0,0,0]] 0=null 1=square1 2=square2 if square1 is in level[3][3] how i put move the square1 move and collide in all square2 in this array level?can you post a very simple example for i understand d basic for this please?very thanks lento and sorry for the trouble Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 5 Dicembre 2011 Segnalazione Share Pubblicato: 5 Dicembre 2011 (modificato) Can you post a very simple example for i understand d basic for this... Ok. Modificato 5 Dicembre 2011 da lento Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 5 Dicembre 2011 Autore Segnalazione Share Pubblicato: 5 Dicembre 2011 Thanks lento for for your reply Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 5 Dicembre 2011 Autore Segnalazione Share Pubblicato: 5 Dicembre 2011 Thanks lento for your reply Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 5 Dicembre 2011 Segnalazione Share Pubblicato: 5 Dicembre 2011 Thanks lento for your reply Eccomi qua. Per rendere comprensibile ho semplificato il tutto. Usa i tasti cursore per spostarti ui.leftkey,ui.rightkey,ui.upkey,ui.downkey e il tasto ui.gokey per terminare. es.txt Questo quanto vedi a schermo usando la tua matrice leve[]. In seguito potrai usare maxRow maxCol per muoverti in parti di disegno non visibili a schermo. Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 5 Dicembre 2011 Autore Segnalazione Share Pubblicato: 5 Dicembre 2011 Very thanks lento i will try Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 5 Dicembre 2011 Autore Segnalazione Share Pubblicato: 5 Dicembre 2011 Very thanks lento i will try Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 6 Dicembre 2011 Autore Segnalazione Share Pubblicato: 6 Dicembre 2011 If i want make this game with squares moving and when squares are in correct base the level go to level 2 how put squares move and how activate level 2 with this 2 squares? Square 1=moving others squares with faces square []=square for activate level 2 square X=square for activate level 2 the 2 squares will have activate the next level if stand in correct base example image how make this thanks? Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 6 Dicembre 2011 Autore Segnalazione Share Pubblicato: 6 Dicembre 2011 Example Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 6 Dicembre 2011 Autore Segnalazione Share Pubblicato: 6 Dicembre 2011 image Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 6 Dicembre 2011 Autore Segnalazione Share Pubblicato: 6 Dicembre 2011 Here Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 8 Dicembre 2011 Segnalazione Share Pubblicato: 8 Dicembre 2011 Here You want to make sokoban ? Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 8 Dicembre 2011 Autore Segnalazione Share Pubblicato: 8 Dicembre 2011 (modificato) The name i not know but i see this game in a place no record where /when the blocks are in correct place the level change I read in net sokoban and find;yes is this style game the blocks activate the next level Modificato 8 Dicembre 2011 da Darkangel Link to comment Condividi su altri siti More sharing options...
lento Pubblicato: 8 Dicembre 2011 Segnalazione Share Pubblicato: 8 Dicembre 2011 'Nalcwap' ti rispondo in questo altro post: https://www.nokioteca.net/home/forum/index.php/topic/214756-mshell-sokoban/page__view__findpost__p__1848208 Buon divertimento. Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 8 Dicembre 2011 Autore Segnalazione Share Pubblicato: 8 Dicembre 2011 Very thanks lento i will try if i have a question i tell here thanks buddy Link to comment Condividi su altri siti More sharing options...
Nalcwap Pubblicato: 9 Dicembre 2011 Autore Segnalazione Share Pubblicato: 9 Dicembre 2011 If i want put level=1 if level=1 then return [[1,1,1,1,1,1,1,1,1,1], [1,0,0,0,0,0,0,0,0,1], [1,4,0,0,0,0,2,0,0,0], [1,0,0,0,0,0,0,0,0,0], [1,0,0,1,1,1,1,0,0,0], [1,0,0,0,1,0,0,0,0,1], [1,0,2,0,1,0,0,3,0,1], [1,0,0,0,1,0,0,3,0,1], [1,0,0,0,0,0,0,0,0,1], [1,1,1,1,1,1,1,1,1,1], ]; elsif level=2 then return level=[[1,1,1,1,1,1,1,1,1,1], [1,0,0,0,0,0,0,0,0,1], [1,4,0,0,0,2,2,0,0,0], [1,0,0,0,0,0,0,0,0,0], [1,0,0,1,1,1,1,0,0,0], [1,0,0,0,1,0,0,0,0,1], [1,0,2,0,1,0,0,3,0,1], [1,0,0,0,1,0,0,3,0,1], [1,0,0,0,0,0,0,3,0,1], [1,1,1,1,1,1,1,1,1,1], ] how make this easy change in your code ?thanks buddy Link to comment Condividi su altri siti More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Accedi Ora