• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Aeris130

Member
C. Type is a name of the variable. The idea is that Blue is constant. I guess the better example of what I am trying to do is, yeah it's actually really similar to that.

Think I have a pokemon of grass type against a pokemon of water type. I want to compare their types AND use the same variable to calculate bonus damage(int).

I can come up with a large chunk of code to get the result, but I'm challenging myself to find most simplest possible solution to this and now I can't get it out of my head.

Plain C? Not that versed, but if you're using C++, I guess an easy way would be to define a class Type, containing an enum Color and methods modify(int x):int and isType(enum):boolean.

Code:
Type myType (GREEN, 3);

1 + myType.modify(8); // 1+8*3

if (myType.isType(BLUE)) {
// Won't reach here since the type of myType is GREEN
}

However, if you want the modification to vary depending on two types, maybe modify could take an external color as well:

Code:
Type myType (BLUE);

1 + myType.modify(8, RED); // 1+8*6 (omfg)

// No if-case needed, shit is in modify() now.

This way, the implementation of modify is responsible for knowing that water (blue) is effective against fire (red), and subsequently modifies 8 with 6 instead of the usual 1 (super effective).

Of course, at the end of the day you're going to have to do some sort of matching to find out what the response to RED (or whatever) should be, and that check now needs to be performed inside modify (not sure if C has a predefined datatype suitable for this, or if you have to define something on your own, using if cases or whatever) before returning the value that you get by modifying 8. But at least you only have to define it once this way.

Basically, modify needs access to a function that takes two colors (the local type color BLUE, and the external one, RED) and returns a modifier value that gets multiplied with 8 and returned. Since this function will keep track of default values as well (1 for blue, 3 for green etc), there's no need for the user to supply anything but the type name when instantiating the type.

Actually, I'm not sure you even need classes to define modify this way, but I'm used to oop.
 
Alright just some musings, working on a simple searching program for someone to enter and store values (name, number etc). I was over thinking it earlier, now I realised I can just use three separate variables to get the information, then copy them over to an external file to be archived in order to search.

Now my issue is, what would be the most efficient way of sorting into an order, whilst keeping a secondary and tertiary characteristic attached to the first

Like so:

Code:
First characteristic
|
> Secondary characteristic
|
-> Tertiary characteristic

Assuming treating each initial characteristic and subsequent ones as an array when searching/indexing would work? Just trying to figure out how to read from, lets say a text file and treating it as an array...
 

Kalnos

Banned
If you're interested in grouping and want to keep using text files then you will probably just need to delimit your files somehow. I.E.

Code:
FirstCharacteristic^SecondCharacteristic^ThirdCharacteristic | FirstCharacteristic^SecondCharacteristic^ThirdCharacteristic | FirstCharacteristic^SecondCharacteristic^ThirdCharacteristic

In that example, when processing a text file a ^ symbol denotes that you're moving on to the next characteristic and | denotes a new segment. If the first characteristic isn't what you're looking for you simply move to a new segment and don't bother reading the rest.
 

Bollocks

Member
Yeah, Eclipse with PyDev is the best Solution, you can also try Aptana, it's a web editor based on Eclipse and also supports Python
 

wolfmat

Confirmed Asshole
I just use a normal text editor with source tree stuff and junk. Whatever's available.

Speaking of Python, I wrote an ASCII skyline generator yesterday for shits and giggles (also had to watch a dog, which is boring). It's great fun, try it some time.

Observe:
JMNIl.png
 

usea

Member
I just use a normal text editor with source tree stuff and junk. Whatever's available.

Speaking of Python, I wrote an ASCII skyline generator yesterday for shits and giggles (also had to watch a dog, which is boring). It's great fun, try it some time.

Observe:

Seeing this right before I go to work is the worst thing. God. Now I'll be thinking about doing something like that all day.
 

GaimeGuy

Volunteer Deputy Campaign Director, Obama for America '16
I just use a normal text editor with source tree stuff and junk. Whatever's available.

Speaking of Python, I wrote an ASCII skyline generator yesterday for shits and giggles (also had to watch a dog, which is boring). It's great fun, try it some time.

Observe:

Now format the code in a way that it creates a skyline when you place the pages next to each other!

