I'm new to programming, and I wanted to start by making a snake game like snake.io. So as you can see by clicking the link below, I created the snake and all its movements, then I made a red border and coded the "health" of the snake, representing them with some upside-down triangles. What is supposed to happen is that each time the snake touches the red border, it should lose half a heart, and its "health" should go down. However, what actually happens is that I can't move anymore as soon as I touch the border, and my health goes down(since my health is printed in the output), but I don't lose any hearts(visually).
movement code
main part of the problem
I tried to change the entire code, but I was not too fond of it, so I switched back. Can you help me? Thanks.
Related
I get an image of a games 3D scene (using render to texture) rendered in OpenGL. How would I go about generating what looks like the image being sketched in real time? I'm just talking outlines with this, not colouring.
I haven't been able to find a decent example. I know they exist, but sadly I wasn't thinking of trying to imitate it, the last time I saw the effect, so I can't retrieve the original source.
The idea would be that the player would enter a new location. They would see a white screen, upon which the "scene" would appear to be sketched in real time, before fading into the actual 3D scene.
I would like to do this procedurally, rather than prerender it, so that any changes to the scene wouldn't need the extra work of changing the intro every time the scene is updated.
I'm creating a procedural terrain in unity with hexagons. When the camera is fairly close the textures and colours work perfectly fine but... as soon as I zoom out I get this.
Map view from an angle:
As you can see I get these weird dots that become more exagerated the further I zoom...
When I'm up close I don't get this and the hexes blend very well toghether.
The textures blend very nicely when it's close and you can't see any boundaries. But as you go further out, some dots start appearing and even further so the colours get completly distorted.
Does anyone know what's causing it and how it could be fixed? I'm sorry, I'm really new to unity and this is my first unity project
Also, I presume this wouldn't be due to the texture bleding at boundaries because when I set the colour of the hexagons to be the same, I still get that effect.
(for example the sea in the pic below)
Same Colour hexes still show the problem
And when it gets further out, the problem pops up
Any help would be greatly appreciated! :)
Hmm, these might be artifacts caused by mipmapping (lower texture resolution as you zoom out). Try disabling mipmaps in your textures. It will negatively affect your game's performance but it might fix the problem.
I don't really want to move the whole world in my game but I do want the screen to follow my character.
So for example, normally pygame would render at the position of 0,0 and the window height width would allow you to expand that viewing area. But I want to move the starting position so that I can view something at coordinates 1000x1000 even if my screen is only 500x500 big.
Is it possible to make camera tracking without moving the whole world?
No.
By relativity, moving the player within the world is the same as moving the world around the player. Since your camera is fixed on the player, by definition you will see the world moving when the player moves within it. Therefore, you must draw your world in a different place.
It is more explicit in 3D graphics; we represent the scene's motion as one matrix, and the camera's as another. The renderer uses their product. It doesn't care which contributed to the motion.
Mario plays multiple games. Normally, while playing in a game, when he jumps [underneath] a question block, he gets a free surprise. When he encounters a Goomba or another dangerous hooligan, he simply jumps on its head. After coming to a different game, Mario jumps under a question box as usual and finds that nothing happens. Mario jumps on top of a Goomba and dies. Mario is very confused, what is wrong here?
This new game has collision detection (hence the death from the Goomba) but doesn't know how to tell which side has been collided with. Assuming only one side can collide at a time, and that the left of Mario can only collide with the right side of an object (right->left; top->bottom; etc.).
How can I do collision testing that also returns which side of poor Mario collided (to ensure jumping [underneath] a box gives him a surprise but jumping [on] a box doesn't give him anything).
Pseudo-code would be appreciated.
You could use current velocity, if your engine/game doesn't have lag issues.
For instance:
touching box: if vertical speed isn't 'positive', no gift
touching foe: if vertical speed isn't 'negative', death
I'm using vertical axis as usual in geometry, up toward the top of the screen, not usual in screen space where pixels starts at the top, so up is going down.
In my application I want to draw polygons using Windows Create Graphics method and later edit the polygon by allowing the user to select the points of the polygon and allowing to re-position them.
I use moue move event to get the new position of the point to get the new coordinates of the point being moved and use Paint event to re-draw the polygon. The application is working but when a point is moved the movement is not smooth.
I dont know weather the mouse move or the paint event the performance hindrance.
Can anyone make a suggestion as to how to improve this?
Make sure that you don't repaint for every mouse move. The proper way to do this is to handle all your input events, modifying the polygon data and setting a flag that a repaint needs to occur (on windows possibly just calling InvalidateRect() without calling UpdateWindow()).
You might not have a real performance problem - it could be that you just need to draw to an off screen DC and then copy that to your window, which will reduce flicker and make the movement seem much smoother.
If you're coding using the Win32 api, look at this for reference.
...and of course, make sure you only invalidate the area that needs to be repainted. Since you're keeping track of the polygons, invalidate only the polygon area (the rectangular union of the before and after states).