Simple Tetris. free for you to improve on « Next Oldest | Next Newest »

 ▼ cyrille de Brébisson Member Posts: 193 Threads: 10 Joined: Mar 2008 11-20-2013, 02:43 AM Around 80 lines of code... not bad for an interractive game.. Among the first things that needs to be improved (appart from the graphics!) is the key handling... specificaly, the wait should be cut in sub waits with key checking to allow more movements per 'cycles'... ```DoesNotFit(game, piece, p) // return true if piece does not fit begin local j; if game(im(p), re(p)) then return 1; end; for j:=1 to size(piece) do p:= p+piece(j); if game(im(p), re(p)) then return 1; end; end; return 0; end; EXPORT Tetris() BEGIN local game= makemat(J=1 or J=12 or I=1 or I=25,25,12), pause=0.200, score= 0; local shapes= {{(1, 0), (0, 1), (-1, 0)}, {(1, 0), (0, 1), (1, 0)}, {(-1, 0), (0, 1), (-1, 0)}, {(1, 0), (1, 0), (0, 1)}, {(-1, 0), (-1, 0), (0, 1)}, {(1, 0), (1, 0), (-1, 1)}, {(1, 0), (1, 0), (1, 0)}}; // Bar while 1 do local piece=shapes(randint(6)+1), p=(5,2), i, j; // get a random piece if DoesNotFit(game, piece, p) then return score; end; // test if we lose // create background dimgrob_p(G1, 320, 240); dimgrob_p(G2, 320, 240); line_p(G1,99, 0, 99, 232, #FF); line_p(G1, 99, 232, 202, 232, #FF); line_p(G1,202, 232, 202, 0, #FF); for i:=1 to 23 do for j:=1 to 10 do if game(i+1,j+1) then rect_p(G1, j*10+91, i*10-9, j*10+100, i*10, #0); end; end; end; while NOT DoesNotFit(game, piece, p) do // Draw the background on back buffer blit_p(G2, G1); // draw the piece i:=p; rect_p(G2, i*10-(-81,19), i*10-(-90,10), #0); for j:=1 to size(piece) do i:= i+piece(j); rect_p(G2, i*10-(-81,19), i*10-(-90,10), #0); end; // draw backbuffer on screen blit_p(G2); // pause wait(pause); // keys? if IsKeyDown(37) then if NOT DoesNotFit(game, piece, p-1) then p:= p-1; end; end; if IsKeyDown(39) then if NOT DoesNotFit(game, piece, p+1) then p:= p+1; end; end; if IsKeyDown(33) then local rotate= piece*(0, 1); if NOT DoesNotFit(game, rotate, p) then piece:= rotate; end; end; // try to go down... if DoesNotFit(game, piece, p+(0,1)) then break; else p:= p+(0,1); end; end; // put piece in game! game(im(p), re(p)):= 1; for j:=1 to size(piece) do p:= p+piece(j); game(im(p), re(p)):=1; end; // remove lines? for i:=24 downto 2 do if game(i)=[1,1,1,1,1,1,1,1,1,1,1,1] then for j:=i-1 downto 2 do game(j+1):= game(j); end; game(2):= [1,0,0,0,0,0,0,0,0,0,0,1]; score:= score+1; i:= i+1; end; end; // faster! pause:= pause-0.001; end; END;``` Edited: 20 Nov 2013, 2:54 a.m. ▼ Erwin Ried Junior Member Posts: 45 Threads: 4 Joined: Nov 2013 11-20-2013, 08:29 AM Is this a demo how to hang the Prime? Trying to run it I get invalid input, and it reboots the calculator when stepping (also crashes the emulator) Mic Member Posts: 190 Threads: 82 Joined: Aug 2012 11-20-2013, 11:10 AM J'ai une erreur entrée non valide à l'exécution. Erwin Ried Junior Member Posts: 45 Threads: 4 Joined: Nov 2013 11-20-2013, 05:43 PM By the way... I added txt support in my small utility, full hpprgm support, multiple file upload :) so this tetris is a perfect example for the little video... but since it does not work :/ https://www.youtube.com/watch?v=FxG-R0QZ-qI

 Possibly Related Threads... Thread Author Replies Views Last Post Tetris for HP Prime Mic 2 870 12-07-2013, 12:49 PM Last Post: Cristian Arezzini [OT] Mathematica free for Raspberry PI BruceH 32 4,052 11-23-2013, 05:24 AM Last Post: Nick_S [HP-Prime] Simple Game (Bugs) CompSystems 1 671 11-01-2013, 10:18 AM Last Post: Han Simple Math Question Namir 2 707 08-09-2013, 06:13 PM Last Post: Eddie W. Shore Is the HP-35S bug free? Matt Agajanian 22 2,944 07-01-2013, 04:03 PM Last Post: Andrés C. Rodríguez (Argentina) Great news - Vicinno's HP 15C Scientific Calculator iPhone app is FREE now John 21 3,024 06-07-2013, 05:49 AM Last Post: Mike (Stgt) hp-30b with free shipping sjthomas 9 1,507 04-14-2013, 02:46 AM Last Post: Gerson W. Barbosa HP-42S with Electroluminescent screen and simple I/O port Jose Poyan 8 1,431 03-27-2013, 07:11 PM Last Post: Jose Poyan Simple sample programs for the HP-41CX? Tom Lewis 5 982 03-25-2013, 07:11 PM Last Post: Allen Simple? programming question [WP34S] Shawn Gibson 3 765 03-15-2013, 11:56 AM Last Post: Didier Lachieze

Forum Jump: