Poll of the Day > Easy-ish programming question

Topic List
Page List: 1
Yellow
07/08/18 5:39:58 AM
#1:


I'm in the middle of rewriting my entire game engine. I started writing it when I didn't know how to use objects. I tried salvaging what I could, but only so much can be reworked before it's easier to just rewrite the whole thing.

Then I learned about polymorphism, and now I'm sure I'm just going to throw the whole thing away, because polymorphism seems too fundamental to objects working with each other to not design your program around. There's also a ton of rogue code in my main loop.

Am I ever going to finish my game? Probably not. Am I going to have fun solving this puzzle on how to make a professionally designed game engine? Yeah.

Anyway, I want a predefined constant object, I remember there was a color class I could access with

Color col = Color::Red;

Now I'm trying to figure out how to do it myself.

class AirState
{
public float gravity;
public float air_resistance;

// This is broken
public const AirState Earth = new AirState { gravity = -1f, resistance = 0.02f };
}
---
... Copied to Clipboard!
Digimon
07/08/18 5:48:10 AM
#2:


is this a question, or
---
F***IN' DIGITAL MONSTERS
... Copied to Clipboard!
Yellow
07/08/18 5:52:57 AM
#3:


Sorry, I'm asking how to do this

Color my_color = Color::Red;

in my own class, which I only know from using XML and VB's color classes.

Basically I can make a color and set it to the color red immediately using Microsoft's Color class. I want to do the same thing with states of world objects reacting to constants in their environments such as air resistance and gravity.

Basically what I want to do is

AirState state = AirState::Earth;

and I don't know how.
---
... Copied to Clipboard!
Judgmenl
07/08/18 8:01:21 AM
#4:


I'm not doing your homework for you and I suggest nobody else does. TC should be asking his classmates / professor for assistance, not PotD.

Edit: You seem have zero idea what you are doing. Do you even have programming experience? Maybe I am wrong about the homework part.
---
Judge, Nostalgia is a hell of a drug.
You're a regular Jack Kerouac
... Copied to Clipboard!
Yellow
07/08/18 3:32:55 PM
#5:


Judgmenl posted...
I'm not doing your homework for you and I suggest nobody else does. TC should be asking his classmates / professor for assistance, not PotD.

Edit: You seem have zero idea what you are doing. Do you even have programming experience? Maybe I am wrong about the homework part.

Apparently you can't read

I don't want you to answer my question. I'll figure it out myself, like I have with everything I know about the 5 languages I taught myself in my free time.

Clean your room
---
... Copied to Clipboard!
SinisterSlay
07/08/18 3:36:37 PM
#6:


So you want static variables or constants?
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
... Copied to Clipboard!
TheWorstPoster
07/08/18 3:44:30 PM
#7:


Is it Java or C# you're coding in?

If it's C++, then I can't help you.

I also never saw :: before for my programming assignments, so I have no idea what to do with it.
... Copied to Clipboard!
ParanoidObsessive
07/08/18 3:50:10 PM
#8:


TheWorstPoster posted...
I also never saw :: before for my programming assignments, so I have no idea what to do with it.

I feel like ADA uses that, but I've completely forgotten nearly everything I ever knew about coding in ADA, so I can't remember for sure.


---
"Wall of Text'D!" --- oldskoolplayr76
"POwned again." --- blight family
... Copied to Clipboard!
Judgmenl
07/08/18 4:14:57 PM
#9:


Yellow posted...
I don't want you to answer my question. I'll figure it out myself, like I have with everything I know about the 5 languages I taught myself in my free time.


Ooooh you know five languages. Nice.
---
Judge, Nostalgia is a hell of a drug.
You're a regular Jack Kerouac
... Copied to Clipboard!
MacrossSpecial
07/08/18 4:34:00 PM
#10:


You're using scope resolution incorrectly in the context of c++ and c#, you are supposed to declare a primitive as a member of your class.

