• Create Account

Banner advertising on our site currently available from just \$5!

Misc questions

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

#1nesseggman  Members   -  Reputation: 370

Like
0Likes
Like

Posted 16 December 2012 - 12:52 AM

#2Servant of the Lord  Crossbones+   -  Reputation: 23931

Like
4Likes
Like

Posted 16 December 2012 - 01:36 AM

Q1: Is using a giant list of if/else if statements or a giant switch ever a bad idea?
Like, is there another way to go about checking for many conditions?

Not "bad" as in, horrible, but there are better ways. I'd suggest looking up state machines and game states.
States often boil down to if() statements or something similar anyway, but they are much easier to maintain and expand, and are easier to manage in a large project.

For example, I was imagining creating a pet game in which you play through days which are like turns. You can do things during the turn in any order, but at the beginning of the day, you will be updated on the pet's status if there is a trouble or curiosity. There may be many troubles like... sick, injured, run away, stressed out, tired, grown up, angry, acting strangely, the pet's birthday, etc etc etc. Is there a better way to check for these other than a giant else if list or something similar?

Yeah, sounds like 'states' would be your best bet. The time of day might be a state, and the pet's status would definitely be a state. And the current player interactions might be managed by a "gamestate", which probably has its own logic (taking into account the states of the different objects in the game).

Also, is it very draining on resources to use a giant case list like this, or is it really no big deal and I'm overthinking it?

Don't worry about resources or optimization until you actually encounter a slowdown; then you can profile and find out where the slowdown actually is.

Q2: How would you implement something to tell if the user is "petting" on the pet, for example, you could have pets of many sizes and the "petting" is clicking and holding a click, then moving back and forth at least two times across the pet's head area. The pet could also be moving around so its location is very dynamic. I figured use some kind of collision detection with a cursor to tell if you are clicking in the head area but I don't know really how you would go about recognizing that you are moving left and right without letting up (and not accepting up and down movements, circle movements, etc.).

Hmm, that would be an interesting challenge for myself as well. Here's one possible way that comes to mind: I'd use a "mousemap" for the creature's sprite. This would be a hidden image that the player can't see, but that the program "sees". It'll be invisibly "overlaid" over the monster's sprite. I'd assign each body part of the creature a specific color, then when the mouse is over the creature, I can find what (invisible) color is under the mouse in the mouse map. For example, the left ear might be red, the right ear might be green, and so on. This way the game knows whether you clicked on the creature's ear to whisper something to it, clicked on its mouth with food to feed it, or clicked on its head to exercise it.

Example mousemap I just slapped together: (Ignore the white flecks of pixels that I missed)

Creature sprite | Mouse map

(I'm just using this image as an example. If you actually use Pokemon, Nintendo will sic their lawyers on you faster than you'd think possible)

The same applies to 3D, except you texture your 3D model with solid colors.

You'll need a mousemap like that for every normal movement frame of the creature's animation (you can skip special animation frames, since you probably don't want the user interacting with the creature during those frames anyway).

Now, since you want to find out if the player is "scratching"/"petting" the head, I put the head into three colors: the left, the right, and a thin buffer in the middle. Now all we need to do is:
• When the user clicks the mouse, find out if he's over the creature at all.
• If so, set "touching creature" to true.
• As he moves the mouse back and forth, if he touches the left or right side of the head, set a variable to that side of the head.
sideOfHeadLastTouched = LeftSideOfHead;
• As he moves the mouse, if he crosses over and touches the other side, you do this:
if(sideOfHeadLastTouched == LeftSideOfHead)
{
timesScratched++;
}
sideOfHeadLastTouched = RightSideOfHead;
• If 'timesScratched' goes above a certain number, say, three, then the user is officially "scratching"/"petting" the creature.
• When the user lets go of the mouse, 'timesScratched' and 'sideOfHeadLastTouched' get reset.

This seems kind of advanced for me.

At first it seemed advanced to me too. But like all advanced problems, if you think of the individual pieces of what you need to accomplish, it's easier to find a solution.
(Piece A: Find what part of the body the mouse is over. Piece B: Figure out how many times the mouse goes between two points on the body)

And lastly, Q3: I am going to be downloading Unity soon as I just got a new computer and would like to try it out. I was wondering, how easy is it to create a project for one platform in mind (for example, windows exe) and then use the same project to make another platform version (like iOS)? Is it as simple as a Save As... or is there a lot more involved? I'm sure this answer is available easily somewhere but I don't really know what to call that so I don't know how to search for it.

It's called "cross platform". I don't use Unity, so I'm not familiar with it. However, even if there was a "Save as iOS" option, it wouldn't be able to figure out in what way mouse controls should change to touch controls (which are wildly different) or in what the GUI should change to fit on the smaller screen. There will still be at least some work you'll have to manually decide.

sorry for giant paragraph... I really wish pressing enter would work (it works everywhere but in this text box...)

Odd. You ought to report that here, with your browser version and OS, because enter should work in the text box (it works for me on Google Chrome).

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

[Need web hosting? I personally like A Small Orange]

#3nesseggman  Members   -  Reputation: 370

Like
0Likes
Like

Posted 16 December 2012 - 02:00 AM

Thanks a lot! The mousemap actually seems very simple to me, now, too. One of the things I love about programming is the more I learn about it, the more I realize it is always pretty simple/easy. Sometimes if you are thinking about a problem the wrong way, you can get stuck or frustrated, but the solution ends up being pretty simple in the end. I tell people I am teaching myself to program and they say "Wow that sounds so hard" but I want to say "It's really easy when you really start trying" but they think I am bragging that I am smart or something. Anyway, your solutions are very helpful and I was planning on learning about states next since it seems to be where everything is pointing anyway (to make bigger games/projects than simple board/number games and stuff). Even though I'm sure I'll learn about it, but is it easy to implement having more than one condition state for the pet? Like it could have its birthday, be stressed out, and have an injury all at the same time (... what a sad birthday...) Well, I'll figure it out. And I will go report that. I am using IE10 (it's like... 10.0.9something something) and Windows 8. In case you were curious O_o;; Thanks again!

#4L. Spiro  Crossbones+   -  Reputation: 17855

Like
0Likes
Like

Posted 16 December 2012 - 02:04 AM

I also want to note that when I press enter in this text box, it does not make a new line.

Hold Alt and on the number pad hit 013, then release Alt.

L. Spiro

#5Nypyren  Crossbones+   -  Reputation: 6540

Like
0Likes
Like

Posted 16 December 2012 - 03:43 AM

You can work around the IE10 enter key bug by hitting the 'Toggle editing mode' button on the reply box (it's the the upperleftmost button). The enter key works properly in the raw editing mode.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS