Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
In the spirit of Terry's Tutorials - GUARDIAN Alien Space Ship Game
#12
Well, boring as it is, here is the code as TYPE variables with a certain amount of name changes to improve the naming conformity. Naming things is just not my strong suit. I used to say if I was the first man on earth, and asked to name all the lesser creations, you know, fish, foul, and Democrats, etc., I'd just name them all widgets. Hey, that widget just flew right into head. Ouch, that widget just swam up my fig leaf and bit me in the what-u-ma-call-it! So with that in mind...

Code: (Select All)
TYPE gen_var
    nol AS INTEGER ' Number of game levels.
    level AS INTEGER ' Current game level.
    level_up AS INTEGER ' Routes code to next game level.
    top AS INTEGER ' Top boundary. (Changeable).
    bottom AS INTEGER ' Bottom boundary. (Changeable).
    left AS INTEGER ' Left boundary. (Changeable).
    right AS INTEGER ' Right boundary. (Changeable).
    kb_router AS INTEGER ' Routes code to either Guardian/Alien or general keyboard routine. -1 Guardian/Alien, 0 keyboard.
    snd1 AS LONG ' Explosion sound effect.
    snd2 AS LONG ' Explosion sound effect.
END TYPE

DIM SHARED v AS gen_var

TYPE guardian
    num AS INTEGER ' Number of Guardians aka lives.
    diry AS INTEGER ' Guardian row move. +1, 0, -1.
    dirx AS INTEGER ' Guardian column move. +2, 0, -2. Equals vertical pixel movement. 16x8.
    y AS INTEGER ' Guardian coordinates row.
    x AS INTEGER ' Guardian coordinates column.
    speed AS INTEGER ' Guardian speed. (User Determined).
    m_max AS INTEGER ' Restricts # of missiles fired in one direction.
    m_status AS INTEGER ' Missile status. -1 when fired, 1 while moving.
    m_fired AS INTEGER ' The number of missile deployed and still active.
    m_n AS INTEGER ' Missile number. 1 to m_max. (Counter).
    m_d AS INTEGER ' Missile direction. (1-8).
    m_y AS INTEGER ' Missile row advancement increment: +1, 0, -1 Note: Missile row and column coordinates are defined in arrays.
    m_x AS INTEGER ' Missile column advancement increment: +2, 0, -2. Equals vertical pixel movement. 16x8.
    m_asc AS INTEGER ' ASCII charater representing a fired missile.
    icon AS STRING
END TYPE

DIM SHARED g AS guardian

TYPE alien
    max AS INTEGER ' Maximum # of alien ships on screen.
    count AS INTEGER ' Number of alien ships. (Counter).
    itr AS INTEGER ' Iteration array number to cycle through the active alien ships. (Counter).
    cycle_delay AS SINGLE ' Timer cycle controls how fast alien ships move.
    ship AS STRING ' Alien ship ASCII design.
END TYPE

DIM SHARED a AS alien

CALL set_up ' Loads sound files and some starting variables.

DO
    v.level = v.level + 1
    g.y = (v.bottom - v.top) \ 2 + v.top: g.x = (v.right - v.left) \ 2 + v.left ' Set initial column and row for Guardian craft.
    LOCATE g.y, g.x: PRINT "*"; ' Show Guardian.
    i = 15 ' Default max setting for number of alien ships used here to intially dim arrays.
    REDIM SHARED a_y(i), a_x(i), a_mask_y(i), a_mask_x(i), a_inertia(i) ' Alien movement.
    REDIM SHARED a_ran(i), a_olda_ran(i), a_y_loc(i), a_x_loc(i) ' Alien motvement.
    REDIM SHARED m_n(g.m_max), m_x(g.m_max, 8), m_y(g.m_max, 8) ' Guardian missiles.

    ' Array descriptions and actions.
    ' a_y() , a_x() Alien ship postions rows and columns.
    ' a_mask_y(), a_mask_x() Alien ship last position. Masked on next move.
    ' a_inertia(i) Number of moves in one direction selected by random for an alien ship.
    ' a_ran(i), a_olda_ran(i) Determines the direction in which the inertia will travel and the prior direction is kept to disallow the same direction twice.
    ' a_y_loc(i), a_x_loc(i) The row and column cordinates of the aliens ships.
    ' m_n(g.m_max), m_x(g.m_max, 8), m_y(g.m_max, 8)  Missile number and Missile index 1 to g.m_max for position. 8 is the fixed number of 8 different directions.

    CALL game

    ' Zero variables.
    g.diry = 0: g.dirx = 0: g.m_status = 0: g.m_fired = 0: g.m_n = 0: g.m_d = 0: g.m_y = 0: g.m_x = 0
    g.m_asc = 0: a.count = 0: a.itr = 0: a.cycle_delay = 0: a.ship = "": v.level_up = 0

LOOP

What's interesting with TYPE variables is they are a bit safer to use, because they are usually more unique, which means it's harder to create a duplicate and unrelated variable in some other sub, when we are using DIM SHARED instead of passing variables by reference or value.

So next up will be combining a player move and fire routine to confront the alien ships. Stay tuned for the debut of: ASCII Guardian

Pete
Reply


Messages In This Thread
RE: In the spirit of Terry's Tutorials - Alien Space Ship - by Pete - 10-08-2022, 01:53 AM



Users browsing this thread: 13 Guest(s)