Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
AJay
21
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 23rd Mar 2004 03:54
Im makeing a 2d shootemup game and i was wondering how i can get the enemies to come on the screen and move without them doing the same thing every time.





thanks

P4 3.2GHZ, 256MB DDR Ram, 64MB NVidea G-Force 4, Sound Blaster Live, 40 Gig HD Thanks to Coding Area

oooPSYooo
21
Years of Service
User Offline
Joined: 21st Mar 2004
Location:
Posted: 23rd Mar 2004 04:18
hum...

1. random pop up positions on screen, e.g.
x=rnd(1000):y=rnd(700)
paste image 33,x,y

2. enemies start to move (random direction), e.g.
direction(enemyx)=rnd(3)+1
do
select direction(enemiex)
case 1: paste image 33,x-3,y:endcase rem left
case 2: paste image 33,x,y-3:endcase rem up
case 3: paste image 33,x+3,y:endcase rem right
case 4: paste image 33,x,y+3:endcase rem down
endselect
...
...
...
loop

3. random direction changes, e.g.
x=rnd(5000)
if x=333 then change_direction(enemyx)

cu,
psy


p.s. dont forget to do a randomize timer() at the beginning of your code
walaber
21
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 23rd Mar 2004 04:45 Edited at: 23rd Mar 2004 04:46
are you using DBPro? if so, TYPES are your friend here!



...something like that might get you started... if you are already using Types, then just ignore this!! also, if you implement some of the stuff in the above post, you'll get nice random movement!

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB
zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 23rd Mar 2004 21:47
Another trick it to create random goals and not random movement. When an enemy spawns/respawns, set a random location for them to move to. That way they'll avoid the drunkard's walk of random movement.

To make random goals work, you need to decide on how fast an enemy is and how many 'steps' it will take to get there. Let's say that an enemy always takes 100 steps to reach a goal. If the enemy starts at 0,0 and the random goal is +125,-200, the enemy would only need to move +1.25,-2.0 every loop to reach the goal in 100 steps.

A more sophisticated method would be to make that system timer based and not frame rate based. But, that's another post, if desired. Of course, not all enemy units move in a straight line either. So, advanced units might move in a pattern towards a goal and some units might be able to detect a player and either change course when within a set range or perhaps change their goal to intercept the player.
--
TAZ

AJay
21
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 23rd Mar 2004 22:34
could you give me some example code Zircher



Thanks to all for your help

P4 3.2GHZ, 256MB DDR Ram, 64MB NVidea G-Force 4, Sound Blaster Live, 40 Gig HD Thanks to Coding Area

UnderLord
21
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 23rd Mar 2004 23:35
its easy just set up a random movement if you have movement code for the AI right now then modify it for random movement using rnd() command

The search continues.

Current project - A space game
zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 24th Mar 2004 00:05 Edited at: 24th Mar 2004 00:07
Quote: "could you give me some example code Zircher"


Not yet since I know nothing about your game setup, how you define enemy units, their entry and exit points, how they are stored (arrays and UDTs), etc.

It's not hard to do, but I'd be basically writing the in dark code that would be useless at this moment.

Do you have some code that I can modify or have you not gotten past the design stage yet?

If you're still in the design stage, I strongly suggest creating a user defined type that contains your enemy data. Include fields such as ID number, enemy type, current location X & Y, goal X & Y, and perhaps an IsDead flag and a Respawn flag. All that data can later be used to control your enemy units in a loop so they appear to be all moving at the same time when you SYNC the screen.
--
TAZ

walaber
21
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 24th Mar 2004 04:57
Zircher's idea (as usual) has some sauce!

in basic terms, you'd do something like this:



this in not complete, but should give you an idea of how you could do it. you could also add a variable for NumOfSteps to each enemy, so they don't all reach their goal at the same time, etc etc etc

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB
zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 24th Mar 2004 16:59 Edited at: 24th Mar 2004 17:07
Walaber is on the money, but I want to take the time and reorganize his code to avoid some problems with function declarations...



