May 08, 2024, 08:03:28 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


fantasy shooter game with AI and all

Started by yujinwunz, December 23, 2008, 02:42:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

yujinwunz

this i made ages ago, im running into problems so if anyone is kind enough to lend me two hands at general discussions "for / next crash"
on the version im working on.

here it is:

IF CREATESCREEN(800,600,32)<0
MESSAGEBOX 0, "error creating screen","error"
END
ENDIF

CONST DIK_ESCAPE = 0x01
CONST DIK_1 = 0x02
CONST DIK_2 = 0x03
CONST DIK_3 = 0x04
CONST DIK_4 = 0x05
CONST DIK_5 = 0x06
CONST DIK_6 = 0x07
CONST DIK_7 = 0x08
CONST DIK_8 = 0x09
CONST DIK_9 = 0x0A
CONST DIK_0 = 0x0B

CONST DIK_RETURN = 0x1C
CONST DIK_SPACE = 0x39 'shoot!

CONST DIK_UP = 0xC8 /* UpArrow on arrow keypad */
CONST DIK_LEFT = 0xCB /* LeftArrow on arrow keypad */
CONST DIK_RIGHT = 0xCD /* RightArrow on arrow keypad */
CONST DIK_DOWN = 0xD0 /* DownArrow on arrow keypad */

CONST DIK_W = 0x11 'second player
CONST DIK_A = 0x1E
CONST DIK_S = 0x1F
CONST DIK_D = 0x20




DEF ret as INT
DEF request as INT

DEF dx[112] as float
DEF dy[112] as float
DEF da[112] as float
DEF dv[112] as float
DEF dh[112] as INT
DEF ds[112] as INT   'shooting status
DEF dda[112] as INT 'def destined angle


DEF tx[112] as FLOAT
DEF ty[112] as FLOAT
DEF ta[112] as float
DEF tv[112] as float
DEF th[112] as INT
DEF tls[112] as INT 'need to replace
DEF tda[112] as INT

DEF distance as INT
DEF target[112] as INT


DEF dis as float
DEF ttarget[112] as INT 'enimy proposed target




DEF lx[112,17] as float 'alliance laser variables
DEF ly[112,17] as float
DEF la[112,17] as float
DEF le[112,17] as INT
DEF lr[112] as INT
DEF l[112] as INT

DEF elx[112,17]  as float 'enimy laser variables
DEF ely[112,17]  as float
DEF ela[112,17]  as float
DEF ele[112,17]  as INT
DEF elr[112]  as INT
DEF el[112] as INT

DEF wings as INT
DEF es as INT
DEF back as float

DEF crt as INT
DEF exitGame as INT
crt = 57.2957795


DEF i as INT
DEF c AS INT
DEF j as INT
DEF exit as INT

DEF panx as INT
DEF pany as INT


ta = 1

es = 111
wings = 15

FOR i = 0 to wings 'set initial variables----------------------

dv[i] = 1
da[i] = RAND(360)
dx[i] = RAND(000,1000)
dy[i] = RAND(850,1450)
dh[i] = 20
ds[i] = 1
le[i] = 1
lr[i] = 30
l[i] = 1




NEXT i


FOR j = 0 to es


ta[j] = RAND(360)
tx[j] = RAND(000,1100)
ty[j] = RAND(50,650)
th[j] = 2
elr[j] = 30
ele[j] = 1

NEXT j

'menu===================================================================================

DO
FILLSCREEN RGB(10,10,15)

WRITETEXT 350, 100, "SPACE BATTLES 0.0.6"

WRITETEXT 350, 310, "Play"

WRITETEXT 350, 350, "Instructions"

WRITETEXT 350, 390, "Credits"

DRAWFILLEDRECT 340, request * 40 + 310, 10, 10, RGB(255,0,0)
FLIP

WAITKEY

IF KEYDOWN(DIK_UP) & request <> 0 THEN request --

IF KEYDOWN(DIK_DOWN) & request <> 2 THEN request ++

IF KEYDOWN(DIK_RETURN) | KEYDOWN(DIK_ESCAPE) THEN ret = 1

UNTIL ret = 1
'game--------------------------------------------------------------------------------------



IF request = 1 THEN

DO

FILLSCREEN RGB(10,10,15)

WRITETEXT 100, 300, "Shoot the green circles before they shoot you"
WRITETEXT 50, 350, "use left and right for direction. Up and Down for engines. space to shoot"
WRITETEXT 100, 400, "You have teammates! They shoot and die just like you."
FLIP

WAITKEY

UNTIL KEYDOWN(DIK_RETURN)

