Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » This should be a very common problem.

This thread is locked; no one can reply to it. rss feed Print
This should be a very common problem.
keprast
Member #16,794
January 2018

:)Hello.

If I shot 100 bullets,at a time.

But you know, I have only a piece of code.
I can't write 100 code.Let 100 bullets go to use:-/.

How do I do it?
:)Can you help me?
---------------------------------
Maybe I can't describe it correctly. I'm sorry.

My problem is:
There are 100 people, shooting at the instantaneous.
Each bullet is an independent data.

Array? It can only be like while.
It is impossible to do parallel computing

raynebc
Member #11,908
May 2010

Pick up a basic programming book. You'll learn about methods to repeat code dynamically (ie. loops).

Ariesnl
Member #2,902
November 2002
avatar

Do yourself a favor, enroll to harvard's CS50 (it's free), than come back ;)

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

keprast
Member #16,794
January 2018

100 objects use the same code at one time.
This inevitably leads to data confusion.
It's not a simple while.

I don't think time difference can make logical synchronization.
This is a thread problem.

Ariesnl
Member #2,902
November 2002
avatar

1 you stuff the bullets into a datastructure ( array, list, vector, whatever)
2 you MOVE every bullet one frame/gameloop..
3 you check for collisions
4 goto 2 until your bullets go out of range

or .. you want to use a single thread for every bullet ? wtf ???

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

keprast
Member #16,794
January 2018

@Ariesnl
Thank you. It's a good way to do it.

I didn't know where the problem was before.:-[Up to now.
I found the key.It is: how to use "frame" decision.timer?

The problem is always so one by one.
For students, teachers are always changing.

Chris Katko
Member #1,881
January 2002
avatar

I already told you in the collision detection thread you posted. ???

I agree with the others, you should definitely pick up some basic programming books or lectures on YouTube / Harvard. If you don't know the fundamentals, you're going to have trouble learning every other part of game programming.

At least spend a couple days learning how to use data structures, arrays, and functions before trying any more game programming.

I'm normally eager to help anyone with a question, but you've got to do your part of the work too and meet us half-way.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

beoran
Member #12,636
March 2011

First, a free book to lean C with:

http://publications.gbdirect.co.uk/c_book/

Then, to answer your question. In programming we normally don't need to have a separate thread of execution per (game) object. The CPU is fast enough to handle updates to thousands of objects in a few milliseconds. So we can do everything in a single thread. The bullets are kept together in a single (dynamic) array, and then we go over them with a loop to update them. This we do in-between drawing the graphics of the game.

Go to: