Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
I've been using pygame for a roguelike I've started to develop and notice a little flickering everytime I update the screen. I might take a look at pyglet.

As for windows binaries, py2exe has been my best friend for showing off my work to my brother. All you have to do is write a small 10ish line setup.py file and then go to console with: "python setup.py py2exe"

It builds a distribution folder with all dependencies taken care of. My brother unzips the folder I send him and double click my .exe

Adbot
ADBOT LOVES YOU

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

more falafel please posted:

Either you're running that on a 386 or the problem is not with PyGame, it's with your code.

Could be the code, but seriously, it's like 150 lines of code max. All I'm doing is placing strings on a surface, blit, and flip. Am I missing something to cut down on the flicker?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

poemdexter posted:

Could be the code, but seriously, it's like 150 lines of code max. All I'm doing is placing strings on a surface, blit, and flip. Am I missing something to cut down on the flicker?

Figured it out. I was creating a new Surface everytime I wanted to print something to the screen. I moved my Surface initialization to my __init__ and reuse it to print to screen. Flicker gone.

quote != edit

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
I'm not sure this goes in here but I'll take a stab. I've currently been modding minecraft using a plugin system introduced by another user who rolled his own API for this game. I've written some pretty cool stuff like floodgates, hearthstones, fishing, and an in game economy.

The problem is that I know poo poo all about game design and I'd really like things to be balanced. Are there any really decent texts on the game design aspect? I want the game to be fun but I don't want users to play for 8 hours and end up with a boat load of cash. My in game store really isn't pulling as much money out of the world as I thought it would.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

hayden. posted:

Give me your email, I got stuff for you.

:woop: poemdexter at gmail

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

pseudorandom name posted:

When they have a boatload of diamonds and steel and whatnot spawn an army of Creepers.

When your players complain, explain that the point of Minecraft is to beat the hubris out of them.

If they keep whining, point out that the Turtles in Time arcade machines would explicitly kill you with a giant bomb if you managed to survive for more than 5 minutes in order to suck the quarters out of you.

An excellent suggestion, but I was looking for more balancing suggestions instead of just killing everyone on the server. I can already spawn creepers at people's positions modded in.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

The Cheshire Cat posted:

Thanks for this link, it's exactly the kind of thing I was looking for!

If you're going the python route, look at the pygame library. It's a handy library for handling windows and buffers and drawing. More pertinent to you is the fact that you absolutely can write a roguelike in python since I've already done a very very very proof of concept type thing in college.

http://roguebasin.roguelikedevelopment.org/index.php?title=How_to_Write_a_Roguelike_in_15_Steps

I'm still searching for a cool written guide on how to generate a dungeon dynamically that I used. It has no code examples but just outlines the techniques you need to use.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Mustard Snobbery posted:

Perhaps this is what you were looking for?
http://properundead.com/2009/03/cave-generator.html

While equally awesome, this was some wiki page or something that had like X amount of steps to create a roguelike dungeon. It drew hallways and then created rooms. I can't find it to save my life. :(

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Me and a buddy are working on a multiplayer asteroids game together for fun using XNA. We've really never ever messed with netcode before and are really completely lost as to what best practices are for what data the player should be sending to the server. We plan on having a dedicated server. So far we kinda think the client should send it's new position vector to the server, but we're not sure if we should take it a step further back and just send the server keyboard input. We figure we'll use UDP but we just need some simple documentation/book/blog posts/etc just to get us started.

Our most pressing questions would be:
1. For a very simple asteroids game, what should the client be sending the server?
2. What is ok for the client to handle and what should the server handle?
3. I assume we should be limiting the packet sending somehow in the main game loop so it's not pushing packets out as fast as the game loops.

Another generic XNA question would be does the XNA library handle timing by itself natively? As in, will we need to add some timing functionality so that the clients run at the same speed across all hardware?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

PnP Bios posted:

I've been working on a 2D graphics library in C# that will work well with OpenTK. I'm fine tuning the sprite batching, but the cool thing about mine is how it handles drawing the sprites.

The idea is to make calls that look like this.

code:
_context.Draw( sprite.Translate(64,64));
_context.Draw( sprite.Translate(512,512).Scale(1.5,1.5).RotateCenter(30));

or

_bakedSprite = sprite.Translate(512,512).Scale(1.5,1.5).RotateCenter(30);

_context.Draw( _bakedSprite);
If anybody is interested in trying it out, here is the codeplex for it. http://mannagum.codeplex.com/