ENDIF

IF request = 2 THEN 'credits------------------------------

DO
FILLSCREEN RGB(10,10,15)

WRITETEXT 100, 300, "Space Battles Va0.0.6 18-12-08 by Yujin Wu"
WRITETEXT 100, 340, "All Rights Reserved 2008 Yujin Wu"
WRITETEXT 100, 380, "Entirely Made on Emergence Basic 1.68"
WRITETEXT 100, 420, "Special thanks to the EB Support forum,"
WRITETEXT 100, 480, "Alex D, Anthony P, Harry D and Nicholas V."

FLIP

WAITKEY

UNTIL KEYDOWN(DIK_RETURN)

ENDIF


'game===============================================================


DO
FILLSCREEN RGB(10,10,15)

'keycontrols!----------------------------------------------------------------------

IF KEYDOWN(DIK_ESCAPE) THEN exitGame = 1

'aiming!-------------------------------------------------------------------


'the ai for the fighters!-----::::::::::::::::

FOR i = 1 to wings

FOR j = 0 to es 'finding target, es is taerget number

IF distance > SQRT(ABS(dx[i]-tx[j]) * ABS(dx[j]-tx[j])  + ABS(dy[j] - ty[j] ) * ABS(dy[i] - ty[j] ) ) & th[j] > 0 THEN
target[i] = j
distance = SQRT(ABS(dx[i]-tx[j]) * ABS(dx[j]-tx[j]) + ABS(dy[j] - ty[j] ) * ABS(dy[i] - ty[j] ))

ENDIF

NEXT j


dda[i] = ATAN((dy[i]-ty[target[i]])/(dx[i]-tx[target[i]])) * crt -90 'locking target to your ship by setting all variables
IF ABS(dx[i]-tx[target[i]]) <> dx[i] - tx[target[i]] THEN dda[i] = dda[i] + 180

IF dda[i] < 0 THEN dda[i] = dda[i] + 360 'angle correction



'aiming of AI------------------

back = da[i] - 180

IF dda[i] > back & dda[i] < da[i] THEN da[i] = da[i] - 1.5
IF dda[i] > 0 & dda[i] < back THEN da[i] = da[i] + 1.5

back = da[i] + 180

IF dda[i] < back & dda[i] > da[i] THEN da[i] = da[i] + 1.5
IF dda[i] < 360 & dda[i] > back THEN da[i] = da[i] - 1.5

'end of aiming


IF ABS(dda[i] - da[i]) < 3 & distance < 800 THEN 'toggle shoot
ds[i] = 1
da[i] = dda[i]
ELSE
ds[i] = 0
ENDIF




IF ABS(dda[i] - da[i]) < 90 & distance < 50 THEN
dv[i] = 0.6
ELSE
dv[i] = 0.6
ENDIF
distance = 1000
NEXT i





IF KEYDOWN(DIK_LEFT) THEN da = da - 1.5                   'turn left
IF KEYDOWN(DIK_RIGHT) THEN da = da + 1.5 'turn right

'angle adjustments--------------------------------




IF KEYDOWN(DIK_UP) THEN
IF dv[0] < 1 THEN dv[0] = dv[0] + 0.01 'speed up
ENDIF

IF KEYDOWN(DIK_DOWN) THEN
IF dv[0] > 0.35 THEN dv[0] = dv[0] - 0.01 'slow down
ENDIF

'mk laser!----------------------------------------------

IF KEYDOWN(DIK_SPACE) & lr[0] < 0 THEN 'make laser

lx[0,l[0]] = dx[0]
ly[0,l[0]] = dy[0]
la[0,l[0]] = da[0]
le[0,l[0]] = 1
l[0] = l[0] + 1
lr[0] = 10
IF l[0] = 16 THEN l[0] = 1
ENDIF

'alliance laser shooting



FOR i = 1 to wings 'make teammate's laser

IF ds[i] = 1 & lr[i] < 0 & dh[i] > 0 & dh[i] > 0 THEN

lx[i,l[i]] = dx[i]

ly[i,l[i]] = dy[i]
la[i,l[i]] = da[i] 
le[i,l[i]] = 1
l[i] = l[i] + 1
lr[i] = 15
IF l[i] = 16 THEN l[i] = 1


ENDIF

NEXT i




'end of alliance----------------------======================================



FOR i = 1 to es

IF th[i] < 1 THEN GOTO nex

FOR j = 0 to wings 'finding target, es is taerget number