Doing it in python is extra fun :D
 

wolfmat

Confirmed Asshole
Now format the code in a way that it creates a skyline when you place the pages next to each other!

Doing it in python is extra fun :D
No. :mad:

But I've thought about self-representing code a lot lately. Like, code that displays itself in some fashion. So you take the sourcefile and use its hash as a seed to generate a randomly obfuscated variant of said code, to make a trivial example.

vim is always available, so I use that.
Yeah, vim is awesome, for example. I also like TextWrangler.


That's neat! Is it randomly generated or do you provide parameters or a source image?

That's randomly generated. Various ranges are parametrized.

Edit: Maybe I'll transfer it to JS at some point. py -> js: always a really easy thing to do.
 

Minamu

Member
I'm attending a basic programming course (c++) over the summer and I need to make a "simple" schmup to pass :( I'm using SFML instead of a home made library from our teacher (I figure, it's better to learn something that's actually used in real life to some extent). I have a 2d ship controlled by the mouse and enemies randomly spawn at the top of the screen but at this point, I have no clue how to make them move diagonally and bounce off the corners of the screen and shoot at me :S I have three bullets flying out of my own ship but I need to make two of them shoot diagonally as well. And I need to force inheritance and polymorfism into the code, needed or not,(and functions, classes etc ofc) to pass. It's getting a bit too massive to handle :(
 

Lathentar

Looking for Pants
wolfmat's skyline generator sprung up a fun idea. We should do some weekly procedural generation challenges in here. Just for fun, whatever language you want and share the results/code. Would anyone be interested?
 

KorrZ

Member
wolfmat's skyline generator sprung up a fun idea. We should do some weekly procedural generation challenges in here. Just for fun, whatever language you want and share the results/code. Would anyone be interested?

I think having weekly/monthly programming challenges in general would be extremely awesome. It'd be fun and some good learning for all the novice programmers (like myself) in this thread.
 
Hey guys, sorry to bother you but I need some advice.

Coding is not really my thing, but during my master's degree (finance) I took a couple of courses that taught me some C. Nothing really deep... let's say I know what a pointer is :p Then, after graduating, I started studying Lua on my own. Great language, I really like it.
In the last couple of months I've been thinking about making a (simple) videogame. Writing down algorithms is not really a problem, actually (I'm talking about 30-50 lines of code) as I'm decently good at solving small problems.
I'm really having a hard time figuring out how to organize the whole work though. It's like I can't see the bigger picture, you know what I mean? I don't even know where to start to build an entire program and not just a simple algorithm.

Any useful tip/advice? Any good book?

Thanks in advance!
 

Kalnos

Banned
@Minamu

Sin/Cos are used heavily in shmups to give diagonal wave movements, that would be the easiest way to make your enemies move in such a way.

To make enemies shoot at your player you will have to look at some basic vector math. You can also use the distance formula if you want them to only shoot once they have gotten within a certain distance. Same thing with having the player shoot diagonally... vectors.

Forcing inheritance/polymorphism should be pretty easy if you have multiple enemies. All of your enemies need to move/shoot/draw/update/etc so these functions can be located in a base class.

It sounds like you have plenty of time, so try to write out some ideas before you try to implement them. Going straight for the code is usually a disaster. Breaking everything up into manageable chunks helps a lot.
 
Hey guys, just wanted to throw out a resources I've been using to learn C thats really good. It's the intro level Harvard course.

cs50.tv or www.cs50.net

It's also available on iTunes U if you have the app. It's great, very useful and informative
 

wolfmat

Confirmed Asshole
Any useful tip/advice?

Write a relatively simple game, and bring it to completion.

Since you seem to be confident you know your stuff with Lua, I'd recommend using LÖVE as a starting point. It already does cool stuff for you, but you'll have to actually bring it all together yourself.

The game to make as a learning project I would recommend is Tetris, or rather a Tetris clone.

Note that you want to make it as complete a game as possible. So don't forget configuration, maybe controller support, a highscore list, maybe an endgame, maybe some achievements thingamajing. You need music and sound effects, graphics for the tiles, a font, all that.

If you get through that, you know what it's like to make a game. It's the essential thing to do for an aspiring game programmer.
 