http://mannagum.codeplex.com/releases/view/66880 -- release files

There is documentation, and the sampler project contains a few examples (switch screens by pressing 1-3)

Thanks.

I really like this idea instead of having a draw method that is overwritten like 7 times and takes anywhere from 1 to 9 parameters.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Another game networking question.

We want to keep the game logic seperate from the networking logic So our dedicated server will create 2 threads, a networking thread that handles incoming and outgoing messages and a game logic thread that will handle each tick of game and updating objects in the game. The two will talk to each other via event handlers/delegates. This is all XNA/C# with the libgren lib for networking (not using the built in networking since we aren't doing GFWL).

My question is this:

Is this the best way to do a dedicated server? We've been looking for dedicated server architecture examples or tutorials or blog posts or something, but we're coming up short.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Paniolo posted:

I don't see that working very well. Not only would you need locks everywhere but you would need to code your entire game engine with the assumption that state can change at any given time which is pretty much impossible. Look into using buffered states or message queues instead.

each thread would use events to fill each other's message queue. How's that?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

OneEightHundred posted:

What kind of game is this?

It's multiplayer asteroids with a dedicated server and clients that act like dummy terminals sending keyboard inputs to the server. I understand the architecture of how things work. I'm actually just looking for implementation guidelines/best practices.

Server with 2 threads? Server with no threads and 2 objects inside a loop? Event handlers for recieving messages passing messages between objects or just straight up call a updateGame() method passing what I'm parsing from messages?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Twernmilt posted:

You don't need to lock anything if you use message passing to have the network and game logic communicate and avoid mutating those messages, which isn't difficult. It sounds like that's what he's doing with handlers.

poemdexter: If you find any good guides, be sure to post them here. I've been pretty much winging it because I can't find any solid examples. I've been piecing things together from Valve's wiki about the networking infrastructure in Source and blogs.

I saw that wiki as well! I understand the why for networking, just need a little guidance on the how.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Right, so for just the Server part, would you separate your two parts listed into separate threads with messaging? Would you mash them together inside one object and just handle inputs as fast as possible while ticking and updating players?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
I guess a better question would be how would YOU implement a dedicated server? What classes/objects/threads/etc would you create and how would the interact with the client and each other?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Money.

That's just the sort of thing I was looking for. I guess we needed to dip a little deeper into exactly what goes into networking games. This stuff is pretty complicated! You've been a tremendous help 1 800.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
XNA? Things are simple enough and then all you'd do is a matrix transformation to jerk your camera 45 degrees for the isometric part.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
http://blog.spacestro.com/

There. You guys have convinced me to do it. We just hit milestone 2 which was too god drat long and we didn't feel like refactoring at the end. :saddowns:

However, for milestone 3, we're just going to implement a small amount of features so we're not bogged down with too much and still have the mental fortitude to clean up code. Here, have a screenshot.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

The Fool posted:

Isn't that also an issue with java? And any other language that uses "virtualized" machine code?

(i'm not 100% certain i'm using the correct words, or even understanding the technology)

You are correct.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Physical posted:


The thing I am getting hung up on is I cant do
code:
if( Pangea.ContainsKey(_x) && Pangea[_x].ContainsKey(_z))
Because the [_x] entry must exist before I can check if _z exists, otherwise a runtime error gets thrown. This kind of thing comes up at other times too so I'd like to know a better way to format the if/elses without using break;/continue; or some variable that tells me if both things passed/failed


Is this true? I thought if the first statement was false then it didn't bother to check the second statement after a && because the whole thing is false if the first statement is false. I do this in javascript all the time to save time doing validation. Is this not true in other languages?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Physical posted:

Oh cool. Well how would I do it if c# wasn't so nice.

Basically what you posted as "want to avoid."

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Physical posted:

Oh cool. Well how would I do it if c# wasn't so nice.

edit: Wait || would have to evaluate either wouldn't it since it returns true if either entry returns true?

True if either entry returns true, but remember if the first is true, why even bother checking the second? It's a waste of resources.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Physical posted:

Oh ya durp I was only thinking of falses.

Really? Isn't there a slicker, more efficient way to do it that someone smarter than me came up with forever ago?

Yes, the statement you were hung up on. Are you looking for the magical 3rd option that isn't the efficient way or the nested if statement way? I'm sure someone can write a one line zinger that uses threads and flipping bits or something. :pwn:

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Physical posted:

I want them to both share the same else statement. Like if there is a failure it collapses to the same else (kind of like a switch statement without a "break;" for a couple of the cases in a consecutively.

I guess a "try/catch" would work since if there is a failure the same catch expression can be run on both.

edit:

I mean in the context of a language that doesn't support that like C++ or maybe AS3

Bah, don't use try/catch like that. Really, the "hung up" code is the best since it fills your requirements of "on false of either, go to else". I'm interested to know if ANY language actually executes both statements in an && or || situation where the first statement is false or true respectively.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Rocko Bonaparte posted:

More questions about my favorite topic in this thread: component-based design. I now have entities and components and they're working together for the most part. I foresee some dependency problems though. I have one component that represents position and some other components are interested in position within the entity. I define the position first, so I get lucky here, and I also try to make sure any components relying on information from other ones will not fall apart if the information is not there yet. I wondered at a more general design level if there's something better I could be doing.

The one thought I had was each component would get a message when there were live. At that moment they then should be able to get all the information they needed. I can think of hypothetical situations with things like circular dependencies where this still might not work.

At this point I think it's not really worth the effort to worry about though. Where I think problems might show up is when I get entities loading from templates. There I don't think I can always guarantee a safe order anymore.

You can always force a certain order when loading from templates.

Also, most of the components that need to know about each other can be handled with the actions. So player.do("TakeDamage", 5) would do the TakeDamage Action which would go through and modify the player HP component as well as take into account if the entity has a shield or resistances or whatever other components. And all of that is just if this.getComponent("Shield") != null.

For other dependency issues, you could create managers like a Collision manager that would fire off the needed actions that modify velocity, acceleration, and HP for collided entities on impact. So instead of trying to fire off these yourself, you can have a manager have a method called checkCollision(entity a, entity b) and then handle all your dependency stuff inside so the components never need to worry about other components since that's the method's job to make sure they exist or handle cases where something might not exist.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Hughlander posted:

One consideration for that specific issue though not the problem itself. Many proponents of an entity system place the position in the world in the game object, not in any of the components. I remember reading one paper where it was basically "Position, and list of components" was the entirety of the object.

Interesting. But what about inventory items? Or NPC chat messages, or things that don't require a position?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Rocko Bonaparte posted:

More component-based design stuff, but I think this is more in the fun realm than anything else. I was curious for some examples of how people are splitting up things into components.

For a basic human-controlled character right now I have something like:

Health: for managing health. It services requests for taking damange or getting healed, and emit a death dignal if the player is considered dead.
AnimationState: for mapping movements to frames of some kind. This stores whether to player is walking, running, slumping backwards, and whatnot.
Position: for position, but this is an interface implemented by a PhysicsPosition which knows to interact with the physics engine for the most up-to-date. There's a stub one for dealing with positions not in the physics engine.
Facing: which pretty much just stores where the entity is facing
Velocity: like facing, but for movement, and this is tied to the physics engine.
Faction: Which side they're on, who are their friends and enemies.
HumanControl: Translating controller messages into movement and facings. This emits signals that a lot of other components listen to. For example, Velocity would takes signals for movement and try to make good on them.
AnimatedMesh: To be added, since AnimationState manages the mesh too much right now.
Physical: Physics information like mass. This interacts directly with the physics subsystem, but takes a lot of stuff from other components.

I intend to add something like a GhostPhysics for bounding boxes and such for thinks like melee and ranged attacks, but I haven't scribbled them out yet.

Is this looking like the right idea?

With your components you have actions right? Should probably discuss both. My setup is similar to yours but my game is a roguelike so no need for much physics.

Health: Hp yah, has actions that heal or take damage.
AnimationState: This is a biggie for me. It stores the sprite or sprite sheet for the character as well as the direction it's facing. Also says if it's animated and if it loops (torches on walls flicker). So a player moving in the opposite direction will have it's sprite flipped so it's facing the other direction.
Position: Pretty standard. Has actions to change position by delta (move up 1) or completely move (teleport).
HumanControl: This is something I might look into later. Right now I let XNA's keyboard stuff worry about moving and just tells the player entity to do an action for the position component. Of course my only keys at the moment are up,down,left, right so this might get changed later.
AI: Mobs have a component for the A* pathfinding. the action is "MoveTowards". It takes an argument of the target position (in case i want mobs to pick up gold and not just steam towards player). The action will actually do the pathfinding and the tell the position component to move.

The next part of development will be the actual combat so I'm sure I'll have weapon and armor components that will talk to the HP component to determine actual damage taken.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Staggy posted:

I gave a component-based system a go after seeing your earlier posts poemdexter, and it was fun - until I got things all tangled up together.

I do have a question: is there any advantage to using "smart" actions and "dumb" components? I was doing things the other way around - messages were simply an ID string and some data (a position/float/etc.) passed to each component. Each component would then check the ID string and - if it was one they needed to react to - do something with/about the data.

When I create the entity, I add components and actions. That way when i say player.Do("TakeDamage", 5) the action does all the important stuff. And by important stuff, I mean the action will go through the entity checking for other components it might need to determine what kind of damage it will actually take. This keeps components separate from one another so that no component needs to know about another component. The actions do all the heavy stuff.

If you're talking about messages across all the entities, I have an entity manager for each level of the dungeon. In this manager, I have a dictionary of doors and door locations. I also have a list of monsters and a list of items on the ground. If the player moves, then I just enumerate the list and tell each entity which action they need to take depending on what state they are in.

I think this answers your question. It doesn't seem you have actions like I do to go along with your components. Just some messages with an id that says "do this if you see this string". But then you run the risk of having components being dependent on other components to do things.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Your Computer posted:

I don't really "get" component systems (because I've never seen them used, and never tried it myself), but I don't see how it's easier to do string parsing and error-checking then delegating method calls to different components instead of just subclassing and calling, say, 'player.takeDamage(5)'.