IF dis > SQRT(ABS(tx[i]-dx[j]) * ABS(tx[j]-dx[j])  + ABS(ty[j] - dy[j] ) * ABS(ty[i] - dy[j] ) ) & dh[j] > 0 THEN
ttarget[i] = j
dis = SQRT(ABS(tx[i]-dx[j]) * ABS(tx[j]-dx[j]) + ABS(ty[j] - dy[j] ) * ABS(ty[i] - dy[j] ))

ENDIF

NEXT j


tda[i] = ATAN((ty[i]-dy[ttarget[i]])/(tx[i]-dx[ttarget[i]])) * crt -90 'locking target to your ship by setting all variables
IF ABS(tx[i]-dx[ttarget[i]]) <> tx[i] - dx[ttarget[i]] THEN tda[i] = tda[i] + 180

IF tda[i] < 0 THEN tda[i] = tda[i] + 360 'angle correction


'evil aiming-----------------


back = ta[i] - 180

IF tda[i] > back & tda[i] < ta[i] THEN ta[i] = ta[i] - 1.5
IF tda[i] > 0 & tda[i] < back THEN ta[i] = ta[i] + 1.5

back = ta[i] + 180

IF tda[i] < back & tda[i] > ta[i] THEN ta[i] = ta[i] + 1.5
IF tda[i] < 360 & tda[i] > back THEN ta[i] = ta[i] - 1.5

'end of aiming---------------

IF ABS(tda[i] - ta[i]) < 3 & dis < 200 THEN 'toggle shoot
tls[i] = 1
ta[i] = tda[i]
ELSE
tls[i] = 0
ENDIF




IF ABS(tda[i] - ta[i]) < 90 & dis < 50 THEN
tv[i] = 0.6
ELSE
tv[i] = 0.6
ENDIF

LABEL nex
dis = 1000
NEXT i



'mk laser!----------------------------------------------


'evil laser shooting



FOR i = 1 to es 'make teammate's laser

IF tls[i] = 1 & elr[i] < 0 & th[i] > 0 THEN

elx[i,el[i]] = tx[i]

ely[i,el[i]] = ty[i]
ela[i,el[i]] = ta[i] 
ele[i,el[i]] = 1
el[i] = el[i] + 1
elr[i] = 90
IF el[i] = 16 THEN el[i] = 1


ENDIF

NEXT i





'CALCULATE POSITIONS AND UPda[i]TE!---------------------------------

';ship new position----------

FOR i = 0 to wings              'i = ship

dx[i] = dx[i] + dv[i] * SIN(da[i] / crt)
dy[i] = dy[i] - dv[i] * COS(da[i] / crt)
FOR j = 1 to 16

lx[i,j] = lx[i,j] + 6 * SIN(la[i,j] / crt)
ly[i,j] = ly[i,j] - 6 * COS(la[i,j] / crt)

NEXT j

NEXT i


'enimy laser new position and eimy ship new position

FOR j = 0 to es

tx[j] = tx[j] + tv[j] * SIN(ta[j] / crt)
ty[j] = ty[j] - tv[j]  * COS(ta[j] / crt)

FOR i = 0 to 16

elx[j,i] = elx[j,i] + 4 * SIN(ela[j,i] / crt)
ely[j,i] = ely[j,i] - 4 * COS(ela[j,i] / crt)

NEXT i

NEXT j

'move lasers


'laser collisions!----------------------------------------------------------------

for i = 1 to wings

FOR j = 0 to 16        'j is laser

IF le[i,j] = 1 THEN          'make sure the laser exists

IF lx[i,j] - tx[target[i]] < 10 & ly[i,j] - ty[target[i]] < 10 & lx[i,j] - tx[target[i]] > 0 & ly[i,j] - ty[target[i]] > 0 THEN 'collide with target?
th[target[i]] --
DRAWRECT lx[i,j] - 3 + panx, ly[i,j] - 3 + pany, 6,6, RGB(100,100,0)
le[i,j] = 0
ENDIF 'end of collide with target?

ENDIF  'end of laser calculations

NEXT j 

NEXT i


i = 0
FOR j = 0 to 16
IF le[i,j] = 1 THEN          'make sure the laser exists

FOR c = 0 to es

IF lx[i,j] - tx[c] < 10 & ly[i,j] - ty[c] < 10 & lx[i,j] - tx[c] > 0 & ly[i,j] - ty[c] > 0 & th[c] > 0 THEN 'collide with target?
th[c] --
DRAWRECT lx[i,j] - 3 + panx, ly[i,j] - 3 + pany, 6,6, RGB(100,100,0)
le[i,j] = 0
ENDIF 'end of collide with target?

NEXT c

ENDIF  'end of laser calculations
NEXT j



