Throwing Snowballs...Again

Blitz3D Forums/Blitz3D Beginners Area/Throwing Snowballs...Again

Happy Llama(Posted 2012) [#1]


I decided to improve on my game a little. I had accidently deleted my previous code so I have to start from scratch. Anyway, I need to make the enemy shoot (last function) but it is not working correctly. It is basically my player shooting code (which works perfectly) but just modified a bit. I don't know why it isn't working.

Last edited 2012


Happy Llama(Posted 2012) [#2]
OK, I've fixed the previous problem. Now I have a different one. The collisions between the player snowball and the enemy work but not the other way around. I don't know why it isn't working.

Function that isn't working:


Entire Code:



All help is greatly appreciated!


Midimaster(Posted 2012) [#3]
there is no difference between an "enemy snowball" and a "player snowball".

So if you in a first function check the collisions between snowball and enemy, this will reset the CountCollisions() and the second function EnemyCollisions() will find none.

The solution is to move the "PLAYER_TYPE collision" code into the PlayerCollisions() too.

I did not check it, but i may work:

[bbcode]Function PlayerCollisions()
For s.snowball = Each snowball
For collision_id = 1 To CountCollisions(s\mesh)
collision_entity = CollisionEntity(s\mesh, collision_id)
If GetEntityType(collision_entity) = ENEMY_TYPE
enemyhealth = enemyhealth - s\damage
DebugLog "enemyhealth " + enemyhealth
FreeEntity s\mesh
Delete s
Exit
ElseIf GetEntityType(collision_entity) = PLAYER_TYPE And Crouch=False
health=health-s\damage
DebugLog "playerhealth " + health
FreeEntity s\mesh
Delete s
Exit
End If
Next
Next
End Function [/bbcode]


I think a second problem will be the EXIT statement in this function. Why do you do it? Process all Collisions in this function! In a future version also collisions with e.g. a wall could be be detected here....

Last edited 2012


Happy Llama(Posted 2012) [#4]
I get an error message that says "variable must be a type" and highlights "health = health - a\damage. What does this mean?

Last edited 2012


Midimaster(Posted 2012) [#5]
of course "a" must now be renamed in "s", because you talking about the snowballs and in this function you called them "s"

also the EXIt makes sense, because it exits from inner FOR/NEXT only. That's ok...

I will correct my code...

Last edited 2012


Happy Llama(Posted 2012) [#6]
But isn't the else part of the if statement checking for when the enemy snowball hits the player? The function only works for the player hitting the enemy.

Last edited 2012


Midimaster(Posted 2012) [#7]
but when you create snowballs you make no difference betweeen enemy or player snowballs. All are in the list SNOWBALL.

It should work...

Could it be, that you created a camera named "Player" and now try to find collisions between camera and snowball? I'm not sure, whether the camera is a "normal" entity that can interact with other entities...

I tested it with a normal cube as "player" and it works!

So you have to use a cube as player and add the camera as a child.



You should re-think about your two different "snowballs". For Blitz3D they are in the same list and will be move always twice in one loop: In the ThrowEnemySnowballs() and in the ThrowPlayerSnowballs()

It does not help if you call them once "a" and later "s". Blitz3D handles it as the same type snowball.

Also in reality it is one type of snowball. You should move alle with the same function. It does not matter where it started. The moving is always the same, also the collision. Depending on the "emitter" only the direction differs.

This reduction makes your code much shorter and more logical.

Last edited 2012


Happy Llama(Posted 2012) [#8]
Still having some trouble. The player is still not taking damage. I tried replacing If GetEntityType(collision_entity) = ENEMY_TYPE with
If GetEntityType(collision_entity) = PLAYER_TYPE and it still does not work! How can the same exact code not work for the player?


Happy Llama(Posted 2012) [#9]
Also, thanks for putting up with my amateur coding skills.


Midimaster(Posted 2012) [#10]
the biggest challenge in learning coding is to find the bugs in the code. Years ago i wrote a tutorial about that, but it is in german...

so... you have to search systematically for the problem. First step: Test my code below! I made some changes and it runs on my machine. Then we can be sure, that in generell the collision works.



Last edited 2012


Happy Llama(Posted 2012) [#11]
The collision works for the player snowballs but the ones for the enemy still don't. I'll keep looking for errors. *sigh*


Midimaster(Posted 2012) [#12]
do you really want to tell me, that the code I wrote you does not work, if you copy it to your Blitzbasic and run it?

What I see is an enemy, that throws balls to the player when pressing SPACE and health of the player goes down.


Happy Llama(Posted 2012) [#13]
Yes your code does work, but it is the enemy snowball collisions, in my code, that don't work. Your code is only for the player snowball collisions which do work in my code. When I press space nothing happens. Are you sure thats the right code?

Last edited 2012


Midimaster(Posted 2012) [#14]
"enemy snowball collision" means enemy is hit by a snowball from the player?


Happy Llama(Posted 2012) [#15]
No it means what you think it does.


Midimaster(Posted 2012) [#16]
Hi, sorry for the delay of my answer... I was in holidays...

I changed my code in post #10 to show you, that both collision are working: now the eney shoots and the player too. And in the DEBUG-window you can see both collisions are working.

I did not combin shooting on the SPACE bar but it works automatic.


Happy Llama(Posted 2012) [#17]
Great, i'll have a look.


Happy Llama(Posted 2012) [#18]
I think the problem is that you only have one collection of snowballs (s\mesh) for both the player and the opponent. In my code, I have two, a\mesh and s/mesh.

Last edited 2012


Midimaster(Posted 2012) [#19]
Ah....
Why? A snowball is a snowball! I would not differ between the both. A snowball can hit a player or a enemy or a tree or even a other snowball!!! From the moment it is thrown, it is a independent object without relationship to his owner.

That will make your code short and logic.


YOUR ERROR:
You can call the snowballs what you want, the list of all cannot differ them in the end! It does not matter whether you call one snowball a\ and the next s\. This names are only temporary for the creation function. In the list the have no names, no more!

test this:
Type Test
     Field X%
End Type

A.Test=New Test
A\X=123
B.Test=New Test
B\X=456

For C.Test =Each Test
     Print C\X
Next


As you see the A\ and the B\ object can be printet with the name C\.