It'd be fun to try a system like that though. Any good tutorials (and not just talks about what it is/why it's the best/XNA)?

I see it as more of a way to get away from crazy inheritance trees. I'm sure delegating methods to different pieces of classes would work just fine. It's really just a different way of doing it when you know you're going to have a giant mess of different objects in the game that are sorta related but not quite and really gives you the power to create some pretty interesting creatures on the fly without having to figure out where it fits on the inheritance tree or worse, creating a new subclass to extend. As far as tutorials go, I just use this barebones project and expanded on it: http://dl.dropbox.com/u/11893120/EntityPrototype.zip

You can also google "component based game development" and find more links than you could possibly want. Most of it is pretty abstracted out so it's hard to find concrete examples, but that EntityPrototype project should be pretty good at showing what it does.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Rocko Bonaparte posted:

I didn't do actions--I think. I guess we should make sure I understand the nomenclature here. By "actions," I am assume code that is applied to an entity that does whatever with the components. I think with everything I have in place I could, but it didn't really cross my mind as a thing to do. Instead, I'm doing stuff with signals and requests. When components are added to an entity, it registers signals it cares about, and requests it can accommodate. So eventually another component may request a signal, and the servicing component gets notified with the request ID, and it sends back a message containing the relevant data.

HumanControl works particularly with signals, with the idea that I could swap out for an AIControl component that would control the entity using the exact same signals, and all the components listening for them would be none the wiser.

Yah, I think we're on the same page. I actually have an action class that all actions extend but they pretty much operate in the same fashion as your signals and requests.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Rocko Bonaparte posted:

I thought I would update the thread--and particularly you for expressing some interest--in what came up while I was getting HumanControl working. It gets a little hairy when it comes to activities that could get cancelled.

Say that you are doin something with real-time rendering with a 3d animated mesh, although it isn't entirely necessary. Once an attack animation is triggered, you probably don't want to let the player just let go of the attack button, and move around, aborting that animation. Similarly, you wouldn't want an enemy to always be able to abort an attack sequence. So once the attack animation starts, a lot of animation is suspended.

In my case, the state of animation is in one component, but human control is the one trying to request things happen up front. So there's some interplay there. What I have right now is that HumanControl will send a request out to anything that will tell it if the entity isn't accepting movement at the moment. If it's accepting movement, it will update the position component, which here has a relation to physics. That figures out the physical possibilities of movement. Once that component says it's okay, it sends out yet another signal that everything is in fact moving, and the mesh better get animated like it is.

It's kind of ugly. Another thing I thought I'd try is have the animation component send a signal when it wasn't moving, and then other components could unregister for certain signals until another comes along saying all is well again.

----