Any recommended Python IDEs for Linux?

Usually use Kwrite, trying out Ninja-IDE, wondering what's considered cream of the crop. Thanks.


edit: NM, found Geany, seems pretty good.
 
Hey, I've also been asking this in the indie game development thread, but maybe I have more luck here.

I want to make a 2D game for a mobile device, I do not really mind which platform (IOS, Android, Windows Phone), but I'd like an engine. I have some experience with Marmelade but wasn't too fond of it. Also, I already have some experience with XNA, so that should work with Windows Phone right?

So, please recommend some engines.
 

Slavik81

Member
So, I'm trying out Sublime. The first thing I'd like to do is recreate my colour scheme. This seems to be impossible, though. Is there any way to get it to highlight C++ variables, classes/structs/enums/unions/namespaces, functions, enum values, and macros in different colours? I've managed to get strings, literals and keywords recoloured.

I posted an example of my colour scheme under VS earlier in this thread:
 

Ixian

Member
Hey guys, I'm more of a book person when it comes to languages. Does anyone have any recommendations for a C# book written for people with prior programming experience (I'm a C++ dev)?
 

mike23

Member
Hey guys, I'm more of a book person when it comes to languages. Does anyone have any recommendations for a C# book written for people with prior programming experience (I'm a C++ dev)?

I have C# in Depth. I've also heard good things about Effective C#.

If you want to get real deep into C#, check out C# Programming language by by Anders Hejlsberg.
 

Ixian

Member
I have C# in Depth. I've also heard good things about Effective C#.

If you want to get real deep into C#, check out C# Programming language by by Anders Hejlsberg.
Thanks, picked up C# in Depth and Effective C# (Effective C++ was a great book so I'm expecting good things from the latter!). Hurray Amazon points!
 

Ambitious

Member
Why are dark color themes for text editors so popular? Is it just a matter of taste? Maybe I would get used to it, but every time I turn one on I just feel terribly uncomfortable.

By the way, which graphical text editor for OS X would you recommend and why? I'm mostly using Textmate (2) but I've also got Chocolat and now Sublime Text 2. I like the interface of Chocolat most, but after it having experienced crashes on saving several times (and once losing a big piece of work), I'm refraining from using it for a long time.
 
Why are dark color themes for text editors so popular? Is it just a matter of taste? Maybe I would get used to it, but every time I turn one on I just feel terribly uncomfortable.

By the way, which graphical text editor for OS X would you recommend and why? I'm mostly using Textmate (2) but I've also got Chocolat and now Sublime Text 2. I like the interface of Chocolat most, but after it having experienced crashes on saving several times (and once losing a big piece of work), I'm refraining from using it for a long time.

They tend to be healthier on the eyes. It's not as straining looking at a dark screen all day as opposed to a light one.
 

Hari Seldon

Member
So I'm going to try and parley some limited academic java experience and some hobby experience into trying to land a Java programming job at a bank. They have J2EE listed, but I have never done that. I have done some extremely low level networking stuff, so maybe that will help lol. I want to get into higher level coding, I need to do something different and the coding world is a lot hotter than the hardware world right now it seems.
 

Tashi

343i Lead Esports Producer
I think having weekly/monthly programming challenges in general would be extremely awesome. It'd be fun and some good learning for all the novice programmers (like myself) in this thread.

I'm also all for this
 

Ambitious

Member
They tend to be healthier on the eyes. It's not as straining looking at a dark screen all day as opposed to a light one.

That's what I suspected. Huh, it doesn't really bother me. I prefer the strong contrast of black on white. I'm currently using the Mac Classic theme, though I'm not fully satisfied. Guess I'll try to modify it to my liking when I've got some time.

What about the typeface? Consolas and Inconsolata seem to be popular, but I've stayed with MenloPlus so far.
 
where would one start with C? i checked out the "learn C the hard way", but it seems like thats targeted to people with prior programming experiences, which i have none.
 

Minamu

Member
@Minamu

Sin/Cos are used heavily in shmups to give diagonal wave movements, that would be the easiest way to make your enemies move in such a way.

To make enemies shoot at your player you will have to look at some basic vector math. You can also use the distance formula if you want them to only shoot once they have gotten within a certain distance. Same thing with having the player shoot diagonally... vectors.

