Author Topic: Problem with shooter code  (Read 8052 times)

0 Members and 1 Guest are viewing this topic.

Offline LemonDrop

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +4/-0
    • View Profile
    • tin.gy
Re: Problem with shooter code
« Reply #30 on: August 05, 2013, 11:30:56 pm »
Hmm, I recognise the problem, but I did not see the issue in your source code immediately. Hopefully I will take a look at it tomorrow and possibly figure out the issue.

I would also like to point out that you can do signed comparisons. For example, {J-6}<<0 to see if it went below zero. I think Axe probably does an auto-optimisation for that.


I tried my attempt above and found that it doesn't work (I forgot some of the nuances of Axe x.x). I did get it to work in BASIC, though.
Well if you can show me the basic code that would be nice because I know that really well, also I would be using singed numbers except a 8bit one is limited to -127 to 126 or whatever, and there is a possibility of the accumulator exceeding that (its maximum possible value is 250)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4655
  • Rating: +718/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Problem with shooter code
« Reply #31 on: August 05, 2013, 11:53:11 pm »
This is the BASIC line drawing routine (I don't have easy access to my calculator at the moment, so this is just what I wrote in my notebook):
Code: [Select]
;draw from B,C to D,E (b=x1)
D-B→D
E-C→E
1→F:1→G    ;these are the xinc and yinc
If D<0
-1→F
If E<0
-1→F
abs(E→E
abs(D→D
If not(Ans
Then       ;draw a vertical line
For(A,C,C+E,G
Pxl-On(A,B
End
Return
End

D→A
2D→D
2E→E
For(H,1,.5D
Pxl-On(C,B
B+F→B
A-E→A
While A<0
C+G→C
Pxl-On(C,B    ;ideally, this should come first and be skipped on the first iteration of the loop, but this isn't that easy in BASIC
A+D→A
End
End
Pxl-On(C,B


In this part of the code above:
Code: [Select]
While A<0
C+G→C
Pxl-On(C,B    ;ideally, this should come first and be skipped on the first iteration of the loop, but this isn't that easy in BASIC
A+D→A
End
To work better, it should be more like this in Axe:
Code: [Select]
If 0
Lbl 01
Pxl-On(B,C
End
C+G→C
A+D→A
If <0      ;well, change this to the proper Axe syntax
Goto 01
End
That skips the first pixel plotting which is only a problem if you are inverting the pixels. Hopefully you can derive a working algorithm from this!

Offline LemonDrop

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +4/-0
    • View Profile
    • tin.gy
Re: Problem with shooter code
« Reply #32 on: August 06, 2013, 01:04:11 am »
-snipped-
Ok so I completely fixed my code:
On line 41 and 44 X should've been Y, thats just a stupid mistake, but there was also a problem with the pseudo code of your algorithm I was basing my calculations off of. You mixed up the width and height calculations for the accumulator, causing it to not work properly. Just because I was completely out of Ideas I just switched them in my if statement and it worked perfectly (well sometimes the bullets take really sharp turns but its only in certain positions). Heres an image:

So thank you so much and sorry it took so long to get something working, but couldn't have done it without your algorithm.
« Last Edit: August 06, 2013, 05:56:56 am by LemonDrop »

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Problem with shooter code
« Reply #33 on: August 06, 2013, 02:00:28 am »
Looks good, I'd also say credit goes to you persistence. :)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4655
  • Rating: +718/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Problem with shooter code
« Reply #34 on: August 06, 2013, 05:39:19 pm »
That looks great! I was in town earlier today with no obligations, so I programmed for a bit and converted my BASIC code to Axe and then modified it a little. It currently only does one bullet at a time, but I am going to add in code to have a bullet buffer. I managed to figure out a way to make sure bullet movement was not bugged except for one case with an acceptable bug (I think). Shooting vertically will cause it to shift 1 pixel off course, but I don't think that should be a problem. Anyways, see the screenshot :)

EDIT: Updated the code, now it uses a bullet buffer. It currently handles 64 bullets on screen at a time and it is still at 6MHz. Feel free to use any of the code or look at it or whatever!

Offline LemonDrop

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +4/-0
    • View Profile
    • tin.gy
Re: Problem with shooter code
« Reply #35 on: August 06, 2013, 08:19:36 pm »
That looks great! I was in town earlier today with no obligations, so I programmed for a bit and converted my BASIC code to Axe and then modified it a little. It currently only does one bullet at a time, but I am going to add in code to have a bullet buffer. I managed to figure out a way to make sure bullet movement was not bugged except for one case with an acceptable bug (I think). Shooting vertically will cause it to shift 1 pixel off course, but I don't think that should be a problem. Anyways, see the screenshot :)

EDIT: Updated the code, now it uses a bullet buffer. It currently handles 64 bullets on screen at a time and it is still at 6MHz. Feel free to use any of the code or look at it or whatever!
Nice, I'll definitely have to check that code out, might use something from it. My next thing to be dealing with however is the enemy movement. I see you have some sort of AI in that second image so I'll see how you did that too and maybe get some ideas.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4655
  • Rating: +718/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Problem with shooter code
« Reply #36 on: August 06, 2013, 08:55:05 pm »
For the AI, all I did was have it randomly move toward the user. As an example, if playerX>enemyX and rand^2 (which returns 0 or 1) is 1, then do enemyX++

Offline LemonDrop

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +4/-0
    • View Profile
    • tin.gy
Re: Problem with shooter code
« Reply #37 on: September 05, 2013, 06:42:43 pm »
Apparently after all this time I still cannot figure out how to make an effective AI system for enemies (firstly what values to even store for each enemies, and also how the ai would work). I could easily just make enemies come down from the top of the screen or do a space-invaders style thing but I wanted them more to actually have more curved movements (some enemies just coming down at angles, others trying to run into players or avoid bullets, etc) but it is complex to try to make a system that allows them to do this type of movement, and also calculates positions for them to go to in the first place. I guess the best way for me to learn is to look at examples of other stuff with the same style (shooter space game thingy) so if anyone knows a game like that that is open source, sharing it would be helpful so I can learn.