Author Topic: Bullet Coding  (Read 5855 times)

0 Members and 1 Guest are viewing this topic.

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Bullet Coding
« on: October 19, 2011, 02:43:10 pm »
OK I need help with adding a code into my source for shooting bullets out of a ship on the screen using the 2nd button... Help please!

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: Bullet Coding
« Reply #1 on: October 19, 2011, 02:55:03 pm »
what language are you using?

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: Bullet Coding
« Reply #2 on: October 19, 2011, 02:55:33 pm »
Axe :D

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: Bullet Coding
« Reply #3 on: October 19, 2011, 03:00:45 pm »
To create an array of say, 30 bullets, use
Code: [Select]
For(A,0,29)
0->{L1+A}->{L1+1+A}->{L1+2+A}->{L1+3+A}
End
This creates thirty bullets with x,y of 0,0 and are not moving
Then, you can store better coordinates to the x,y, and the x and y velocities

To move them, simply add the x velocity, whether or not it is negative, to the x coordinate, and the same for the y
Code: [Select]
For(A,0,29)
{L1+A}+{L1+2+A}->{L1+A}
{L1+1+A}+{L1+3+A}->{L1+1+A}
End

Hope this helps, and be warned, while messing around with this, you may crash your calc, so archive stuff you don't want deleted :P


Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Bullet Coding
« Reply #4 on: October 19, 2011, 03:11:34 pm »
create bullet
Code: [Select]
:Lbl CREATE
:For(r3,0,9  //maximum of 10bullets on screen
:!If {r3*3+L1}
:1->{r3*3+L1}
:r1->{r3*3+L1+1}
:r2->{r3*3+L1+2}
:10->r3       //escape from loop
:End
:End

destroy bullet
Code: [Select]
:Lbl DESTR
:0->{r1+L1}

update
Code: [Select]
:Lbl UPDAT
:For(r1,0,9
:If {r1*3+L1}
:{r1*3+L1+1}++  //when it moves horizontally
:If 96          //outside the screen borders
:Sub(DESTR,r1
:End
:End
:End

You will have to come up with your own collision code since we are no magicians.
If you like my work: why not give me an internet?








Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Bullet Coding
« Reply #5 on: October 19, 2011, 03:27:27 pm »
What's kind of tricky about bullets in general is removing them from the array safely--when a bullet in the middle of the array needs to be removed.  What I ended up doing for Essence was a Copy() to bring the data for the bullets after the one being deleted.  Also you'll probably want some sort of variable to tell how many bullets there are.
I'm not the best at explaining things :P
There's some code that does it here and a tutorial explaining a different method which is pretty helpful to read through here and here.
Hope this helps :)
« Last Edit: October 19, 2011, 03:27:51 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Bullet Coding
« Reply #6 on: October 19, 2011, 03:33:28 pm »
I thought DT had a tutorial for this
Sig wipe!

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Bullet Coding
« Reply #7 on: October 19, 2011, 03:34:05 pm »
Both of the tutorials are his :P
« Last Edit: October 19, 2011, 03:34:23 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Bullet Coding
« Reply #8 on: October 19, 2011, 03:46:00 pm »
What's kind of tricky about bullets in general is removing them from the array safely--when a bullet in the middle of the array needs to be removed.  What I ended up doing for Essence was a Copy() to bring the data for the bullets after the one being deleted.
Actually, it's a lot easier to copy the final bullet into the position of the deleted bullet and then decrease the bullet count :D
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Bullet Coding
« Reply #9 on: October 19, 2011, 03:51:23 pm »
Moved to the correct forum.

And calc84maniac, that would make the code smaller and faster, but if you're currently looping through the array for other purposes, it could cause problems. On the other hand all you would have to do would be to stay at the same position in the array after copying the last element back, but honestly I didn't think of that XD




Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Bullet Coding
« Reply #10 on: October 19, 2011, 04:12:41 pm »
Here's another way to do bullets in Axe. I assumed that the array would be stored in L1, but L1 can be changed to the pointer of your choice pretty trivially. Note that 0,0 is assumed to be an impossible coordinate. That can likewise be changed to -1 or something if it conflicts with your program.

Initialize array:
Code: [Select]
:Lbl INI
:Fill({L1},2*<max number of bullets>+1,0)

Add bullet
Code: [Select]
:Lbl ADD
:!If {L1}-10
:.10 is max number of bullets
:X->{L1+{L1}+1}
:Y->{L1+{L1}+2}
:End

Destroy bullet
Code: [Select]
:Lbl DESTR
:Copy(L1+{L1},Ptr to cell,2)
:{L1+{L1}}-1->{L1}
:Return

Update bullet array and print bullets onscreen.
Code: [Select]
:Lbl UPD
:.Store X Increment in U
.Y increment in V
:For(A,1,{L1}
:{L1+A}+U->{L1+A}
:{L1+A+1}+V->{L1+A+1}
:Pt-ON({L1+A},{L1+A+1},<Sprite data>)
:End
:DispGraph^rr
:Return
« Last Edit: October 19, 2011, 04:15:22 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Bullet Coding
« Reply #11 on: October 19, 2011, 04:44:22 pm »
What's kind of tricky about bullets in general is removing them from the array safely--when a bullet in the middle of the array needs to be removed.

What I do is just go ahead and remove it, regardless where it is in the array. Then, when the user presses [2ND], I search through the array and put a new one wherever it fits. So every iteration of the main game loop, I move the bullets and display them and do collision checks with objects and such.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Bullet Coding
« Reply #12 on: October 19, 2011, 05:21:22 pm »
Yeah, there are several ways to do an array in Axe.




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Bullet Coding
« Reply #13 on: October 19, 2011, 05:53:29 pm »
What's kind of tricky about bullets in general is removing them from the array safely--when a bullet in the middle of the array needs to be removed.

What I do is just go ahead and remove it, regardless where it is in the array. Then, when the user presses [2ND], I search through the array and put a new one wherever it fits. So every iteration of the main game loop, I move the bullets and display them and do collision checks with objects and such.

This is also very very useful if you use the address of the bullets elsewhere, since with this method the address of the bullets never change

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Bullet Coding
« Reply #14 on: October 19, 2011, 07:31:45 pm »
What's kind of tricky about bullets in general is removing them from the array safely--when a bullet in the middle of the array needs to be removed.

What I do is just go ahead and remove it, regardless where it is in the array. Then, when the user presses [2ND], I search through the array and put a new one wherever it fits. So every iteration of the main game loop, I move the bullets and display them and do collision checks with objects and such.

This is also very very useful if you use the address of the bullets elsewhere, since with this method the address of the bullets never change
Same with my method :)

Edit: Wait a second, never mind. The bullet at the end of the list moves.
« Last Edit: October 19, 2011, 07:32:11 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman