Newsgroups: comp.sys.apple2.programmer Subject: Re: Apple IIe programming help wanted... From: dempson@actrix.gen.nz (David Empson) Date: Mon, 3 May 1999 21:29:53 +1200 Message-ID: <1dr8yoz.17cx01dshs8ayN@dempson.actrix.gen.nz> References: Organization: Empsoft X-Newsreader: MacSOUP 2.3 NNTP-Posting-Host: 202.49.157.176 X-Trace: 3 May 1999 21:28:04 NZST, 202.49.157.176 Lines: 122 Path: news1.icaen!news.uiowa.edu!NewsNG.Chicago.Qual.Net!128.174.5.49!vixen.cso.uiuc.edu!logbridge.uoregon.edu!news.bbnplanet.com.MISMATCH!su-news-hub1.bbnplanet.com!lsanca1-snf1!news.gtei.net!news.netgate.net.nz!news.xtra.co.nz!news.iprolink.co.nz!news.actrix.gen.nz!dempson Xref: news1.icaen comp.sys.apple2.programmer:10550 Jared Falvo wrote: > I am a novice of novices BASIC programmer. I barely know enough to do > anything, yet since having bought a IIe/Apple IIc monitor combo... no floppy > disk drives yet, so the $10 spent in hardware is just sitting idle, and > gotten a IIe emulator (AppleWin), I've become reinterested in learning to > program... in what else, but Applesoft BASIC (always a good place to start > for the absolute know-nothing beginner). Naturally, the emulator has > everything I need hardware-wise, so... > > I'm interested in writing a lo-res maze-like game and need to know a few > things... That seems like rather an ambitious start to learning programming. I'll answer your questions, but I expect you won't fully understand the answers. > 1) How do you control a PLOT "brick" (player and game characters) with the > arrow keys on a PC keyboard? In general, your program needs to go through a loop checking to see if a key has been pressed. If so, identify whether it is an arrow key, and if so, adjust the position of the character accordingly (unless limited by an obstacle). There is no built-in mechanism to map keypresses to on-screen activity. Typical organisation would be to have a main loop which includes the following line: 400 IF PEEK(-16384) > 127 THEN GOSUB 2000: REM Handle keypress Your subroutine (at line 2000 in this example) would use something like the following: 2000 GET K$: REM Get keypress 2010 IF K$ = CHR$(8) THEN GOTO 2100: REM Left 2020 IF K$ = CHR$(21) THEN GOTO 2200: REM Right 2030 IF K$ = CHR$(11) THEN GOTO 2300: REM Up 2040 IF K$ = CHR$(10) THEN GOTO 2400: REM Down [Add more lines here to handle any other keys that might be needed] 2090 RETURN Assuming your player position is in the variables PX and PY, the move left routine would look something like this: 2100 REM Move Left 2110 IF PX > 0 AND SCRN(PX-1,PY)=0 THEN GOSUB 3000: PX=PX-1: GOTO 3100 2120 RETURN The erase and draw routines would look something like this. You could do these steps in each of the move routines rather than calling another subroutine. 3000 REM Erase player 3010 COLOR=0: PLOT PX, PY: RETURN 3100 REM Draw player 3110 COLOR=10: PLOT PX, PY: RETURN > At the very least, what command(s) are used to activate Apple joystick > control. Use the PDL(0) function to read the X position, and PDL(1) to read the Y position. Both these functions return a value from 0 to 255, where 0 is left and 255 is right for X, 0 is top and 255 is bottom for Y. You can't read both paddles in sequence unless you use a PEEK to identify whether the desired paddle circuit has timed out yet. The usual way to handle this is to ensure there is a delay of at least three milliseconds between reading X and Y (or vice versa). Once you have coordinates, you need to do a range check to identify which direction the joystick is pointing, and then use similar logic to the keyboard code described above. > There's probably a way to remap the control to other PC keys, as need be. Nope. > 2) Can you generate walls without having to manually HLIN and VLIN all of > them in? Not unless you want to PLOT each block. > 3) How do you make a game character (represented as a PLOT "brick") run > around the playfield semi-randomly with variations in speed, as needed? You use a random number generator and test for values as appropriate, feeding the output into a routine which moves the character. > 4) How do you detect collision between your character (also a PLOT "brick") > and the walls or a game character? Two methods occur to me: (a) Keep a data structure (probably a two dimensional array) which defines the game map, and do all collision detection within this array. (b) Use the SCRN(X,Y) function to detect whether a target lo-res graphics position is in use. This is probably easier. > I assume keeping all individual elements (player/computer character/maze > walls) as separate colors would help in this respect. Yes. The result of the SCRN function will be the colour of the target position. > 5) How do you (or can you?) incorporate text on the game screen? You can't draw text in the lo-res graphics area, but you can run the screen in a mixed mode (as set up by the GR command), where you have 40 lo-res rows and 4 lines of text. The best you could manage in the lo-res area would be to draw very large characters by PLOTting individual "pixels" in something like a 5x7 grid. Not many characters, in other words. -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand