Hi i need help with my boss
i want him to move randomly in the top 570x150 area like bounce off walls i have this code but it dont work.... im new to this shit
IF Boss[1]<20 THEN Bfa=45+RND(90)
IF Boss[1]>570 THEN Bfa=225+RND(90)
IF Boss[2]<100 THEN Bfa=135+RND(90)
IF Boss[2]>20 THEN Bfa=-45+RND(90)
Boss[1]=INTEGER(Boss[1]+SIN(Bfa)*1)
Boss[2]=INTEGER(Boss[2]+COS(Bfa)*1)
i dunno much about programming so any help is much appreciated.
This is probably totally not what you want to do, so I don't know why I wrote it :)
But this is a simple example of movement you might be interested to just to try it out.
It may help you learn something
If you want a more random smooth movement you could use interpolation
I could explain that if you want
//Inital stuff
GETSCREENSIZE sx,sy // this gets the screen size eg. 640,480
GLOBAL boss_x = RND(sx) //random start position on the screen
GLOBAL boss_y = RND(sy) //random start position on the screen
GLOBAL boss_speed_x = 10 // the x speed the boss is going to move
GLOBAL boss_speed_y = 10 // the y speed the boss is going to move
main:
//move boss
boss_x=boss_x + boss_speed_x // we take the bosses position and add the x speed to it
boss_y=boss_y + boss_speed_y // we take the bosses position and add the y speed to it
IF boss_x < 0 OR boss_x > sx THEN boss_speed_x = -boss_speed_x // reverse the speed if we hit the sides
IF boss_y < 0 OR boss_y > sy THEN boss_speed_y = -boss_speed_y // reverse the speed if we hit the sides
//draw boss
FILLRECT boss_x,boss_y,boss_x+40,boss_y+40,RGB(250,200,200) // draw the evil cube
SHOWSCREEN // don't for get to show everything!!!
GOTO main
i got it 2 work have a look took me a while but
Boss[1]=Boss[1]+SIN(Bfa)*2
Boss[2]=Boss[2]+COS(Bfa)*2
IF Boss[1]<20;Bfa=55+RND(80);ELSE
IF Boss[1]>550;Bfa=235+RND(80);ELSE
IF Boss[2]>100;Bfa=145+RND(80);ELSE
IF Boss[2]<20;Bfa=-35+RND(80);
ENDIF;ENDIF;ENDIF;ENDIF
that works but it keeps bouncing up and down more than left to right sorta thing i need to eliminate the middle numbers or add the player possie or something i dont know... Whats interpolation?
http://local.wasp.uwa.edu.au/~pbourke/other/interpolation/
You can use cosine interpolation to move something between two points smoothly
You might want to check out
http://www.shmup-dev.com/
if you are trying to do a shooter..... there might be loads of info there.
If you want a predictable movement you might want to look at
splines, you can use a utility to draw your enemy paths
my game wont run when its not in debug mode ive left it on so long i dont know where its *love making* up hmm... maybe i do
sprcoll dont work when debug isnt on how come and how can i fix it?
send a small program where you think SPRCOLL does not work. It definitely does work.
FOR f=0 TO BOUNDS(Ei[],0)-1
IF SPRCOLL(21,Shot[1],Shot[2],40,Ei[f][0],Ei[f][1])
Explode(1,Ei[f][0],Ei[f][1],f)
FOR v=0 TO 1
Shot[v]=-20
NEXT
ENDIF
NEXT
Can i use FOR to load multiple bmps and use the var as the number?
like this sorta thing
FOR e=00 TO 31
LOADSPRITE "carstraight" + e + ".bmp",e
NEXT
Quote from: WAAAAAAFOR f=0 TO BOUNDS(Ei[],0)-1
IF SPRCOLL(21,Shot[1],Shot[2],40,Ei[f][0],Ei[f][1])
Explode(1,Ei[f][0],Ei[f][1],f)
FOR v=0 TO 1
What is this line about?
Quote Shot[v]=-20
The rest looks OK.
Quote NEXT
ENDIF
NEXT
Can i use FOR to load multiple bmps and use the var as the number?
like this sorta thing
FOR e=00 TO 31
LOADSPRITE "carstraight" + e + ".bmp",e
NEXT
Sure you can. It works perfectly.
the shot[v]-20 makes the bullets dissapear when i get hit or when he gets hit sorta thing
funny thing is it only crashes if i get hit from a monster or i hit a monster if i hit the boss or the boss hits me. its fine when debug isnt on. as soon as debug coems off the game will work till sprcoll comes into affect.. but i can still attack the boss fine????
this is crap how am i supposed to find the error when it works in debug mode?
think it would have something to do with my explosions and how there affecting the dim arrays?
FOR e=0 TO BOUNDS(Ex[],0)-1
IF Ex[e][1]<>0
ROTOZOOMSPRITE 35,Ex[e][2],Ex[e][3],Ex[e][4],Ex[e][4]/4
INC Ex[e][4],1
IF Ex[e][4]>6
IF Ex[e][1]=1;k=Ex[e][5];DIMDEL Ei[],k;ENDIF
Ex[e][1]=0
DIMDEL Ex[],e
ENDIF
ENDIF
NEXT
What's the DIM of Ex? It must be at least: DIM Ex[num][6]
yeah it is...
whats ur email i could send u my small program and u could look at it????
wow it crashed in debug mode and debug didnt pick it up and a red bar came up outline in white and that not in my coding at all lol
how could u use types on a mass scale? like if u had all these enemies as types how would u handle movement for each one? bliztbasic has an for each command sorta thing happening....
you mean a "for each ... in ..." command? Does not exist. What is the Blitz way. I might implement it.
its for types specifically blizt has soem nice stuff on it
For EnemyShips.Ship = Each Ship
EnemyShips\iX = EnemyShips\iX + iDirectionX
EnemyShips\iY = EnemyShips\iY + iDirectionY
Next
OK. "FOR EACH" is a nice method. I'll implement it some day.
For now you do:
LOCAL es AS EnemyShip
FOR i=0 TO BOUNDS(EnemyShips.Ship[], 0) -1
// Get that thing
es = EnemyShips[i]
// change data of es.xxx
// ...
// put es pack into the array:
EnemyShip[i] = es
NEXT
It's a bit awkard, since TYPEs are new in GLBasic. I'll fix that.
yea i dont get it
format$ doesnt work? atleast the help file version all it does is cut down how many numbers are after the decimal
i think i found an easier way
CHR$()
TYPE THING
x;y
ENDTYPE
FOR i=0 to BOUNDS(num_things,0)
x=CHR$(i+64)
x.thing=x.thing+1
NEXT
reckon it will work?
coz u cant use numbers as types so u cant just go FOR TO
lol
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::Create_player()':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:29: error: `x' has not been declared
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:29: error: request for member of non-aggregate type before '=' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:30: error: `y' has not been declared
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:30: error: request for member of non-aggregate type before '=' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:31: error: `shld' has not been declared
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:31: error: request for member of non-aggregate type before '=' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:32: error: `lives' has not been declared
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:32: error: request for member of non-aggregate type before '=' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:33: error: `state' has not been declared
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:33: error: request for member of non-aggregate type before '=' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:34: error: `speed' has not been declared
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:34: error: request for member of non-aggregate type before '=' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::Reset_player(DGInt)':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:41: error: no match for 'operator=' in 'i = __GLBASIC__::CHR_Str(DGInt)()'
C:\Program Files\GLBasic\Compiler\platform\/gpc_temp.h:35: note: candidates are: __GLBASIC__::PLAYER& __GLBASIC__::PLAYER::operator=(const __GLBASIC__::PLAYER&)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::Update_player(DGInt)':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:50: error: no match for 'operator=' in 'i = __GLBASIC__::CHR_Str(DGInt)()'
C:\Program Files\GLBasic\Compiler\platform\/gpc_temp.h:35: note: candidates are: __GLBASIC__::PLAYER& __GLBASIC__::PLAYER::operator=(const __GLBASIC__::PLAYER&)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::Render_player(DGInt)':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:69: error: no match for 'operator=' in 'i = __GLBASIC__::CHR_Str(DGInt)()'
C:\Program Files\GLBasic\Compiler\platform\/gpc_temp.h:35: note: candidates are: __GLBASIC__::PLAYER& __GLBASIC__::PLAYER::operator=(const __GLBASIC__::PLAYER&)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::Update_Game()':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:77: error: no match for 'operator=' in 'i = 1'
C:\Program Files\GLBasic\Compiler\platform\/gpc_temp.h:35: note: candidates are: __GLBASIC__::PLAYER& __GLBASIC__::PLAYER::operator=(const __GLBASIC__::PLAYER&)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:77: error: no match for 'operator<=' in 'i <= __GLBASIC__::num_players'
../../Include/glb.h:230: note: candidates are: DGInt __GLBASIC__::operator<=(int, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(int, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(float, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(float, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(double, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(double, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, int)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, float)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, double)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, int)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, float)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, double)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:77: error: no `operator++(int)' declared for postfix `++', trying prefix operator instead
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:77: error: no match for 'operator++' in '++i'
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::Render_Game()':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:87: error: no match for 'operator=' in 'i = 1'
C:\Program Files\GLBasic\Compiler\platform\/gpc_temp.h:35: note: candidates are: __GLBASIC__::PLAYER& __GLBASIC__::PLAYER::operator=(const __GLBASIC__::PLAYER&)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:87: error: no match for 'operator<=' in 'i <= __GLBASIC__::num_players'
../../Include/glb.h:230: note: candidates are: DGInt __GLBASIC__::operator<=(int, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(int, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(float, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(float, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(double, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(double, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, int)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, float)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(__GLBASIC__::CGStr, double)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, __GLBASIC__::CGStr)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, const __GLBASIC__::DGStr&)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, int)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, float)
../../Include/glb.h:230: note: DGInt __GLBASIC__::operator<=(const __GLBASIC__::DGStr&, double)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:87: error: no `operator++(int)' declared for postfix `++', trying prefix operator instead
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:87: error: no match for 'operator++' in '++i'
linking:
gpc_temp0.o:gpc_temp0.cpp:(.text+0x36): undefined reference to `__GLBASIC__::a'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x4c): undefined reference to `__GLBASIC__::a'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xa5): undefined reference to `__GLBASIC__::a'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xb1): undefined reference to `__GLBASIC__::a'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x1df): undefined reference to `__GLBASIC__::a'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x1f8): more undefined references to `__GLBASIC__::a' follow
*** FATAL ERROR - Please post this output in the forum
FUNCTION Create_player:
LOCAL i
num_players=num_players+1
i=CHR$(65+num_players)
GLOBAL i AS PLAYER
i.x=sx/2-16
i.y=sy-45
i.shld=3
i.lives=3
i.state=1
i.speed=2
ENDFUNCTION
nvm i think i see problem i dunno how to fix but
The FORMAT$ function goes: FORMAT$(minimum_number_of_characters, number_of_digits_after_the_comma, the_number_to_format);
the BOUNDS function takes an array as first argument. To pass an array, you must specify the name, followed by a [ ] like:
DIM arr[5]
FOR i=0 TO BOUNDS( arr[], 0 )
PRINT arr[i], 0, i*20
NEXT
Working with types as a beginner might be frustrating, since the precompiler errors are not covering all problems. As said - it's very new in GLBasic. If you keep the syntax, it works perfectly, if not, you might get into trouble.
Please, do post source code that gives the error, not just the smallest potion of it.
The error basically starts with:
In function "CreatePlayer", you used a member variable called ".x", which does not exist in the type you are using.
You got my mail? Send me the code, I'll fix it for you.
FUNCTION Create_player:
LOCAL i // now i is a number
num_players=num_players+1
i=CHR$(65+num_players) // now you assign a string of word ('A', or 'B') to a number -> that results in '0'
GLOBAL i AS PLAYER // yuck!!!! you're creating a GLOBAL with the same name as the local 'i'
i.x=sx/2-16 // here you're referencing the LOCAL i
// writing:
GLOBAL i.x = sx/2-16
// would do, but...
// why not writing
LOCAL ply AS PLAYER
ply.y=sy-45
ply.shld=3
ply.lives=3
ply.state=1
ply.speed=2
ENDFUNCTION