Jump to content

Any programmers in the house?


morgans303
 Share

Recommended Posts

Ok, so I kinda screwed this up.

I achieved background scrolling by keeping my character at a fixed point, and moving the background. It worked fine, until I added an patrolling enemy.

He syncs with the background when standing still, but I haven't figured out how to make him patrol without falling out of sync with the level. One possible solution is to add collidable objects, but then he'd behave more like a lemming.

Is there a better solution?

Link to comment
Share on other sites

Generally, the more intuitive the design is, the easier it is to add things to it without breaking other things. Keeping the player still and moving everything else on the stage seems like a really unintuitive workaround to me.

I've never really used pygame, so I don't know what functionality it gives you, but in standard OOP design, these are the objects I'd have for this:

Camera - invisible object who lives just to keep track of what the offset in the room is to draw everything. The other objects are draw with respect to this, and the background can simply be offset by the camera's x/someScale, y/someScale.

Player - the human player, who moves based on keyboard input, and draws itself at its current x,y position each frame.

Enemy - same concept as above, moves around and draws itself.

Does that make sense? If you have a sample of the code, it'd be a lot easier to explain that way.

Link to comment
Share on other sites

Generally, the more intuitive the design is, the easier it is to add things to it without breaking other things. Keeping the player still and moving everything else on the stage seems like a really unintuitive workaround to me.

I've never really used pygame, so I don't know what functionality it gives you, but in standard OOP design, these are the objects I'd have for this:

Camera - invisible object who lives just to keep track of what the offset in the room is to draw everything. The other objects are draw with respect to this, and the background can simply be offset by the camera's x/someScale, y/someScale.

Player - the human player, who moves based on keyboard input, and draws itself at its current x,y position each frame.

Enemy - same concept as above, moves around and draws itself.

Does that make sense? If you have a sample of the code, it'd be a lot easier to explain that way.

Helpful. I'll have to research how to go about this in Python. There's a shortage of Python game development tutorials for sidescrollers.

Link to comment
Share on other sites

You're referring to Parallax Scrolling. This is a common technique in 2d game development.

Syncing the parallax bgs with your fg though can be difficult, if you need it. Usually you'll need to use math to determine the right offsets as they relate to your bg.

In most cases the BGs aren't important to the FG content so this isn't an issue.

Your level should never move. Instead move the player, then have the camera follow the player.

Link to comment
Share on other sites

A useful skill you'll need to learn is the separation of the abstractions of the game from the programming language. In other words, it shouldn't matter here whether you're using Python, C#, Ruby, or any other language. The language is a vehicle to accomplish your goal (from a broad perspective, anyway. If you choose to program it in Scheme, that's a different issue altogether, hahah).

From what I've seen of Python, you should be able to represent the camera as an object-type (or class). The camera would store, for example, the coordinates of the top-left view corner that would be presented to the player. In your game's logic loop, when drawing the graphics, you would then ask the current camera object where the corner is, and based on that, you would know where to draw the other entities in the level.

If you're having a hard time understanding how an object-oriented system would work, I'd strongly advise picking up some books or, if possible, taking a course or two in basic programming. Even online tutorials can help you with those concepts. Trying to make any program - let alone a game - without understanding how to use the program structures available to you would just be fruitless and frustrating to you very quickly. Also make sure you know what Pygame does and doesn't do for you; you might need to build other supplementary structure that interfaces with Pygame to suit your game's system.

Aaaaand sorry for the heavy jargon. D:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...