Откомпилировал свои игры написанные 1991-1998 гг. Как понизить скорость? - QBasic

Узнай цену своей работы

Формулировка задачи:

Насколько я знаю минимальное значение Sleep и Timer 1 секунда. Если в каждую итерацию вставить такую задержку, то игры будут тормозить. Что делать? Может библиотечка есть, чтобы вставить задержку 10 миллисекунд? Пока в голову приходит только выбор задержки скорости в самом начале игры. Выбранное значение, например 500 000, используется для пустого цикла for i=0 to 500000: next Но так как в QuckBASIC 4.5 не было опроса сенсорной клавиатуры, то непонятно как выбрать задержку потянув за бегунок пальцем. Кто сталкивался с такими проблемами в QB64?

Решение задачи: «Откомпилировал свои игры написанные 1991-1998 гг. Как понизить скорость?»

textual
Листинг программы
DATA 3,3,2,8,8,8,7,4,4,2,1,2,4,4,4,4,4,4,3,3,8,8,8,8,8,8,8,8
DATA 7,7,6,6,4,4,4,6,7,7,7,7,6,7,2,3,6,6
DATA 6,6,6,6,6,4,4,3,6,6,6,6,6,6,6,8,10,10,9,7,3,2,4,5,7,7,7,7,7,7,7,6,6,6
DIM a(500), B(500), c(1000), e(1000), w(10000), w1(1000), z(100), m(100), t(100), v(100)
SCREEN 1, 0
PRESET (205, 20)
DRAW "c2d15e5g5h5"
9
LINE (155, y5)-(165, y5), 2
a$ = INKEY$
IF a$ = "2" AND y5 < 199 THEN y5 = y5 + 1
IF a$ = "q" OR a$ = "Q" THEN END
'IF NOT a$ = " " THEN 9
y5 = 1000
y5 = y5 * 1000
 
COLOR 8, 0
x1 = 143
y1 = 74
f = 0
m = 2
m1 = 1
PRESET (7, 11) 'tank 2
DRAW "c1 h2 u2 e2 r5u1e3r6f1 r10l10f3 r2f1r1f1r1f1r1d1g2l23"
PAINT (18, 8), 1, 1
LINE (12, 4)-(24, 4), 0
FOR w = 7 TO 33 STEP 4
    CIRCLE (w, 9), 1, 0
NEXT 'tank 2
GET (0, 0)-(33, 11), t()
CLS
PRESET (6, 9)
DRAW "c3u3l1r2u1d1r2l1d3u2l1"
GET (100, 100)-(136, 136), B()
PRESET (105, 117)
DRAW "c1r24l12u12d24u5c0u14d7l7r14"
GET (100, 100)-(134, 134), e()
GET (0, 0)-(14, 14), a()
 
CLS
PRESET (5, 10) 'jeep
DRAW "c1u5r1d5u3r3u5l1h1r1u1r4d1r3u1d2u1r2u1d2u1r2u1d2u1r2l9d1l2dd5r2f2r4u5d1r6f1d1f1d2l1u2d3l1h2l1g2d1f2r1e2g2l1h2u1l6h2l1g2d1f2r1e3g3l1h3u3"
PAINT (10, 1), 1, 1
PAINT (16, 11), 1, 1
PSET (22, 8), 2
GET (0, 0)-(26, 15), m() 'jeep
CLS
PRESET (28, 18)
DRAW "c1r10l5u5d10u4c0l1u2r2d1"
CIRCLE (33, 18), 7, 1, , , 1
GET (15, 0)-(51, 36), c()
CLS
 
FOR t = 0 TO 240 STEP 80 'The town
    RESTORE
    FOR i = t TO t + 79
        READ j1
        LINE (i, 65)-(i, 65 - j1), 2
NEXT i, t
LINE (0, 66)-(319, 75), 2, BF
PAINT (160, 7), 1, 2
 
PRESET (5, 2)
DRAW "c2 r4f3r10u1e2r2u2l10r20l9d2r1f4d2g2f2h2l7g2e2h2u2l12h3"
PAINT (27, 8), 2, 2
PAINT (9, 4), 2, 2
PSET (9, 4), 3
PRESET (28, 3)
DRAW "c3d2r2h1"
GET (5, 0)-(36, 12), z() 'helicopter
 
