Advertisement
Bisqwit

Simple goalless game with mario-like controls

Aug 15th, 2016
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 5.93 KB | None | 0 0
  1. DEFINT A-Z
  2.  
  3. TYPE actor
  4.   alive   AS INTEGER
  5.   oldx    AS INTEGER
  6.   oldy    AS INTEGER
  7.   oldface AS INTEGER
  8.   x       AS SINGLE
  9.   y       AS SINGLE
  10.   xs      AS SINGLE
  11.   ys      AS SINGLE
  12.   face    AS INTEGER
  13.   onfloor AS INTEGER
  14.   jumping AS INTEGER
  15. END TYPE
  16.  
  17. ' Objects. 0 = player
  18. DIM SHARED actors(0 TO 7) AS actor
  19. ' Playfield
  20. DIM SHARED playfield(0 TO 39, 0 TO 24) AS INTEGER
  21. ' Graphics
  22. DIM SHARED plrl(50), plrr(50), enml(50), enmr(50), tile(50)
  23. ' Keyboard
  24. DIM SHARED keys(0 TO 127) AS INTEGER
  25.  
  26. ' Initialize screen
  27. InitializeGraphics
  28.  
  29. ' Main loop
  30. quit = 0
  31. DO
  32.   ' Process input
  33.   xmove = 0
  34.   jump  = 0
  35.   DO
  36.     a = INP(&H60) ' Read keyboard I/O port
  37.     IF a < 128 THEN
  38.       keys(a) = 1
  39.     ELSEIF a < &HE0 THEN
  40.       keys(a - 128) = 0
  41.     END IF
  42.   LOOP WHILE INKEY$ <> ""
  43.   IF keys(1) THEN quit = 1      ' esc
  44.   IF keys(&H48) THEN jump = 1   ' up
  45.   IF keys(&H50) THEN REM        ' down
  46.   IF keys(&H4B) THEN xmove = -1 ' left
  47.   IF keys(&H4D) THEN xmove =  1 ' right
  48.  
  49.   ' Handle movement requests
  50.   FOR n=0 TO 7
  51.     IF xmove < 0 THEN actors(n).face = 1
  52.     IF xmove > 0 THEN actors(n).face = 0
  53.     IF xmove < 0 AND actors(n).xs > -2 THEN actors(n).xs = actors(n).xs - 0.25
  54.     IF xmove > 0 AND actors(n).xs <  2 THEN actors(n).xs = actors(n).xs + 0.25
  55.     IF xmove = 0 THEN actors(n).xs = actors(n).xs * 0.8: IF ABS(actors(n).xs) < 0.2 THEN actors(n).xs = 0
  56.     IF jump <> 0 AND actors(n).jumping = 0 AND actors(n).onfloor <> 0 THEN
  57.       actors(n).ys = -3
  58.       actors(n).jumping = 1
  59.     END IF
  60.     IF jump = 0 THEN actors(n).jumping = 0
  61.     IF jump = 0 AND actors(n).onfloor = 0 AND actors(n).ys < 0 THEN
  62.       actors(n).ys = 0
  63.     END IF
  64.     actors(n).ys = actors(n).ys + 0.1 ' Apply gravity
  65.    
  66.     ' Very stupid enemy AI for actors 1-7
  67.     xmove = INT(RND*3)-1
  68.     jump  = INT(RND*2)    
  69.   NEXT
  70.  
  71.   ' Check collisions
  72.   FOR n=0 TO 7
  73.     IF actors(n).alive THEN
  74.       xs = SGN(actors(n).xs)
  75.       ys = SGN(actors(n).ys)
  76.       x = actors(n).x + actors(n).xs
  77.       y = actors(n).y + actors(n).ys
  78.       IF playfield(INT((x+1)\8), INT(y\8)) <> 0 THEN actors(n).xs = actors(n).xs +0.3: IF xs < 0 THEN actors(n).xs = 0
  79.       IF playfield(INT((x+7)\8), INT(y\8)) <> 0 THEN actors(n).xs = actors(n).xs -0.3: IF xs > 0 THEN actors(n).xs = 0
  80.       IF ys < 0 AND playfield(INT((x+4)\8), INT((y+2)\8)) <> 0 THEN actors(n).ys = 0
  81.       actors(n).onfloor = playfield(INT((x+4)\8), INT((y+6)\8)) <> 0
  82.       IF ys > 0 AND actors(n).onfloor <> 0 THEN
  83.         actors(n).y = INT(actors(n).y \ 8)*8+1 ' Normalize the Y position
  84.         actors(n).ys = 0
  85.       END IF
  86.       actors(n).x = actors(n).x + actors(n).xs
  87.       actors(n).y = actors(n).y + actors(n).ys
  88.     END IF
  89.   NEXT
  90.  
  91.   ' Wait for screen refresh to hide flickering
  92.   WAIT &H3DA, &H8
  93.   ' Wait for start of rendering
  94.   WAIT &H3DA, &H8, &H8
  95.   ' Render screen
  96.   FOR n=0 TO 7
  97.     x = actors(n).oldx: y = actors(n).oldy
  98.     m = actors(n).oldface
  99.     IF n=0 THEN
  100.       IF x>0 THEN IF m=0 THEN PUT(x,y), plrr, XOR ELSE PUT(x,y),plrl, XOR
  101.     ELSE
  102.       IF x>0 THEN IF m=0 THEN PUT(x,y), enmr, XOR ELSE PUT(x,y),enml, XOR
  103.     END IF
  104.    
  105.     x = actors(n).x: y = actors(n).y
  106.     m = actors(n).face
  107.     IF n=0 THEN
  108.       IF x>0 THEN IF m=0 THEN PUT(x,y), plrr, XOR ELSE PUT(x,y),plrl, XOR
  109.     ELSE
  110.       IF x>0 THEN IF m=0 THEN PUT(x,y), enmr, XOR ELSE PUT(x,y),enml, XOR
  111.     END IF
  112.  
  113.     actors(n).oldx = x: actors(n).oldy = y
  114.     actors(n).oldface = m
  115.   NEXT
  116. LOOP WHILE quit = 0
  117.  
  118.  
  119.  
  120. SCREEN 0,1,0,0
  121. WIDTH 80,25
  122.  
  123. ' Define playing field
  124. DATA XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  125. DATA X......................................X
  126. DATA X......................................X
  127. DATA X......................................X
  128. DATA X...............XXXXXXXXXXXXXXX........X
  129. DATA X......................................X
  130. DATA X......................................X
  131. DATA X.................................X....X
  132. DATA X....XXXXXXXXXXXXX................XXXXXX
  133. DATA X......................................X
  134. DATA X......................................X
  135. DATA X.......................X..............X
  136. DATA X.......................X..............X
  137. DATA X...............XXXXXXXXXXXXX..........X
  138. DATA X.....XXXXXX...........................X
  139. DATA X..........................XXXXXXX.....X
  140. DATA X..XXXXX.......................X.......X
  141. DATA X.................X............XXXX....X
  142. DATA X.................X....................X
  143. DATA X.....XXXXXXXXXXXXX..............XXXXXXX
  144. DATA X......................................X
  145. DATA X......................................X
  146. DATA X......................................X
  147. DATA X......................................X
  148. DATA XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  149. DATA 1,10,170
  150. DATA 1,40,20
  151. DATA 1,100,20
  152. DATA 1,140,20
  153. DATA 1,220,20
  154. DATA 1,40,100
  155. DATA 1,100,100
  156. DATA 1,140,120
  157.  
  158. SUB InitializeGraphics
  159.   SCREEN 13
  160.   LINE (0,0)-(15,15),0,BF:CIRCLE(4,4),3,70:PAINT(4,4),73,70:PSET(4,4),1:PSET(6,4),1
  161.   GET (0,0)-(7,7), plrr
  162.   LINE (0,0)-(15,15),0,BF:CIRCLE(4,4),3,70:PAINT(4,4),73,70:PSET(2,4),1:PSET(4,4),1
  163.   GET (0,0)-(7,7), plrl
  164.  
  165.   LINE (0,0)-(15,15),0,BF:CIRCLE(4,4),3,&H27:PAINT(4,4),4,&H27:PSET(4,4),1:PSET(6,4),1
  166.   GET (0,0)-(7,7), enmr
  167.   LINE (0,0)-(15,15),0,BF:CIRCLE(4,4),3,&H27:PAINT(4,4),4,&H27:PSET(2,4),1:PSET(4,4),1
  168.   GET (0,0)-(7,7), enml
  169.  
  170.   LINE(0,0)-(7,7),0,BF:LINE(0,3)-(7,3),4:LINE(0,0)-(7,0),12:LINE(0,1)-(7,2),6,BF
  171.   LINE(0,4)-(7,4),12:LINE(0,5)-(7,6),6,BF:LINE(0,7)-(7,7),4:LINE(4,0)-(4,2),12:LINE(6,4)-(6,6),12:LINE(3,0)-(3,3),4:LINE(5,4)-(5,7),4
  172.   GET(0,0)-(7,7),tile
  173.  
  174.   ' Clear screen
  175.   LINE(0,0)-(319,199),0,BF
  176.  
  177.   FOR y=0 TO 24
  178.     READ s$
  179.     FOR x=0 TO 39
  180.       playfield(x,y) = MID$(s$, x+1, 1) = "X"
  181.       IF playfield(x,y) THEN
  182.         PUT (x*8, y*8), tile, PSET
  183.       END IF
  184.     NEXT
  185.   NEXT
  186.   FOR n=0 TO 7
  187.     READ actors(n).alive, actors(n).x, actors(n).y
  188.     actors(n).onfloor = 1
  189.     actors(n).xs = 0
  190.     actors(n).ys = 0
  191.     actors(n).oldx = -8
  192.     actors(n).face = 0
  193.   NEXT
  194. END SUB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement