| Mines Plus C16 |
External links: GitHub
User Rating: 7.0/10 (2 votes)
| |
|
| |
| Description | MINES PLUS for the Commodore 16/116/+4
Original game idea by Fabrizio Caruso
This is strategy game. Move carefully.
You are in a minefield where mines appear both - under your feet once you move and - around you (more if you do not move) You start with 3 lives and 9 anti-mine charges. You can clear the area around you with anti-mine charges but you can only carry a maximum of 9. If you reach a "$" item you get an extra anti-mine charge. The field has upper and lower borders. If reached you lose all your lives. Left and Right border wrap around. The rate of mines appearing around you, increases continuously. If you end up on a mine, you lose one life.
Goals: - Reach the highest score possible by walking on empty positions or collecting charges "$" - Avoid stepping on mines or the upper and lower borders. - Reach the next 500 points to get an extra life and a full recharge of your anti-mine charges
SCORE: - Walk into an empty position: 1 point - Walk into a anti-mine charge "$": 10 points
CONTROLS: - Use I J K L to move - Use SPACE to clear nearby area (if you have charges left) |
| |
| Commented Code | VARIABLES o upper right border location d lower left border location t offset to access correspong color ram j score f use charges r record p player's position a space character (32) e vertical vs horizontal movement c -1 for left/up movement, +1 for right/down movement m mine character n number of lives left k counter for next extra life bonus x position of new random mine l counter for next random anti-mine charge y flag for valid key-pressed g position of new random anti-mine charge s ASCII code of pressed key q probability of not generating a new random mine
EXTENDED CODE (using CBM Prg Studio notation for special characters) 0h=500:g=3073:o=3191:color.,1:color4,1:k=1:n=3:m=87:deffnu(x)=int(rnd(1)*x):ifj>rthenr=j 1d=4032:t=1024:j=.:p=o+h:q=.7:print"{white}{clear}ijkl {gray}spc":getkeyk$:fori=.tom:pokeo+1+fnu(840),m:next 2color4,1:printspc(18)"{red}mines+":ifj=.orpd-41thenfori=.to39:pokeo-i,102:poked+i,102:next 3print"{home}{yellow} ${white}"9-f" {red}Q{white}"n" {cyan}score{white}"j" {blue}hi{white}"r:ifpeek(p)=36thensound2,h,2:j=j+9:f=f+(f>.) 4l=jand3:y=.:geta$:ifrnd(.)>qthenx=p-4+2*fnu(5)+80*fnu(2-(p<3990))-80:pokex,m:pokex-t,113 5s=asc(a$+"@"):n=-n*(po):a=32:e=sand1:c=s-75+e:ifj>=k*hthenk=k+1:f=.:n=n-(n<9) 6pokep,81:pokep-t,113:ifsgn(c)=ctheny=1:pokep,m:p=p+c*39*e+c:j=j+1:q=q-.001:sound2,9,2 7pokep-t,1+k:pokeg-t,119:pokeg,36:g=3073:ifl=3thenifytheng=o+1+fnu(840):pokeg-t,4:pokeg,90 8ifs=atheniff<9thencolor4,11:pokep,90:pokep-1,a:pokep+1,a:pokep-i,a:pokep+i,a:f=f+1:sound3,9,2:goto2 9vol5:on-(n>.andpeek(p).)goto3:fork=-ttot:next:getkeyk$:goto0
COMMENTED, EXTENDED, INDENTED CODE
0 // Initialization and color setting for border and background h=500:g=3073:o=3191:color.,1:k=1:n=3:color4,1:m=87:
// Random integer function deffnu(x)=int(rnd(1)*x):
// Check for and set new record ifj>rthenr=j
1 // Initialization d=4032:t=1024:
// Initial score j=.:
// Initial player's position p=o+h:
// Initial probability of not generating a random mine q=.7:
// Display instructions and wait for key press print"{white}{clear}ijkl {gray}spc":getkeyk$:
// Create some random mines fori=.tom:pokeo+1+fnu(840),m:next
2 --- MAIN LOOP ENTRY when key-pressed is space bar // Reset border color (necessary to create flash effect for anti-mine charge) color4,1:printspc(18)"{red}mines+" // Display Mines printspc(18)"{red}mines+":
// Draw walls if either starting from scratch or p is close to wall ifj=.orpd-41then fori=.tow:pokeo-i,102:poked+i,102:next
3 --- LOOP entry when key-pressed is not space bar
// Display score print"{home}{yellow} ${white}"9-f" {red}Q{white}"n" {cyan}score{white}"j" {blue}hi{white}"r:
// If on an anti-mine charge, then increase 9 more points (10 total) and decrease number of used mines if not yet zero ifpeek(p)=bthensound2,h,2:j=j+9:f=f+(f>.)
4
// Compute counter for next random anti-charge mine l=jand3:
// Initialize flag for no valid key pressed y=.:
// Read keyboard geta$:
// Generate random mine with probability 1-q ifrnd(.)>qthen x=p-4+2*fnu(5)+80*fnu(2-(p<3990))-80:pokex,m:pokex-t,113
5
// Compute ASCII code of key-pressed s=asc(a$+"@"):
// If on wall, then lives left are zero n=-n*(po): // Set constant a to 32 (space character) a=32:
// Part of IJKL trick (see [*]) e=sand1:c=s-75+e:
// If reached next 500 points, then // - increase next extra extra-life counter // - increase life if not max // - max charges ifj>=k*hthen k=k+1:f=.:n=n-(n<9) 6
// Display player with white color pokep,81:pokep-t,113:
// If IJKL key pressed than set flag y, display mine, compute new player's position, increase point, decrease q, produce beep ifsgn(c)=cthen y=1:pokep,m:p=p+c*39*e+c:j=j+1:q=q-.001:sound2,9,2
7 // Set player's color pokep-t,1+k: // Display newly created anti-mine charge (created in the previous loop) pokeg-t,119:pokeg,36:
// Reset position of anti-mine charge in the score line g=3073:
// If IJKL key pressed and l has reached 3, then generate new charge and display it as a diamond (it will be morphed to charge in the next loop) ifl=3thenifythen g=o+1+fnu(840):pokeg-t,4:pokeg,90
8
// If key pressed is space bar and there are charges left, ifs=atheniff<9then // then change border color, display player as diamond, remove anything at top,bottom,left,right of the player, decrease charges, noise, goto to 2 color4,11:pokep,90:pokep-1,a:pokep+1,a:pokep-i,a:pokep+i,a:f=f+1:sound3,9,2:goto2
9 // if lives left and player is not on mine, goto 3
// Set volume level vol5
on-(n>.andpeek(p) goto3:
// Otherwise, decrease lives, set charges to max, produce noise n=n-1:f=.:sound3,m,5:
// if no lives left, go to 3 on-(n>.) goto3: // Otherwise, pause, wait for key press, restart game fork=-ttot:next:getkeyk$:goto0
[TRICK] (*) I have come up with this trick (by myself) in 2019. It may be a new trick. I do not use conditionals, nor precomputed offsets, nor Boolean expressions. I use an interpolating formula that computes the offset from the ASCII code of the pressed key.
I exploit the special symmetry of the ASCII codes of the keys I J K L: - I and K have odd codes and a distance of 2 bytes - J and L have even codes and a distance of 2 bytes - I and K have odd ASCII codes - J and L have even ASCII codes So, given s=ASC(a$) with a$ either I or J or K or L, we update the position p with p=p+c*(39*e+1) where - e=s and 1 -> parity of the code, i.e., vertical vs horizontal movement - c=s-75+e -> -1 for left/up vs +1 for right/down - 39*e+1 -> vertical vs horizontal offset absolute value, i.e., 1 vs 40 |
| |
Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon |