Hello!!
Im working on new projects and there is two things that I dont understand.
Question 1:I know how I can make a Collision with this Code:
object.getGlobalBounds().intersects( player.getGlobalBounds()....
I know, how I can "destroy" the object or the player, set a other position for the players etc.
But.. if I want to make a 2D-RPG game, how should the Code looks like, if I want that the Player "stops" to the object? Should I work with booleans? I never implented this and I have no idea how I can do this.
I think, I would do this (pseudo code):
if (object.getglobalBounds intersects player globalbounds
&&pressRight=true)
{
Walkspeed = 0;
}
else if(object.getglobalBounds intersects player globalbounds
&&pressRight=true)
{
Walkspeed = 0;
} //(...)
else
{
Walkspeed = X
}
or this:
if(...) &&right=true
{
move(x-1,y)
}
But I know its stupid and wrong, and I dont know if this stupid code is working.
Can you tell me, how you do this? How you create a Code that the player "stops" at the objects?
Question 2:This is a bit more complex (maybe..): I want to give every Sprite his own moves.
For example, please have a look at this pseudo code:
timer >= 100
{
randomz = rand() % 5 + 1;
if(randomz = 1)
randomx = 5, randomy = 3;
if(randomz = 2)
randomx = -2, randomy = -5;
(...)
Create Sprite process
sprite*move(randomx, randomy)
timer = 0
}
The problem is: I dont know, if every sprite get his "own" move, or its a "global move" like: movement is changing every time for all sprites.
Kursukia
Sorry for my broken english!