Home > iphone > How do I randomly create and store enemy data for my iPhone game?

How do I randomly create and store enemy data for my iPhone game?

February 15Hits:3

In my game you need to protect something from enemies. There can be many on the screen at once. But I don't know how to create the enemies randomly, and how I can save the data to each enemy? Can give good tips or good links to tutorials?


In short:

  • To generate random numbers use rand()
  • To keep track of enemies make arrays/lists of them


You can use the rand() function to generate random numbers. You could use these random numbers to set the position/health points or any other attribute or your enemies.

As for saving the enemies data (I'm assuming you just mean store the variables, correct me if I'm wrong) you need to store the data in an array or list. This can be done in many different ways.

If your enemy is a C-Struct then you can store your enemies in a plain C-Array. If your enemy is implemented as an Objective-C class, then you can store your enemies in a NSArray class (such as NSMutableArray).

Simple thing that you can do is iterate for few times for each enemy generation with the 'rand' function such that the generated values are at a specific distance(MINIMUM_ENEMY_DISTANCE_FROM_PLAYER) from the player.

something like this...

    #define SCREEN_WIDTH 480      //just assuming Landscape mode
    #define SCREEN_HEIGHT 320
   for(i from 1..100) // 100 is some random number-for number of iterations
       enemyPositionX = arc4random()% SCREEN_WIDTH ;
       enemyPositionY = arc4random()% SCREEN_HEIGHT ;
       if(distanceToPlayer(enemyPositionX,enemyPositionY) > MINIMUM_ENEMY_DISTANCE_FROM_PLAYER)
   //Now use enemyPositionX , enemyPositionY as spawn points for your enemies.

Other option can be... If the enemies generated are moving enemies,you can have some predefined spawnpoints and generate from that positions.You can have a check of this kind of game something like 'Robokill'.

I got a tutorial in my blog about how i made bomb rush that is basically protecting the base from some enemies, it's as3 oriented but the enemies generation concept is the same.

Here is a link to it BliipStudio

Hope it helps you.

If you look through the tutorials at this link, you will find ideas for creating enemies, storing their data, etc.


Related Articles

  • How do I randomly create and store enemy data for my iPhone game?February 15

    In my game you need to protect something from enemies. There can be many on the screen at once. But I don't know how to create the enemies randomly, and how I can save the data to each enemy? Can give good tips or good links to tutorials? -----------

  • Word randomly creating file called EnglishOctober 3

    2nd Revision since I'm getting new information on this problem. Word is randomly creating a file called English in places that a Word document has been opened or Saved to. This includes network drives and local drives. One person says that the Englis

  • Allow users to create and store data and retrieve it on loginSeptember 10

    I write a wedding blog and would like to allow the subscribers to login and be able to create and save their own wedding guest lists. The data they store, should be retrievable on future login to the site. I would like to know if this functionality w

  • Guest user randomly created on my Mac, after setting up Find My MacJuly 17

    How do I disable the guest user? Is there a reason why it gets created? It won't mess up any of my files or data on my computer right? Is find my Mac suppose to randomly create it? --------------Solutions------------- With Find My Mac enabled, someon

  • Ideal database to store/query data submitted through dynamic user created formsSeptember 30

    I am designing a web application that allows administrators to create public facing forms. The fields that can be included in the forms are anything from text fields to radio buttons. I need a solution that allows the users to filter through form sub

  • What is a good way to store tilemap data?

    What is a good way to store tilemap data?November 11

    I'm developing a 2D platformer with some uni friends. We've based it upon the XNA Platformer Starter Kit which uses .txt files to store the tile map. While this is simple it does not give us enough control and flexibility with level design. Some exam

  • Securely store session data in cookiesAugust 8

    I'm trying to create a stateless application server architecture and I would like to store session data in cookies. All pages using the session would be served over HTTPS. I was planning on using AES256 to ensure the client can't change the value of

  • How to store private data both securely and publicly accessible?December 14

    The task may not be solvable in as broad a formulation as in the title, but this is my scenario (which is somewhat similar e.g. to newsletter subscriptions and therefore certainly has already been thought about) I want to implement a database on a we

  • What is the most efficient way to store this data?December 16

    I am in charge of rewriting some old VB code. I understand how it works, but I feel like there is a far-more efficient way to do what they did. I just can't figure out what it is. Here is a contrived example that in terms of data requirements is real

  • Store Temporary data of Posts IOS Swift March 27

    I'm looking into building an application which works just as well offline as it does online. Since the application cannot communicate with the server while in offline, there is some level of synchronization which needs to take place. What are some go

  • Using LDAP to store customer dataFebruary 10

    We wish to store some data in 389 Directory Server LDAP that doesn't fit that well into the standard set of schema's that come with the product. Nothing too amazing, things like: when the customer joined are they currently active customer certificate

  • store simple data in get_option()October 18

    I am trying to store simple data, a few links inside wp_options. Basically using the following way: update_option( 'simple_links', '<a href="">link 1</a>' ); my question is if it is allowed, I dont want to create new table for it, ju

  • Is this a good way to store XML data in SQL SERVER 2008?October 20

    I'm doing a feasibility study for storing data in the following structure with SQL SERVER 2008: -MYTABLE |ID|RECORDS|BRANCH_OFFICE|MONTH|YEAR The RECORDS column has the XML data type and it will look like: <visits> <visit id="000112233"

  • Is it possible to store arbitrary data in an image file?November 15

    Is it possible to store arbitrary data such as documents or a program in the form of an image file, such as a PNG image? My concern is that someone could encode data for use by malware into an image and upload it to a site like Flickr. --------------

  • What "tool" to use for monitoring instances and where to store this data?January 19

    I have three SQL Server instances in my DW project, development, test and production. I also have two SSIS servers (dev/test, production). My intention is to query data from these three SQL Server instances for monitoring purposes. My problem is what

  • What's a good way store borehole data in SQLite / SpatiaLite?March 18

    I have a bunch of bores / wells with downhole data. The 'header' info for each borehole can easily go into a single table, but I'm wondering how best to store the downhole log data. Typically they are stored in spreadsheets as semi-continuous depth-v

  • How to check for a key *and* store encrypted data?April 18

    I wish to create a system wherein I store encrypted data. Users can access this data if they have the key. If they give a wrong key, they don't get access at all. If they give the right key, they get the data, and they may modify that data. One idea

  • How to store a date without the year componentMay 25

    I have to store climate (temperature) data for a few cities. This would mean that each city will have 365 values (ex: The value for Jan 1, is the average temperature for that city for all Jan 1 for 50 years (1955-2004). Hence I am not at all concerne

  • How to store raster data in spatialite?June 23

    I want to cache my raster data(large geotiff files) on local database. I thought to use spatialite. I found librasterlite which provide functionality to do that. Can anybody point to some tutorial on it. Or is there any other alternative. Programming

  • Store User Data Using Simple Text Files and APIs in Android

    Store User Data Using Simple Text Files and APIs in AndroidAugust 20

    Android apps have a wide variety of features, functionalities, and purposes. These various Android apps require similarly varied support from Android system APIs. Many apps require storing data in short-term memory that lasts only as long as the app

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 1.028 s.