using C++ and allegro 5,
I'm doing a maze-type game and wanted to find out the best way of creating the maze ??
is it simply a case of putting down a bunch of rectangles/squares ??
How would you do collision detection once you have a maze (stop player from passing through walls) ??
i'm o.k with bounding box collision detection between 2 objects but i cant think of what to do with a whole maze.
(note, i've just recently started learning allegro)
any advice appreciated.
I am new at this as well, but creating a bitmap inside allegro and then drawing your maze to the bitmap.
ALLEGRO_BITMAP *maze = NULL;
al_set_target_bitmap(maze);
al_draw_filled_square(x,y,x,y);
al_draw_filled_rectangle(x,y,x,y);
since you change target to maze, all the drawing done after will be in the maze bitmap.
then you can just draw maze to the screen and it will have all your squares and rectangles in it.
just reset you target to the display after drawing you maze.
al_set_target_bitmap(al_get_backbuffer(display));
Related
Really new for Unreal Engine 4.
My main point is draw transparent 3d object with sprecific border made by lines.
For these i have array of points which make lines.
so i have a procedural mesh for creating in c++ object, but it can only draw polygons.
After searching information about line drawing in UE4, have tried to use "draw
debug lines", but it is only for debug and only for 2 points (i need draw array of points)
so - my problem is : drawing lines in c++ code of UE4.
how can i draw not debug lines?
If you have an array with all your linked point, why not iterate throught this array and create a DebugLine for each "linked points" ?
TArray<FVector> myArray = .... ;
for (size_t i = 0; i < myArray.Num() - 1; ++i)
{
FVector LinkStart = myArray[i];
FVector LinkEnd = myArray[i+1];
DrawDebugLine(GetWorld(), LinkStart, LinkEnd,
FColor(255,0,0), false, -1, 0, 10 );
}
If you really do not want debug line, there is another method to Drawline in the SceneManagement from the FPrimitiveDrawInterface classes.(I've never used it, not sure it's the better solution for your issue)
In a harder way, you can use the procedural generation of mesh in C++, where you create mesh and populate vertices and edges. Take a look at the doc, and you may be able to adapt the code for your case
For those who are struggling (like myself, once):
ULineBatchComponent::DrawLine - if you are looking to draw in world-space (https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Components/ULineBatchComponent/DrawLine/)
AHUD::DrawLine - if you need to draw on screen-space (https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/GameFramework/AHUD/DrawLine/)
When my programm start, it must display a circle on a background. Also i must controll all displaying circles. I use class VertexController and class Vertex for that purpose. In Vertex i have constructor:
Vertex::Vertex(const ci::Vec2f & CurrentLoc){
vColor = Color(Rand::randFloat(123.0f),Rand::randFloat(123.0f),Rand::randFloat(123.0f));
vRadius = Rand::randFloat(23.0f);
vLoc = CurrentLoc;
}
and in VertexController i have
VertexController::VertexController()
{
Vertex CenterVertex = Vertex(getWindowCenter());
CenterVertex.draw(); // function-member draw solid circle with random color
}
and in setup{} method i wrote
void TutorialApp::setup(){
gl::clear(Color(255,204,0));
mVertexController=VertexController();
}
Unfrtunatelly, my way didnt work.I see only background.
So the main question - in CINDER_APP_BASIC drawing possible only in draw{},update{},setup{} directly? If yes, advise a solution, else say where is my fail.
this line of code does not make any sense to me:
mVertexController=VertexController();
Anyways, you should use draw() function just for drawing circles to window. This it why by default there is gl::clear(Color(0,0,0)); to clear background and start drawing new frame from scratch (this is the way drawing in OpenGL, used by default in Cinder, works).
I suggest to use Vector container for storing all circles (this way you can add and remove circles on the fly with some effort), add the first one in VertexController constructor, and make separate function VertexController::draw() to draw all circles using for loop.
I am developing a jig-so puzzle like app using cocos2d. I have put some sprites into the scene and particular two sprites are matching. If i have put rectangle shaped sprites, i can determine their positions. If they are close enough, therefore re arrange two of them.
float distanceFromCorrectPos = ccpDistance(selectedSprite.position, sda.position);
if( distanceFromCorrectPos <= 70 ){
if(selectedSprite == [movableSprites objectAtIndex:0]){
[selectedSprite setPosition:ccp(sda.position.x+75, sda.position.y)];
}
}
My problem is if i using asymmetric images for sprites. How can i detect matching sprites are close enough.
I'm new to Cocos2dx and I'm trying to create a planet animation rotate itself by using a 3:1 rectangle texture, which contains 3 squares are two faces (map) of sphere (the third square is a clone of the first one). I create a frames array by cropping the texture and add them to CCAnimation. Then I test this animation with two effects to make square frame become a 3D circle: CCLens and CCTurnOffTiles (I will modify it in the future to turn off only grids outside the circle).
But there is a problems: two effects don't stack. If CCTurnOffTiles is added after CCLens, CCLens will not work; if CCLens is added after CCTurnOffTiles, CCDirector will throw reading violation exception at runtime.
Is there any solution to run many effects simultaneously or implement planet animation in other way? Thanks.
Try using CCSpawn.
// Create the effects
CCLens3D * lensEffect; // Your CCLens3D create()
CCTurnOffTiles * turnOff; // Your CCTurnOfftiles create()
// Create a spawn to run them simultaneously
CCSpawn * sphereEffect = CCSpawn::createWithTwoActions( lensEffect, turnOff );
// Run the spawn
myObject -> runAction( sphereEffect );
Both CCTurnOffTiles and CCLens3D inherits of CCGridAction.
But one cancels the other: CCTurnOffTiles will turn off grid tiles, and CCLens3d need these grid tiles.
I recommend you to draw all planet sprites, already circled and using a SpriteSheet, and animate then with CCAnimation, without using CCTurnOffTiles or CCLens3D. It is easiest and will consume less cpu.
Hi i want to develop game like 'Doodle jump'.But i have some problem with the following features-
1.How to move background scene/image.
2.How to detect collision between object.Is it needed a physics engine like box2d or i should just use manual collision.
3.what should be the size of the background image.
4.In fact i have no idea how does background move .So i need a explanation from someone.
Background Movement
A) You could create a TMX Tilemap and then make a very high Tiled-Map.
B) You could create one texture and then cycle the texture coords instead of really moving it.
Detect it manually. Best is detect it via "Point in Boundingbox" or "Rect in Rect".
For more detail visit my blog entry for collision detection with cocos2d : http://www.anima-entertainment.de/?p=262
Size of an Image
Keep in Mind that textures are always at power of 2 in the memory. If you want to create one Background-Image at retina highresolution (960x640 Pixel) in the memory will be a texture of 1024x1024. If possible use smaller Background-Images and stretch them. (like 512x512). But I really would recommend for big scrolling images the TMX Support.
CCTMXTiledMap * tmxNode = [CCTMXTiledMap tiledMapWithGMXFile:#"Level.tmx"];
// lets say you want to move it 50 pixels down in 1 second :
[tmxNode runAction:[CCMoveBy actionWithDuration:1.0 position:ccp(0,-50)];
To create a tilemap : http://www.mapeditor.org/
In the folder of cocos2d, you could get many demos of tilemap.
TileMapTest.h
TileMapTest.m
refer this tutorial this will helpful for you.
http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d
this is used screen movement with pan recognizer