I have attempted to use BASIC2D to create bullets and check the bullet collision many times without success. Any help would be appreciated. I have extracted and modified the necessary source code from my program to use for solving this problem.
Goals of the bullet mechanics is:
Goal 1: To be independent from the character
Reason: Bullet cannot have random behavior because of being dependent on character's position. Bullet collision will be checked independently from the character.
Goal 2: The bullet should be a variable
Reason: Bullet collision will be checked independently from the character
Goal 3: Amount of bullets dissipated from the character is limited to 15 in a given time
Reason: To control the amount of bullets in the environment.
Also note that I call the bullet a 'mechanism part'.
Sam
REM Author: Sam Weddington
REM Created: April 24, 2011 6:36PM
REM Project: Bullet Mechanics With BASIC2D
GOTO Main_Loop
Main_Loop:
GOSUB Program_Data
DO
GOSUB Program_Controls
GOSUB Program_Graphics
LOOP
Data_Design:
TYPE Mechanism_Design
AYPos AS Float
AXPos AS Float
BYPos AS Float
BXPos AS Float
CYPos AS Float
CXPos AS Float
Degree AS Float
mType AS Integer
ENDTYPE
TYPE MechanismPart_Design REM character().Mech.Part
pXPos AS Float REM x position of the bullet
pYPos AS Float REM y position of the bullet
pLength AS Float REM length of the bullet; used to determine x2 and y2 of the bullet
isActive AS Integer REM used to determine if bullet has collided
ENDTYPE
TYPE Character_Design
Height AS Float
Radius AS Float
XPos AS Float
YPos AS Float
Color AS String
Parts AS Integer
Choice AS String
Mech AS Mechanism_Design
Part AS MechanismPart_Design
ENDTYPE
RETURN
Program_Data:
GOSUB Data_Design
DIM character(1) AS Character_Design
character(1).Height = 1
character(1).Radius = 10
character(1).XPos = 100
character(1).YPos = 100
character(1).Color = "GREEN"
character(1).Parts = 100
character(1).Mech.AXPos = character(1).XPos
character(1).Mech.AYPos = character(1).YPos - character(1).Radius
character(1).Mech.BXPos = character(1).XPos + (character(1).Radius * 2)
character(1).Mech.BYPos = character(1).YPos
character(1).Mech.CXPos = character(1).XPos
character(1).Mech.CYPos = character(1).YPos + character(1).Radius
character(1).Mech.mType = 1
RETURN
Program_Controls:
FOR A = 0 TO ARRAY COUNT(character())
IF upKey() = 1 THEN resolveCharacter("UP", 1)
IF downKey() = 1 THEN resolveCharacter("DOWN", 1)
IF rightKey() = 1 THEN resolveCharacter("LEFT", 1)
IF leftKey() = 1 THEN resolveCharacter("RIGHT", 1)
`IF keyState(17) = 1 THEN GOSUB resolveCharacter `Not implemented
IF keyState(31) = 1 THEN resolveCharacter("DISSIPATE", 1)
IF keyState(30) = 1 THEN resolveCharacter("TURNL", 1)
IF keyState(32) = 1 THEN resolveCharacter("TURNR", 1)
NEXT T
RETURN
Program_Graphics:
CLS
drawMechanism()
drawCharacter()
SYNC
RETURN
REM ----- Behaviors -----
FUNCTION resolveCharacter(command$, A)
IF command$ = "UP" THEN character(A).YPos = character(A).YPos - 0.3 : resolveMechanism(A)
IF command$ = "DOWN" THEN character(A).YPos = character(A).YPos + 0.3 : resolveMechanism(A)
IF command$ = "LEFT" THEN character(A).XPos = character(A).XPos + 0.3 : resolveMechanism(A)
IF command$ = "RIGHT" THEN character(A).XPos = character(A).XPos - 0.3 : resolveMechanism(A)
IF command$ = "TURNR" THEN DEC character(A).Mech.Degree, 0.3 : resolveMechanism(A)
IF command$ = "TURNL" THEN INC character(A).Mech.Degree, 0.3 : resolveMechanism(A)
IF command$ = "DISSIPATE"
ENDIF
ENDFUNCTION
FUNCTION resolveMechanism(A)
character(A).Mech.AXPos = character(A).XPos + (character(A).Radius * sin(character(A).Mech.Degree))
character(A).Mech.AYPos = character(A).YPos - (character(A).Radius * cos(character(A).Mech.Degree))
character(A).Mech.BXPos = character(A).XPos + ((character(A).Radius * 2) * cos(character(A).Mech.Degree))
character(A).Mech.BYPos = character(A).YPos + ((character(A).Radius * 2) * sin(character(A).Mech.Degree))
character(A).Mech.CXPos = character(A).XPos - (character(A).Radius * sin(character(A).Mech.Degree))
character(A).Mech.CYPos = character(A).YPos + (character(A).Radius * cos(character(A).Mech.Degree))
ENDFUNCTION
REM ----- Graphics -----
FUNCTION drawMechanism()
FOR T = 1 TO ARRAY COUNT(character())
IF character(T).Mech.mType = 1
LINE character(T).Mech.AXPos, character(T).Mech.AYPos, character(T).Mech.BXPos, character(T).Mech.BYPos
LINE character(T).Mech.CXPos, character(T).Mech.CYPos, character(T).Mech.BXPos, character(T).Mech.BYPos
ENDIF
IF character(T).Mech.mType = 2
ENDIF
IF character(T).Mech.mType = 3
ENDIF
NEXT T
ENDFUNCTION
FUNCTION drawCharacter()
FOR D = 1 TO ARRAY COUNT(character())
CIRCLE character(D).XPos, character(D).YPos, character(D).Radius
fillCircle(character(D).Color, character(D).Radius, D)
NEXT D
ENDFUNCTION
FUNCTION fillCircle(color$, depth, character)
FOR E = 1 TO depth
INK RGB(0, 255, 0), RGB(0, 255, 0)
CIRCLE character(character).XPos, character(character).YPos, E
INK RGB(255, 255, 255), RGB(255, 255, 255)
NEXT E
ENDFUNCTION