Boss help

Previous topic - Next topic

WAAAAAA

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.

mikiex

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


Code (glbasic) Select
//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

WAAAAAA

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?

mikiex

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

WAAAAAA

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

WAAAAAA

sprcoll dont work when debug isnt on how come and how can i fix it?

Kitty Hello

send a small program where you think SPRCOLL does not work. It definitely does work.

WAAAAAA

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

Kitty Hello

Quote from: WAAAAAA
Code (glbasic) Select
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
What is this line about?
Quote
Code (glbasic) Select
Shot[v]=-20
The rest looks OK.
Quote
Code (glbasic) Select
NEXT
ENDIF
NEXT
Can i use FOR to load multiple bmps and use the var as the number?
like this sorta thing
Code (glbasic) Select
FOR e=00 TO 31
LOADSPRITE "carstraight" + e + ".bmp",e
NEXT
Sure you can. It works perfectly.

WAAAAAA

the shot[v]-20 makes the bullets dissapear when i get hit or when he gets hit sorta thing

WAAAAAA

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?

WAAAAAA

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

Kitty Hello

What's the DIM of Ex? It must be at least: DIM Ex[num][6]

WAAAAAA

yeah it is...

WAAAAAA

whats ur email i could send u my small program and u could look at it????