Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Making Monsters in a game?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
feebas200




PostPosted: Wed Jun 08, 2011 9:09 pm   Post subject: Making Monsters in a game?

Hey there,
Well, what I'm trying to do is to make monsters in my 2d game with gravity it (similar to mario) The problem I'm having is making monsters/objects that move around or jump eg.Shrooms walking around in mario. Can anyone please help me out on how I could accomplish this? I need to make a game for my final project. I've looked into randint but haven't found much. I hope someone helps. Thanks in advance Smile
Sponsor
Sponsor
Sponsor
sponsor
ProgrammingFun




PostPosted: Wed Jun 08, 2011 9:13 pm   Post subject: RE:Making Monsters in a game?

Do you have any code so far?
Is there any specific part you are having a problem with or do you need general algorithms?
mirhagk




PostPosted: Wed Jun 08, 2011 10:27 pm   Post subject: RE:Making Monsters in a game?

Sit down and ask yourself these questions:
What will these monsters do?
When will they change what they do?
Can you code what they do and when they change what they do?

Then sit down with a piece of paper, solve these questions, and come up with a plan of what you want to do. Then we can help you figure it all out.
feebas200




PostPosted: Thu Jun 09, 2011 5:48 pm   Post subject: RE:Making Monsters in a game?

I just want them to walk back an forth or up and down, an example would to make an oval drawn in during move back and forth. I got the part of when you touch it you lose hp but I can't think of how to make it move a certain direction back and forth constantly or even jump up and down non stop.
SNIPERDUDE




PostPosted: Thu Jun 09, 2011 6:14 pm   Post subject: RE:Making Monsters in a game?

So the creatures need some type of AI. So think about how it moves, and make it automatic for each frame.
Example (in this case a side-scrolling game):
- x velocity is -5 (moving left at a speed of 5)
- if character + velocity (-5) = wall, velocity *= -1 (reverse by multiplying by -1)
- cycle through check and location update.

Is this a side scroller, or top-down view?
feebas200




PostPosted: Fri Jun 10, 2011 8:22 am   Post subject: RE:Making Monsters in a game?

right now it's only a full map amd you can see everything. Kinda confusing
DanShadow




PostPosted: Sat Jun 11, 2011 2:02 am   Post subject: RE:Making Monsters in a game?

Well, seeing as its Turing im guessing you don't need/want to implement anything complex such as behaviourism, and judging by the fact you said it can move up/down/left/right im guessing your screen is drawn as top-down or isometric.

My recommendation would be that your monster moves in a random direction, for a random amount of time, then change to another random direction, for a random amount of time.

For example (pseudo-code):

Quote:

if (monster_is_moving = false)
{
direction = randomInteger(1..4)
//1=north, 2=south, 3=east, 4=west
distance = randomInteger(1..4)

monster_is_moving = true
}


if (monster_is_moving = true)
{
if (direction = 1)
{
monster_y += 1
}
else if .... etc

//Track the distance the monster has moved
distance -= 1
}

if (distance = 0)
{
monster_is_moving = false
}


This is basic random monster movement logic.
He will pick a random direction, and move in that direction for a random amount of paces. Once he has moved that amount of paces, he will switch direction and move a random amount of paces.

With enemies (such as mushrooms) in Mario, they generally only move in one direction (left, opposite to the direction of level progression in that side-scroller) until they collide with an object, to which point they turn around.
This type of behavior is that an enemy will essentially travel between points A and B, where these two points are objects to the left and right of the enemy (objects which the enemy cannot move beyond, so must move between).

Hopefully this gives you more of an idea how you can develop your monster behavior.

If you want to do something more complex, you can add other behaviors such as, if a player moves within a certain radius of the enemy (aggro radius), the enemy will change direction and chase the player until the player is out of range (monster view radius).

Good luck!
feebas200




PostPosted: Thu Jun 16, 2011 4:03 pm   Post subject: RE:Making Monsters in a game?

I don't really know how to use randomint in this way for monsters. Can someone help me out.
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Thu Jun 16, 2011 6:39 pm   Post subject: RE:Making Monsters in a game?

I'll convert that to Turing then:
Turing:

if monster_is_moving = false then
     direction := randomInteger(1, 4)
     %1=north, 2=south, 3=east, 4=west
     distance = randomInteger(1, 4)
     monster_is_moving = true
end if


if monster_is_moving = true then
     if direction = 1 then
          monster_y += 1
     elsif direction = 2 then
          monster_y += -1
     elsif direction = 3 then
          monster_x += 1
     elsif direction = 4 then
          monster_x -= 1
     end if
     %Track the distance the monster has moved
     distance -= 1
end if

if (distance = 0) then
     monster_is_moving = false
end if
feebas200




PostPosted: Thu Jun 16, 2011 9:50 pm   Post subject: RE:Making Monsters in a game?

thank you very much for the help, but for the randominteger variable do I declare it as an integer? It didn't work when i tried that. I also tried array of integers.
Tony




PostPosted: Thu Jun 16, 2011 9:56 pm   Post subject: RE:Making Monsters in a game?

You are not supposed to copy-paste the code in; it's really meant to just be an example for you to get ideas from.

To generate random values, read the documentation for Rand.Int; it has working examples too.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
feebas200




PostPosted: Sat Jun 18, 2011 5:12 pm   Post subject: RE:Making Monsters in a game?

thanks for the help everyone, everything is working out great except how do I make it so that monsters will die when u jump on it or press a button in front of it. Should i use whatdotcolour?
Insectoid




PostPosted: Sat Jun 18, 2011 6:37 pm   Post subject: RE:Making Monsters in a game?

What do you want to use whatdotcolor for?

code:

draw.dot (5, 5, black)
if whatdotcolor (5, 5) = black then
    kill_enemy_procedure
end if


Hrmm, no, I don't think that will work.

You need to figure these things out on your own. It's all related. Keyboard input is related to AI, which is related to firing bullets, which is related to killing NPCs. By related, I mean, it's all coded almost exactly the same.
feebas200




PostPosted: Sat Jun 18, 2011 7:29 pm   Post subject: RE:Making Monsters in a game?

how exactly do I remove the mosnter from my screen when it dies?
Insectoid




PostPosted: Sat Jun 18, 2011 7:33 pm   Post subject: RE:Making Monsters in a game?

Stop drawing it?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 23 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: