Sign in to follow this  
lordseanington

ascii game camera

Recommended Posts

I am creating a text based game in the console using a special windows only technique and my own image class system, that can easily be drawn with
Console.draw(x,y,image) and
Console.render();

I am trying to create a camera class using this method which has smooth movement, by none of.them.have worked. I want the camera to center on player.x and player.y as well as use VIEW_width and VIEW_height.
Each image is 4x4 characters.
Does anybody have a solution?

Share this post


Link to post
Share on other sites

Usually you will subtract each pixel from the camera's position before rendering. The idea is to transform vertices from world space to your camera space.

 

So if you have a picture at location { x, y } and the camera is centered at { a, b }, when you draw the picture it will be drawn at { x - a, y - b }.

 

If the camera has a width and height, then you need to scale your screen to be that size. I'm not really sure what you're looking for here since it's just a console game though.

Edited by Randy Gaul

Share this post


Link to post
Share on other sites
What I am wanting is a scrolling camera, using the double buffer system, I created my own image class and loading system, and what I need is for the camera to follow the player, meaning, showing any part that the player can see and disregard what the player isn't supposed too, as this is a tile map. The problem I'm.having with the x-a system, is transforming player coordinates to.block coordinates, as a player moves by pixel, and a block is 4 pixels, (when I say pixels I mean single chars) , and when I devide the player coordinates to access blocks, the camera only shows a new block every 4 steps.

Share this post


Link to post
Share on other sites

Well yeah, characters on-screen are kinda big and so things on the screen will move discretely. I'm not really seeing the problem.

 

Could you write down the math that you're performing (or code), and then explain what you want it to do instead? Right now what I am hearing is things like "I divide the player coordinates to access blocks", but I don't know what this divide operation is, and I don't know what "access blocks" means, and so I can't really help you yet.

Share this post


Link to post
Share on other sites

What he's trying to do is to scroll blocks by characters, one at time.

Instead, since he takes player x and maps it to a character by division to block size, he only gets the block the player is in.

 

Solution: divide character position by block size, keep the original value (which is probably already there) and consider the modulo by block size. This will give you position of character relative to containing char tile.

 

At this point you have to update your char tile drawing routines to draw only a part of the tile. Maybe using advanced console io you can also draw outside the visible area; should that be the case you wouldn't need to mess with sub-tile drawing. I'm not aware of those possibilities.

Share this post


Link to post
Share on other sites
You can first draw to your own buffer that is bigger than the screen, and then draw the visible section to the actual output. This way you dont need to have if checks for every tile or character to check if its in screen (could be a performance problem). A small 1-tile wide buffer region around the screensize buffer basically. (any remains of half visible tiles go there)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this