allegro - How to draw limited part of display [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm coding a game like agar.io and I want to create a world like 5000x5000 but for example player can see only 900x600 part.
Namely player must have a scope. My background is not a bitmap, I'm basicaly make backbuffer black, draw primitives on it and flip it.
How can I do this?

It sounds like transforms could help you out here.
Basically, you have a 900x600 display (al_create_display(900, 600)), but let your objects have positions anywhere in the 5000x5000 space.
When your player moves, you shift the camera transformation along with them. Your draw loop might look like this:
al_clear_to_color(al_map_rgb(0,0,0));
ALLEGRO_TRANSFORM trans;
al_identity_transform(&trans);
al_translate_transform(&trans, -player_x, -player_y);
al_use_transform(&trans);
// draw the player
al_draw_filled_circle(player_x + SCREEN_W / 2, player_y + SCREEN_H / 2,
32, al_map_rgb(255,0,0));
// draw all other entities
// ....
al_flip_display();
Note that the camera is shifted by -player_x,-player_y. If the player is at
(1000, 1000), an object at (1500, 1500) should be drawn at
(1500-1000,1500-1000), or (500,500) relative to the player. An object at (500,
500) would be drawn at (500-1000,500-1000) or (-500,-500); it will be
off-screen.
We don't actually have to perform this subtracion for every object though. You just draw every object at its absolute position, and the transform will translate it to a position relative to the player (the player's 'local' space).
Note also that we add half the screen size so the player is centered.
There are a number of ways to approach this, but the above should give you a
good start. As a bonus, using transforms makes it easy to add things like zoom
and rotation.

Related

real x, y in window in C using XCB [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 days ago.
Improve this question
I need a very simple example in C, using the XCB library. With a simple window that, when moved, shows its x and y position in the title or terminal. One event that works to capture motion is XCB_CONFIGURE_NOTIFY.
Preferably counting its borders and title, that is, that when I position it in the upper left corner it actually marks 0,0.
My difficulty started the moment everything I tried only displays 0.0 in any position or at most 5.19 in the top left corner.
NOTE:
Please, don't use examples of Xlib or any other library that someone's imagination has. I want to learn XCB!
Examples only in the C language, remembering that C is not C++.
For those who want to know why: NONE important! What comes to mind at this moment is being able to see on my screen what size I imagine I'll need for something else, because for me this is just basic!
And no, I don't want to use a ruler on the screen to know the size of my window :)
I tried several like: xcb_get_geometry (All), xcb_translate_coordinates, xcb_configure_notify_event_t, xcb_expose_event_t

Simple C - Extracting instant value of a variable and storing it [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Disclaimer: I’ve never used C before a few weeks ago, and I’m somewhat new to programming in general.
I’m writing a really basic space invaders type game in C. We have a little motherboard with a screen, joystick and buttons to port it to. I’m far from done but how it currently works is this:
-the character can move around the bottom of the screen from left to right with the joystick
-when the button is pressed, it creates a bullet right above his head that moves up to the top then vanishes
Now here’s where there’s a problem. In order to make the bullet spawn right above his head, I had to use the x coordinate of the character to define where to create the bullet. These are stored in variables, which are modified in the joystick code whenever the joystick is moved.
The movement of the bullet occurs like this: a black square quickly covers up the bullet, and a new bullet is drawn just above it. This repeats until the bullet hits the top.
So, the problem is that the bullet moves about the x-axis just like the character does. This is because all the rectangles for the bullet’s “movement” are defined such that their x coordinate is the variable of the Character’s x coordinate, which of course changes with the joystick.
so my question is this: is it possible in C to extract the INSTANT, integer value of a variable? For example, if I can nab the instant value of the character’s x-coordinate when the first rectangle of the bullet is created, then re-use that unchanging integer (as another variable) for the x-coordinate for subsequent rectangles, it will appear as if the movement of the bullet is straight up, despite the character still moving about.
TLDR: Is it possible in C to extract the instant integer value of an often-changing variable and store it in another variable for temporary use?
Yes of course. Put the assignment in a code block that will only be executed when the button is pressed. This way the bullets x position won't be updated until you shoot again.

How to use language C to obtain the intensity of every pixel of an image? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
AKA how to transform a bmp image into a 2D matrix of its intensity value for every pixel?
Fgg,
One way could be to average the intensities of each pixel (red, green, and blue for example) and average them.
For example:
Red is 128, Blue is 128, and Green is 128, the intensity would be 128.
Red is 0, Blue is 100, Green is 255, the intensity would be 118.
If the pixel has an intensity value built into it, you can average those across the entire image. Some images have meta tags which include a brightness, that could be used as well. The averaging above though, is a way I've used in the past inside of a program and it's worked rather well to determine the brightness of the image.
Edit: I need to warn you though, that more complex algorithms may be needed, because the overall average of the RGB values may not work the way you want them to, because of the limits of averaging. For example, really bright pixels may actually increase the brightness of the image, but you may not see it in your result. Similarly, the brightness value obtained through averaging may not accurately represent the true brightness of the image, depending on the pattern of bright pixels.
Question is a bit vague but I hope my answer helps!
Dan Chase
There are several approaches for deriving intensity from RGB coordinates.
One of the most popular ones, used in the YCbCr color model is by applying a linear transformation, typically Y = 0.299*R + 0.587*G + 0.114*B
Other approaches either average or take the max(R, G, B). You can read more here.

How much to increment the Scrollbar position when the arrow buttons are clicked? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am using a Scrollbar to scroll a bitmap.
When I click on the right or left arrow button, how much should I increment/decrement the Scrollbar position (I mean is there a convention that people use)? should it be only 1 unit?
Note that the range for the horizontal Scrollbar is the same as the width of the image (and the same goes for the vertical Scrollbar), and so when I increment the Scrollbar position by 1, I am shifting the image by 1 pixel.
Above all, ensure the scrolling feels natural, and provides a good user experience. Adjusting by 1 pixel will have varying results, which depend on the image size.
Try having a small unit of measurement, and a larger for paging (when the user clicks it the track region). Try 1% of the corresponding width or height for small, and 5% for large. That way the user will have a consistent experience, regardless of the image size.

Transparent avi in WPF MediaElement [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a mediaelement tag in my wpf-window. It's playing a simple animation, similar to the windows xp copy file dialog.
The animation has an ugly pink background #FF00FF, that I want to be transparent. I've tried setting the color in the OpacityMask attribute, but the color remains. Any ideas on how I can remove the color from the video?
You can use a shader effect to remove a specific color. Luckily this type of shader is part of the WPF Pixel Shader Effects Library - http://www.codeplex.com/wpffx which is available free of charge. The effect that you should look at is called ColorKeyAlpha.
Here you can find more info on the subject and if you are new to shaders this blog series has all the information you will need -

Resources