Forcing inheritance/polymorphism should be pretty easy if you have multiple enemies. All of your enemies need to move/shoot/draw/update/etc so these functions can be located in a base class.

It sounds like you have plenty of time, so try to write out some ideas before you try to implement them. Going straight for the code is usually a disaster. Breaking everything up into manageable chunks helps a lot.
Thank you :) I'm thinking of doing bullets with polymorfism. I only have one enemy type so it's fairly basic. We're gonna look at some example code for the teacher's version of the game tomorrow so maybe I can use some of that in my own game. Writing down what everything should do would probably have helped a lot, yeah. But doing a paper design doesn't help all that much when you've never seen the language before and don't actually know what to write, or when ;) But I'm getting there. I need to draw two text strings on the screen, stop the player from moving outside the screen, make enemies shoot and not just move straight downward and I'm done. And I have until August 24th to finish it plus a report and exam studying.
 

RJT

Member
where would one start with C? i checked out the "learn C the hard way", but it seems like thats targeted to people with prior programming experiences, which i have none.

Why do you need to learn C? I would suggest you to start learn programming with Python.
 

James-Ape

show some balls, man
where would one start with C? i checked out the "learn C the hard way", but it seems like thats targeted to people with prior programming experiences, which i have none.

If you have some experience then K&R's the C Programming Language is a good place to start.
 
i only have some html/css experience but never touched anything else. id like to make some basic apps and i read that it would be wise to get started with C before moving onto objective-C.

if i start with python, would i be able to jump into obj-C? i dont know how programming hierarchies work.
 

RJT

Member
The reason why I suggested Python is that there are a lot of free online resources for beginners. I especially recommend Udacity's Computer Science 101 (how to build a search engine) and MIT's Introduction to computer science (on iTunes U).
 

Kalnos

Banned
i only have some html/css experience but never touched anything else. id like to make some basic apps

I can't comment on Objective-C because I have never used it before, but HTML5/Javascript is a relatively new and powerful option.

if i start with python, would i be able to jump into obj-C? i dont know how programming hierarchies work.

Most concepts can be applied across many languages. So while you have to learn new syntax, libraries, etc. when learning a new language you will find each new language increasingly easier to pick up. Python is a great language to start with IMO.
 
The reason why I suggested Python is that there are a lot of free online resources for beginners. I especially recommend Udacity's Computer Science 101 (how to build a search engine) and MIT's Introduction to computer science (on iTunes U).

thanks! the udacity link looks great. ill also pick up the "learn python the hard way" course as well.


I can't comment on Objective-C because I have never used it before, but HTML5/Javascript is a relatively new and powerful option.



Most concepts can be applied across many languages. So while you have to learn new syntax, libraries, etc. when learning a new language you will find each new language increasingly easier to pick up. Python is a great language to start with IMO.

ah awesome, ill start with python then. isnt HTML5 only web based? i imagined its used mostly for web apps and not mobile ones.
 

Chris R

Member
HTML 5 is a better choice for mobile apps in my opinion. No need to code something once in Obj-C and then submit it to the App Store and then recompile/recode it in Java for the Play Store, and once again in C# or whatever for the Windows 7 store when you can just publish a single website :p
 

RJT

Member
thanks! the udacity link looks great. ill also pick up the "learn python the hard way" course as well.

Udacity is great. It's owned by the dude that heads the driverless cars project at Google (Sebastian Thrun), who has quickly become one of my favorite human beings.
 
HTML 5 is a better choice for mobile apps in my opinion. No need to code something once in Obj-C and then submit it to the App Store and then recompile/recode it in Java for the Play Store, and once again in C# or whatever for the Windows 7 store when you can just publish a single website :p

do you have any examples i can check out? :D

Udacity is great. It's owned by the dude that heads the driverless cars project at Google (Sebastian Thrun), who has quickly become one of my favorite human beings.

oh wow, i just checked out their about page. some brilliant minds behind that site :O
 

dabig2

Member
But doing a paper design doesn't help all that much when you've never seen the language before and don't actually know what to write, or when ;)

