• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=Mr_Razzums;32475710]I'm super super new at programming in general, and I'm doing c++. I'm making a tic tac toe game and this is the code I'm using the check to see if there is a winner (just winning via column or row. Not diagonally.) Is there any way I can compress this code????[/QUOTE] Something like this... [CODE]for ( int j = 0; j <= 2; ++j ) { if ( ( iaBoard[0][j] == iaBoard[1][j] ) && ( iaBoard[1][j] == iaBoard[2][j] ) ) iWinner = iaBoard[0][j] == 1 ? 1 : 2; else if ( ( iaBoard[j][0] == iaBoard[j][1] ) && ( iaBoard[j][1] == iaBoard[j][2] ) ) iWinner = iaBoard[j][0] == 1 ? 1 : 2; }[/CODE]
[QUOTE=leontodd;32475966]How would I access it from the RAM, without any of it going to the HDD?[/QUOTE] Programs can [i]only[/i] access data in RAM. Accessing a file on disk works by reading it into RAM, and/or writing data from RAM back to disk. When a program downloads a file, the incoming packets are stored in a RAM buffer in the network card, and the network card sends an interrupt to the processor which signals the OS to copy the data from there into system RAM so the program can access it. The program can choose to keep it there, or it can write it to disk and then discard the RAM copy.
Trying to make a simple Shmup in XNA C# but am having trouble with creating my list so I can shoot multiple bullets at a time. [code]using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Shmup { public class Game1 : Microsoft.Xna.Framework.Game { Texture2D playerTexture; Texture2D backgroundTexture; Texture2D bulletTexture; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; int Php; int shootTimer = 0; Vector2 bulletPosition; Vector2 playerPosition; bool shooting = false; List<Vector2> bulletList = new List<Vector2>(); Random randomizer = new Random(); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 600; graphics.IsFullScreen = false; base.Initialize(); } protected override void LoadContent() { playerTexture = Content.Load<Texture2D>("shmupship2"); backgroundTexture = Content.Load<Texture2D>("background"); bulletTexture = Content.Load<Texture2D>("bullet"); spriteBatch = new SpriteBatch(GraphicsDevice); SetUpPlayer(); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); ProcessKeyboard(); BulletUpdate(); shootTimer = shootTimer + 1; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); DrawBackground(); BulletDraw(); DrawPlayer(); spriteBatch.End(); base.Draw(gameTime); } private void SetUpPlayer() { Php = 100; playerPosition.X = graphics.PreferredBackBufferWidth / 2; playerPosition.Y = 400; } private void DrawPlayer() { if (Php > 0) { Vector2 playerOrigin = new Vector2(20, 20); spriteBatch.Draw(playerTexture, new Vector2(playerPosition.X, playerPosition.Y), null, Color.White, 0, playerOrigin, 1, SpriteEffects.None, 0); } } private void DrawBackground() { spriteBatch.Draw(backgroundTexture, new Vector2(0, 0), null, Color.White, 0, new Vector2(0, 0), 1, SpriteEffects.None, 1); } private void ProcessKeyboard() { KeyboardState keybstate = Keyboard.GetState(); if (keybstate.IsKeyDown(Keys.A)) playerPosition.X = playerPosition.X - 2; if (keybstate.IsKeyDown(Keys.D)) playerPosition.X = playerPosition.X + 2; if (keybstate.IsKeyDown(Keys.Space)) { if (shootTimer > 30) { Vector2 bulletPosition; shooting = true; bulletPosition = playerPosition; bulletPosition.Y = playerPosition.Y - 20; [b]bulletList.Add(bulletPostion);[/b] shootTimer = 0; } } } private void BulletDraw() { //if (shooting) { foreach (Vector2 bulletPosition in bulletList) spriteBatch.Draw(bulletTexture, bulletPosition, null, Color.White, 0, new Vector2(2, 5), 1, SpriteEffects.None, 0); } } private void BulletUpdate() { { bulletPosition.Y = bulletPosition.Y - 5; } } } } [/code] But I'm getting a this error. The name 'bulletPostion' does not exist in the current context 125 39 Shmup (line is bolded) I may be going about this all the wrong way. I'm so dazed and confused. Any help would be appreciated.
does microsoft visual c++ 2010 let me view my programs output? I need something to check it because its due tomorrow.
[IMG]http://i.imgur.com/EMG2G.png[/IMG] Creating a windows form, set the border to fixed single to get the 1px border. There dont seem to be any preferences to change the colour. Any ideas?
[QUOTE=MadPro119;32480039]Trying to make a simple Shmup in XNA C# but am having trouble with creating my list so I can shoot multiple bullets at a time. [code] [/code] But I'm getting a this error. The name 'bulletPostion' does not exist in the current context 125 39 Shmup (line is bolded) I may be going about this all the wrong way. I'm so dazed and confused. Any help would be appreciated.[/QUOTE] bulletPos[B]i[/B]tion*
[QUOTE=Rocket;32481401]It's the ForeColor property.[/QUOTE] I did try changing the forecolor. I'll try again. [editline]26th September 2011[/editline] Yeah, It doesent change the border colour just the font.
[QUOTE=xxncxx;32481312]does microsoft visual c++ 2010 let me view my programs output? I need something to check it because its due tomorrow.[/QUOTE] I've always wanted to find this out. The only way I could do it was drag the .exe into cmd prompt and type some shit, like: app.exe > output.txt I know VS has a debug properties and you can enter command line parameters there but that never worked for me. =/ I have an exam on Friday and learning how to do this would be SUPER helpful. ** EDIT ** Bingo! Right-click on your project, go to Properties, go to Debugging section. In where it says "Command Arguments", type in: > output.txt (can be any random name) Then CTRL + F5 (start without debugging). It MUST be start without debugging, or else it will not work. The output.txt file will be in your project's directory.
-Snip- Human Error.
How would i do tilemap collisions in XNA? I have a list of tiles, each has their own properties. The easiest way to test is to scroll through each of the tiles, and check if the player's bounding box collides with the tiles bounding box. This may not be that efficient, since the map can have way over 5000 tiles.
[QUOTE=Funley;32490222]How would i do tilemap collisions in XNA? I have a list of tiles, each has their own properties. The easiest way to test is to scroll through each of the tiles, and check if the player's bounding box collides with the tiles bounding box. This may not be that efficient, since the map can have way over 5000 tiles.[/QUOTE] player's tile position = floor(player's pos / tile size) Use that to figure out which tile(s) the player is over and just check those.
[QUOTE=Chris220;32490271]player's tile position = floor(player's pos / tile size) Use that to figure out which tile(s) the player is over and just check those.[/QUOTE] Doesnt that return the current tile the player is on? So i should check collision for the tiles surrounding that tile, right?
I'm trying to make a (C#) class library from my game code, I have these two classes I want accessible: [csharp] namespace WorkingTitle1_ClassLibrary { public class WorkingTitleInstance: IDisposable { //stuff } } [/csharp] [csharp] namespace WorkingTitle1_ClassLibrary { class Camera { //stuff } } [/csharp] The first, WorkingTitleInstance, which is a new class I made for the class library, IS accessible from applications that reference WorkingTitle1_ClassLibrary, whereas the Camera class is NOT accessible. If I type in WorkingTitle1_ClassLibrary. intellisense only says WorkingTitleInstance exists in that namespace. What am I doing wrong?
Could be something with the default modifier for classes which is internal. [url]http://msdn.microsoft.com/en-us/library/7c5ka91b.aspx[/url]
[QUOTE=Funley;32490331]Doesnt that return the current tile the player is on? So i should check collision for the tiles surrounding that tile, right?[/QUOTE] Yes indeedy.
[QUOTE=FlashStock;32490748]Could be something with the default modifier for classes which is internal. [url]http://msdn.microsoft.com/en-us/library/7c5ka91b.aspx[/url][/QUOTE] That was it, thanks!
Hi, so I got my list working for making multiple bullets in XNA. It uses a foreach to draw multiple bullets for each key press. Unfortunately when I try to add a foreach to my bullet update method which moves the bullet. [code]private void BulletUpdate() { { bulletPosition.Y = bulletPosition.Y - 5; } } } } [/code] When I change this to (add the foreach) [code] private void BulletUpdate() { { foreach (Vector2 bulletPosition in bulletList) bulletPosition.Y = bulletPosition.Y - 5; } } } } [/code] It does not move the bullets. I assumed it would. Am I going about this all the wrong way? Here is all the code. [code]using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace Shmup { public class Game1 : Microsoft.Xna.Framework.Game { Texture2D playerTexture; Texture2D backgroundTexture; Texture2D bulletTexture; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; int Php; int shootTimer = 0; Vector2 bulletPosition; Vector2 playerPosition; bool shooting = false; List<Vector2> bulletList = new List<Vector2>(); Random randomizer = new Random(); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 600; graphics.IsFullScreen = false; base.Initialize(); } protected override void LoadContent() { playerTexture = Content.Load<Texture2D>("SHMUP"); backgroundTexture = Content.Load<Texture2D>("background"); bulletTexture = Content.Load<Texture2D>("bullet"); spriteBatch = new SpriteBatch(GraphicsDevice); SetUpPlayer(); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); ProcessKeyboard(); BulletUpdate(); shootTimer = shootTimer + 1; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); DrawBackground(); BulletDraw(); DrawPlayer(); spriteBatch.End(); base.Draw(gameTime); } private void SetUpPlayer() { Php = 100; playerPosition.X = graphics.PreferredBackBufferWidth / 2; playerPosition.Y = 400; } private void DrawPlayer() { if (Php > 0) { Vector2 playerOrigin = new Vector2(20, 20); spriteBatch.Draw(playerTexture, new Vector2(playerPosition.X, playerPosition.Y), null, Color.White, 0, playerOrigin, 1, SpriteEffects.None, 0); } } private void DrawBackground() { spriteBatch.Draw(backgroundTexture, new Vector2(0, 0), null, Color.White, 0, new Vector2(0, 0), 1, SpriteEffects.None, 1); } private void ProcessKeyboard() { KeyboardState keybstate = Keyboard.GetState(); if (keybstate.IsKeyDown(Keys.A)) playerPosition.X = playerPosition.X - 2; if (keybstate.IsKeyDown(Keys.D)) playerPosition.X = playerPosition.X + 2; if (keybstate.IsKeyDown(Keys.Space)) { if (shootTimer > 30) { Vector2 bulletPosition; shooting = true; bulletPosition = playerPosition; bulletPosition.Y = playerPosition.Y - 20; bulletList.Add(bulletPosition); shootTimer = 0; } } } private void BulletDraw() { //if (shooting) { foreach (Vector2 bulletPosition in bulletList) spriteBatch.Draw(bulletTexture, bulletPosition, null, Color.White, 0, new Vector2(2, 5), 1, SpriteEffects.None, 0); } } private void BulletUpdate() { { foreach (Vector2 bulletPosition in bulletList) bulletPosition.Y = bulletPosition.Y - 5; } } } }[/code]
[QUOTE=MadPro119;32494099]Hi, so I got my list working for making multiple bullets in XNA. It uses a foreach to draw multiple bullets for each key press. Unfortunately when I try to add a foreach to my bullet update method which moves the bullet. [code] private void BulletUpdate() { { foreach (Vector2 bulletPosition in bulletList) bulletPosition.Y = bulletPosition.Y - 5; } } } }[/code][/QUOTE] You have to do something like for(int i = 0; i < bulletList.Count; i++) bulletList[i] = new Vector2(bulletList[i].X, bulletList[i].Y - 5); As Vector2 is a struct so it gets copied by value and not by reference. This means the Vector2 bulletPosition is separate from the Vector2 inside the list.
I seem to be having problems tracing my mouse cursor onto the 3D gui. Here is my code: [code]private Vector2 TraceMouse(Vector2 mousecoord, Matrix world) { Vector3 pos1 = GraphicsDevice.Viewport.Unproject(new Vector3(mousecoord, 0f), mtxProjection, mtxEye, Matrix.Identity); Vector3 pos2 = GraphicsDevice.Viewport.Unproject(new Vector3(mousecoord, 1f), mtxProjection, mtxEye, Matrix.Identity); Vector3 direction = Vector3.Normalize(pos2 - pos1); Ray ray = new Ray(camPos, direction); Plane plane = new Plane(quad.Origin, quad.Origin + quad.Up, quad.Origin + quad.Left); var t = ray.Intersects(plane); Vector3 worldPos = ray.Position + (ray.Direction * t.Value); Matrix invObj = Matrix.Invert(mtxMVQuad); Vector4 objCoord = Vector4.Transform(new Vector4(worldPos, 1f), invObj); Vector2 result = new Vector2((objCoord.X + 1f) / 2f, (objCoord.Y + 1f) / 2f); result.Y = 1f - result.Y; result = (result ) * 512f; return result; }[/code] The gui is internally sized at 512x512. It [i]mostly[/i] works, but it's just not very accurate - the projected position is somewhat off, and doesn't move at the right speed either.
I need some help with a Java issue. I've got some library initializing a subclass in another thread, and then it flips a shit when that inner class tries to access its parent. How can I go about fixing this?
Does anyone know anything about setting up SFML.NET for Visual C# 2010? I've been looking at the C++ setup tutorials regarding linker settings and so on but there doesn't seem to be anything similar for C# - I've managed to find a "build" tab for my project and I guess I'll find out how to use compiler arguments to include the library files, but does anyone know how to have this done automatically in the VS2010 settings?
I want to read a file and have it output 20 lines of that file at the press of a button. Im trying todo this with Fprintf or getting one string of the file with Gets but I have no clue how I can get it to read annything else but the first line of the file. TLDR: How do I write a specific line from a file to a string in [B]C[/B.
Is there a binary operation to do this: [code]1100001100111100 -> 10010110 0011110011000011 -> 01101001 1100 -> 10 1111110011 -> 11101 ...[/code] Which is compressing the string by skipping every second digit. Is there a series of operations I can do to achieve this without just iterating through the string? I can't think properly today. [editline]27th September 2011[/editline] [QUOTE=Cello;32502811]Does anyone know anything about setting up SFML.NET for Visual C# 2010? I've been looking at the C++ setup tutorials regarding linker settings and so on but there doesn't seem to be anything similar for C# - I've managed to find a "build" tab for my project and I guess I'll find out how to use compiler arguments to include the library files, but does anyone know how to have this done automatically in the VS2010 settings?[/QUOTE] You should get a set of .dlls after building the .NET bindings from the SFML svn (bindings/dotnet/lib/). Take these and add them as references to your project. You'll also need to move the .dlls from bindings/dotnet/extlibs/ to the build directory of your project.
Why doesnt this work: It just prints gibberish. [code]#include <stdio.h> #include <stdlib.h> /*****************************************************************************/ int main () { char String [255]; char a [255]; FILE *BEW1; BEW1 = fopen ("Opdr_4_text.txt","r"); if(BEW1 == NULL) { printf ("Cannot open file\n"); } else { //Methode 1************************************************** if ( fgets (a , 100 , BEW1) != NULL )puts (a); if ( fgets (a , 100 , BEW1) == NULL ) printf ("nope.\n\n,"); //Methode 2************************************************** fgets (String , 100000000 , BEW1) != NULL ; puts (String); //Methode 3************************************************** fscanf(BEW1,"%s \n",&a); printf("%s\n",a); } fclose (BEW1); return 0; } [/code] [editline]27th September 2011[/editline] 1:Returns Nope (So NULL) 2:Returns aaaaaAAAAAaaaa-dfkdfj4_knfui4h <-- Random crap There is actually the word wikipedia in Opdr_4_text.txt on 290 lines. 3:Returns gibberish but only 4 characters of it. [editline]27th September 2011[/editline] Nvm had to reset filepointer. rewind(BEW1);
[QUOTE=Ziks;32503788]You should get a set of .dlls after building the .NET bindings from the SFML svn (bindings/dotnet/lib/). Take these and add them as references to your project. You'll also need to move the .dlls from bindings/dotnet/extlibs/ to the build directory of your project.[/QUOTE] Alright I've managed to add the dlls inside dotnet/lib to my references, but for some reason it's not detecting the extlibs stuff in my project folder - "Unable to load csfml-graphics" and so on. Any idea as to what's causing this?
Does anyone know how to get any kind of decent texture filtering on Images in SFML? I can't find anything about it or about auto-mipmaps, and Image.setSmooth(true) makes almost no difference. I'm using textures that normally only scale down (from 1024).
Playing around with console applications on C#, I'm trying to make a little math quiz but I don't know how to check for user input, any help? [editline]27th September 2011[/editline] Would it be close to this? [code]System.Console.Write("Hello!\n"); System.Console.Write("1+1 = args{0}?", args[0]); if args = 2 System.Console.Write("Correct!");[/code]
[QUOTE=Themage;32510002]Playing around with console applications on C#, I'm trying to make a little math quiz but I don't know how to check for user input, any help?[/QUOTE] [code] System.Console.Write("Hello!\n"); System.Console.Write("1+1 = ?"); string answer = System.Console.ReadLine(); if(answer == "2") System.Console.Write("Correct!"); [/code]
Thanks!
I need to write a recursive function in java that takes one int stars and prints a triangle starting with one star and ending with the number entered. I have the printStars method which takes an int for the number of stars to print on one line. For example: printRecur(5); should print * ** *** **** ***** Any idea how to do this? I already made the reverse of this which was much easier, just subtract one each time until it reaches 0.
Sorry, you need to Log In to post a reply to this thread.