• Create Account

# sandorlev

Member Since 18 Mar 2010
Offline Last Active Sep 27 2013 08:22 AM

### In Topic: Article #2: Managing Entities (gameprogblog)

13 January 2013 - 08:50 PM

I didn't read the whole thing yet, but it seems pretty awesome!

### In Topic: C++ falling asteroids

26 November 2012 - 10:59 AM

Oh sorry, complety missunderstood what you said.

In this case I believe you need something like this:

[source lang="cpp"]srand(time(NULL));unsigned numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second unsigned chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid bool up = rand() % 2; if (up == false){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]

EDIT: in this case y = 0 is top part of the screen.

Thank you, that answer was worth waiting for!

### In Topic: C++ falling asteroids

26 November 2012 - 10:03 AM

The movement part I already have, I'm looking for a solution to making them appear at random times with their number of asteroids onscreen capped from above and below but increasing.

### In Topic: Going crazy, collision detection

08 August 2012 - 02:20 PM

Now I must be either a terrible thinker or I just went full crazy but I cannot find out how to solve this one:

```# If there is a collision
if (bottom == platformTop) and \
(left >= platformLeft) and \
(right <= platformRight):
self.rect.y = platformTop - self.rect.h
#if self.falling:
#   self.vector.y = 0
self.falling = False
# ^^^ this doesn't work, you cannot jump from the platform
# this is how you fall down from it
elif (bottom == platformTop) and \
(left <= platformLeft) or \
(right >= platformRight):
self.falling = True
```

### In Topic: Going crazy, collision detection

08 August 2012 - 02:02 PM

The collision model for the "bypassable" platforms should not apply to objects that don't have their feet above the platform. In other words: For all objects below the platform, that platform doesn't exist.

So, however you're actually doing your overall collision detection, modify the algorithm to include a special pass for that particular circumstance.

A quick thought is, if you you get a new collision (ie, it wasn't colliding in the last frame), then check the vertical velocity. If it's positive (moving up), ignore the collision. If it's negative (falling), then you need to check where the collision occurs on your player.

If it collides at the feet, then you can make the collision stick, and keep the player on top of the platform. If you're player collidies mid-body (or head, etc.), then he's probably moving left to right and falling, and needs to fall through.

That is just a quick thought about how I might try it, but i don't have any experience directly with this.

Good Luck!

EDIT: beat by Goran, but his idea is better than mine, to ensure the feet are above the top of the platform in question.

Thank you both, solid ideas, I hope I will get it right!

PARTNERS