Author Topic: Preliminary AstroSmash 64 sneak peak.  (Read 3323 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Preliminary AstroSmash 64 sneak peak.
« on: November 10, 2018, 08:51:46 pm »
Give it a try, a sort of sneak peak of my Astrosmash clone, AstroSmash 64.
Still have a long way to go. Bombs don't kill you if they hit the ground yet, Tracker and SpaceShips don't show up yet, and the speed is way off. but you up levels, gain extra lives, and get scoring so it is playable. the collision is a little off between asterOIDs and the player ship.
Have not integrated the font with the game yet so you still need the font as a second file, hoping to fix that eventually
If you want sound, you will just have to make your own at the moment too, don't worry you wont look too silly. :)
 
Code: QB64: [Select]
  1. TYPE oids
  2.  Xpos AS SINGLE
  3.  Ypos AS SINGLE
  4.  Angle AS SINGLE
  5.  Speed AS SINGLE
  6.  Rotation AS _BYTE
  7.  Colr AS _BYTE
  8.  Kind AS _BYTE
  9.  Tracking AS _BYTE 'tells whether its a tracker and which direction its moving
  10.  CollideColr AS _BYTE
  11.  
  12. TYPE Gamedata
  13.  level AS _BYTE
  14.  Score AS LONG
  15.  OidCount AS _BYTE
  16.  BlastCount AS _BYTE
  17.  Count AS INTEGER
  18.  Movement AS _BYTE 'How fast player moves
  19.  ShotSpeed AS _BYTE 'how fast player shots move
  20.  GameOver AS _BYTE 'has player lost all lives
  21.  CurrentBG AS _BYTE 'current background color
  22.  
  23. TYPE Explosions
  24.  Xpos AS INTEGER
  25.  Ypos AS INTEGER
  26.  Frame AS _BYTE
  27.  
  28. TYPE Player
  29.  Xpos AS INTEGER
  30.  Ypos AS INTEGER
  31.  ShotCount AS _BYTE
  32.  
  33. 'Load sprites--------------------------------
  34. DATA 311,16,16,16,56,124,238,254,68,16,84,56,108,56,124,254,170,76,124,118,174,252,127,90,48,118,255,122,47,15,60,126,44,104,252,124,62,122,222,252,56,124,126,126,55,63,250,239,102,32,120,236,254,120,95,47,58,124,127,253,218,110,126,58,16,12,60,126,118,127,255,250,60,124,126,111,255,254,126,108,32,24,24,60,36,36,60,24,24,0,6,30,36,36,120,96,0,0,0,60,231,231,60,0,0,0,96,120,36,36,30,6,0,0,0,36,24,24,36,0,0,0,66,60,36,36,60,66,0,0,60,102,90,90,102,60,0,60,0,153,165,165,153,0,60,66,153,36,66,66,36,153,66,153,66,0,129,129,0,66,153,0,0,0,16,16,124,16,16,0,0,0,16,56,124,56,16,0,0,0,56,124,124,124,56,0,0,0,16,56,124,56,16,16,16,16,16,16,16,16,56,56,124,108,238,254,254,68,68,128,128,64,64,64,32,112,112,60,108,110,126,120,32,32,32,128,128,64,64,48,48,62,62,23,23,28,28,24,24,8,8,0,0,128,192,108,127,63,22,22,28,28,28,8,8,8,0,0,0,0,2,7,15,30,250,250,30,15,7,2,0,0,0,0,0,24,60,60,24,0,0,60,126,255,213,255,60,0,0,24,90,255,171,126,153,0,0,153,90,255,171,126,90,0,0,0,0,84,42,84,42,0
  35. READ Count%
  36. DIM SHARED Sprites(Count%) AS _UNSIGNED _BYTE
  37. FOR i% = 0 TO Count% - 1
  38.  READ Sprites(i%)
  39. NEXT i%
  40. '********************************************
  41. 'Load Main & Title screens
  42. MainScreen:
  43. DATA 205,0,487,15,1,0,194,15,1,0,12,15,1,0,115,15,1,0,106,15,1,0,275,15,1,0,71,15,1,0,174,15,1,0,480,15,1,0,39,15,1,0,455,15,1,0,123,15,2,0,786,15,1,0,32,15,1,0,18,15,1,0,7,15,1,0,367,15,2,0,30,15,2,0,14,15,2,0,775,15,1,0,31,15,1,0,1170,15,1,0,195,15,1,0,36,15,1,0,354,15,2,0,591,15,1,0,162,15,1,0,7,15,1,0,20,15,1,0,39,15,1,0,394,15,1,0,31,15,1,0,294,15,1,0,317,15,1,0,151,15,1,0,110,15,1,0,347,15,1,0,83,15,2,0,257,15,1,0,365,15,1,0,42,15,1,0,192,15,1,0,103,15,1,0,31,15,1,0,135,15,1,0,138,15,2,0,305,15,1,0,1063,5,4,0,160,5,4,0,149,5,3,0,8,5,3,0,143,5,3,0,14,5,3,0,129,5,2,0,7,5,2,0,20,5,3,0,14,5,1,0,39,5,2,0,67,5,3,0,2,5,3,0,29,5,3,0,8,5,3,0,37,5,3,0,2,5,3,0,34,5,4,0,23,5,3,0,8,5,3,0,29,5,3,0,2,5,3,0,4,5,2,0,31,5,3,0,8,5,3,0,29,5,2,0,4,5,2,0,10,5,4,0,6,5,1,0,14,5,1,0,31,5,2,0,9,5,2,0,10,5,4,0,12,5,3,0,14,5,3,0,12,5,4,0,8,5,2,0,8,5,2,0,5,5,3,0,4,5,3,0,63,5,2,0,5,5,3,0,4,5,3,0,6,5,3,0,20,5,3,0,6,5,3,0,4,5,3,0,3,5,2,0,12,5,5,0,10,5,3,0,62,5,5,0,10,5,6,0,26,5,6,0,10,5,3,0,960,5,320,0,1600
  44. TitleScreen:
  45. DATA 129,4,1617,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,13136
  46.  
  47. SCREEN _NEWIMAGE(640, 480, 32)
  48.  
  49. DIM SHARED Layer(12) AS LONG, Colors(16) AS _UNSIGNED LONG, FFX(1) AS LONG
  50. DIM SHARED G AS Gamedata, O(15) AS oids, E(15) AS Explosions, P AS Player
  51. DIM SHARED s(8) AS Explosions
  52. G.Count = Count%
  53. 'Color CONSTs
  54. CONST Black = 0, Blue = 1, Red = 2, Tanc = 3, Olive = 4, DkGreen = 5
  55. CONST BGGreen = 6, Yellow = 7, Grey = 8, SkyBlue = 9, Orange = 10
  56. CONST Pink = 11, Purple = 12, FadeGreen = 13, Maroon = 14, White = 15
  57. 'Sprite CONSTs
  58. CONST NullShip = 0, Ship = 1, SmallA = 2, SmallB = 3, SmallC = 4, SmallD = 5
  59. CONST LargeA = 6, LargeB = 7, LargeC = 8, LargeD = 9, Bomb = 10, Tracker = 11
  60. CONST SpaceShip = 12, SmallE = 13, SmallF = 14, SmallG = 15, SmallH = 16
  61. CONST Blast = 17, SpaceShipShot = 18
  62. 'Zoom CONSTs
  63. CONST None = 0, H4 = 128, H2 = 64, H12 = 32, H14 = 16, V4 = 8, V2 = 4
  64. CONST V12 = 2, V14 = 1, HF = 512, VF = 256
  65. '4-x4, 2-x2, 12-x1/2, 14-x1/4, HF-Flip Horizontal, VF-Flip Vertical
  66. 'Layer CONSTs
  67. CONST SPRITE = 1, TITLE = 3, BGPLATE = 2, TEMP = 6, COLLIDE = 7, BGCOLOR = 8
  68. CONST TRUE = -1, FALSE = NOT TRUE
  69. 'Game Scores CONSTs
  70. CONST SmallOid = 20
  71. CONST LargeOid = 10
  72. CONST LargeBomb = 40
  73. CONST SmallBomb = 80
  74. CONST Seeker = 100
  75. CONST Aliens = 150
  76. CONST AlienShot = 75
  77.  
  78. Layer(0) = _DISPLAY
  79. Layer(SPRITE) = _NEWIMAGE(640, 400, 13)
  80. Layer(BGPLATE) = _NEWIMAGE(640, 480, 32)
  81. Layer(TITLE) = _NEWIMAGE(640, 480, 32)
  82. Layer(4) = _NEWIMAGE(640, 480, 32) 'Sprite draw layer
  83. Layer(5) = _NEWIMAGE(640, 480, 32) 'Composite layer
  84. Layer(TEMP) = _NEWIMAGE(64, 64, 32) 'temp sprite layer for transparency
  85. Layer(COLLIDE) = _NEWIMAGE(640, 480, 32) 'collision shadow layer
  86. Layer(BGCOLOR) = _NEWIMAGE(640, 480, 32) 'background color
  87.  
  88. FFX(1) = _LOADFONT("PixelIntv.ttf", 40, "monospace")
  89. IF FFX(1) THEN _FONT FFX(1), Layer(4)
  90. IF FFX(1) THEN _FONT FFX(1), Layer(TITLE)
  91.  
  92.  
  93. Colors(0) = _RGB32(0, 0, 0) '       Black
  94. Colors(1) = _RGB32(0, 45, 255) '    Blue
  95. Colors(2) = _RGB32(255, 61, 16) '   Red
  96. Colors(3) = _RGB32(201, 207, 171) ' Tan
  97. Colors(4) = _RGB32(84, 110, 0) '    Olive Green
  98. Colors(5) = _RGB32(56, 107, 63) '   DkGreen
  99. Colors(6) = _RGB32(0, 167, 86) '    BGGreen
  100. Colors(7) = _RGB32(250, 234, 80) '  Yellow
  101. Colors(8) = _RGB32(189, 172, 200) ' Purpleish Grey
  102. Colors(9) = _RGB32(36, 184, 255) '  Sky Blue
  103. Colors(10) = _RGB32(255, 180, 31) ' Orange
  104. Colors(11) = _RGB32(255, 78, 87) '  Pinkish
  105. Colors(12) = _RGB32(164, 150, 255) 'Purplish
  106. Colors(13) = _RGB32(117, 204, 128) 'Faded Green
  107. Colors(14) = _RGB32(181, 26, 88) '  Maroon
  108. Colors(15) = _RGB32(255, 255, 255) 'White
  109.  
  110. 'color test
  111. 'FOR i% = 0 TO 15
  112. ' LINE (0 + (i% * 31), 0)-STEP(32, 256), Colors(i%), BF
  113. 'NEXT i%
  114. 'END
  115. '----------
  116. 'draw sprites
  117. DrawSpriteSheet Layer(1)
  118. RESTORE MainScreen
  119. DrawScreen BGPLATE
  120. RESTORE TitleScreen
  121. DrawScreen TITLE
  122. 'IF _FILEEXISTS("debugshot.txt") THEN KILL "debugshot.txt"
  123. 'OPEN "debugshot.txt" FOR OUTPUT AS #2
  124.  
  125. 'main
  126. TitleScreen
  127. ON TIMER(t&, .125) AnimOids
  128. 'start data
  129. G.Movement = 4
  130. G.ShotSpeed = 8
  131. G.Lives = 4
  132. G.level = 1
  133. P.Xpos = 300
  134. P.Ypos = 321
  135. G.Score = 0
  136. _CLEARCOLOR Colors(Black), Layer(BGPLATE)
  137. ChangeBGColor Black
  138. G.OidCount = 5
  139. FOR i%% = 0 TO G.OidCount - 1
  140.  Makeoid i%%
  141. NEXT i%%
  142.  
  143. TIMER(t&) ON 'timer animates bombs, trackers, SpaceShip and explosions
  144.  
  145.  KBD& = _KEYHIT
  146.  SELECT CASE KBD&
  147.   CASE 27
  148.    Exitflag%% = TRUE
  149.  
  150.  Controls 'keypress routine
  151.  
  152.  FOR i%% = 0 TO G.OidCount - 1
  153.   Moveoid i%% 'move the asteroids(aka Oids)
  154.  NEXT i%%
  155.  IF Exitflag%% THEN
  156.   _PUTIMAGE (0, 0), Layer(COLLIDE), Layer(0)
  157.   END
  158.  
  159.  ClearLayer COLLIDE
  160.  
  161.  IF NOT G.GameOver THEN
  162.   BackGroundColor
  163.   'Back Ground Plate
  164.   _PUTIMAGE (0, 0), Layer(BGCOLOR), Layer(5)
  165.   _PUTIMAGE (0, 0), Layer(BGPLATE), Layer(5)
  166.   'draw Oids
  167.   FOR i%% = 0 TO G.OidCount - 1
  168.    PlaceSprite O(i%%).Xpos, O(i%%).Ypos, O(i%%).Kind, O(i%%).Zoom, O(i%%).Colr, O(i%%).Rotation
  169.    PlaceSpriteShadow O(i%%).Xpos, O(i%%).Ypos, O(i%%).Kind, O(i%%).Zoom, O(i%%).CollideColr, O(i%%).Rotation
  170.   NEXT i%%
  171.   'draw explosion if any
  172.   IF G.BlastCount THEN
  173.    FOR i%% = 0 TO G.BlastCount - 1
  174.     PlaceSprite E(i%%).Xpos, E(i%%).Ypos, Blast, None, Red, E(i%%).Frame
  175.     PlaceSpriteShadow E(i%%).Xpos, E(i%%).Ypos, Blast, None, 126, E(i%%).Frame
  176.    NEXT i%%
  177.   END IF
  178.   'draw player
  179.   PlaceSprite P.Xpos, P.Ypos, Ship, None, White, 0
  180.   PlaceSpriteShadow P.Xpos, P.Ypos, Ship, None, 127, 0
  181.   'draw players shot
  182.   IF P.ShotCount THEN
  183.    FOR i%% = 0 TO P.ShotCount - 1
  184.     MovePlayerShot i%%
  185.     DrawPlayerShot i%%
  186.    NEXT i%%
  187.   END IF
  188.   DisplayStats
  189.   _CLEARCOLOR _RGB32(0, 0, 0), Layer(4)
  190.   _PUTIMAGE (0, 0), Layer(4), Layer(5) 'combine sprites and BG Plate
  191.   _PUTIMAGE (0, 0), Layer(5), Layer(0) 'Move to display
  192.   ClearLayer 4
  193.   Exitflag%% = TRUE
  194.  _LIMIT 60
  195. LOOP UNTIL Exitflag%%
  196.  
  197. SUB AnimBlast
  198.  FOR I%% = 0 TO G.BlastCount - 1
  199.   E(I%%).Frame = E(I%%).Frame + 1
  200.   IF E(I%%).Frame = 6 THEN
  201.    FOR j%% = I%% TO G.BlastCount
  202.     SWAP E(j%%), E(j%% + 1)
  203.    NEXT j%%
  204.    E(j%%).Frame = 1
  205.    E(j%%).Xpos = 1
  206.    E(j%%).Ypos = 1
  207.    G.BlastCount = G.BlastCount - 1
  208.   END IF
  209.  NEXT I%%
  210.  
  211. SUB AnimOids
  212.  FOR I%% = 0 TO G.OidCount - 1
  213.   O(I%%).Rotation = O(I%%).Rotation + 1
  214.   IF O(I%%).Rotation = 5 THEN O(I%%).Rotation = 1
  215.  NEXT I%%
  216.  IF G.BlastCount THEN AnimBlast 'go ahead and animate explosions if any.
  217.  
  218. SUB ClearLayer (id%%)
  219.  old& = _DEST
  220.  _DEST Layer(id%%)
  221.  CLS
  222.  _DEST old&
  223.  
  224. SUB Controls
  225.  STATIC SlowFlag%%, CoastFlag%%, ShotLock%%, BombLock%%
  226.  
  227.  ' IF _KEYDOWN(18432) THEN P.SpeedY = P.SpeedY + .25: CoastFlag%% = FALSE
  228.  ' IF _KEYDOWN(20480) THEN P.SpeedY = P.SpeedY - .25: CoastFlag%% = FALSE
  229.  
  230.  IF _KEYDOWN(19200) THEN P.Xpos = P.Xpos - G.Movement
  231.  IF P.Xpos <= 8 THEN P.Xpos = 8
  232.  IF _KEYDOWN(19712) THEN P.Xpos = P.Xpos + G.Movement
  233.  IF P.Xpos >= 600 THEN P.Xpos = 600
  234.  
  235.  
  236.   IF NOT ShotLock%% AND P.ShotCount <= 2 THEN
  237.    'shoot blaster
  238.    MakeShot P.ShotCount
  239.    P.ShotCount = P.ShotCount + 1
  240.    ShotLock%% = TRUE 'must release key to shoot again
  241.   END IF
  242.   ShotLock%% = FALSE
  243.  
  244.   IF NOT BombLock%% THEN
  245.    'drop bomb
  246.    BombLock%% = TRUE 'must release key to shoot again
  247.   END IF
  248.   BombLock%% = FALSE
  249.  
  250. SUB DisplayStats
  251.  'displays Score, Level, Extra Lives
  252.  level$ = LTRIM$(STR$(G.level)) + "x"
  253.  Score$ = LTRIM$(STR$(G.Score))
  254.  _PRINTSTRING (546, 357), level$, Layer(4) 'level
  255.  _PRINTSTRING (287 - (LEN(Score$) * _FONTWIDTH(FFX(1))), 357), Score$, Layer(4) 'score
  256.  IF G.Lives <= 7 THEN
  257.   FOR i%% = 0 TO G.Lives - 1
  258.    PlaceSprite 316 + (i%% * 33), 360, Ship, None, BGGreen, 0
  259.   NEXT i%%
  260.   Lives$ = "x" + LTRIM$(STR$(G.Lives))
  261.   PlaceSprite 316, 360, Ship, None, BGGreen, 0
  262.   _DEST Layer(4)
  263.   COLOR Colors(BGGreen)
  264.   _PRINTSTRING (354, 361), Lives$, Layer(4) 'level
  265.   COLOR Colors(White)
  266.   _DEST Layer(0)
  267.  
  268. SUB DrawPlayerShot (id~%%)
  269.  _DEST Layer(4)
  270.  LINE (s(id~%%).Xpos, s(id~%%).Ypos)-STEP(8, 32), Colors(White), BF
  271.  _DEST Layer(0)
  272.  
  273. SUB DrawScreen (id&)
  274.  READ count%
  275.  l2& = _NEWIMAGE(160, 100, 32)
  276.  _DEST l2&
  277.  x% = -1: y% = 0
  278.  FOR i% = 0 TO count% - 1
  279.   READ colr%%
  280.   READ Numbr%
  281.   FOR j% = 1 TO Numbr%
  282.    PSET (x%, y%), Colors(colr%%)
  283.    x% = x% + 1
  284.    IF x% = 160 THEN x% = 0: y% = y% + 1
  285.   NEXT j%
  286.  NEXT i%
  287.  _PUTIMAGE (0, 0)-(639, 399), l2&, Layer(id&)
  288.  
  289. SUB DrawSpriteSheet (id&)
  290.  old& = _DEST
  291.  _DEST id&
  292.  FOR j% = 0 TO G.Count
  293.   FOR i%% = 7 TO 0 STEP -1
  294.    IF Sprites(j%) AND (2 ^ i%%) THEN LINE ((i%% * 4) + xx%, y% + yy%)-STEP(3, 3), 31, BF ELSE nul = 1 'PRINT "1"; ELSE PRINT "0";
  295.   NEXT i%%
  296.   y% = y% + 4
  297.   IF y% = 32 THEN y% = 0: xx% = xx% + 33
  298.   IF xx% = 330 THEN xx% = 0: yy% = yy% + 33
  299.  NEXT j%
  300.  _DEST old&
  301.  
  302. SUB ExplodePlayer
  303.  DIM PieceX(5), PieceY(5)
  304.  ChangeBGColor Red
  305.  FOR i%% = 1 TO 5
  306.   PieceX(i%%) = P.Xpos
  307.   PieceY(i%%) = P.Ypos
  308.  NEXT i%%
  309.  FOR j%% = 0 TO 48
  310.   FOR i%% = 1 TO 5
  311.    PlaceSprite PieceX(i%%), PieceY(i%%), SmallC, V12, White, 0
  312.    SELECT CASE i%%
  313.     CASE 1
  314.      PieceX(i%%) = PieceX(i%%) - 3
  315.     CASE 2
  316.      PieceX(i%%) = PieceX(i%%) + 3
  317.     CASE 3
  318.      PieceX(i%%) = PieceX(i%%) - 2
  319.      PieceY(i%%) = PieceY(i%%) - 2
  320.     CASE 4
  321.      PieceX(i%%) = PieceX(i%%) + 2
  322.      PieceY(i%%) = PieceY(i%%) - 2
  323.     CASE 5
  324.      PieceY(i%%) = PieceY(i%%) - 4
  325.    END SELECT
  326.   NEXT i%%
  327.   _PUTIMAGE (0, 0), Layer(BGCOLOR), Layer(5)
  328.   _PUTIMAGE (0, 0), Layer(BGPLATE), Layer(5)
  329.   _CLEARCOLOR _RGB32(0, 0, 0), Layer(4)
  330.   _PUTIMAGE (0, 0), Layer(4), Layer(5) 'combine sprites and BG Plate
  331.   _PUTIMAGE (0, 0), Layer(5), Layer(0) 'Move to display
  332.   _DELAY .05
  333.   ClearLayer 4
  334.  NEXT j%%
  335.  ChangeBGColor G.CurrentBG
  336.  
  337. SUB GroundCollide (id~%%)
  338.  'when things hit the ground layer
  339.  'lose points or DIE!
  340.  SELECT CASE O(id~%%).Kind
  341.   CASE SmallA TO SmallD
  342.    G.Score = G.Score - (SmallOid * G.level \ 2)
  343.   CASE LargeA TO LargeD
  344.    G.Score = G.Score - (LargeOid * G.level \ 2)
  345.   CASE Bomb
  346.    IF O(id~%%).Zoom = H2 + V2 THEN G.Score = G.Score - (LargeBomb * G.level \ 2)
  347.    IF O(id~%%).Zoom = None THEN G.Score = G.Score - (SmallBomb * G.level \ 2)
  348.    '   KillPlayer
  349.   CASE Tracker 'special
  350.    'changes direction to target player
  351.    'may need special routine for them.
  352.  
  353.  
  354. SUB KillPlayer
  355.  G.Lives = G.Lives - 1
  356.  ExplodePlayer
  357.  P.ShotCount = 0
  358.  P.Xpos = 300
  359.  G.Score = G.Score - (100 * G.level)
  360.  IF G.Lives = 0 THEN G.GameOver = TRUE
  361.  
  362. SUB MakeBlast (id~%%, Oid~%%)
  363.  'center explostions for large Oids and large bombs
  364.  IF O(Oid~%%).Kind >= LargeA AND O(Oid~%%).Kind <= LargeD THEN
  365.   E(id~%%).Xpos = O(Oid~%%).Xpos + 8
  366.   E(id~%%).Ypos = O(Oid~%%).Ypos - 8
  367.  ELSEIF O(Oid~%%).Kind = Bomb AND O(Oid~%%).Zoom = H2 + V2 THEN
  368.   E(id~%%).Xpos = O(Oid~%%).Xpos + 8
  369.   E(id~%%).Ypos = O(Oid~%%).Ypos - 8
  370.   E(id~%%).Xpos = O(Oid~%%).Xpos
  371.   E(id~%%).Ypos = O(Oid~%%).Ypos
  372.  E(id~%%).Frame = 1
  373.  
  374. SUB Makeoid (id~%%)
  375.  STATIC CollisionColor%%
  376.  
  377.  O(id~%%).Xpos = INT(RND * 600) + 20
  378.  O(id~%%).Ypos = INT(RND * 64) - 96
  379.  
  380.  O(id~%%).Angle = RND * _PI
  381.  O(id~%%).Angle = O(id~%%).Angle
  382.  
  383.  O(id~%%).Rotation = 1
  384.  O(id~%%).Kind = INT(RND * 9) + 2
  385.  O(id~%%).Speed = RND * (2 * G.level) + .1
  386.  O(id~%%).Colr = INT(RND * 5) + 6
  387.  CollisionColor%% = CollisionColor%% + 1
  388.  O(id~%%).CollideColr = CollisionColor%%
  389.  IF CollisionColor%% >= 64 THEN CollisionColor%% = 1
  390.  'set size of object
  391.  SELECT CASE O(id~%%).Kind
  392.   CASE 2 TO 5
  393.    O(id~%%).Zoom = V12
  394.   CASE 6 TO 9
  395.    O(id~%%).Zoom = V12 + H2
  396.   CASE 10 'make bombs big or small
  397.    IF INT(RND * 2) THEN O(id~%%).Zoom = H2 + V2 ELSE O(id~%%).Zoom = None
  398.    O(id~%%).Colr = White
  399.   CASE 11
  400.    O(id~%%).Zoom = None
  401.    O(id~%%).Colr = White
  402.  'randomly flip object around
  403.  IF O(id~%%).Kind >= 2 AND O(id~%%).Kind <= 9 THEN
  404.   IF INT(RND * 1) THEN O(id~%%).Zoom = O(id~%%).Zoom + HF
  405.   IF INT(RND * 1) THEN O(id~%%).Zoom = O(id~%%).Zoom + VF
  406.  
  407. SUB MakeShot (id~%%)
  408.  s(id~%%).Xpos = P.Xpos + 12
  409.  s(id~%%).Ypos = 320
  410.  
  411. SUB MovePlayerShot (id~%%)
  412.  s(id~%%).Ypos = s(id~%%).Ypos - G.ShotSpeed
  413.  IF s(id~%%).Ypos > 0 THEN Hit%% = ShotCollision%%(id~%%) ELSE Hit%% = -1
  414.  IF Hit%% > -1 THEN
  415.   s(id~%%).Ypos = -32 'move shot for removal
  416.   ScoreShot Hit%% 'incress score
  417.   MakeBlast G.BlastCount, Hit%%
  418.   G.BlastCount = G.BlastCount + 1 'add a new blast
  419.   Makeoid Hit%% 'replace the oid with a new one
  420.  IF s(id~%%).Ypos < -16 THEN
  421.   P.ShotCount = P.ShotCount - 1
  422.   FOR i%% = id~%% TO P.ShotCount
  423.    SWAP s(i%%), s(i%% + 1)
  424.   NEXT i%%
  425.   s(i%% - 1).Xpos = -10: s(i%% - 1).Ypos = 0
  426.  
  427. SUB Moveoid (id~%%)
  428.  O(id~%%).Xpos = O(id~%%).Xpos + O(id~%%).Speed * COS(O(id~%%).Angle)
  429.  O(id~%%).Ypos = O(id~%%).Ypos + O(id~%%).Speed '*sin(o(id~%%).angle)
  430.  IF O(id~%%).Ypos > 335 THEN GroundCollide id~%%: Makeoid id~%%
  431.  hit%% = OidCollide(id~%%)
  432.  IF hit%% = TRUE THEN
  433.   ScoreShot id~%%
  434.   MakeBlast G.BlastCount, id~%%
  435.   G.BlastCount = G.BlastCount + 1 'add a new blast
  436.   Makeoid id~%%
  437.  ELSEIF hit%% = -2 THEN
  438.   KillPlayer
  439.   Makeoid id~%%
  440.  IF O(id~%%).Xpos > 640 OR O(id~%%).Xpos < -16 THEN Makeoid id~%%
  441.  
  442. SUB PlaceSprite (x%, y%, ID%%, Zoom~%, C%%, Frame%%)
  443.  SpriteColor Colors(C%%)
  444.  EX% = 30: EY% = 30 'base size
  445.  
  446.  IF (ID%% < LargeA) OR (ID%% > LargeD) THEN
  447.   IF Zoom~% > None THEN
  448.    'Flipping Options
  449.    IF Zoom~% AND 512 THEN EX% = -EX% 'flip Horizontal
  450.    IF Zoom~% AND 256 THEN EY% = -EY% 'Flip Vertical
  451.  
  452.    'Scaling options
  453.    IF Zoom~% AND 128 THEN EX% = EX% * 4 + 0 ' Horizontal x4
  454.    IF Zoom~% AND 64 THEN EX% = EX% * 2 + 0 '  Horizontal x2
  455.    IF Zoom~% AND 32 THEN EX% = EX% * .5 + 0 ' Horizontal 1/2
  456.    IF Zoom~% AND 16 THEN EX% = EX% * .25 + 0 'Horizontal 1/4
  457.    IF Zoom~% AND 8 THEN EY% = EY% * 4 + 0 '   Vertical x4
  458.    IF Zoom~% AND 4 THEN EY% = EY% * 2 + 0 '   Vertical x2
  459.    IF Zoom~% AND 2 THEN EY% = EY% * .5 + 0 '  Vertical 1/2
  460.    IF Zoom~% AND 1 THEN EY% = EY% * .25 + 0 ' Vertical 1/4
  461.   END IF
  462.  
  463.  SELECT CASE ID%%
  464.   CASE NullShip 'the ship used for Meteor!
  465.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (0, 0)-STEP(31, 31)
  466.   CASE Ship 'the ship Used for AstroSmash
  467.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (33, 0)-STEP(31, 31)
  468.   CASE SmallA
  469.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (198, 0)-STEP(31, 31)
  470.   CASE SmallB
  471.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (264, 0)-STEP(31, 31)
  472.   CASE SmallC
  473.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (66, 0)-STEP(31, 31)
  474.   CASE SmallD
  475.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (132, 0)-STEP(31, 31)
  476.   CASE SmallE
  477.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (165, 0)-STEP(31, 31)
  478.   CASE SmallF
  479.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (99, 0)-STEP(31, 31)
  480.   CASE SmallG
  481.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (297, 0)-STEP(31, 31)
  482.   CASE SmallH
  483.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (231, 0)-STEP(31, 31)
  484.   CASE LargeA
  485.    IF Zoom~% AND VF THEN
  486.     PlaceSprite x%, y%, SmallD, Zoom~%, C%%, Frame%%
  487.     PlaceSprite x%, y% - 16, SmallE, Zoom~%, C%%, Frame%%
  488.    ELSE
  489.     PlaceSprite x%, y% - 16, SmallD, Zoom~%, C%%, Frame%%
  490.     PlaceSprite x%, y%, SmallE, Zoom~%, C%%, Frame%%
  491.    END IF
  492.   CASE LargeB
  493.    IF Zoom~% AND VF THEN
  494.     PlaceSprite x%, y%, SmallC, Zoom~%, C%%, Frame%%
  495.     PlaceSprite x%, y% - 16, SmallF, Zoom~%, C%%, Frame%%
  496.    ELSE
  497.     PlaceSprite x%, y% - 16, SmallC, Zoom~%, C%%, Frame%%
  498.     PlaceSprite x%, y%, SmallF, Zoom~%, C%%, Frame%%
  499.    END IF
  500.   CASE LargeC
  501.    IF Zoom~% AND VF THEN
  502.     PlaceSprite x%, y%, SmallB, Zoom~%, C%%, Frame%%
  503.     PlaceSprite x%, y% - 16, SmallG, Zoom~%, C%%, Frame%%
  504.    ELSE
  505.     PlaceSprite x%, y% - 16, SmallB, Zoom~%, C%%, Frame%%
  506.     PlaceSprite x%, y%, SmallG, Zoom~%, C%%, Frame%%
  507.    END IF
  508.   CASE LargeD
  509.    IF Zoom~% AND VF THEN
  510.     PlaceSprite x%, y%, SmallA, Zoom~%, C%%, Frame%%
  511.     PlaceSprite x%, y% - 16, SmallH, Zoom~%, C%%, Frame%%
  512.    ELSE
  513.     PlaceSprite x%, y% - 16, SmallA, Zoom~%, C%%, Frame%%
  514.     PlaceSprite x%, y%, SmallH, Zoom~%, C%%, Frame%%
  515.    END IF
  516.   CASE Bomb
  517.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (0 + ((Frame%% - 1) * 33), 33)-STEP(31, 31)
  518.   CASE Tracker
  519.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (0 + ((Frame%% - 1) * 33), 66)-STEP(31, 31)
  520.   CASE SpaceShip
  521.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), ((165 + (Frame%% - 1) * 33), 99)-STEP(31, 31)
  522.   CASE Blast
  523.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (132 + (Frame%% - 1) * 33, 33)-STEP(31, 31)
  524.  _CLEARCOLOR Colors(Black), Layer(TEMP)
  525.  _PUTIMAGE (x%, y%), Layer(TEMP), Layer(4)
  526.  SpriteColor Colors(White)
  527.  ClearLayer TEMP
  528.  
  529. SUB PlaceSpriteShadow (x%, y%, ID%%, Zoom~%, C%%, Frame%%)
  530.  SpriteColor _RGB32(C%%, C%%, C%%)
  531.  EX% = 30: EY% = 30 'base size
  532.  
  533.  IF (ID%% < LargeA) OR (ID%% > LargeD) THEN
  534.   IF Zoom~% > None THEN
  535.    'Flipping Options
  536.    IF Zoom~% AND 512 THEN EX% = -EX% 'flip Horizontal
  537.    IF Zoom~% AND 256 THEN EY% = -EY% 'Flip Vertical
  538.  
  539.    'Scaling options
  540.    IF Zoom~% AND 128 THEN EX% = EX% * 4 + 0 ' Horizontal x4
  541.    IF Zoom~% AND 64 THEN EX% = EX% * 2 + 0 '  Horizontal x2
  542.    IF Zoom~% AND 32 THEN EX% = EX% * .5 + 0 ' Horizontal 1/2
  543.    IF Zoom~% AND 16 THEN EX% = EX% * .25 + 0 'Horizontal 1/4
  544.    IF Zoom~% AND 8 THEN EY% = EY% * 4 + 0 '   Vertical x4
  545.    IF Zoom~% AND 4 THEN EY% = EY% * 2 + 0 '   Vertical x2
  546.    IF Zoom~% AND 2 THEN EY% = EY% * .5 + 0 '  Vertical 1/2
  547.    IF Zoom~% AND 1 THEN EY% = EY% * .25 + 0 ' Vertical 1/4
  548.   END IF
  549.  
  550.  SELECT CASE ID%%
  551.   CASE NullShip 'the ship used for Meteor!
  552.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (0, 0)-STEP(31, 31)
  553.   CASE Ship 'the ship Used for AstroSmash
  554.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (33, 0)-STEP(31, 31)
  555.   CASE SmallA
  556.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (198, 0)-STEP(31, 31)
  557.   CASE SmallB
  558.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (264, 0)-STEP(31, 31)
  559.   CASE SmallC
  560.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (66, 0)-STEP(31, 31)
  561.   CASE SmallD
  562.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (132, 0)-STEP(31, 31)
  563.   CASE SmallE
  564.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (165, 0)-STEP(31, 31)
  565.   CASE SmallF
  566.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (99, 0)-STEP(31, 31)
  567.   CASE SmallG
  568.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (297, 0)-STEP(31, 31)
  569.   CASE SmallH
  570.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (231, 0)-STEP(31, 31)
  571.   CASE LargeA
  572.    IF Zoom~% AND VF THEN
  573.     PlaceSpriteShadow x%, y%, SmallD, Zoom~%, C%%, Frame%%
  574.     PlaceSpriteShadow x%, y% - 16, SmallE, Zoom~%, C%%, Frame%%
  575.    ELSE
  576.     PlaceSpriteShadow x%, y% - 16, SmallD, Zoom~%, C%%, Frame%%
  577.     PlaceSpriteShadow x%, y%, SmallE, Zoom~%, C%%, Frame%%
  578.    END IF
  579.   CASE LargeB
  580.    IF Zoom~% AND VF THEN
  581.     PlaceSpriteShadow x%, y%, SmallC, Zoom~%, C%%, Frame%%
  582.     PlaceSpriteShadow x%, y% - 16, SmallF, Zoom~%, C%%, Frame%%
  583.    ELSE
  584.     PlaceSpriteShadow x%, y% - 16, SmallC, Zoom~%, C%%, Frame%%
  585.     PlaceSpriteShadow x%, y%, SmallF, Zoom~%, C%%, Frame%%
  586.    END IF
  587.   CASE LargeC
  588.    IF Zoom~% AND VF THEN
  589.     PlaceSpriteShadow x%, y%, SmallB, Zoom~%, C%%, Frame%%
  590.     PlaceSpriteShadow x%, y% - 16, SmallG, Zoom~%, C%%, Frame%%
  591.    ELSE
  592.     PlaceSpriteShadow x%, y% - 16, SmallB, Zoom~%, C%%, Frame%%
  593.     PlaceSpriteShadow x%, y%, SmallG, Zoom~%, C%%, Frame%%
  594.    END IF
  595.   CASE LargeD
  596.    IF Zoom~% AND VF THEN
  597.     PlaceSpriteShadow x%, y%, SmallA, Zoom~%, C%%, Frame%%
  598.     PlaceSpriteShadow x%, y% - 16, SmallH, Zoom~%, C%%, Frame%%
  599.    ELSE
  600.     PlaceSpriteShadow x%, y% - 16, SmallA, Zoom~%, C%%, Frame%%
  601.     PlaceSpriteShadow x%, y%, SmallH, Zoom~%, C%%, Frame%%
  602.    END IF
  603.   CASE Bomb
  604.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (0 + ((Frame%% - 1) * 33), 33)-STEP(31, 31)
  605.   CASE Tracker
  606.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (0 + ((Frame%% - 1) * 33), 66)-STEP(31, 31)
  607.   CASE SpaceShip
  608.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), ((165 + (Frame%% - 1) * 33), 99)-STEP(31, 31)
  609.   CASE Blast
  610.    _PUTIMAGE (0, 0)-STEP(EX%, EY%), Layer(SPRITE), Layer(TEMP), (132 + (Frame%% - 1) * 33, 33)-STEP(31, 31)
  611.  _CLEARCOLOR Colors(Black), Layer(TEMP)
  612.  _PUTIMAGE (x%, y%), Layer(TEMP), Layer(COLLIDE)
  613.  SpriteColor Colors(White)
  614.  ClearLayer TEMP
  615.  
  616. SUB ScoreShot (id~%%)
  617.  STATIC Highest AS _UNSIGNED LONG, last AS LONG
  618.  SELECT CASE O(id~%%).Kind
  619.   CASE SmallA TO SmallD
  620.    G.Score = G.Score + (SmallOid * G.level)
  621.   CASE LargeA TO LargeD
  622.    G.Score = G.Score + (LargeOid * G.level)
  623.   CASE Bomb
  624.    IF O(id~%%).Zoom = H2 + V2 THEN G.Score = G.Score + (LargeBomb * G.level)
  625.    IF O(id~%%).Zoom = None THEN G.Score = G.Score + (SmallBomb * G.level)
  626.   CASE Tracker
  627.    G.Score = G.Score + (Seeker * G.level)
  628.   CASE SpaceShip
  629.    G.Score = G.Score + (Aliens * G.level)
  630.   CASE SpaceShipShot
  631.    G.Score = G.Score + (AlienShot * G.level)
  632.  IF G.Score > Highest THEN Highest = G.Score
  633.  IF INT(Highest / 1000) > last THEN last = INT(Highest / 1000): G.Lives = G.Lives + 1
  634.  
  635. FUNCTION ShotCollision%% (id~%%)
  636.  result%% = TRUE
  637.  _SOURCE Layer(COLLIDE)
  638.  FOR i%% = 0 TO 32 STEP 2
  639.   test~& = POINT(s(id~%%).Xpos + 4, s(id~%%).Ypos + i%%) 'check collision layer for color
  640.   IF test~& <> Colors(Black) THEN i%% = 33
  641.  NEXT i%%
  642.  _SOURCE Layer(0)
  643.  IF test~& <> Colors(Black) THEN 'non black hit something
  644.   FOR i%% = 0 TO G.OidCount - 1 'find which oid was hit
  645.    IF test~& = _RGB32(O(i%%).CollideColr, O(i%%).CollideColr, O(i%%).CollideColr) THEN result%% = i%%
  646.   NEXT i%%
  647.  ShotCollision%% = result%%
  648.  
  649. SUB SpriteColor (id~&)
  650.  old& = _DEST
  651.  _DEST Layer(SPRITE)
  652.  _PALETTECOLOR 31, id~&
  653.  _DEST old&
  654.  
  655. SUB TitleScreen
  656.  _DEST Layer(TITLE)
  657.  _PRINTSTRING (32, 104), "Mattel Electronics"
  658.  _PRINTSTRING (196, 144), "Presents"
  659.  _PRINTSTRING (132, 232), "ASTROSMASH!"
  660.  _PRINTSTRING (36, 329), "Copr @ 1981 Mattel"
  661.  LINE (0, 400)-(639, 479), Colors(Olive), BF
  662.  _PRINTSTRING (50, 392), "Clone 2018 Cobalt"
  663.  _DEST Layer(0)
  664.  _PUTIMAGE (0, 0), Layer(TITLE), Layer(0)
  665.  DO: _DELAY .05: LOOP WHILE INKEY$ = ""
  666.  CLS
  667.  
  668. SUB ChangeBGColor (id%%)
  669.  old& = _DEST
  670.  _DEST Layer(BGCOLOR)
  671.  LINE (0, 0)-(639, 399), Colors(id%%), BF
  672.  _DEST old&
  673.  
  674. FUNCTION OidCollide%% (id~%%)
  675.  result%% = FALSE
  676.  _SOURCE Layer(COLLIDE)
  677.  FOR y% = O(id~%%).Ypos TO O(id~%%).Ypos + 32 STEP 4
  678.   FOR x% = O(id~%%).Xpos TO O(id~%%).Xpos + 32 STEP 4
  679.    SELECT CASE O(id~%%).Kind
  680.     CASE SmallA TO SmallD
  681.      test~& = POINT(x%, y%)
  682.     CASE LargeA TO LargeD
  683.      test~& = POINT(x%, y%)
  684.     CASE Bomb
  685.     CASE Tracker
  686.      '     IF test~& <> Colors(Black) THEN x% = O(id~%%).Xpos + 33: y% = O(id~%%).Ypos + 33: result%% = TRUE
  687.    END SELECT
  688.    IF test~& = _RGB32(126, 126, 126) THEN x% = O(id~%%).Xpos + 33: y% = O(id~%%).Ypos + 33: result%% = TRUE
  689.    IF test~& = _RGB32(127, 127, 127) THEN x% = O(id~%%).Xpos + 33: y% = O(id~%%).Ypos + 33: result%% = TRUE - 1 '-2
  690.   NEXT x%
  691.  NEXT y%
  692.  _SOURCE Layer(0)
  693.  OidCollide%% = result%%
  694.  
  695. SUB BackGroundColor ()
  696.  STATIC oldscore AS _UNSIGNED LONG
  697.  IF G.Score >= oldscore + 1000 OR G.Score < oldscore THEN 'only bother if
  698.   IF oldcolor = 0 THEN oldcolor = Colors(id%%) 'happens on first run
  699.   SELECT CASE G.Score
  700.    CASE IS < 1000
  701.     ChangeBGColor Black
  702.     G.level = 1
  703.     G.CurrentBG = Black
  704.    CASE 1000 TO 4999
  705.     ChangeBGColor Blue
  706.     G.level = 2
  707.     G.CurrentBG = Blue
  708.    CASE 5000 TO 19999
  709.     ChangeBGColor Maroon
  710.     G.level = 3
  711.     G.CurrentBG = Maroon
  712.    CASE 20000 TO 49999
  713.     ChangeBGColor SkyBlue
  714.     G.level = 4
  715.     G.CurrentBG = SkyBlue
  716.    CASE 50000 TO 99999
  717.     ChangeBGColor Grey
  718.     G.level = 5
  719.     G.CurrentBG = Grey
  720.    CASE IS >= 100000
  721.     ChangeBGColor Black
  722.     G.level = 6
  723.     G.CurrentBG = Black
  724.   oldscore = INT(G.Score / 1000) * 1000 'remove values from 1 to 999
  725.  ' _DEST Layer(BGCOLOR)
  726.  ' LOCATE 26, 1: PRINT oldscore; G.BlastCount
  727.  ' _DEST Layer(0)
  728.  

LEFT and RIGHT arrow keys move your ship, while SPACE shoots, you must release the button to shoot again. teleporting is not in place yet.
I am trying something different with this one, using LIMIT instead of DELAY, and due to this its very CPU hungry, (55-75% cycle use on my machine, as opposed to 5-8% using DELAY) so you might watch having much of anything else running at the same time.
Everything should run, the only dependency is the TTF below. and having a more recent copy of QB64.
* PixelIntv.ttf (Filesize: 19.43 KB, Downloads: 198)
Granted after becoming radioactive I only have a half-life!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Preliminary AstroSmash 64 sneak peak.
« Reply #1 on: November 10, 2018, 10:03:43 pm »
Very 'retro'. Nice 'simple' game but I still got killed off... Brilliant!!
Logic is the beginning of wisdom.