Re: bgt, having trouble with classes, again

The error it gave points to this line:
if(shipx-3==barrier.x or shipx-2==barrier.x or shipx-1==barrier.x or shipx==barrier.x or shipx+1==barrier or shipx+2==barrier or shipx+3==barrier)

It should be:

if(shipx-3==barrier.x or shipx-2==barrier.x or shipx-1==barrier.x or shipx==barrier.x or shipx+1==barrier.x or shipx+2==barrier.x or shipx+3==barrier.x)


However, there is a much simpler way to accomplish that condition:

if(absolute(barrier.x-shipx)<=3)
^ Since you want to know if the distance between shipx and the barrier is less than or equal to 3, just take the absolute value of the difference, and that is the total distance.

A problem you will run up on rather quickly is writing collision detection for all the different walls. A way to speed this up would be to add a method to the wall class. It might be something like:

bool contains(int px, int py) {
return (absolute(x-px)<=3 and absolute(y-py)<=3);
}

Or something like that.

As for handles in general... if you need an object to be a property of a class, or if you just need an object to survive multiple scopes, or if you need an array of objects, you'll need to use handles. You can treat handles like the objects they point to for almost everything; you mostly only need to bother with the at sign for assignment and equality (E.G., if(@handle==null) ). The biggest difference between handles and regular variables is that variables get copied when they are assigned, but multiple handles can still point to the same object.

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : coltonhill01 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Omar Alvarado via Audiogames-reflector

Reply via email to