arrowkeys.
click to fire.
just a simple bullet engine for everyone to use. its really easy to implement and allows for easy management of hundreds of machine_gun bullets.
i made it a while ago so this is a less cleaned up version.
Rem Project: web
Rem Created: 4/15/2006 9:31:36 PM
Rem ***** Main Source File *****
RANDOMIZE TIMER()
SET DISPLAY MODE 1280,1024,0
AUTOCAM OFF
MAKE CAMERA 1
POSITION CAMERA 1,0,0,0
POSITION CAMERA 1,0,50,0
MAKE OBJECT CUBE 101,20
POSITION OBJECT 101,0,0,100
`DECLARES BULLET CHARACTERISTICS
type bullet
ID AS INTEGER
SPEED AS FLOAT
FIRED AS BOOLEAN
COLORR AS INTEGER
COLORB AS INTEGER
COLORG AS INTEGER
ALIVE AS BOOLEAN
VISIBLE AS BOOLEAN
START_X_POS AS FLOAT ` STARTING POSITION OF BULLET
START_Y_POS AS FLOAT
START_Z_POS AS FLOAT
X_ANGLE AS FLOAT
Y_ANGLE AS FLOAT
Z_ANGLE AS FLOAT
SIZE AS FLOAT
RANGE AS FLOAT
endtype
DIM SHELL(100) AS BULLET `CREATES AN ARRAY OF BULLETS
FOR T=1 TO 100
SHELL(T).ID = T
SHELL(T).SPEED = 1
SHELL(T).FIRED = 0
SHELL(T).START_X_POS = OBJECT POSITION X(101)
SHELL(T).START_Y_POS = OBJECT POSITION Y(101)
SHELL(T).START_Z_POS = OBJECT POSITION Z(101)
SHELL(T).SIZE = 5
SHELL(T).RANGE = 200
SHELL(T).X_ANGLE = OBJECT ANGLE X(101)
SHELL(T).Y_ANGLE = OBJECT ANGLE X(101)
SHELL(T).Z_ANGLE = OBJECT ANGLE X(101)
SHELL(T).COLORR = RND(255)
SHELL(T).COLORG = RND(255)
SHELL(T).COLORB = RND(255)
MAKE OBJECT SPHERE T,SHELL(T).SIZE `MAKES BULLETS
POSITION OBJECT T,SHELL(T).START_X_POS,SHELL(T).START_Y_POS,SHELL(T).START_Z_POS `POSITIONS BULLETS AT BOX COORDINATES
ROTATE OBJECT T,SHELL(T).X_ANGLE,SHELL(T).Y_ANGLE,SHELL(T).Z_ANGLE `AIMS BULLETS
COLOR OBJECT T,RGB(SHELL(T).COLORR,SHELL(T).COLORG,SHELL(T).COLORB) `COLORS BULLETS
NEXT T
CURRENT_BULLET AS INTEGER
AMMO AS INTEGER
TIME AS FLOAT
CURRENT_BULLET = 1 `DETERMINES WHICH BULLET IS BEING FIRED
AMMO = 100
TIME = 10 `TIME UNTIL NEXT BULLET IS FIRED
DO
IF CURRENT_BULLET >100 THEN CURRENT_BULLET = 1
DEC TIME
IF MOUSECLICK() = 1 AND TIME <= 0 ` BULLET CAN ONLY BE FIRED AFTER TIMER HAS COUNTED DOWN
SHELL(CURRENT_BULLET).FIRED = 1 `CHANGE THE BULLET TO FIRING STATE
SHELL(CURRENT_BULLET).RANGE = 1000
SHELL(CURRENT_BULLET).ALIVE = 1
SHELL(CURRENT_BULLET).START_X_POS = OBJECT POSITION X(101) `REPOSITIONS BULLETS THAT WERE CALLED
SHELL(CURRENT_BULLET).START_Y_POS = OBJECT POSITION Y(101) `BACK TO THE GUN THAT HAVE NOT REACHED THEIR RANGE
SHELL(CURRENT_BULLET).START_Z_POS = OBJECT POSITION Z(101)
SHELL(CURRENT_BULLET).X_ANGLE = OBJECT ANGLE X(101)
SHELL(CURRENT_BULLET).Y_ANGLE = OBJECT ANGLE X(101)
SHELL(CURRENT_BULLET).Z_ANGLE = OBJECT ANGLE X(101)
TIME = 20 `RESET THE COUNTER FOR THE TIME UNTIL THE NEXT BULLET CAN BE FIRED
INC CURRENT_BULLET `SWITCH TO NEXT BULLET
ENDIF
FOR T= 1 TO 100
IF SHELL(T).FIRED = 1
SHOW OBJECT T
MOVE OBJECT T,SHELL(T).SPEED
SHELL(T).RANGE = SHELL(T).RANGE - 1
IF SHELL(T).RANGE <= 0 THEN SHELL(T).FIRED = 0 : SHELL(T).ALIVE = 0
ELSE
HIDE OBJECT T
pOSITION OBJECT T,SHELL(T).START_X_POS,SHELL(T).START_Y_POS,SHELL(T).START_Z_POS
ROTATE OBJECT T,SHELL(T).X_ANGLE,SHELL(T).Y_ANGLE,SHELL(T).Z_ANGLE
ENDIF
NEXT T
fOR T= 1 TO 100 ` MAKE SURE THAT BULLETS AIM THE RIGHT WAY AND START AT THE CORRECT COORDINATES
SHELL(T).START_X_POS = OBJECT POSITION X(101)
SHELL(T).START_Y_POS = OBJECT POSITION Y(101)
SHELL(T).START_Z_POS = OBJECT POSITION Z(101)
SHELL(T).X_ANGLE = OBJECT ANGLE X(101)
SHELL(T).Y_ANGLE = OBJECT ANGLE Y(101)
SHELL(T).Z_ANGLE = OBJECT ANGLE Z(101)
NEXT T
IF RIGHTKEY() = 1 THEN TURN OBJECT RIGHT 101,.2
IF LEFTKEY() = 1 THEN TURN OBJECT LEFT 101,.2
IF UPKEY() = 1 THEN PITCH OBJECT UP 101,.2
IF DOWNKEY() = 1 THEN PITCH OBJECT DOWN 101,.2
LOOP