Mintoris Forum

Author Topic: asteroid blast  (Read 4332 times)

SkidMarcUK

  • Full Member
  • ***
  • Posts: 35
asteroid blast
« on: Oct 08, 2016, 06:58 PM »
Why are my missiles bouncing off my asteroids sometimes. Getting a bit confusing for me now and still loads to add. Think my structure is all wrong.

SkidMarcUK

  • Full Member
  • ***
  • Posts: 35
Re: asteroid blast
« Reply #1 on: Oct 08, 2016, 10:06 PM »
In the on collision sub I reset the missile back to the centre and fire it again. But it is rebounding off the asteroid. Not all the time though. Explosions and sounds to come later hopefully.

sraffens

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 220
Re: asteroid blast
« Reply #2 on: Oct 09, 2016, 03:24 AM »
This is what I found.

Timing problems are hard to track down, do the following:
Keep your foreground polling loops as small as you can. Us callback function as much as you can setOnxxx
Keep you onXxx function as small as you can.

GenSetSpriteVisible missile,on
gensetspritecenterxy ship,width/2,height/2
gensetspritecenterxy missile,width/2,height/2
angle=GenGetSpriteDirectionAngle(ship)
gensetspritevelocity missile,150,angle-90
GenRotateSpriteTo missile,angle
GenAddSprite missile,10

I change to a sub fireMissile()
  gensetspritecenterxy missile,centerX,centerY
  gensetspritevelocity missile,150,angle-90
  GenRotateSpriteTo missile,angle
  GenSetSpriteVisible missile,on
  GenAddSprite missile,10
end sub

sub missilecollision(sprite1,sprite2)
Gensetspritecenterxy missile,width/2,height/2
GenSetSpriteTimerA missile,off
angle=GenGetSpriteDirectionAngle(ship)
gensetspritevelocity missile,150,angle-90
GenRotateSpriteTo missile,angle
GenSetSpriteTimerA missile,750
end sub

sub missilecollision(sprite1,sprite2)
  GenKillSprite missile
  fireMissile()
  GenSetSpriteTimerA missile,750
end sub

The changes in yellow did the most, the other changes where to find out what the code was doing

Hope this helps

FYI
  When foreground loops are callback function get delayed getting called.
  When callback functions are big other callback function get delayed getting called.
  Wake the wait xxx as large as you can in the main loop
  wait 50 in your loop is close to real time polling the getAccelerometer(). wait 100 is jerking.

  Try changing the "Setting" so the "Auto-Init Variables" is tuned OFF.
  All variables must be initialized before using them.
  You will get a will get an error message indicating the uninitialized variable.

  If "Auto-Init Variables" is tuned ON (ON is the default),
    then any variable that is not initialized will be set to var$ = "" or var = 0.

  When I first started the code would not run cause of uninitialized variable.
     "trimx" was never initialized defaulted to zero, not a problem this time
  When I change the indention I found some errors:
    look at If…Then and If…Then…Endif
    If…Then is on a single line
    If…Then…Endif can't be on a single line
    labels like attract: should end with a return.
      Some time labels are required but I try to stay away from them
      I put them in a sub labels() that way the variables are not global, I know the scope
    sub attract() should end with a end sub
    Use sub subName() it will make the variables local and only use global that are declared GLOBAL or CONST.
       Keep the code scope as local as possible.
    Use Const when you can set them and BASIC will error if you attempt to change that variable.
    I work to keep GLOBAL to a minimum

  This is what I followed converting your code.
Scott
« Last Edit: Oct 09, 2016, 05:15 AM by sraffens »

SkidMarcUK

  • Full Member
  • ***
  • Posts: 35
Re: asteroid blast
« Reply #3 on: Oct 15, 2016, 02:31 PM »
Tried everything I can think of. On collision sub still not calling every time. Think this also happens on the space invaders 2 game on here but hard to tell.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: asteroid blast
« Reply #4 on: Oct 15, 2016, 09:15 PM »
It may be that the asteroid is detecting the collision before the missile. Does the asteroid have an onCollision sub?

Edit: I checked it out, that is the problem. I've made a change in the game engine so that the onCollision sub on both sprites gets called when a collision occurs. Right now it's a flip of the coin whether the missile detects the collision.

It will be fixed in the release in a few days.
« Last Edit: Oct 15, 2016, 09:27 PM by Chuck »

SkidMarcUK

  • Full Member
  • ***
  • Posts: 35
Re: asteroid blast
« Reply #5 on: Oct 15, 2016, 09:57 PM »
😁 I can get on with it now. Thanks

SkidMarcUK

  • Full Member
  • ***
  • Posts: 35
Re: asteroid blast
« Reply #6 on: Oct 21, 2016, 10:41 PM »
Had another go on this. I would like to thank sraffens for helping on it but need more time to understand the changes so for now just updated my code. After looking at space invaders 2 events realise I have a long way to go but this was the best I could do with my limited knowledge of programming.
« Last Edit: Oct 22, 2016, 12:12 AM by SkidMarcUK »

TonyaCon

  • Full Member
  • ***
  • Posts: 19
asteroid blast
« Reply #7 on: Oct 16, 2019, 12:40 AM »
Hey, Marc we have 3 or 4 guys and dogs, for the 13th of Feb.
this date works better than the 27th of Feb. for us. Any good?
Can you run it by the rooster? Thanks, Paul

Evelynwed

  • Full Member
  • ***
  • Posts: 26
asteroid blast
« Reply #8 on: Oct 18, 2019, 09:45 AM »
Is there a limit on the amount of groups that can be made or is it to late to sign up?  I potentially might have a group of guys that would be interested in going.  What does the big blast consist of?

Thanks guys.
-Bill

CarolclOry

  • Full Member
  • ***
  • Posts: 13
asteroid blast
« Reply #9 on: Oct 24, 2019, 12:59 AM »
I cant wait for Saturday, gonna head down for the Big Blast at Rooster Heaven with my Dad and a few buddies.  Any other CTA members gonna be in attendance?

We are planning to meet for breakfast at usual spot at 630am.

-BD76

KarenNof

  • Newbie
  • *
  • Posts: 1
asteroid blast
« Reply #10 on: Nov 14, 2019, 02:29 PM »
I havent been icefishing much this past month, but I will put the short sticks aside this weekend to shoot some birds at Rooster Heaven with some buddies.

Anyone else heading out this weekend?

-BD76