|
|
|
|
|
|
two words,(next input)
. No space needed around the comma. This way you can use std::getline(inFile, name, ',');
and it will extract everything up to and including the comma then discard the comma.
|
|
|
|
|
|
|
|
|
|
|
|
SDL_Rect rectangle
a rectangle, rectangle can store 4 values, respectively x, y, w, and h, being x and y coordinates, height and width.
|
|
Level *level = new Level[3];
____Level 0____ #0 _number: &0 _Background path: &textures/lvl0.png _Foreground path: &textures/lvl0obst.png _Render SDL_Rect: x: &0 y: &0 h: &640 w: &640 _Player spawn position: x: &50 y: &10 h: &160 w: &160 _Walkable area: x: &80 y: &80 h: &560 w: &560 #1 *Obstacle 1: x: &325 y: &241 h: &75 w: &75 #1 *Teleporter 1: _Number: &0 _Coordinates: x: &513 y: &353 h: &5 w: &5 _Teleports the player to: x: &150 y: &150 h: &160 w: &160 _Leads to level number: &1 ____Level 1____ #1 _number: &1 _Background path: &textures/lvl1.png _Foreground path: &textures/lvl1obst.png _Render SDL_Rect: x: &0 y: &0 h: &640 w: &640 _Player spawn position: x: &380 y: &200 h: &160 w: &160 _Walkable area: x: &45 y: &240 h: &400 w: &550 #4 *Obstacle 1: x: &60 y: &245 h: &35 w: &105 *Obstacle 2: x: &60 y: &355 h: &45 w: &110 *Obstacle 3: x: &480 y: &255 h: &100 w: &95 *Obstacle 4: x: &540 y: &455 h: &95 w: &55 #1 Teleporter 1: _Number: &0 _Coordinates: x: &320 y: &620 h: &5 w: &5 _Teleports the player to: x: &250 y: &480 h: &160 w: &160 _Leads to level number: &2 END OF FILE #-1 |
|
|
|
|
|
|
|
|
____Level 0____ #0 _number:0 _Background path:textures/lvl0.png _Foreground path:textures/lvl0obst.png _Render SDL_Rect: x:0 y:0 h:640 w:640 _Player spawn position: x:50 y:10 h:160 w:160 _Walkable area: x:80 y:80 h:560 w:560 #1 *Obstacle 1: x:325 y:241 h:75 w:75 #1 *Teleporter 1: _Number:0 _Coordinates: x:513 y:353 h:5 w:5 _Teleports the player to: x:150 y:150 h:160 w:160 _Leads to level number:1 ____Level 1____ #1 _number:1 _Background path:textures/lvl1.png _Foreground path:textures/lvl1obst.png _Render SDL_Rect: x:0 y:0 h:640 w:640 _Player spawn position: x:380 y:200 h:160 w:160 _Walkable area: x:45 y:240 h:400 w:550 #4 *Obstacle 1: x:60 y:245 h:35 w:105 *Obstacle 2: x:60 y:355 h:45 w:110 *Obstacle 3: x:480 y:255 h:100 w:95 *Obstacle 4: x:540 y:455 h:95 w:55 #1 Teleporter 1: _Number:0 _Coordinates: x:320 y:620 h:5 w:5 _Teleports the player to: x:250 y:480 h:160 w:160 _Leads to level number:2 END OF FILE #-1 |
new
just to obtain a pointer, which is bad news. I have looked at some SDL tutorials and none of them seem to do this. I am aware that SDL is written in C, I am pretty sure it would internally allocate memory with malloc
or something similar, so it is already on the heap.new
is that if anything throws an exception the neither the destructor nor the delete
is reached, so memory is leaked.emplace_back
which constructs an item in place in a container like std::vector.TheIdeasMan wrote: |
---|
So why not have a data structure containing these SDL objects directly? |
emplace_back
, SDL is C so there are no constructors for the API objects.
|
|
level
could be level_num
or level_id
? This sounds a bit pedantic, but it can cause problems - maybe when one is tired :+) One might wonder why this doesn't compile : levelDataFile >> level[count].Level;
unsigned
type, because they are used as array or vector subscript. It's better to use std::size_t
, that is what the STL does.Tp *tp = new Tp;
new
|
|
|
|
using namespace std;
, I've seen that seemingly controversial topic before. Could you elaborate on what is to be gained by putting std::
in front of everything instead of including the namespace?