Back to Index
[Gameplay Functions]
void _UpdateInitCursor(dword *CastleArray, dword *X, dword *Y, word InputFlags)
- Author: Ki Chung
- Inputs:
- CastleArray - array of castles
- X - offset of x coordinate
- Y - offset of y coordinate
- InputFlags - input flags
- Outputs:
- [X] - X updated with new x coordinate
- [Y] - Y updated with new y coordinate
- Returns: -
- Calls: -
- Updates initialize phase cursor; Since initialize phase cursor needs to move between castles, it looks up the castle array for location info and updates the cursor. (eg. If left key is pressed, the function finds the castle with the closest x distance to the left of current and sets the location of this castle as the current location)
void _UpdateCursor(dword *X, dword *Y, word MinX, word MinY, word MaxX, word MaxY, word InputFlags)
- Authors: initially written by Gihyun Ko, rewritten by Ki Chung
- Inputs:
- X - offset of x coordinate
- Y - offset of y coordinate
- MinX - minimum x of the boundary
- MinY - minimum y of the boundary
- MaxX - maximum x of the boundary
- MaxY - maximum y of the boundary
- InputFlags - input flags
- Outputs:
- [X] - X updated with new x coordinate
- [Y] - Y updated with new y coordinate
- Returns: -
- Calls: -
- Updates cursor depending on which key is pressed; if cursor is out of boundary, wraps around the location.
void _RotateBlock(dword *Block, word InputFlags)
- Authors: Ki Chung, Gihyun Ko
- Inputs:
- Block - offset of block to rotate
- InputFlags - input flags
- Outputs: Block rotated 90 degrees counter-clockwise
- Returns: -
- Calls: -
- Rotates 3 x 3 Block 90 degrees counter-clockwise if secondary key is pressed; Shifts the block word as described the map description section
dword _BoundaryInRegion(dword *MapOff, word X, word Y, word Width, word Height, word RegionVal)
- Inputs:
- Authors: Gihyun Ko, Seunghoon Kim, Ki Chung
- MapOff - offset of map buffer
- X - current x coordinate
- Y - current y coordinate
- Width - width of the region
- Height - height of the region
- RegionVal - map value of particular region
- Outputs: -
- Returns: 1 if boundary is filled with RegionVal; 0 otherwise
- Calls: -
- Compares the values held by the grids specified and the region value passed by the user. For instance, if the cannon image with x and y coordinates is passed in, then the function will compare all four grids with respect to the region value. If any of them does not satisfy the region value, the function will return 0, which means invalid for placement.
dword _BlockInRegion(dword *MapOff, word Block, word X, word Y, word RegionVal)
- Author: Gihyun Ko, Seunghoon Kim
- Inputs:
- MapOff - offset of map buffer
- Block - block to check if it is in region
- X - current x coordinate
- Y - current y coordinate
- RegionVal - map value of particular region
- Outputs: -
- Returns: 1 if Block is filled with RegionVal; 0 otherwise
- Calls: -
- Similar to BoundaryInRegion. The difference is that there are various blocks that have different shapes, therefore occupying only part of the 3x3 grid. The function consists of 9 different comparisons for each grid, and returns 0 or 1, respect to the satisfaction to the region value.
void _UpdateEnclosedRegion(dword *MapOff)
- Author: Seunghoon Kim
- Inputs:
- MapOff - offset of map buffer
- Outputs:
- [_NumP1Territory] - updates number of conquered grid by P1
- [_NumP2Territory] - updates number of conquered grid by P2
- Returns: -
- Calls: -
- Uses a floodfill algorithm presented in MP4. Due to the limited number of recursive calls that can be made in assembly programming, queue implementation was used instead. The function starts off at the center of the map. It enqueues the x and y coordinates for the center of the map, and executes a loop, where the first element in the queue is dequeued, and goes through number of comparisons. If the grid specified is not a wall nor marked, and inside the map region, then its flag will be marked, and its 8 neighbors will be inserted in the queue. It repeats until queue is empty.
void _BuildCastle(dword *MapOff, word X, word Y, word WallVal, dword *NumTerritory, word InputFlags, word CurrentPhase)
- Author: Ki Chung
- Inputs:
- MapOff - offset of map buffer
- X - x coordinate of location around which to build castle walls
- Y - y coordinate of location around which to build castle walls
- WallVal - map value for wall
- NumTerritory - offset of variable holding number of territory
- InputFlags - input flags
- CurrentPhase - current phase
- Outputs:
- MapOff - updates map with correct wall and region values
- [_Phase] - removes CurrentPhase from [_Phase] if walls are built
- NumTerritory - updates amount of territory with NUM_INIT_TERRITORY
- walls built around (X, Y) in the map buffer pointed to by MapOff
- Returns: -
- Calls: -
- Updates map buffer pointed to by MapOff with walls around location (X, Y) if primary key is pressed. Then it removes CurrentPhase from [_Phase] indicating that the player is ready for the next phase. Also updates NumTerritory to reflect the change in amount of territory conquered
void _BuildCannon(dword *MapOff, dword *CannonArray, dword *NumCannon, dword *TotalCannon, word X, word Y, word InputFlags, word Region, word CurrentPhase)
- Author: initially written by Gihyun Ko, rewritten by Ki Chung
- Inputs:
- MapOff - offset of map buffer
- CannonArray - offset of cannon array
- NumCannon - number of cannons available for deployment
- X - x coordinate of location at which to place cannon
- Y - y coordinate of location at which to place cannon
- InputFlags - input flags
- Region - map value of allowed region for cannon placement
- Outputs:
- NumCannon - number of cannons available updated if cannon is built
- [_Phase] - removes CurrentPhase from [_Phase] if number of cannons reaches 0
- CannonArray - cannon array updated with new cannon
- TotalCannon - total number of cannons available
- MapOff - walls built around (X, Y) in the map buffer pointed to by MapOff
- Returns: -
- Calls: _BoundaryInRegion
- First checks to see if the cannon can be built at the location of the cursor. This is done by calling _BoundaryInRegion. If there's nothing in the cannon's way, it updates the map buffer and the cannon array with new cannon
void _BuildWall(dword *MapOff, word X, word Y, dword *Block, word InputFlags)
- Author: Gihyun Ko
- Inputs:
- MapOff - offset of map buffer
- X - x coordinate of location at which to place block
- Y - y coordinate of location at which to place block
- Block - offset of block to place in the map buffer
- InputFlags - input flags
- Outputs:
- MapOff - map buffer updated with new wall piece
- Block - new wall piece generated and stored in block if old block is used
- Returns: -
- Calls: _BlockInRegion, _GenerateRandomBlock, _UpdateEnclosedRegion
- Takes input InputFlags and checks to see if primary key is pressed. If primary key is pressed then it will check if the land is not occupied for each cell of the 3x3 grid selected for the block. This is done by calling _BlockInRegion. If it's not occupied for cells of the blocks needed, new wall pieces are place by changing the region values and functions _GenerateRandomBlock, and _UpdateEnclosedRegion are called at the end.
void _GenerateRandomBlock(dword *Block)
- Author: Gihyun Ko
- Inputs: _BlockArray - array holding different types of blocks
- Outputs: Block - updated with new wall piece
- Return: -
- Calls: _Random
- Generates a random block by calling the _Random function to find a random value and using it to choose a block from the _BlockArray.
void _UpdateCannonBall(dword *MapOff, dword *CannonBallArray)
- Author: intially written by Gihyun Ko, rewritten by Ki Chung
- Inputs:
- MapOff - offset of map buffer
- CannonBallArray - offset of array of cannon balls in flight
- [_CBallTick] - tick counter for cannon ball update
- Outputs:
- MapOff - map buffer updated if cannon ball destroys cannon or wall
- CannonBallArray - updated with new position info
- _P1CannonArray - P1 cannon array updated if P1 cannon ball landed
- _P2CannonArray - P2 cannon array updated if P2 cannon ball landed
- Returns: -
- Calls: -
- This function uses Bresenham's line algorithm to make the cannon ball fly in line from source to destination. The function takes three locations from cannon ball array. These are source, destination, and current location. It then calculates the line error from the source and destination locations. The line error is used to calculate the current location and stores the current location back into the array. _DrawCannonBall reads this current location to draw the cannon ball. When the current location is matched with the destination, the function calculates the index in the appropriate cannon array to find out which cannon has fired that cannon ball. Then it resets the cannon enabling it to fire again. The destination is also entered into the explosion array to be displayed on screen. If the destination happens to be a wall piece or a cannon, it assigns proper damage to the object then removes it from the map when the damage reaches the max life of the object.
void _FireCannon(dword *MapOff, dword *CannonArray, dword *CannonBallArray, word X, word Y, word InputFlags)
- Author: initially written by Gihyun Ko, rewritten by Ki Chung
- Inputs:
- MapOff - offset of map buffer
- CannonArray - offset of array of cannons
- CannonBallArray - offset of array of cannon balls in flight
- X - x coordinate of destination for cannon ball
- Y - y coordinate of destination for cannon ball
- InputFlags - input flags
- Outputs:
- CannonArray - cannon array updated if cannon fires
- CannonBallArray - cannon ball array updated with new cannon ball
- Returns: -
- Calls: -
- This function first checks if the fire key is pressed. If it is, it searches for cannon that is ready (that does not have a cannon ball that's still flying) in the given cannon array. If it finds one, it sets the cannon as busy, then updates the cannon ball array with three locations, which are source, destination, and current
void _ScrollBanner(dword *BannerX, dword *BannerY)
- Author: Ki Chung
- Inputs:
- BannerX - offset of x coordinate of banner
- BannerY - offset of y coordinate of banner
- [_AnimateTick] - tick counter for animation
- Outputs: banner positions updated
- Returns: -
- Calls: -
- Updates banner position; used when drawing banner across the screen (eg. Deploy, Battle, Rebuild)
dword _Random(word MaxNum)
- Author: Gihyun Ko
- Inputs: MaxNum - max value to be generated
- Outputs: -
- Returns: random value from 0 to (MaxNum - 1)
- Calls: -
- Takes input MaxNum and uses [_TimeTick] and random algorithm to generate random value from 0 to (MaxNum - 1).