Just an extra comment here. Walaber uses deltaX/15 and deltaY/15 to determine the step size. This will make units travel at different speeds depending on the distance between start and goal positions. If you want a constant speed, you can use a fixed step size. Pros and cons to each method.
--
TAZ

AJay
21
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 24th Mar 2004 17:05 Edited at: 24th Mar 2004 17:07
Ill take a look at that code and see if i can make heads or tails out of it.
Here is the code for what i have of my game right now. The starts on the screen and when you shoot it, it just disappears.



This is as far as i have gotten, would your example code work with this.

Thanks alot

P4 3.2GHZ, 256MB DDR Ram, 64MB NVidea G-Force 4, Sound Blaster Live, 40 Gig HD Thanks to Coding Area

zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 24th Mar 2004 17:11
Did you want to try and merge Walaber's code before continuing? Also, I noticed that you delete sprites on a hit. It might be better to just move those sprites off screen instead of creating/deleting them all the time.
--
TAZ

AJay
21
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 24th Mar 2004 17:13
ok, ill change my code to move them off of screen, would that make it run faster?

P4 3.2GHZ, 256MB DDR Ram, 64MB NVidea G-Force 4, Sound Blaster Live, 40 Gig HD Thanks to Coding Area

AJay
21
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 24th Mar 2004 17:15
i would like ot merge his code with mine. But i dont really know how to go about doing that.

AJAy

P4 3.2GHZ, 256MB DDR Ram, 64MB NVidea G-Force 4, Sound Blaster Live, 40 Gig HD Thanks to Coding Area

zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 24th Mar 2004 21:01 Edited at: 24th Mar 2004 21:01
Take a look at how I re-arranged it. There is an initialization section, a loop code section, and the functions (usually after the END statement and all the sub routines. Just add the code fragments in one section at a time and make any changes you need to prevent syntax errors (F4). After that, we'll have a good starting point.
--
TAZ


BTW, yes you should gain a little speed by skipping the deletion command.

walaber
21
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 25th Mar 2004 05:21
Zircher - thanks for cleaning up my code, I typed it off the top of my head here at work, and later realized (after looking at your fixes) that it might be confusing for someone to try and implement into a program

if you actually get my code up and running for you, let me know

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB
Jason
22
Years of Service
User Offline
Joined: 20th Sep 2002
Location:
Posted: 26th Mar 2004 00:09 Edited at: 26th Mar 2004 00:10
Hello, I have also started working on a 2d side scrolling shoot em up, I have come up with the typical enemies, Sine waves, point and head towards you etc. But I am now looking to find a program that will let you plot paths with the mouse and dump the results to a text file or something. I have spent a long time searching the net but with little luck.....it's starting to look like I am going to have to write this program myself.
zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 26th Mar 2004 02:30
Well, it wouldn't be that hard to do. One thing to watch out for is button bounce. You would want to add a mouse button delay so you don't have multiple way points every time you click.
--
TAZ

AJay
21
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 30th Mar 2004 18:15 Edited at: 30th Mar 2004 18:32
OK, I just got around to trying to put your code into mine and it would not work. Im not even sure if i did it right at all.



When i try to compile it, it says it could not understand for statement at line 61
I know that i probably did this completely wrong.

Im also having trouble with types. What are they and what do they do?
-AJay-
Thanks

P4 3.2GHZ, 256MB DDR Ram, 64MB NVidea G-Force 4, Sound Blaster Live, 40 Gig HD Thanks to Coding Area

zircher
22
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 30th Mar 2004 18:58 Edited at: 30th Mar 2004 18:59
I'll try to look at the code at lunch time.

Types allow you to organize your data in meaningful groups. It also provides for a cleaner design and includes some syntax/error checking for you. [This can be a life saver.]

For example, you can have separate arrays for each of your enemies:

dim enemyX(20)
dim enemyY(20)

For a complex object with many properties, that can get tedious and if you need to change the array size you have to change it everywhere. With types, you declare the type once and the array once. If you need to edit or add fields, you only have to change the type definition and not the array calls.

Types are similar to C structures and are a big step towards better design and code structure.
--
TAZ

Login to post a reply

Server time is: 2025-05-28 05:20:40
Your offset time is: 2025-05-28 05:20:40