Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 498 499 [500] 501 502 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886421 times)

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7485 on: May 31, 2015, 03:00:36 am »

I think you need to have an endgoal in mind on the type of thing you'd like to create.

Then, work backwards from that and make micro-projects that build up the skills and codebase that will be useful in the bigger project. If you make a bunch of little projects it's often much faster to assemble something more complex later.

For example one goal might be you want to make a roguelike, in which case you'd work on how to make a game using curses for graphics, then look at how you'd represent entities and objects and maps and stuff, making a few simpler games and going on to more complex ones as you go.

If you want basic game projects that can help you learn to code in general, make clones of classic arcade games. Any game programmer worth their salt should be able to crank out Tetris clones etc.

Consider the order: Pong, Breakout, Space Invaders, Galaga, Caterpillar etc. All these games can be built off one engine which you develop as you go, and can be evolved into a top-down bullet hell shooter engine. Bonus points if you extract out the code differences to data and have the specific game rules loaded from a text file.
« Last Edit: May 31, 2015, 03:08:37 am by Reelya »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7486 on: May 31, 2015, 05:11:50 am »

So in Unity (using c#) I have a player space ship which is mostly driven by physics, which instantiates projectiles that move forward using a simple constant transform.Translate. However, when the player shoots in the same direction that they are moving, the ship very quickly outruns the projectile. I'm aware I could probably do some buggery like finding the player object by its tag and adding the player's velocity to the projectile's translation, but is there maybe a less clunky way to do that while still keeping the transform.Translate?
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7487 on: May 31, 2015, 05:27:53 am »

maybe make the bullets faster than your ship.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7488 on: May 31, 2015, 06:40:35 am »

You probably do have to add the player's velocity to the bullet's velocity :v
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7489 on: May 31, 2015, 06:47:39 am »

if you're using transform.Translate, then make velocity variables in the projectile, which you set when the projectile is spawned. you can add the ship velocity component then.

But I think it would be better for gameplay to just give the bullets a set velocity that is just higher than the ship.

DJ

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7490 on: June 02, 2015, 09:53:04 am »

So I'm trying to position a camera to capture a group of objects with no extra space (ie the outermost objects should be flush with the screen edges).  After a week of trying to do it right I've thrown in the towel and decided to look for the algorithm that's normally used for this (it seems like a fairly common situation), but my google-fu is weak. Can anyone point me in the right direction? Additional constraints are that all the objects are parallel squares that are moving on a track in the same direction, and the camera is at a fixed distance from the track's edge. Bonus points if the algorithm can make the objects flush with arbitrary xMin, xMax, yMin and yMax screen coordinates rather than just the edges of the screen.
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7491 on: June 02, 2015, 02:27:46 pm »

You can work it out just using trigonometry. You need to know the cameras FOV angle. Then it's easy to work out how far the camera must be placed to put certain points on the view edges.

First up, are all the objects on a plane? If so that makes the algorithm simpler.

Assuming that everything is on a plane, then the x/y value for the camera will just be halfway between minx/maxx and miny/maxy. The only thing you need to work out then is how high to place the camera (z, if your axes are set up like this), and that's straight trigonometry once you know the field of view angle.
« Last Edit: June 02, 2015, 02:34:03 pm by Reelya »
Logged

DJ

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7492 on: June 02, 2015, 03:02:19 pm »

The camera is at a fixed distance from the track's inner edge (the track is an oval) and it should only move forwards and backwards along the track while facing inwards (ie perpendicular to the line of motion). The moving objects can be at a variable distance from the inner edge, within limits that are less than the camera's distance. I managed to figure out how to find a visual center between two objects (ie a point on the camera's path where the angles to those two object are equal), but I can't figure out which two objects I should be using as reference points. Testing all the combinations and checking which one includes every object in the camera's field of view would be too expensive I think. Oh, and the FoV is variable, it needs to adjust to keep all the objects within it without any extra space between the first or last object and the screen edge.
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7493 on: June 02, 2015, 04:25:51 pm »

Variable FoV doesn't sound like a great idea. That would make background objects veer wildly in scale compared to foreground objects.

I'm quite sure you should use a set FoV angle and move the camera back and forth instead. Either way, you're keeping the foreground objects the same scale (since you plan to scale them to fit the screen), but the variable FoV would play havoc with your backgrounds: it would make background objects look like they were receding or approaching rather than static.
« Last Edit: June 02, 2015, 04:29:04 pm by Reelya »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7494 on: June 02, 2015, 07:22:18 pm »

Trying to add a "shop" to my game where the player can buy stuff for coins. This requires messing with the variable for total coins and total dice (what the player buys from the shop currently) that are saved in the inventory class. Namely, the dice totals increase while the coin total decreases.

I want to make a separate class for shop stuff rather than stuff my whole game in one class but it would probably be way easier to just nest all the shop functions in the already existing inventory class so I can directly change the required variables rather than need to put the variables into the separate class functions as parameters.

But putting everything in one class seems like the easy way out and seems really lame.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7495 on: June 02, 2015, 07:24:02 pm »

Unless you're planning on having that be the only shop thing, I'd roll up something new for the shop instead of having it be part of the inventory.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7496 on: June 02, 2015, 11:25:14 pm »

Heh, I've been trying to upgrade an ancient rails 2.0.2 app on ruby 1.8.6 to Sinatra on Ruby 2.2.2.  Its going well(I love sinatra) but today I ended up copying and pasting a bunch of old rails actionview html/form generation code into a helper so I wouldn't have rewrite a bunch of the app. 

There is no way in hell it should have worked, but apparently it mostly did.   :P
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7497 on: June 03, 2015, 12:40:56 am »

Quote
I want to make a separate class for shop stuff rather than stuff my whole game in one class but it would probably be way easier to just nest all the shop functions in the already existing inventory class so I can directly change the required variables rather than need to put the variables into the separate class functions as parameters.

That sort of sounds like you're passing references around to internal class variables and letting other classes edit them directly. That is not how you're meant to do it.

It might sound "easier" to do everything as one class because they can directly edit the variables, but it's really not any easier from a programming point of view. Typing up class and function headers is trivially quick to do.

Trying to rewrite shop code that's directly embedded in your inventory class would be a slow and laborious task. Say you wanted two types of shop later. Are you going to double-up on the shop code now? Since it's hard-coded you'd have to duplicate all your buy and sell commands and manually edit what they buy and what they cost.

Whereas if you wrote them separate from the start and created some sort of struct for a "sale item" (including cost and what you get), then adding new sale items and new shops would take a couple of seconds to create. You'd make a struct for a sale item something like this:

struct sale_item
{
   string text, description;
   int cost;
   item_type item; // item_type would be an enum used by the inventory class
   int amount;

   sale_item(string _text, int _cost, item_type _item, int _amount, string _description):
       text(_text), description(_description), cost(_cost), item(_item), amount(_amount)
   {}
}

^ text would be the menu label, description a detailed text that you get when you're over the item, cost is the cost in gold, "item" is a reference to the item type you get and amount is how much you get.

You could then implement shops as just an array of sale_item objects, and you could used sale_item[0]'s text and description as the name / description of the shop. Because I included a constructor you can just write the shop as a table like this example ...

sale_item food_shop[] =
{
   sale_item("Food Shop", 0, item_null, 0, "A shop that sells food"),
   sale_item("Bread", 5, item_bread, 8, "8 bread rolls"),
   sale_item("Meat", 15, item_meat, 4, "4 chunks of meat")
};

That will do the job, then you just have to write some menu code to display the shop things and let you pick stuff, and code to send changes to the inventory class. The code is pretty compact and clean and you can edit the needed things as data now.
« Last Edit: June 03, 2015, 01:03:06 am by Reelya »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7498 on: June 03, 2015, 01:01:38 am »

Just tell me you're not actually passing references around to internal class variables. That should never be done. It's not needed and it breaks the entire point of having object oriented programming.

Internals of the class always stay internal, and ideally you only expose the interface.
I am rubbish at remembering proper terms and vocabulary for programming. No I wasn't planning on passing references to class variables.

By internals you mean the variables defined in the class and used in the class? What do you mean by exposing an "interface"?

While typing this I realized I could make a separate shop class with functions and pass the variables defined in main to the shop functions. In theory. Haven't tested it. This isn't the same as passing references like what I posted earlier in the thread, is it?

Spoiler: psuedocode (click to show/hide)
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7499 on: June 03, 2015, 01:05:13 am »

the interface for a class is just whatever stuff you make public for other things to manipulate it.

It's what the client needs to know. One of the core design principles is keeping that public stuff as simple as possible. By only exposing functions instead of variables you also ensure that you can change the internals of a class later without breaking all the connected code.
Pages: 1 ... 498 499 [500] 501 502 ... 796