Also, you can use .this to accomplish this in java as well if your aim is to make a true four pillars object.
---
...Dude, you're a ****ing douche. Get off my god damn internets.
- RX7Infinitilll
... Copied to Clipboard!
Judgmenl
07/08/18 4:48:47 PM
#11:


MacrossSpecial posted...
You're using scope resolution incorrectly in the context of c++ and c#, you are supposed to declare a primitive as a member of your class.

Also, you can use .this to accomplish this in java as well if your aim is to make a true four pillars object.


He can also just use static to use a method / variable without instantiating the class.
---
Judge, Nostalgia is a hell of a drug.
You're a regular Jack Kerouac
... Copied to Clipboard!
Yellow
07/09/18 1:14:29 AM
#12:


There are serious answers itt but I'm so annoyed I don't really want to think about it too hard. That might seem like a weird thing to say, I'm just going to do a method.
---
... Copied to Clipboard!
Yellow
07/13/18 7:52:03 AM
#13:


Brainfart

Im confusing enums with objects enums represent. Duh.
---
"Everyone knows the law doesn't matter if it's a little kid breaking it!"
~TheOrangeMisfit on 1 year olds
... Copied to Clipboard!
Yellow
07/15/18 3:04:19 AM
#14:


Finally done with my input binding system. Not only does it serialize controller profiles to and from the disk, I can add any other controller support with a couple lines. If controller support isn't as good as or better than Smash Bros., it isn't good enough, so I spent 3 days getting it perfect. Most devs just say "fuck it, jump = spaceBar".

After nesting it in another object I should have one for each player, with automatic re-aranging and controller swapping.

input.AddBinding(Keys.B, ActionType.jump);


bool jump = input.GetAction(ActionType.jump, Keyboard.GetState()).triggered;


I have 4 separate classes working with this function, it worked on the first test.

Button GetButton(ControllerType controller_type, KeyboardState? keyboard_state, int xbox_input_placeholder)
{
List<int> combo = controller_bindings[(int)controller_type].buttons_combo as List<int>;
List<int> buttons = controller_bindings[(int)controller_type].buttons as List<int>;

if ((combo.Count == 0) && (buttons.Count == 0))
{
Debug.WriteLine("Button Action.GetButton: No bindings on this Action set for ControllerType." + controller_type.ToString());
return new Button();
}

// This will go through each and every controller binding and generate a 'Button' return value

// First it will evaluate 'button_combos'.
// For the 'triggered' value, it will return true if every button in the 'button_combos' is held down.
// For the 'analog' value, it will return the lowest value in 'button_combos'.
bool combo_triggered = false;
float combo_analog = 0f;

if (combo.Count > 0)
{
combo_triggered = true;
combo_analog = 1f;

for (int i = 0; i < combo.Count; i++)
{
combo_triggered &= GetPressedButton(controller_type, combo[i], InputType.trigger, keyboard_state).triggered;
combo_analog = Math.Min(
GetPressedButton(controller_type, combo[i], InputType.trigger, keyboard_state).analog,
combo_analog
);
}
}

// Next it will evaluate 'buttons'.
// For the 'triggered' value, it will return true if any button in the 'buttons' is held down.
// For the 'analog' value, it will return the highest value in 'buttons'.
bool button_triggered = false;
float button_analog = 0f;

if (buttons.Count > 0)
{
button_triggered = false;
button_analog = 0f;

for (int i = 0; i < buttons.Count; i++)
{
button_triggered |= GetPressedButton(controller_type, buttons[i], InputType.trigger, keyboard_state).triggered;
button_analog = Math.Max(
GetPressedButton(controller_type, buttons[i], InputType.trigger, keyboard_state).analog,
button_analog
);
}
}

// The highest final values between 'buttons' and 'button_combos' are used.

return new Button(
combo_triggered | button_triggered,
Math.Max(combo_analog, button_analog)
);
}


@Judgmenl some real noob shit here, huh?
---
"Everyone knows the law doesn't matter if it's a little kid breaking it!"
~TheOrangeMisfit on 1 year olds
... Copied to Clipboard!
Topic List
Page List: 1