LINE (0, 0)-(36, 12), 1, BF
CIRCLE (255, 17), 7, 3, , , .93: PAINT (255, 17), 3
LINE (0, 20)-(40, 32), 1, BF
LINE (0, 0)-(319, 199), , B
GET (0, 0)-(319, 80), w()
 
FOR x = 3 TO 318 STEP 2.5 'The bridge
    LINE (x, 99)-(x - 2, 98), 1
NEXT
 
FOR i = 100 TO 106
    LINE (0, i)-(319, i), 1, , &HAAAA
NEXT
 
PRESET (25, 115) '‚®«*л
DRAW "c1r2e2u1d1f1"
GET (25, 112)-(30, 115), v()
FOR i = 14 TO 300 STEP 6
    PUT (i, 112), v(), PSET
NEXT '‚®«*л
 
FOR g = 0 TO 10 STEP 2
    LINE (g, 107)-(g, 116), 1
NEXT
FOR g = 308 TO 318 STEP 2
    LINE (g, 107)-(g, 116), 1
NEXT
h = 8
FOR g = 12 TO 28 STEP 2
    LINE (g, 107)-(g, 107 + h), 1
    h = h - 1
NEXT
h = h + 1
FOR g = 290 TO 306 STEP 2
    LINE (g, 107)-(g, 107 + h), 1
    h = h + 1
NEXT
GET (0, 98)-(319, 116), w1() 'The bridge
1
 
f = 0
x = INT(RND(1) * 243) + 20
y = INT(RND(1) * 21) + 127
v2 = 1
LINE (138, 195)-(150, 184), , B: LINE (167, 195)-(179, 184), , B
2
LINE (110, 198)-(134, 174)
LINE (210, 198)-(186, 174)
LINE (134, 174)-(186, 174)
 
'FOR r5 = 0 TO y5: NEXT 'compensation of speed
 
IF j = 1 THEN LINE (139, 194)-(149, 185), 2, BF ELSE LINE (139, 194)-(149, 185), 0, BF
IF m5 = 1 THEN LINE (168, 194)-(178, 185), 2, BF ELSE LINE (168, 194)-(178, 185), 0, BF
PUT (0, 0), w(), PSET
PUT (0, 98), w1(), PSET
LOCATE 23, 19: PRINT v
 
IF m < 283 THEN PUT (m, 32), z(), PSET: m = m + 6 ELSE m = 1
IF m1 < 299 AND v3 <> v2 THEN PUT (m1, 82), m(), PSET: m1 = m1 + 5
IF v3 = v2 AND m1 < 283 THEN PUT (m1, 86), t(), PSET: m1 = m1 + 5
IF m1 > 285 AND v2 = v3 THEN m1 = 1: LINE (m1, 82)-(318, 97), 0, BF: v1 = v1 + 1: v2 = INT(v1 / 3): v3 = v1 / 3
IF m1 > 292 AND v2 <> v3 THEN m1 = 1: LINE (m1, 82)-(318, 97), 0, BF: v1 = v1 + 1: v2 = INT(v1 / 3): v3 = v1 / 3
 
IF a$ = "9" THEN m5 = 1
IF a$ = "0" THEN m5 = 0: j = 0: f = 0: LINE (1, 117)-(318, 173), 0, BF
IF a$ = "1" THEN m5 = 1: j = 1: f = 1
IF x1 < 0 THEN x1 = x1 + 11
IF x1 > 283 THEN x1 = x1 - 11
IF y1 < 11 THEN y1 = y1 + 11
IF y1 > 148 THEN y1 = y1 - 11
IF f = 0 THEN
    PUT (x1, y1), c(), XOR  'the cross-sight
 