I picked up some of the Game Programming Gems books and saw some neat stuff. I've been doing C for... almost 20 years (holy poo poo!) and never really respected macros too much, but there was some good stuff about how to use them effectively. I haven't really interacted with expert C or C++ developers too much so it was enlightening to see why they decide to do this or that. Amongst some of the stuff was A*. I haven't worked on the AI side with pathfinding at all, so I have been worried about this. I'm kind of wondering how this has worked out for anybody else on here. In my case, I'm not working with systematic tiles so it sounds like I should probably define waypoints in my levels to guide AI.

It seems kind of ugly, but that's probably how I'd do the animation honestly. I'm lucky enough where I'm only dealing with sprites in a roguelike so your problem is a little out of my scope.

For A*, you'd definitely want some sort of waypoints in your game. The more waypoints you use, the more interesting the movement of your AI can be. Also remember that you have the option to add weights to your points so that the AI might go around a puddle of mud instead of walking through it if it turns out it's faster to go around.

http://www.policyalmanac.org/games/aStarTutorial.htm

I love this link. It explains everything very very clearly and even has some images so you can follow it along. There's no code examples so don't worry about trying to parse java to C++ or anything like that.

Personally, I have a "move via AI" component. You pass the target to the entity and it gives you the queue of moves you need to take to get to the target. Very handy.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Internet Janitor posted:

The one thing to watch out for in this type of system is to make sure the queue of moves doesn't go "stale" as things in the world move around and change the paths that are available. Ask me how many times I've created bugs that centered around this!

I do the exact opposite and refresh the queue every turn. I'm banking on the fact that roguelikes don't have that many monsters at the player at once as well as being small rooms and hallways making the A* not take long at all. So far so good.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Internet Janitor posted:

Oh. Well usually I do the same but I just return a single delta that will move you toward the target. If the path is regenerated every tick you don't really need to return a queue at all. If you aren't generating an entire path you can potentially speed things up a lot by first walking a low-rez graph of components in the map, possibly representing rooms. In a dungeon-like maze there will be a lot of rooms that are only accessible from a limited number of small chokepoints. Then if you know a sequence of rooms is in the optimal path you can do a normal A* to the closest chokepoint leading you along that path. I think Dwarf Fortress does something along these lines, but I think the DF implementation loses path optimality.

Hmmm. That's actually pretty interesting! However, all mobs are docile until the player opens the door. So even then, there's maybe max 10 spaces the mob needs to traverse to get to the player. I probably will switch up the method to return a single point to move to howevever, it's one extra line of code and not a big deal at the moment.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Internet Janitor posted:

poemdexter: Totally. Always go with the most straightforward implementation of pathfinding you can and then add complexity when you realize performance is becoming an issue. Often it never is. The main advantage of just returning a single delta is that it's a weaker contract and thus gives you more flexibility for changing the underlying pathfinding algorithm later without disturbing your consumers.

Agreed on straightforward implementation. The developer for Braid had a talk at some college and the audio was on the internet and he talked a lot about just putting your mechanic in in the most simple way possible and then dealing with performance ONLY when it is an issue. I'm looking for it now but a lot of the media is blocked on company firewall so I'm not sure which it is.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Fren posted:

Does anyone have experience distributing games, in Python (using OpenGL) on multiple platforms (Linux, OS X, Windows XP/7)? I'd like for each platform to have a one-click application that simply runs the app and doesn't gently caress with the user's system; and for the Python to be compiled as at least one level of obfuscation preventing users from simply seeing the source code.

py2exe

As for the component stuff, I agree with Unormal. Have components be completely independent of one another and mutable and attached to the Entity in whatever way you wish. Personally, I also register actions with the Entity where all of the logic sits. Any dependencies I have are within the Action and it's my responsibility that I have the correct components attached for any actions I attach.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

The Cheshire Cat posted:

A good safety net here would be that in your EntityFactory, the final step could be to scan through the list of actions you've attached to the entity, and have it automatically add any required components for those actions that the entity is missing, whether or not those components are specified in the entity description (you could document it as those actions imply those components, so any entity that performs those actions can implicitly be said to have those components - just make sure you set up your dependencies so that it always makes sense).

Oh that's a good idea. I'll definitely do this!

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Silver Alicorn posted:

Here's the short version:

