Computer Science Canada

Making Monsters in a game?

Author:  feebas200 [ 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

Author:  ProgrammingFun [ 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?

Author:  mirhagk [ 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.

Author:  feebas200 [ 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.

Author:  SNIPERDUDE [ 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?

Author:  feebas200 [ 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

Author:  DanShadow [ 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!

Author:  feebas200 [ 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.

Author:  Raknarg [ 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

Author:  feebas200 [ 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.

Author:  Tony [ 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.

Author:  feebas200 [ 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?

Author:  Insectoid [ 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.

Author:  feebas200 [ 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?

Author:  Insectoid [ Sat Jun 18, 2011 7:33 pm ]
Post subject:  RE:Making Monsters in a game?

Stop drawing it?

Author:  feebas200 [ Sun Jun 19, 2011 2:17 pm ]
Post subject:  RE:Making Monsters in a game?

how do I make a save file for my game so that people can recontinue?

Author:  goroyoshi [ Sun Jun 19, 2011 2:34 pm ]
Post subject:  RE:Making Monsters in a game?

http://compsci.ca/v3/viewtopic.php?t=12972
check file input/output
essentially it is using a text file to save a bunch of variables

Author:  feebas200 [ Sun Jun 19, 2011 11:15 pm ]
Post subject:  RE:Making Monsters in a game?

I can get the score to save, but it overwrites the old one each time a new one is entered.

Author:  Tony [ Sun Jun 19, 2011 11:32 pm ]
Post subject:  RE:Making Monsters in a game?

What do you want it to do instead?

Author:  feebas200 [ Sun Jun 19, 2011 11:49 pm ]
Post subject:  RE:Making Monsters in a game?

i want it to make a list of the top 10 scores.
this is what i tried, it would overite the old one each time. I want to make a list of top 10 players.
This is for my final culminating project that is due tomorrow. Please help! Thanks

for i : 1 .. 1
open : stream, "myText.txt", get
get : stream, name (i)
open : stream, "myText.txt", put
cls
put "What is your name"
View.Update
get name (i) : *
View.Update
put : stream, name (i), " " : 10, minutes, ":", seconds, ".", milliseconds
put "Your score will be saved!"
put name (i), " ", minutes, ":", seconds, ".", milliseconds
View.Update
close : stream
end for

Author:  Tony [ Mon Jun 20, 2011 1:34 am ]
Post subject:  RE:Making Monsters in a game?

Nothing in that code suggests that 10 players are involved.

- you need to remember that writing to a file starts from the top, and will over-write previous content.
- "top 10" suggests that scores need to be sorted, to figure out which ones are in that list.

Author:  feebas200 [ Mon Jun 20, 2011 7:40 am ]
Post subject:  RE:Making Monsters in a game?

how will I be able to add code with out overwriting? I tried retrieving the file first so it has the current info and then writing it but it still overites the old text.

Author:  Tony [ Mon Jun 20, 2011 10:02 am ]
Post subject:  RE:Making Monsters in a game?

You are opening a new stream for writing _after_ reading, so that starts at the start again. Besides, this wound't works with variable-sized lines.

Overwriting the entire file is the easiest thing to do.


: