• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Richy19;37490284]Can someone help me out here? Im trying to create a rouguelike dungeon using the simple BSP method, for it I have: ... Now assuming my calculations are correct, the splitting stage should always create rects with enought room to hold the room and a padding/wall the problem is I keep getting, minvalue exceds maxvalue on line 92 as the rects width is negative[/QUOTE] I was trying to run that code in my head but failed, try to find out (by debugging) when the rectangle got an negative width.
[QUOTE=AlienCat;37494286]I was trying to run that code in my head but failed, try to find out (by debugging) when the rectangle got an negative width.[/QUOTE] It seems its only the last rectangle [editline]1st September 2012[/editline] I recoded it and now it works but produces things like this: [code] ################################################## ### ##################################### ### ##################################### ### ################################ ### ############ ############# ### ############ ############# ### ############ ############# ### ######## ############# ### ######## ################## ### ######## ################## ############# ######## ################## ######################### ################## ################################################## # ################################### #### # ################################### #### # ################################### #### # ################################### #### # ######### ##################### #### # ######### ######## ######### #### # ######### ######## ######### #### ############## ######## ######### #### ############## ######## ######### #### ############## ######## ######### #### ############## ######## ################### ############## ######## ################### ################################################## ################################################## ################################################## ### ######################################## ### ######################################## ### ######################################## ### #################################### ### ##################### ######## ### #### ########## ######## ### #### ########## ############ ### #### ########## ############ ### #### ############################# ### ######################################## ################################################## ###### ### ######################### ###### ### ################### # ###### ### ################### # ###### ### ################### # ###### ### ### ############# # ###### ### ### ############# # ###### ### ### ############# # ###### ### ######################### ###### ### ######################### ###### ##################################### ###### ##################################### [/code] Which for the most part works but it doesnt seem to take into count the room margins as there are rooms that are directly on the border and are directly touching. this is the new code [csharp] public static class MakeDungeon { static int depthLevel = 6; static int roomMargin = 1;//Min margin a room has in its rect static int minRoomWidth = 3; static int minRoomHeight = 3; static Random rand = new Random(); public static byte[,] MakeLevel (int pWidth, int pHeight) { return MakeLevel (pWidth, pHeight, rand.Next ()); } static List<Rectangle> SplitHor (Rectangle r) { List<Rectangle> list = new List<Rectangle> (); int splitAt = r.Width / 2; list.Add (new Rectangle (r.X, r.Y, splitAt, r.Height)); list.Add (new Rectangle (r.X + splitAt, r.Y, r.Width - splitAt, r.Height)); return list; } static List<Rectangle> SplitVer (Rectangle r) { List<Rectangle> list = new List<Rectangle> (); int splitAt = r.Height / 2; list.Add (new Rectangle (r.X, r.Y, r.Width, splitAt)); list.Add (new Rectangle (r.X, r.Y + splitAt, r.Width, r.Height - splitAt)); return list; } static Rectangle makeRoom(Rectangle rec) { int width = rand.Next(minRoomWidth, rec.Width - (roomMargin*2) + 1); int height = rand.Next(minRoomHeight, rec.Height - (roomMargin*2) + 1); int x = rand.Next(rec.X + roomMargin, rec.X + ( rec.Width - (width - roomMargin*2) + 1)); int y = rand.Next(rec.Y + roomMargin, rec.Y + ( rec.Height - (height - roomMargin*2) + 1)); return new Rectangle(x,y,width,height); } public static byte[,] MakeLevel (int pWidth, int pHeight, int pSeed) { rand = new Random (pSeed); byte[,] dungeon = new byte[pHeight, pWidth]; List<Rectangle> rectList = new List<Rectangle> (); rectList.Add (new Rectangle (0, 0, pWidth - 1, pHeight - 1)); List<Rectangle> tempRects = new List<Rectangle> (); for (int i = 0; i < depthLevel; i++) { //Subdivide room to max depth foreach (Rectangle rect in rectList) { if (i % 2 == 0) tempRects.AddRange (SplitHor (rect)); else tempRects.AddRange (SplitVer (rect)); } rectList.Clear (); rectList.AddRange (tempRects); tempRects.Clear (); if (i == depthLevel - 1) { //in the final depth level create the actual rooms foreach (Rectangle rect in rectList) { tempRects.Add (makeRoom(rect)); } rectList.Clear (); rectList.AddRange (tempRects); tempRects.Clear (); } } for (int y = 0; y < pHeight; y++) { for (int x = 0; x < pWidth; x++) { byte r = 1; foreach (Rectangle rect in rectList) { if (rect.Contains (x, y)) { dungeon [y, x] = r; break; } else dungeon [y, x] = 0; r++; } } } return dungeon; } } public static void Main (string[] args) { int a = 50; byte[,] room = TheTower.Dungeon.MakeDungeon.MakeLevel (a, a); for (int y = 0; y < a; y++) { for (int x = 0; x < a; x++) { if(room[y,x] == 0) System.Console.Write("#"); else System.Console.Write(" "); } System.Console.WriteLine(""); } } [/csharp]
[QUOTE=elih595;37493466]Anyone know how to make collision between a player and a wall? I'm using c# but any language I use I run into the same problem. I have 2 squares one is the player and one is supposed to be a wall. I can make it so the player cant go through one side of the square. But I can never make the other sides because it just uses the same if statement in different order. I was just wondering how to make very basic collision between 2 squares. if (playerX+playerW >= wallX && playerX <= wallX+wallW && playerY <= wallY+wallH && playerY+playerH >= wallY) { playerX = playerX - speed; }[/QUOTE] Use aabb collision tests and solving. How I do it is like this: [cpp]for (unsigned int i=0;i<Players.size();i++) { //If your tiles are on a fixed grid, you should only loop through a chunk of the tiles that are near the current player. for (unsigned int o=0;o<NearbyTiles.size();o++) { Player* CP = Players[i]; Tile* CT = NearbyTiles[o]; //The functions assume the boxes' positions represent the center of the box. glm::vec4 PBox = glm::vec4(CP->GetPos().x,CP->GetPos().y,CP->GetScale().x,CP->GetScale().y); glm::vec4 TBox = glm::vec4(CT->GetPos().x,CT->GetPos().y,CT->GetScale().x,CT->GetScale().y); if (Intersects(PBox,TBox)) { glm::vec2 Move = MinimumTranslation(PBox,TBox); //If we can only move the player we use this; otherwise you should halve Move and add/subtract it to both boxes' positions. CP->SetPos(CP->GetPos()+Move); } } }[/cpp] I'm using the functions described here: [url]https://github.com/naelstrof/Astrostruct/blob/master/src/NPhysics.hpp[/url] and defined here: [url]https://github.com/naelstrof/Astrostruct/blob/master/src/NPhysics.cpp[/url]
-snip-
I'm trying to connect to my brothers PC to secretly "view" his things, and I've figured out all of the Command Prompt commands for it, but currently I've been getting error 5, So I made an administrator account and I still have to use Remote Desktop Connection-- Which I need a password to connect with, but I don't have it, and CMD is saying I must use a Windows Domain Controller-- I can't find any a credible one anywhere, So facepunch programmers, this is what I ask of you -- I need a Windows Domain Controller. that's all
[QUOTE=Weeds;37500143]I'm trying to connect to my brothers PC to secretly "view" his things, and I've figured out all of the Command Prompt commands for it, but currently I've been getting error 5, So I made an administrator account and I still have to use Remote Desktop Connection-- Which I need a password to connect with, but I don't have it, and CMD is saying I must use a Windows Domain Controller-- I can't find any a credible one anywhere, So facepunch programmers, this is what I ask of you -- I need a Windows Domain Controller. that's all[/QUOTE] ...Shouldn't you be asking in H&S?
I have kind of found myself at a roadblock. I have being learning Lua for a while now, and feel like I have a firm grasp on how it works and how I can use it with Love2D, however I don't know how to advance from here... I know how to use the various APIs for Love2D and such but don't know how to take the next step :| Any suggestions?
[QUOTE=JakeAM;37501872]I have kind of found myself at a roadblock. I have being learning Lua for a while now, and feel like I have a firm grasp on how it works and how I can use it with Love2D, however I don't know how to advance from here... I know how to use the various APIs for Love2D and such but don't know how to take the next step :| Any suggestions?[/QUOTE] Is Love2D unsatisfactory for you? What do you desire? If you want to have more power over what's going on you can try C or C++. If you want to do more faster (with a similar power increase) try C#.
ok so i redid the whole random number roll to hit your opponent and opponent to hit you here is what i get. However it needs to be over 20 to hit. Heres the code. i only posted this because this one has me scratching my head, i fixed most of the errors myself. [IMG]http://puu.sh/11cro[/IMG] [code]#include <iostream> #include <cstdlib> #include <ctime> #include <string> using namespace std; int main() { string name; string prompt = "Welcome to war of the gangs what is your name?: "; cout << prompt; getline(cin, name); cout <<"ok " << name << "prepare for battle!"; int turn = 1; int damage = 5; int playerhealth = 100; int enemyhealth = 100; srand(time(NULL)); int roll; while(playerhealth == 100 && enemyhealth == 100) { roll = rand() % 31; if(roll <= 20) { cout << "\nthe shots missed! " << roll; } else if(roll >= 20) { roll = rand() % 31; cout << " \nRival was hit!" << roll; enemyhealth = enemyhealth - damage; cout << " Rivals health: " << enemyhealth; turn = 2; } if(turn == 2 && roll < 20) { roll = rand() % 31; cout << "\nRivals shots missed! " << roll; turn = 1; } else if(turn == 2 && roll >= 20) { roll = rand() % 31; cout << "\nRival hit you!" << roll; playerhealth = playerhealth - damage; cout << "\nYour health remaining: " << playerhealth; } if(playerhealth == 0) { cout << "you failed your fellow gang memebers respect."; } else if(enemyhealth == 0) { cout << "you have been promoted to high class member."; } } return 0; } [/code]
Whats a way to read a file quickly in Java? I just have a simple text file, and I want to read the map information from there, however using a scanner seems to take a hell of a long time when the map is big enough (right now it's 60*30). Is there a way to make it read faster, or to use an unstructured reader and just ignore newlines and spaces? [editline]2nd September 2012[/editline] Also, for some reason my app takes a long time to compose the screen, according to the show CPU debugger option (Android). This causes the device to heat up, but the thing is pretty simple right now. It does the same thing with my friend's phone, but we both get steady ~66 fps. It does have to render ~4000 triangles on my phone, but the data is all the same (they all make up squares). If this is it, how can I optimize drawing so many triangles?
[QUOTE=confinedUser;37504533]ok so i redid the whole random number roll to hit your opponent and opponent to hit you here is what i get. However it needs to be over 20 to hit. Heres the code. i only posted this because this one has me scratching my head, i fixed most of the errors myself. [code]while(playerhealth == 100 && enemyhealth == 100)[/code][/QUOTE] Dunno really what the problem is, but if you use this condition, the program will quit if anyone get hit once.
[QUOTE=AlienCat;37507087]Dunno really what the problem is, but if you use this condition, the program will quit if anyone get hit once.[/QUOTE] i was going to solve that one but thanks for spotting it, look at the last line it said 14 was a hit when it should of been a miss
You are re-rolling after checking if the enemy roll is above 20: [code]else if(turn == 2 && roll >= 20) { roll = rand() % 31; cout << "\nRival hit you!" << roll; playerhealth = playerhealth - damage; cout << "\nYour health remaining: " << playerhealth; }[/code]
In C#, how can i parse this string "0:5:1000" into an array which will look like {0, 5, 1000}. Note that the array has to have ints. Thanks :)
[code] using System.Collections.Generic; using System.Linq; string nums = "0:5:1000" List<string> strs = nums.Split(':'); List<int> result = new List<int>(); strs.ForEach(item => result.Add(Convert.ToInt16(item))); [/code] something like that, I can't test it right now
[QUOTE=MakeR;37507411]You are re-rolling after checking if the enemy roll is above 20: [code]else if(turn == 2 && roll >= 20) { roll = rand() % 31; cout << "\nRival hit you!" << roll; playerhealth = playerhealth - damage; cout << "\nYour health remaining: " << playerhealth; }[/code][/QUOTE] oh so that's whats been getting me. Thanks :)
[QUOTE=Naelstrom;37503294]Is Love2D unsatisfactory for you? What do you desire? If you want to have more power over what's going on you can try C or C++. If you want to do more faster (with a similar power increase) try C#.[/QUOTE] It's not really unsatisfactory, it's more that I know Lua and how to use Love2D but don't know how to move on to actually make decent things from this.
Does anyone have a good resource for implementing quadtrees or octrees? I understand the concept, but I just don't know what goes into the actual structure.
[QUOTE=pryrotechfan;37508428]Does anyone have a good resource for implementing quadtrees or octrees? I understand the concept, but I just don't know what goes into the actual structure.[/QUOTE] [URL="http://en.wikipedia.org/wiki/Quadtree"]http://en.wikipedia.org/wiki/Quadtree[/URL] [URL="http://www.codeproject.com/Articles/30535/A-Simple-QuadTree-Implementation-in-C"]http://www.codeproject.com/Articles/30535/A-Simple-QuadTree-Implementation-in-C[/URL] [URL="http://www.kyleschouviller.com/wsuxna/quadtree-source-included/"]http://www.kyleschouviller.com/wsuxna/quadtree-source-included/[/URL] [URL="http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves"]http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves[/URL] [URL="http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/quadtrees-r1303"]http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/quadtrees-r1303[/URL] As for octtrees I havent really looked yet, but its pretty much the same as quadtree, but with a nother dimension
[QUOTE=Richy19;37509041][URL]http://en.wikipedia.org/wiki/Quadtree[/URL] [URL]http://www.codeproject.com/Articles/30535/A-Simple-QuadTree-Implementation-in-C[/URL] [URL]http://www.kyleschouviller.com/wsuxna/quadtree-source-included/[/URL] [URL]http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-indexing-with-Quadtrees-and-Hilbert-Curves[/URL] [URL]http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/quadtrees-r1303[/URL] As for octtrees I havent really looked yet, but its pretty much the same as quadtree, but with a nother dimension[/QUOTE] Thanks for all the resources. I should be able to get it after this....hopefully.
[QUOTE=WTF Nuke;37504718]Whats a way to read a file quickly in Java? I just have a simple text file, and I want to read the map information from there, however using a scanner seems to take a hell of a long time when the map is big enough (right now it's 60*30). Is there a way to make it read faster, or to use an unstructured reader and just ignore newlines and spaces? [editline]2nd September 2012[/editline] Also, for some reason my app takes a long time to compose the screen, according to the show CPU debugger option (Android). This causes the device to heat up, but the thing is pretty simple right now. It does the same thing with my friend's phone, but we both get steady ~66 fps. It does have to render ~4000 triangles on my phone, but the data is all the same (they all make up squares). If this is it, how can I optimize drawing so many triangles?[/QUOTE] Can you explain more about the file format and how it is being translated into memory? The fastest way to read data depends on the source and destination format of the data.
Why the hell am I getting this: obj/Debug/src/Shader.o||In function `PrintGLErrors()':| /home/richy/codeblocks/GLUtil/src/./Utilities.hpp|7|multiple definition of `PrintGLErrors()'| obj/Debug/src/FBO.o:/home/richy/codeblocks/GLUtil/src/./Utilities.hpp|7|first defined here| I have [cpp] #ifndef UTILITIES_HPP_INCLUDED #define UTILITIES_HPP_INCLUDED #include "./GLUtilMaster.hpp" bool PrintGLErrors() { GLuint ec = glGetError (); if (ec != 0) { std::cout << ec << std::endl; return false; } return true; } #endif // UTILITIES_HPP_INCLUDED [/cpp] Then GLUtilMaster.hpp includes the utilities.hpp, and all classes include GLUtilMaster.hpp, I thought the ifndef... was meant to prevent this
[QUOTE=calzoneman;37510327]Can you explain more about the file format and how it is being translated into memory? The fastest way to read data depends on the source and destination format of the data.[/QUOTE] It's a TXT file encoded with ANSI, however I can change this at any time. The destination is to be used in an ArrayList, as this is a map. I'm not sure about the encoding though, as I am just using the Eclipse editor to save it to the android app. [editline]2nd September 2012[/editline] So I am trying to speed up my drawing, and this is my current draw function. [cpp]{ GLES20.glUniformMatrix3fv(mTextureMatrixHandle, 1, false, render.mTexMatrix, 0); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, render.mPos.X, render.mPos.Y, 0); Matrix.scaleM(mModelMatrix, 0, render.mWidth, render.mHeight, 1.f); if(camera){ Matrix.multiplyMM(mMVPMatrix, 0, mCameraMatrix, 0, mModelMatrix, 0); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0); } else Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mModelMatrix, 0); GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6); }[/cpp] According to DDMS tracer, this uses up 92% of CPU time. The distribution is self, 37.4%, multiplyMM 17.8%, drawArrays, 11%, and the other functions take about 7%-5% each. What confuses me is that the function itself takes up 37.4% of the CPU time, yet it does nothing but call other functions, apart from a boolean check. Is this normal? And how can I optimize this?
I think I've seen somewhere in this sub forum that they don't like python. I would be nice if why python is bad because I just started learning it and if i should stop and learn something else.
[QUOTE=jung3o;37512894]I think I've seen somewhere in this sub forum that they don't like python. I would be nice if why python is bad because I just started learning it and if i should stop and learn something else.[/QUOTE] Python is a great language for learning. I think there are 2 main reasons Facepunchers don't like it: 1. The syntax is very different from C-like languages (this is just a personal preference) 2. Some people have a superiority complex for languages that get faster scores on arbitrary benchmarks As long as the tutorials you're learning from (if you are using tutorials) are teaching the right practices the language is really irrelevant.
There are some easy way to swap between a native pc application and an android one in java or do you need to keep two different projects?
[QUOTE=AlienCat;37514872]There are some easy way to swap between a native pc application and an android one in java or do you need to keep two different projects?[/QUOTE] Depends on what you're doing.
I'm kind of new to C#, and programming at all. I'm trying to create a fairly simple program in which a you're presented with a conversation and have three replies. Each reply award you with a number of affection points. Obviously just something I'm creating as a learning progress. Anyway, I have a button which is supposed to check what you've chosen. You choose by checking a radiobutton, and the way I wanted it to work was using switch statements. As far as I know, you can't check several different radiobuttons within a switch statement, so I created several switch statements within the button curly braces, and I'm getting errors. Here's the code [code] private void button1_Click(object sender, EventArgs e) { switch (radioButtona.Checked) { case true: MessageBox.Show("You gained 1 affection point!"); break; default: break; } switch (radioButtonb.Checked) case true: MessageBox.Show("You gained 0 affection points!"); break; default: break; } switch (radioButtonc.Checked) { case true: MessageBox.Show("You gained 2 affection points!"); break; default: break; } [/code] Can someone tell me how to fix this, or tell me about a better way to execute this? Thanks :) [editline]3rd September 2012[/editline] Oh by the way, if someone would love to have a noob in his friend list, on Steam, asking questions like this once in a while, feel free to add me ^^
There's no point to switching on a bool, switch is meant for cases where there are a lot of different possible values (for example, [url=http://www.dotnetperls.com/switch-enum]with enums[/url]) and you don't want to create a giant if-else if block. You can turn each switch block into: [csharp] if (radioButtona.Checked) MessageBox.Show("You gained 1 affection point!"); else if (radioButtonb.Checked) MessageBox.Show("You gained 0 affection points!"); else if (radioButtonc.Checked) MessageBox.Show("You gained 2 affection points!"); [/csharp] Also it would help us a LOT if you could post the actual error you get instead of just saying you're getting an error. From just what I see here, you're missing an opening bracket on the second switch block and the closing bracket at the very end.
[QUOTE=robmaister12;37515791]There's no point to switching on a bool, switch is meant for cases where there are a lot of different possible values (for example, [url=http://www.dotnetperls.com/switch-enum]with enums[/url]) and you don't want to create a giant if-else if block. You can turn each switch block into: [csharp] if (radioButtona.Checked) MessageBox.Show("You gained 1 affection point!"); else if (radioButtonb.Checked) MessageBox.Show("You gained 0 affection points!"); else if (radioButtonc.Checked) MessageBox.Show("You gained 2 affection points!"); [/csharp] Also it would help us a LOT if you could post the actual error you get instead of just saying you're getting an error. From just what I see here, you're missing an opening bracket on the second switch block and the closing bracket at the very end.[/QUOTE] Ah thanks a lot :) The reason why I didn't do that is because I get 11, to be quite specific. My guess was that you simply couldn't have several switch statements ^^
Sorry, you need to Log In to post a reply to this thread.