code:
        public MainPage()
        {
            InitializeComponent();

            Windows.UI.Xaml.Media.CompositionTarget.Rendering += new Windows.UI.Xaml.EventHandler(GameLoop);
        }

        int Player1Score = 0;
        int Player2Score = 0;
        int BallXSpeed = 5;
        int BallYSpeed = 5;
        void GameLoop(object sender, object e)
        {

            // Left paddle check
            // Check for collision with paddle, bounce ball and increase speed if true
            
            // Left goal check
            // Increment player2 score if no paddle collision & reset field

            // Right paddle check
            if (BallTranslate.X > (int)LayoutRoot.ActualWidth - 50)
            {
                if (Player2Translate.Y < (BallTranslate.Y + 25) && (Player2Translate.Y + 150) > BallTranslate.Y)
                    BallXSpeed = BallXSpeed * -1;
            }

            // Right goal check
            if (BallTranslate.X > (int)LayoutRoot.ActualWidth - 25)
            {
                Player1Score += 1;
                GameReset();
                return;
            }

            // Wall check
            if (BallTranslate.Y > (int)LayoutRoot.ActualHeight - 25 || BallTranslate.Y < 0)
                BallYSpeed = BallYSpeed * -1;

            // Move ball
            BallTranslate.X += BallXSpeed;
            BallTranslate.Y += BallYSpeed;

            // Move Player 2
            // Update position to match ball, but move no more than 15 pixels per frame

            Player1ScoreBlock.Text = Player1Score.ToString();
            Player2ScoreBlock.Text = Player2Score.ToString();
        }
Full source code

Everything is defined in the XAML file and uses a TranslateTransform to move it to the correct spot on the screen. I didn't know how to get/change the Canvas.Left/Canvas.Top properties when I knocked this out, now I do, so that might be a better way to manipulate everything.

There's still some form of slowdown that's causing it to drop a frame every second or so, but it's definitely a lot less jagged this way. Edit: Oh I still get that slowdown with a dead simple app that uses the official animation methods, so it's something to do with my computer/the underlying framework, oh well.

Is this something that has be be run like an application or is it something that can be modified to just run as sorta a background image that plays itself?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

The Monarch posted:

I'm having a weird issue with XNA. I'm trying to load a Texture2D, but it's not working for some reason.

creaturePath can be ignored, and ArtPath is equal to "\\Art\\Dynamic\\Creatures\\Dog\\".

code:
        public void LoadAnimations(ContentManager content, String creaturePath)
        {

            // Load paths to animation
            String[] filelist = Directory.GetFiles(content.RootDirectory + ArtPath);

            // Add animations to animation dictionary
            foreach (String animationPath in filelist)
            {
                // Get file name
                String animationName = System.Text.RegularExpressions.Regex.Replace
                    (animationPath, @"\\", ",");
                animationName = System.Text.RegularExpressions.Regex.Split
                    (animationName, ",")[5];

                animationName = System.Text.RegularExpressions.Regex.Split
                    (animationName, ".xnb")[0];

                String path = ArtPath + animationName;
                // Load animation texture
                Texture2D animationTexture = content.Load<Texture2D>(path); // <--Error

                ...
            }
        }
The specific error I'm getting is this:

Error loading "\Art\Dynamic\Creatures\Dog\dog3_idle_n". Cannot open file.

I've added the file through Visual studio and if I remove the files and re-add them the proper .xnb files are created. Can anyone tell me what's up?

Edit: Nevermind. I did more reading about how content managers and stuff work so now It's working fine. I'm just passing the content service provider from the main "Game1.cs" class to my creature class, and making a new content manager there.

Is there a reason you aren't using the Content portion of your solution and using direct paths instead? All of that can be condensed into a single line (or more if you're passing ContentManager around).
code:
Texture2D mySprite = Content.Load<Texture2D>("env/door_wood_ns"));

Adbot
ADBOT LOVES YOU

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
2D is a little boring for me and I'd love to dabble in some voxel based terrain stuff ala minecraft world generation. However, I know absolutely 0 about drawing anything in 3 dimensional space or what's required by XNA (I know 2D XNA way too well). I'm looking for some direction, maybe a few tutorials on drawing something in XNA in 3d as well as maybe some guide from going from a cube to a world. I can read all the wiki articles in the world as well as blogs but I just don't know anything about ray tracing or 3 dimensional points.

My basic assumption is this:

1. There's a 3 dimensional array of values (at least bool).
2. Fill this array by hand or use some algorithm to do it (perlin noise heightmap is probably what I'm looking at first since it's easiest.)
3. A ray tracer points from somewhere within or outside the cube of values.
4. If a ray hits a surface of a 'true' value, it renders the face of the voxel.
5. Poof you now have some landscape!

Am I close on this? If so, should I look at implementing some ray tracer first? Help!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply