Jump to content

2D array game going wrong.

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Flaccidbear

Flaccidbear

    Newbie

  • Members
  • Pip
  • 7 posts
  • Programming Language:C++
  • Learning:C++, Python
Hia,
I'm a newbie to programming and trying to learn c++.
I'm having a little trouble with a 2D array game I've been working on and was hoping for some advice on where I'm going wrong.
Here are the problems:
  • Errors pop up that are way over my head whilst the console is active
  • The enemy character doesn't seem to want to move higher up the x-axis
I should mention I'm using Visual C++ 2010.
[ATTACH]4486[/ATTACH]

Attached Files



#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
First, is there a reason why all code is jammed up like this?

Next, use more functions! Also, read on classes (for example, create Player, AIPlayer, Matrix or Grid).

Main problem is that you're not checking for bounds; if you go out of bounds, strange things will happen (like getting garbage values, crashing the program, ...).

Next, your loop should be like this (game loop):
while running
    get input
    do logic
    draw
With console games this usually doesn't show (make) difference, but when you start with 2D/3D, you will see huge difference. You can read more about game loops here (lazyfoo.net) or do a google search.


Overall, game looks pretty sweet and could easily be upgraded to full 2D (maybe even 3D?).
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
Flaccidbear

Flaccidbear

    Newbie

  • Members
  • Pip
  • 7 posts
  • Programming Language:C++
  • Learning:C++, Python
Thank you for the advice. I'm going to start making changes now to my program-I think full 2D or 3D is a bit advanced for me at the moment, sometime in the future.
When you say jammed is it because visually its all bunched together or because I need to use functions?

#4
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
I meant visually. Both. In a sense. You had several if's and else's and return's all bunched into 1 line. It's very hard to see which bits go where when code is all crammed up - you can of course use this style, but I wouldn't recommend it.

Once I heard/read a nice definition when to use functions: when ever you're calling same bit of code at least twice, make it a function.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#5
Flaccidbear

Flaccidbear

    Newbie

  • Members
  • Pip
  • 7 posts
  • Programming Language:C++
  • Learning:C++, Python
okay, I see what you mean and I'll defiantly keep that definition in mind.
Thank you again.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users