'evil's turn!

FOR i = 0 to es

FOR j = 0 to 16        'j is laser

IF ele[i,j] = 1 THEN          'make sure the laser exists

IF elx[i,j] - dx[ttarget[i]] < 10 & ely[i,j] - dy[ttarget[i]] < 10 & elx[i,j] - dx[ttarget[i]] > 0 & ely[i,j] - dy[ttarget[i]] > 0 THEN 'collide with target?
dh[ttarget[i]] --
DRAWRECT elx[i,j] - 3 + panx, ely[i,j] - 3 + pany, 6,6, RGB(100,100,0)
ele[i,j] = 0
ENDIF 'end of collide with target?

ENDIF  'end of laser calculations

NEXT j 

NEXT i


'==================

'angle corrections------------------------------

FOR i = 0 to wings

IF da[i] < 2 THEN da[i] = da[i] + 360                  'angle corrections
IF da[i] > 362 THEN da[i] = da[i] - 360

NEXT i


FOR i = 0 to es

IF ta[i] < 2 THEN ta[i] = ta[i] + 360                  'angle corrections for evil
IF ta[i] > 362 THEN ta[i] = ta[i] - 360

NEXT i

'health checks!---------------------------------------------------------------
for i = 0 to wings

IF dh[i] < 1 THEN
exit ++
ENDIF

NEXT i

IF exit = wings + 1 THEN
exitGame = 1
ELSE
exit = 0
ENDIF



'drawing!--------------------------------------------------------------------------

FOR i = 0 to wings

IF dh[i] > 0 THEN

panx = 400 - dx[i]
pany = 300 - dy[i]
i = wings

ENDIF

NEXT i






FOR i = 0 to wings 'draw lasers

FOR j = 1 to 16

IF  le[i,j] = 1 THEN DRAWAALINE lx[i,j]+ panx, ly[i,j]+ pany, lx[i,j] + 5 * SIN(la[i,j] / crt)+ panx, ly[i,j] - 5 * COS(la[i,j] / crt)+ pany, RGB(255,10,10)

NEXT j

NEXT i

FOR i = 0 to es 'draw lasers of forbidden

FOR j = 1 to 16

IF  ele[i,j] = 1 THEN DRAWLINE elx[i,j]+ panx, ely[i,j] + pany, elx[i,j] + 3 * SIN(ela[i,j] / crt)+ panx, ely[i,j] - 3 * COS(ela[i,j] / crt)+ pany, RGB(10,255,10)

NEXT j

NEXT i


DRAWLINE dx[0]+ panx, dy[0]+ pany, dx[0] + 5 * SIN(da[0] / crt)+ panx, dy[0] - 5 * COS(da[0] / crt)+ pany, RGB(255,0,0)


FOR i = 1 to wings

IF dh[i] > 0 THEN DRAWRECT dx[i]+ panx, dy[i]+ pany, 5, 5, RGB(255,0,0) 'draw fighter

NEXT i

FOR i = 0 to es

IF th[i] > 0 THEN DRAWRECT tx[i]+ panx, ty[i]+ pany,5, 5, RGB(0,255,0) 'draw fighter

NEXT i


FOR i = 0 to wings

IF dh[i] > 0 THEN

DRAWFILLEDRECT 350, 500, 100, 10, RGB(50,10,15) 'health box
DRAWFILLEDRECT 350, 500, dh[i] * 5, 10, RGB(200,0,0)

DRAWFILLEDRECT 350, 520, 100, 10, RGB(10,10,50) 'speed box
DRAWFILLEDRECT 350, 520, dv[i] * 100, 10, RGB(0,0,200)


i = wings


ENDIF

NEXT i

'flash- -       -       -     



c ++

IF c > 60 THEN c = 0
'end of flash -   -    -   -   -

'miscellanious!-------------------------------------------------------------------

FOR i = 0 to wings

lr[i]--

NEXT i

FOR i = 0 to es

elr[i]--

NEXT i

FLIP



'ending====================================================================
UNTIL exitGame <> 0

FILLSCREEN RGB (10,10,15)

IF th = 0 THEN WRITETEXT 350, 300, "YOU HAVE WON! WITH " + STR$(dh[1]) + " HEALTH LEFT"

IF exitGame = 2 THEN WRITETEXT 350, 300, "GAME OVER!"

IF th > 0 & dh[0] > 0 THEN WRITETEXT 0, 0, "press esc key to continue"

FLIP

WAITKEY(DIK_ESCAPE)



CLOSESCREEN
END



its got a rather odd finish though

shoot the green stuff