startTime# = TIMER ' Calculate speed of system
'PRINT startTime#
FOR i# = 1 TO 5000000: NEXT i# ' and do some compensation
stopTime# = TIMER
'PRINT stopTime#
speed = speed * .5 / (stopTime# - startTime#)
curSpeed = speed 'Delay game
FOR a# = 1 TO curSpeed: NEXT a#
 
    PUT (x1, y1), c(), XOR
END IF
 
x = x + x2
y = y + y2
IF x < 20 THEN x = x + 5
IF x > 263 THEN x = x - 5
IF y < 127 THEN y = y + 5
IF y > 148 THEN y = y - 5
PUT (x, y), a(), PSET
x9 = x1 + 18
y9 = y1 + 18
 
'LOCATE 15, 1: PRINT "27"; y1 + 18; "45"
'LOCATE 23, 4: PRINT m - 7; x1 + 18; m + 26 'Џа®ўҐаЄ*
'PSET (m - 7, 21), 3
'PSET (m + 26, 21), 3
 
IF m - 7 < x1 + 18 AND x1 + 18 < m + 26 AND y1 + 18 > 27 AND y1 + 18 < 45 AND a$ = " " THEN m = 283: v = v + 10
IF v2 <> v3 THEN IF x1 > m1 - 20 AND x1 < m1 + 2 AND y1 > 63 AND y1 < 79 AND a$ = " " THEN m1 = 1: v = v + 10: LINE (1, 82)-(318, 97), 0, BF: v1 = v1 + 1: v3 = v1 / 3: v2 = INT(v1 / 3)
IF v2 = v3 THEN IF x1 > m1 - 20 AND x1 < m1 + 10 AND y1 > 63 AND y1 < 79 AND a$ = " " THEN m4 = m4 + 1: IF m4 = 3 THEN m4 = 0: m1 = 1: v = v + 15: LINE (1, 82)-(318, 97), 0, BF: v1 = v1 + 1: v3 = v1 / 3: v2 = INT(v1 / 3)
a$ = INKEY$
a = INT(RND(1) * 20)
IF a = 0 THEN x2 = 5: y2 = 0
IF a = 1 THEN x2 = -5: y2 = 0
IF a = 2 THEN y2 = 5: x2 = 0
IF a = 3 THEN y2 = -5: x2 = 0
IF a = 4 THEN x2 = -5: y2 = -5
IF a = 5 THEN x2 = 5: y2 = -5
IF a = 6 THEN x2 = 5: y2 = 5
IF a = 7 THEN x2 = -5: y2 = 5
IF a$ = "6" THEN x1 = x1 + 11
IF a$ = "2" THEN y1 = y1 + 11
IF a$ = "4" THEN x1 = x1 - 11
IF a$ = "8" THEN y1 = y1 - 11
IF a$ = "q" OR a$ = "Q" OR a$ = "©" OR a$ = "‰" THEN END '‚л室
 
IF m5 = 1 AND x > x1 - 13 AND x < x1 + 35 AND y > y1 - 13 AND y < y1 + 35 THEN f = 1: LINE (1, 117)-(318, 173), 0, BF
IF f = 1 THEN LINE (1, 117)-(318, 173), 0, BF: PUT (x - 10, y - 10), e(), PSET: x1 = x: y1 = y
IF j = 1 AND f = 1 THEN a$ = " "
IF a$ = " " THEN LINE (1, 198)-(x1 + 18, y1 + 18), 3: LINE (318, 198)-(x1 + 18, y1 + 18), 3: LINE (1, 198)-(x1 + 18, y1 + 18), 0: LINE (318, 198)-(x1 + 18, y1 + 18), 0
IF v > 745 THEN CLS: OUT 985, 10: LOCATE 11, 11: PRINT "-  congratulation  -": PLAY "g7e7c7e7d3    c5e7g7f3g7e7c7d7c3": PLAY "E6F6C6E6F6C3E3F6E6C7E7D3 ": END
IF a$ = " " OR a$ = "5" THEN GOSUB 3
 
GOTO 2
3
IF f = 1 THEN x1 = x - 11: y1 = y - 11: y = y1 + 3: x = x1 + 19
IF x > x1 + 2 AND x < x1 + 20 AND y > y1 + 2 AND y < y1 + 20 THEN LINE (1, 117)-(318, 173), 0, BF: v = v + 1: GOTO 1
RETURN

Объяснение кода листинга программы

This code is written in QBasic and seems to be a game. It contains a lot of game logic, including moving objects, drawing bridges, and handling user input. The speed of the game is controlled by a variable called speed, which is reduced by half every time the game is played. The code also includes a number of timers and delays, which are used to compensate for the speed of the system and ensure that the game runs at a consistent speed. There are a number of objects in the game, including a helicopter and a cross-hair, which move around the screen. The movement of these objects is controlled by variables such as x1, y1, x2, and y2, which are updated each time the game is played. The game also includes a number of conditions and if statements, which are used to handle collisions and other events in the game. Overall, this code seems to be a fairly complex game with a lot of moving parts and game logic. It would take some time and effort to fully understand and optimize the code for a specific purpose.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

6   голосов , оценка 4.833 из 5
Похожие ответы