Ah, that's probably not what he meant though. When programming a game such like this, it's best to first approach this like a game designer (who don't need to know how to code) before diving headfirst into the cold lake known as programming.

For instance, a game designer would do this: First, draw a representation of the beginning of your game on a piece of paper. So you'll draw a rectangular box (representing your window screen the program will run in), your hero ship on the bottom of that screen along with the enemies on top and any other stuff such as score or lives remaining and whatnot.

Second, begin scripting. What I mean by that is visualize what's supposed to happen when an event occurs. For instance, hitting the left arrow key moves the spaceship some amount of space to the left. Draw that. When you left-click, the ship fires a projectile. Draw that. When a projectile hits an enemy ship, the ship explodes/disappears and your score increases. Draw that. If an object hits the boundary of your drawn rectangular box, it "bounces" in the opposite direction. Draw that. And so on. (you actually don't have to draw ALL states of the game, but it's good to keep it in mind).

Once you've drawn or thought about the different states of the game, you can now pseudo-code. This is when you start thinking about how you're going to attempt to put this into code without actually putting it into code. Basically, you'll write down a bunch of algorithms that make up specific states of your game. You should also at this point recognize and write down any classes and objects that you see you will need (NOTE: again, no need to code this. Just write down that you need a Class called Enemies that will store these variables and might need such and such methods - no coding required yet!)

***********************************************
Here's an example of the above process related to your boundary question of making sure things don't go offscreen. You've drawn your game screen as a rectangular box. Let's pretend that box is a 640x480 window screen on your computer. Let's also pretend it's a 2-D grid of pixels (each one having x, y coordinates) and that every object on the screen can be shown as existing at some particular point in the grid. The (0,0) point is located at the top left corner of your drawn box. This means X increases going right and Y increases going down. With this information, you know an object has hit a boundary when its coordinates are any one of the following:
1)it's x coordinate is ~0 (hit the far left side of the screen).
2)it's x coordinate is ~640 (hit the far right side of the screen)
3)it's y coordinate is ~0 (hit the top of the screen)
4)it's y coordinate is ~480 (hit the bottom of the screen).
(I'll save why I put approximations for another day to keep this example simple ;)

So the questions here are 1)how do I keep track of the present coordinates of my ships at all times and 2)how to resolve boundary issues.

Well, the first question should immediately tell you that every class object on the screen (Hero class, Enemy class, projectile class, and so on) will possess two float variables that store each object's X and Y coordinates (or you can use a vector, array, etc). From this, you'll also probably figure out that you'll need a couple methods to initialize these coords, change these coords, return these coords at any time, and another method to calculate how close to the edges each variable is (and here we lead into the 2nd question). Again, no need to code what each method will do. Just simply write down its "signature" - that is, write down the return variable if any and its parameters if any, like so:

void moveShip(float X, float Y)
float getXCoord();
boolean hitBoundary();

Now that you have a method that calculates how close to the edge of your game screen an object is, you can have another method that corrects a boundary event. That too is simple to realize now. If the x coordinate is ~0, you simply increase X to move object in the opposite direction. If that X coordinate is instead ~640, you decrease it. Same for Y coordinates.

So that's basically it for the boundary portion. From here, you can move onto breaking down another part of the game, such as figuring out how you know when a projectile has hit a ship (hint: very similar process to figuring out how you have hit a boundary) or how to move an object diagonally.

So the gist here is that it's always beneficial to start out with a pen and paper (or maybe a tablet and stylus in this day and age). No programming required. It sounds like a lot of workr, but once you get into the groove, you'll realize that it's really simple and will go by fast; and most importantly, will help you figure out how to approach coding your program :)
 

Kalnos

Banned
@Dabig2 hit it pretty much on the spot. I'm starting a new project and I have 5-6 pages so far of hand-written notes and absolutely none of it is real code. Pseudo code should be comfortable to you whether you're comfortable with the language or not.

I.E.

Code:
      If numberOfLives > 3
           gameOver = false

That particular logic will be roughly the same no matter what language you write it in, and writing it out can help you prepare to code and spot potential issues. It also helps identify what sorts of things you want to test for.

If you're feeling threatened by the syntax and features of a language you may just want to start with a small project to help familiarize yourself. I saw you already started breaking up your large project into smaller tasks, that's good.
 
Top Bottom