« first day  last day (15 days later) » 

1:25 AM
hey
 
hi again. I was implementing the collision and had trouble using the last Vector
 
the B ?
 
The vel. I call it C
public void update()
{
A.setPos(x, y);

if(Keyboard.isKeyDown(Keyboard.KEY_D))
x+=2;
if(Keyboard.isKeyDown(Keyboard.KEY_A))
x-=2;
if(Keyboard.isKeyDown(Keyboard.KEY_W))
y-=2;
if(Keyboard.isKeyDown(Keyboard.KEY_S))
y+=2;

B.setPos(x, y);

C.setPos(B.getX() - A.getX(), B.getY() - A.getY());
if(IntersectsX(P, E))
if(C.getX() > 0){x = E.getX() - width; System.out.println("col");}

}

public boolean IntersectsX(Rectangle A, Rectangle B)
{
return (B.getX() < A.getX() + A.getWidth()) &&
(A.getX() < (B.getX() + B.getWidth()));
I was checking the x position only because y in opengl is a little odd
it starts from the top and I wwanted to make sure i was using it right
 
this seems right to me
with a couple of small things wrong
 
when im pressing the right key i get thrown to the left of the platform
 
1:31 AM
the right key is supposed to move the player to the right correct ?
E is supposed to be the wall ?
 
yes, should I actually show more code? It's about 100 lines
no E isnt
 
ok whats E
 
public class AABBDemo {


ShapeRenderer batch = new ShapeRenderer();

int x = 100;
int y = 100;
int width = 50, height = 50;

Vec2 A = new Vec2(x, y);//pos of player before movements...
Vec2 B = new Vec2(x, y);//pos of player after movements
Vec2 C = new Vec2(x, y);//B - A


Rectangle P = new Rectangle(100, 100, 50, 50);//player
Rectangle E = new Rectangle(100, 300, 90, 20);//enemy

public AABBDemo() {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setTitle("Testy cles");
Display.create();
 
is the format of this text how you normally write ?
or this chat changes it ?
 
i just pasted it
I think it's normal text
 
1:34 AM
you should use "tab" more
and format the code better
its so hard to understand what you are writting
but
what is E ?
 
P is the player rectangle and E is the enemy or wall
 
and what is the problem and what you wanted the result to be
 
when you press the right key, when your x < the enemy/wall's X you get pushed to the enemy/wall's x
I want to only get pushed to that x when I'm close enough
 
when you press the right key
you player increases its x by 2 pixels
if the player and the enemy/wall intersect
then you set players x to walls.X - player.width
and thats what we do with this code, as far i as can tell without running the code myself
let me just re-format this code a little bit
cause the way you have it write now, is impossible to read :p
and has all kinds of mistakes
 
Oh that's because I pasted it into chat heh
 
1:43 AM
you should have
a class
entity
 
with properties, position(vector2) and bounds(rectangle)
and then have something like
Entity player = new Entity(...);
Entity enemy = new Entity(...);
cause thats how you program in java, an object oriented language
you just have a bunch of variables thrown in a class
named X Y A B C D E
none understands what you are doing
 
oh, I wanted to keep this in one class so it could be more readable for anyone who can help me. But I guess that's a bad idea
 
its a very bad idea, not to be hard, but yea
im gonna go to bed in a bit but
i ll try and change this code a little bit
without trying it
so it might have errors, but i ll show you how to write this a bit better at least
 
okay. Here's the code without some of the random variables i left hastebin.com/ayemalujad.avrasm . heh, sorry about that
 
1:47 AM
can i see the vector 2 class ?
 
you wrote this ?
 
yeah
 
do you have the rectangle code ?
 
this? Rectangle P = new Rectangle(100, 100, 50, 50);//player rectangle
Rectangle E = new Rectangle(100, 300, 90, 20);//enemy or the actual class?
 
1:50 AM
the rectangle class
 
why do you have
a rectangle and a vec2 for the player
when the rectangle.x and rectangle.y is basically the vec2.x and vec2.y ?
 
The rectangle so I can render it and the Vec2 so It could look more readable in the update loop
 
man java sucks
:D
still fixing the code a little bit
the format
 
haha, I'm actually looking into learning c++ or something. Getting bored of Java
 
2:04 AM
this whole get and set thing
is so much easier in C#
you need to stick with 1 bracket format
either void() {
}
or void()
{
}
 
whoops
 
anyway just check the format in the code i ll send you soon
you have major mistakes :p
format-wise
 
that explains why i dont usually get answers for my code
 
That is a lot neater :o . what was the mistake though?
 
2:15 AM
i have no idea
this seems fine to me
i wrote this in notepad
does it compile ?
check the second link i sent
 
i get a syntaz error: The operator - is undefined for the argument type(s) Vec2
on the line with Vec2 PlayerVelocity = new Vec2(Player.getX(), Player.getY()) - PreviousPlayerPosition;
ah, my vector class isnt handling that
 
you cant substract vectors ? holy java :D
aight then just do it the other way
 
I made my own vector class, I don't know about theirs
 
Vec2 PlayerVelocity = new Vec2(Player.getX() - PreviousPlayerPosition.getX(), Player.getY() - PreviousPlayerPosition.getY());
now i remember why i am using C#
 
It sounds cleaner
 
2:19 AM
public int X { get; set; }
this is how you define get set in C#
1 line
and this is how you use it
Y = X;
(thats the get)
X = Y;
(and thats the set)
you arent calling any function, you just write X
just like X was public
 
woah. So when you do that you have x with a null value until you set; it?
 
thats should be a property of a class
for example
 
also the code compiles and works :D
 
class Rectangle
{
public int X { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
done, rectangle class in C#
 
really? That's amazing small
 
2:22 AM
well, needs a constructor
and functionalities, but you get the idea
 
what if you want to get the x + 5?
 
Rectangle asd = new Rectangle(1,1,1,1);
int asd111 = asd.X+ 5;
my code works as you wanted it to ?
 
The syntax is beautiful. But yeah, it works perfectly fine. I just haven't done the other sides yet
 
one thing
if(Keyboard.isKeyDown(Keyboard.KEY_D)) Player.setX(Player.getX() + 2);
this logic
will make your object move slower
if you have an fps spike
so if you run this on a ancient pc
and you press D
the movement will be slow fast fast slow fast fast etc
this is not how you move objects i ngame
you need to calculate the delta time between each update call
 
Delta was a pain
 
2:28 AM
0
A: Help on transition from one position to another

Shiroposition += velocity * DeltaTime * speed; This is a better way of calculating the position. this way your movement wont slow down on framerate drops, because you take into account the time elapsed between the last Update call, if it was longer than usual (low fps) you move more distance. The c...

check both answers in this question
the other answer is probably better than mine
this is how you move objects in games
always
basically you should have
if(Keyboard.isKeyDown(Keyboard.KEY_D)) Player.setX(Player.getX() + DeltaTime.Milliseconds * speed);
 
c# handles vector normalization for you?
 
its just a calculation
normalizedVector = (x/vectorLength, y/vectorLength)
vectorLength = Sqrt(x^2 + y^2);
its not about C#
its the Vector2 class implementation
 
oh
 
Vector2.Normalize(...)
thats how you call a static method
from class Vector2
 
I see
 
2:35 AM
so you actually are using lwjgl
not just openGL
so thats good
 
yeah, it comes with a lot of classes you probably saw in the repository
 
yea i see it now
you should tag your questions lwjgl then also
and learn how to properly write java as well
 
The horrible formatting or bad naming conventions?
 
you didnt need to define the A B C vector inside class AABBDemo
you can just use a "temp" variable
inside the Update() method
the only thing you need is Rectangle Player and enemy
the other stuff, can be calculated
inside Update()
you need to put the variables
in the proper scope
the code you showed me
would be impossible to read, on a real game
you wouldn't understand what variable does what
 
I pretty much threw together what worked for the demo. Didn't think it was that harsh to read for others
 
2:41 AM
even for you
its impossible, trust me
this is how my game hierarchy looks on a simple breakout game
its about 6k lines of code
 
With reusable classes?
 
and its just a simple game
 
It does look nice
 
i mean
you can "reuse" it
in monogame
its just a bunch of variables
and functions and classes, everything is reusable.. yea
this is how i made a trail for example
for the ball
this is how the trail looks like, its a flame
 
woah
 
2:46 AM
public Trail Trail { get; set; }, thats a Trail variable
named "Trail"
inside the ball class
Trail = new Trail(25);
initialize a trail of 25 "small flame balls"
call Trail.Update(Position);//Update trail
to update the trail based on the balls "Position"
and
ball.Trail.Draw(spriteBatch);
draw the ball's trail
thats it
3 lines, makes a trail
 
But don't you loose time making code that organized?
 
this is how you are supposed to write code, by law
its like saying
you waste time writting words in lines
thats how you write, to read it the next day
when you have 6k lines of code, for an unfinished game
with no levels
you can only imagine, that you would take FOREVER to debug the code
 
true
 
without proper syntax, naming, format
 
one sec
 
2:52 AM
take a look
how my Update method looks
my main game update method, and compare its size to your game
i even write comments in english
when i am greek :P
so just think that, on a "game" 500 times more complex than yours, my main Update method is 25 lines long
and your update is 17 lines
 
hah wow
 
if (InputHandler.Released) ExplosionHandler.CreateExplosion(InputHandler.Position, Explosion.ExplosionType.Default, 15);
this line
is not nesseceray
i am just testing a particle engine
when the ball hits the wall
there is an explosion
same when it hits the paddle
 
I have to go to bed at the moment, but I'll stay logged in in case you say anything else.
 
me too, good luck with you coding ! :D
 
Thanks again.
 
2:57 AM
check the update method i have
and organize it like this too
you should have a class entity
with properties
Rectangle Bounds; for example
and have a method Update inside that class
So you would make
Entity player = new Entity(100,100,50,90);
and then call player.Update();
inside the "main" update
good luck with your game
 
you too!
 
you entity class, should also have methods "initialize" and "draw"
and "load" to load a texture to the entity object
just think, how would you add a second player to your game
if you had to add more than 2-5 lines, to add a player to your game
you are doing it wrong
:)
 
 
8 hours later…
11:01 AM
my mouse is messed up. eh
 
 
9 hours later…
8:19 PM
So are you doing Ludum Dare?
 
 
3 hours later…
11:26 PM
i haven't heard that game
 

« first day  last day (15 days later) »