Has anyone here made any tiled engines? As you probably saw from WAYWO I'm making a Chip's Challenge clone in Love2d but currently I'm stumped with how to handle object interaction. I've implemented map reading, but the current tile system was placeholder.
Basically I need a way for tiles to know what objects they hold, and objects themselves have to know what tile they occupy.
Now entities are held a list, and tiles are created and stored in an x,y grid, but for convenience (to loop through all) their references are also put into a list.
Currently it works when I store a reference to a tile in an object, but it seems an infinite loop happens when I store an object reference in a reference table in a tile.
[QUOTE=ZeekyHBomb;42997687]
Didn't review your logic, but after fixing some undefined behaviors it seems to work.
Integers in C++ are not initialized to a known value, you must assign something to them before using them.
Further more, when you have an array of size 300, valid indices are in 0..299; 300 is out of bounds.
It's also considered good to declare variables as late as possible, but as early as necessary.
Here's a version of your code with does both. Also note that I initialize the array with {}, which removed the need of the loop to set all elements to 0.
[code]Code[/code]
[/QUOTE]
Oh my god thank you. I did have a hunch that my array was out of bounds, I changed it and since it didn't affect anything, I had changed it back. I also didn't know that declaring the array and setting it equal to {} zeroes it out. Thanks!
Unfortunately the assignment was due at 8:00AM this morning, but I'm fine to take the hit, at least I know what I was doing wrong now.
[editline]27th November 2013[/editline]
Yea I just had to remove the Cout, which I was using as a test, and then it outputted correctly from what I could tell.
I have an OpenGL question. I'm rendering a few object, some have textures, some don't. Should I enable (glEnable(GL_TEXTURE_2D);) and then disable textures for each textured object? If I don't do that, I get some weird colors on the untextured object, since the last texture coordinate is still being applied. (At least I think that's what's happening, and yeah, I'm using glBegin/glEnd...) Is there another way of solving this problem?
[QUOTE=zero_slo;42998953]I have an OpenGL question. I'm rendering a few object, some have textures, some don't. Should I enable (glEnable(GL_TEXTURE_2D);) and then disable textures for each textured object? If I don't do that, I get some weird colors on the untextured object, since the last texture coordinate is still being applied. (At least I think that's what's happening, and yeah, I'm using glBegin/glEnd...) Is there another way of solving this problem?[/QUOTE]
I think it is generally good practice to enable and disable GL_TEXTURE_2D as needed. But, I could be wrong. I seem to remember hearing that using that function over and over again has some performance impacts. It may be better just to apply a texture that is transparent and turn on GL_MODULATE so that the color will still affect it.
[QUOTE=ZeekyHBomb;42997687][editline]27th November 2013[/editline]
Depends on your definition of "similar", but it doesn't really matter. This is not solely a C++ or C++-like languages help thread :)
What's wrong with the code? If you just want constructive criticism on that tiny snippet, you should probably do the keyboard_check_pressed check for each key once and store the result in a more descriptive boolean variable. And you should make plans to allow the user to re-bind those actions to other keys.
"wall-stop system" is usually called collision detection/handling/avoidance.
[url=http://gamemaker.info/en/manual/403_03_planning]Here[/url]'s an official (?) resource on that topic.[/QUOTE]
I figured out collision fix making levels bigger and wider. Game Maker is mostly Event-based, so code is executed with following event. I was wondering if I should choose other event. But "create" event (Event which is starting when object is created) should be working with that. Still, when I'm using sprite-changes while pressing button (Left button-moving-changing sprite to left) it's bugging, because I'm also using a key release for changing a sprite to non-moving. I have no idea what to do with that.
[QUOTE=Duskling;42999144]I think it is generally good practice to enable and disable GL_TEXTURE_2D as needed. But, I could be wrong. I seem to remember hearing that using that function over and over again has some performance impacts. It may be better just to apply a texture that is transparent and turn on GL_MODULATE so that the color will still affect it.[/QUOTE]
Thanks!
Another OpenGL question: Apparently, if I want a light to stay where it is while I move the camera, I need to set the light position each frame? That seems ... unnecessary?
[QUOTE=mobrockers;42995290][cpp]
File folder = new File("path");
File[] fileNames = folder.listFiles();
[/cpp][/QUOTE]
Wow, why didn't I find that on google. Thanks, a lot.
Now, since I'm sure there'll be an equally obvious solution that I'm not aware of, can anyone tell me why my scroll bars aren't actually scrolling anything? I have a canvas set up like this:
[cpp] int shellStyle = SWT.NO_REDRAW_RESIZE | SWT.TITLE |
SWT.H_SCROLL | SWT.CLOSE | SWT.V_SCROLL | SWT.RESIZE;
Display dis = new Display();
Shell shell = new Shell(dis, shellStyle);
new myCanvas(dis, shell, "Title");[/cpp]
In the myCanvas constructor it creates the display, by making labels with "shell" as the parent and setting the images of those labels. It makes the window with all the pictures I wanted to display on it, and the scroll bars on the sides, but I when I drag the scroll bars nothing happens. I tried using the canvas as the parent for the labels, same thing. Manually making the window bigger reveals the other pictures, so there's more stuff there, the scroll bars just aren't doing anything. I tried a few solutions I found in google but I must have fucked all of them up somehow. Obviously I have no idea what I'm doing so be gentle.
[QUOTE=diwako;42998433]Just started programming in C++, I am only used to java tho, so I don't really understand what is wrong here.
[code]
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QRect"
#include "QDesktopWidget"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QRect position = frameGeometry();
position.moveCenter(QDesktopWidget().availableGeometry().center());
move(position.topLeft());
ui->console->addItem("Starting program");
consoleAdd("Moving window to center");
}
MainWindow::~MainWindow()
{
delete ui;
}
void consoleAdd(String s){
ui->console->addItem(s);
}
[/code]
Basically it tells me the method consoleAdd(String s) is wrong, it is not declared in the scope and apparently setting it void is also wrong. Tried to google the scope error but only found entries which are used to add new objects.[/QUOTE]
I think you meant to make it a member-function, for which you need to prefix the function-name with MainWindow:: like done for the constructor and destructor.
Further more, ensure that the function is declared in the class definition (that thing surrounded by "class MainWindow { ... }"); Here without the MainWindows:: in front (because in the context it is clear that it is a member-function).
[QUOTE=aurum481;42998449]Has anyone here made any tiled engines? As you probably saw from WAYWO I'm making a Chip's Challenge clone in Love2d but currently I'm stumped with how to handle object interaction. I've implemented map reading, but the current tile system was placeholder.
Basically I need a way for tiles to know what objects they hold, and objects themselves have to know what tile they occupy.
Now entities are held a list, and tiles are created and stored in an x,y grid, but for convenience (to loop through all) their references are also put into a list.
Currently it works when I store a reference to a tile in an object, but it seems an infinite loop happens when I store an object reference in a reference table in a tile.[/QUOTE]
Can you break it down to a test-case?
Because this works fine and is like you describe it:
[lua]-- 3x3 map of tiles
-- a tile is a table
tiles = {
{{}, {}, {}},
{{}, {}, {}},
{{}, {}, {}}
}
-- some item storing a reference to the tile it is in
object = { name = "item", myTile = tiles[2][1] }
-- add that item as the tiles object
tiles[2][1].object = object
-- recursive reference works fine
print(tiles[2][1].object.myTile.object.name)[/lua]
but there's probably something missing, which is why it works fine here (both Lua and LuaJIT).
[editline]27th November 2013[/editline]
[QUOTE=JTay;42999311]I figured out collision fix making levels bigger and wider. Game Maker is mostly Event-based, so code is executed with following event. I was wondering if I should choose other event. But "create" event (Event which is starting when object is created) should be working with that. Still, when I'm using sprite-changes while pressing button (Left button-moving-changing sprite to left) it's bugging, because I'm also using a key release for changing a sprite to non-moving. I have no idea what to do with that.[/QUOTE]
Bugging how?
When you change to a moving-sprite when the key gets pressed and change to a non-moving-sprite when the key gets released, what's there to go wrong?
Where should I start with making a text-adventure game sort of parser in Java?
I can make parsers that can process simple phrases like:
'go north'
'take item'
but I really struggle with getting more complex phrases integrated like:
'throw item to south'
'look at item in box'
'put down item'
I tried doing some reading about natural language processing, but it wasn't very helpful to me.
I'm trying to deal with transformations. I want to transform the mouse (which would be in 2D space, with the coords being [0..1024] and [0..768]). I use the following transform for a trimetric view:
[cpp]VP = glm::ortho<float>(-aspect*5, aspect*5, -5, 5, 0, 20) * glm::lookAt(glm::vec3(-std::sin(M_PI*36/180.f)*10,sin(M_PI*34/180.f)*10,10), glm::vec3(0,0,0), glm::vec3(0,1,0));[/cpp]
Aspect is simply 1024/768. Is there a way to map the map coords to screen coords? I want to select tiles and this seems like the simplest way, at least for now.
[QUOTE=ZestyLemons;43003559]Where should I start with making a text-adventure game sort of parser in Java?
I can make parsers that can process simple phrases like:
'go north'
'take item'
but I really struggle with getting more complex phrases integrated like:
'throw item to south'
'look at item in box'
'put down item'
I tried doing some reading about natural language processing, but it wasn't very helpful to me.[/QUOTE]
You could probably allow various optional word. Something like look [at] <item> [in <item>], the stuff in [] being optional and the stuff in <> refering to things in the environment.
You can also take a look at open source text adventures. Zork comes to mind, but there are probably also some more modern ones.
[QUOTE=ZeekyHBomb;43001662]When you change to a moving-sprite when the key gets pressed and change to a non-moving-sprite when the key gets released, what's there to go wrong?[/QUOTE]
Because people are playing like this - moving forward, then using both W and D, so they moving forward and right. They're releasing W, but D is still pressed. And because W was released, sprite changed to non-moving forward, except moving right. And I have no idea how to fix it.
[QUOTE=JTay;43006843]Because people are playing like this - moving forward, then using both W and D, so they moving forward and right. They're releasing W, but D is still pressed. And because W was released, sprite changed to non-moving forward, except moving right. And I have no idea how to fix it.[/QUOTE]
Then change to a sprite representing the currently pressed keys when one is released.
You'll get the best effect if you first check for the opposite and use that if it was pressed previously (and you make opposite keys at the same time equal no movement), then check if there's a sideways movement.
When a key is pressed check if the opposite is pressed too, if it is use the orthogonal motion, otherwise the direction of the new key.
With these rules you should avoid 180° sprite turns in most cases where the character only turns by 90°. Having 9 distinct sprite states including ones for diagonal motion would make more sense though.
[QUOTE=Tamschi;43007207]Then change to a sprite representing the currently pressed keys when one is released.
You'll get the best effect if you first check for the opposite and use that if it was pressed previously (and you make opposite keys at the same time equal no movement), then check if there's a sideways movement.
When a key is pressed check if the opposite is pressed too, if it is use the orthogonal motion, otherwise the direction of the new key.
With these rules you should avoid 180° sprite turns in most cases where the character only turns by 90°. Having 9 distinct sprite states including ones for diagonal motion would make more sense though.[/QUOTE]
I know it would, but now I only want to prevent sprites bugging, then I'll start adding more of them. I'm wondering what code will it be, because I'm starting in GML (It's almost same as C++, but I don't know any programming language) and I don't know what code should it be.
[QUOTE=JTay;43007341]I know it would, but now I only want to prevent sprites bugging, then I'll start adding more of them. I'm wondering what code will it be, because I'm starting in GML (It's almost same as C++, but I don't know any programming language) and I don't know what code should it be.[/QUOTE]
In that case you really need to look a bit more into the basics.
This may sound harsh, but it's likely that you won't gain anything by being given the code at this point.
[QUOTE=Tamschi;43008083]In that case you really need to look a bit more into the basics.
This may sound harsh, but it's likely that you won't gain anything by being given the code at this point.[/QUOTE]
I get it. Do you know any tutorials, that could help me understand it?
[QUOTE=JTay;43008276]I get it. Do you know any tutorials, that could help me understand it?[/QUOTE]
Learn about flow control (if-else, possibly for loops, ...) and maybe dictionaries (e.g. for finding the relative right/left positions and the right sprites), and look up the functions for getting the current key states. You should be able to find examples for these very quickly as they are very basic building blocks.
Once you have understood these you should have a good idea on how to solve your problem.
To anyone interested, I was able to fix my RPi C++ call problem. As we deduced it had nothing to do with calling conventions (verified in userspace), it was just a matter of blatant ignorance on my part; I had not set up a stack, so the stack pointer was just pointing [i]wherever[/i] and it obviously did not behave as expected when I tried to invoke a method which made use of it (which the C++ methods did, whereas their assembly equivalents did not).
Thanks again for putting up with me, it is surprising how easily one overlooks something when it always taken care of for them.
Is there a way to somehow inherit int in C#? I've tried this:
[code]
public struct MyInt : Int32 {}
[/code]
Which doesn't compile,
[code]
public struct MyInt {
private int _myValue;
public MyInt(int value) {
_myValue = value;
}
public static explicit operator MyInt(int value) {
return new MyInt(value);
}
}
[/code]
Which works, but then i have to do
[code]
MyInt i = (MyInt)1;
[/code]
And i'd prefer a solution where i don't have to cast every time
What i need is a class that behaves like an int but with changed get and set methods
[editline]29th November 2013[/editline]
turns out replacing explicit with implicit does exactly what i want, although i'm still wondering if there's a way to inherit Int32 so i don't have to manually add all the functions and operators to it
Int32 is a struct, you cannot inherit from structs.
[QUOTE=Goz3rr;43020228]Is there a way to somehow inherit int in C#? I've tried this:
[code]
public struct MyInt : Int32 {}
[/code]
Which doesn't compile,
[code]
public struct MyInt {
private int _myValue;
public MyInt(int value) {
_myValue = value;
}
public static explicit operator MyInt(int value) {
return new MyInt(value);
}
}
[/code]
Which works, but then i have to do
[code]
MyInt i = (MyInt)1;
[/code]
And i'd prefer a solution where i don't have to cast every time
What i need is a class that behaves like an int but with changed get and set methods
[editline]29th November 2013[/editline]
turns out replacing explicit with implicit does exactly what i want, although i'm still wondering if there's a way to inherit Int32 so i don't have to manually add all the functions and operators to it[/QUOTE]
Structs have no inheritance in C#. They're designed to be extremely lightweight, and as a result, don't have a method table pointer.
[url]http://stackoverflow.com/questions/2310103/why-a-c-sharp-struct-cannot-be-inherited[/url]
Also if you explain what you're trying to do, I can probably help you figure out a better way to do it in C#.
[QUOTE=robmaister12;43020454]Structs have no inheritance in C#. They're designed to be extremely lightweight, and as a result, don't have a method table pointer.
[url]http://stackoverflow.com/questions/2310103/why-a-c-sharp-struct-cannot-be-inherited[/url]
Also if you explain what you're trying to do, I can probably help you figure out a better way to do it in C#.[/QUOTE]
Yeah i figured you can't inherit structs, was just wondering if there were any similar alternatives.
I was messing around with memory editing and was wondering if i could 'obfuscate' a value with as little extra effort needed while programming, so far i've made this which sort of works on the code side, i haven't actually checked if it changes anything in memory though:
[code]
public struct ObfuscatedInt {
public readonly int ObfuscatedValue;
public ObfuscatedInt(int value) {
ObfuscatedValue = ~value;
}
public override string ToString() {
return (~ObfuscatedValue).ToString(CultureInfo.InvariantCulture);
}
public static implicit operator ObfuscatedInt(int value) {
return new ObfuscatedInt(value);
}
public static implicit operator Int32(ObfuscatedInt value) {
return ~value.ObfuscatedValue;
}
}
[/code]
[code]
ObfuscatedInt something = r.Next(Int32.MinValue, Int32.MaxValue);
int somethingelse = something;
Console.WriteLine("something = " + something);
Console.WriteLine("something.ObfuscatedValue = " + something.ObfuscatedValue);
Console.WriteLine("something+1 = " + (something+1));
Console.WriteLine("somethingelse = " + somethingelse);
[/code]
[code]
something = 1530793828
something.ObfuscatedValue = -1530793829
something+1 = 1530793829
somethingelse = 1530793828
[/code]
edit: nvm
[QUOTE=ZeekyHBomb;43001662]
Can you break it down to a test-case?
Because this works fine and is like you describe it:
[lua]-- 3x3 map of tiles
-- a tile is a table
tiles = {
{{}, {}, {}},
{{}, {}, {}},
{{}, {}, {}}
}
-- some item storing a reference to the tile it is in
object = { name = "item", myTile = tiles[2][1] }
-- add that item as the tiles object
tiles[2][1].object = object
-- recursive reference works fine
print(tiles[2][1].object.myTile.object.name)[/lua]
but there's probably something missing, which is why it works fine here (both Lua and LuaJIT).
[/QUOTE]
Well I was doing something like that. But the way I made that object handler container, it wasn't getting garbage collected correctly. I looked up about Lua metatables and tried implementing weak referencing but I messed up something so my current bug is happening. :I
Well I'm rewriting that old thing from scratch, but I could still use help with metatables.
[QUOTE=Goz3rr;43020651]Yeah i figured you can't inherit structs, was just wondering if there were any similar alternatives.
I was messing around with memory editing and was wondering if i could 'obfuscate' a value with as little extra effort needed while programming, so far i've made this which sort of works on the code side, i haven't actually checked if it changes anything in memory though:
[code]
public struct ObfuscatedInt {
public readonly int ObfuscatedValue;
public ObfuscatedInt(int value) {
ObfuscatedValue = ~value;
}
public override string ToString() {
return (~ObfuscatedValue).ToString(CultureInfo.InvariantCulture);
}
public static implicit operator ObfuscatedInt(int value) {
return new ObfuscatedInt(value);
}
public static implicit operator Int32(ObfuscatedInt value) {
return ~value.ObfuscatedValue;
}
}
[/code]
[code]
ObfuscatedInt something = r.Next(Int32.MinValue, Int32.MaxValue);
int somethingelse = something;
Console.WriteLine("something = " + something);
Console.WriteLine("something.ObfuscatedValue = " + something.ObfuscatedValue);
Console.WriteLine("something+1 = " + (something+1));
Console.WriteLine("somethingelse = " + somethingelse);
[/code]
[code]
something = 1530793828
something.ObfuscatedValue = -1530793829
something+1 = 1530793829
somethingelse = 1530793828
[/code][/QUOTE]
Yeah, that's probably the best way to go about it. You could also just define a static Obfuscate function that takes an int and returns an int, or takes a "ref int", depending on how long you want the data to stay obfuscated. If you only want to (de)obfuscate immediately when you load/save the value to a file, then the static function might be better.
can someone tell me why I am getting a "string subscript is out of range" error on runtime with this loop? I feel like it should be breaking out after reaching 8
[code] int counter = 0;
while( counter < 9 )
{
binNum[counter];
if( ( binNum[counter] != '0' ) && ( binNum[counter] != '1' ) )
{
isValid = false;
cout << "nope!!!" << endl;
}
counter++;
}[/code]
[QUOTE=Rofl my Waff;43023558]can someone tell me why I am getting a "string subscript is out of range" error on runtime with this loop? I feel like it should be breaking out after reaching 8[/QUOTE]
Is there actually 9 characters in binNum?
[code]
Word.Application app = new Word.Application();
Word.Document doc = app.ActiveDocument;
string text = doc.Application.Selection.Text;
MessageBox.Show(text);
[/code]
C#
This tells me that no document is open. Is the api broken?
[QUOTE=Rofl my Waff;43023558]can someone tell me why I am getting a "string subscript is out of range" error on runtime with this loop? I feel like it should be breaking out after reaching 8
[code] int counter = 0;
while( counter < 9 )
{
binNum[counter];
if( ( binNum[counter] != '0' ) && ( binNum[counter] != '1' ) )
{
isValid = false;
cout << "nope!!!" << endl;
}
counter++;
}[/code][/QUOTE]
Why isn't this a for-loop, though?
[QUOTE=aurum481;43021619]Well I was doing something like that. But the way I made that object handler container, it wasn't getting garbage collected correctly. I looked up about Lua metatables and tried implementing weak referencing but I messed up something so my current bug is happening. :I
Well I'm rewriting that old thing from scratch, but I could still use help with metatables.[/QUOTE]
You set __mode to "k", "v" or "kv", which means either the keys, the values or both are weak references.
If such a weak reference refers to an object only referred to by weak references, the object will get garbage collected and the entry in the table is removed.
Sorry, you need to Log In to post a reply to this thread.