powerup in race game - xna

I've got a problem: i need to add a powerup to a racegame, using collision detection.
so i drawed the powerup, but the problem is: It has to be drawn after every 5 rounds and it needs to be placed ramdomly on the track.
Someone with any good advice?
Thanks.

Thats a bit vague. So here is my best shot at an answer.
You would want to use the c# Random class, here are the docs
For a simple game, using rectangular collision should be all you need (I assume thats what you are using) - If you want to randomly generate the power-up position, you will want to create a new Vector2 (the powerups position) with the random generator.
You can use the Next function, to pass in a low, and high variable - which you would need to configure the the bounds you wish the powerup to appear.
My advice as a game designer on the other hand, tells me that randomly located power-ups aren't always the go. It makes it harder to control the games flow and balance, and can very easily result in a flawed final product.
So my advice is a hard coded set of possible weapon spawn points - using a random generator to pick one to place.

Related

How would you go about creating a random spawner for coins within a certain area? It has to re-spawn coins after the player has collected enough too

I have a coin which rotates and changes size so far. I want to be able to set an area (which is not a nice square of course) that they can randomly spawn locations. The thing it has to do is once there are less that 7 coins then it spawns more.
Anyone able to give me some advice? Not sure what is most efficient method.
It sounds like you should be making use of ZonePlus and its getRandomPoint function.
If you want a direct reference, the creator of the module made a playground and its source code is publicly viewable. The playground contains a 'CoinSpawner' (literally what you're looking for).
You can either make use of "Region3" or you can set up multiple possible spawn points and run a math.random function to choose which one.

How to add "Action Points" to Scenekit Game using Gameplaykit or something similar

This is a very common question, and I am not asking for technical details. What I am looking for is an approach or best practice guidance for the following situation:
Imagine a jump and run game entirely made with SceneKit. The game is played by controlling a character running to the right or left side, climbing up walls and jump over obstacles. (it is a 2½-D style game where the character always runs in one direction or it's opposite. Mainly on the x-Axis)
At certain "locations" (on the scene x-axis) I need to implement some specific actions, that should occur as soon as the main character walks, jumps or runs over that specific point.
What I have done so far, is adding simple invisible SCNPlanes with static physics bodies, with the bitmask configured to detect only the contact (no collision). In the physics handler (physics delegate) I can now fetch contact of the objects the character trespasses. Currently I have a large switch-statement to fetch the names of the "Action-Walls" as I call the planes through which the character walks. So, I can trigger whatever specific action that I want to happen at that location.
It is working this way, even quite good, but I wonder if there is a way to add some better "action points" using i.e. Gameplaykit, but I only find information about agents and behaviors or pathfinding.
What I am looking for is some static point, when trespassing it, an associated action happens.
I have no clue about the possibilities of Gameplaykit. Can anyone tell me an approach using Gameplaykit or whatever Apple has in its magic box of useful tools to make this better than using action walls of SCNPlanes and the physics handler?

How can you make an object disappear in ROBLOX over a certain interval?

I'm making a game in ROBLOX, which has a cutscene in it at the start. At the end of the cutscene, the camera zooms up on the character and you spawn in. However, when I spawn in, I can see the dummy I used for the cutscene, so how after a certain interval can you make that dummy disappear?
Does the dummy just need to become invisible? If so, every physical object in ROBLOX (or more formally Part) has a .Transparency field that spans from 0 (for no transparency) to 1 (for full transparency, or in other words, invisible). I don't know what your "dummy" looks like in the object hierarchy, but let's say your dummy were a Model located at workspace.dummy, and that it has a head, torso, left arm, etc. located at workspace.dummy.Head, workspace.dummy.Torso, workspace.dummy.LeftArm, etc. To make the Parts of the dummy invisible, you would have code that looks like this:
workspace.dummy.Head.Transparency = 1
workspace.dummy.Torso.Transparency = 1
workspace.dummy.LeftArm.Transparency = 1
...
And so on. This, however, will make the dummy invisible to all players. If you are making a single-player game, this will not matter; however, if it is a multiplayer game, then this could be a problem. Making the dummy non-transparent again to do the cutscene for a new player would make the dummy visible to all players. If this is a problem for you, there are two things you could do that I know of:
The first and easiest way would be to just have the cutscene take place at a location very far away from where your game occurs; for example, you could shift everything in your cutscene 10,000 studs in the X direction. This would ensure the objects in the cutscene would be out of the render distance of the players playing the actual game, so only the players whose cameras are being manipulated to carry out the cutscene would see it.
The second, more complicated, and not future-proof option involves a very useful bug that is frequently taken advantage of but subject to being fixed at any time since it is not an official feature. This bug is the exploitation of a Camera (or less commonly a Message, which is deprecated) to create what are called local parts—Parts only visible to a certain player. How to create local parts and discussion of benefits and consequences of using local parts is a little complicated and beyond the scope of this answer. Go here if you'd like to learn more. Taken directly from the ROBLOX Wiki at the time of writing:
Local parts are in no way supported by Roblox. They exploit unspecified replication behaviour - at any given moment, the development team could release an update that changes how Camera and Message instances behave, preventing you from making local parts.

collision detection and creation in xcode class

I'm working on making a new app in xcode and have run into two problems that always seem to be a problem when I program large projects.
Basically, I want the user of this app to be able to input specifics like size, position, color, and possibly speed and/or direction.
These inputs will create a square of specific size, position, and color which will move around the screen and interact with other squares the user has created.
Now here are my problems:
First: I have absolutely no idea how to create something in code. I know I almost certainly have to do this in a class, but I've never figured out how to do this in a single programming language.
Second: Interaction between the squares. How do I detect collisions between the possibly dozens or hundreds of squares the user creates.
I'd really like to figure out how to do this, especially because I'm sure it'll be helpful in not only this, but many other future projects.
Thanks
I would recommend using sprite kit for the collision detection and creation of the squares. You'll probably want to subclass SKSpriteNode to define the properties for your squares.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Introduction/Introduction.html

how to generate Tetris piece from a given grid

At first I think my question should have been asked before, but I didn't find what I want.
One element of this iOS app I'm developing is break a 8x8 grid into Tetris pieces (every piece is made of 4 blocks). Two particular question I have are:
what is the best way to represent a Tetris piece in objective-C?
what algorithm to present the grid into random Tetris pieces (and later on how to check if two pieces fits together).
Edition on 01/28
#livingtech, I think I implemented pretty much what you say, except the point of "having a hole". My code works with no hole at simple stage when Tetris block is two blocks only (yes, two squares, connected either horizontally or vertically), but at 3-square Tetris block, I would get holes. I just tested and out of 1000 running, I would get one without a hole. So definitely I need some mechanism to check if next square will be a singleton.
I been trying to do the same thing for my game. Though I am a total beginner, and I'm using XNA and C#.
But the way I'm trying to go about it is: 4x6 grid array
--y123456
X1-000000
X2-000000
X3-000000
X4-000000
Here,
0 signifies no block
1 defines a block
Algorithm
Start by taking the very first 0 in the array ( top left corner )
and randomly pick a 0 or a 1.
Randomly choose the coordinates based on x1/x2-y1/y2, decide 1 or 0.
If it is 1, then decide coordinated based on where that 1 was put.
If it was 1 on x2 y1, then decide if a 1 should go on next touching
coordinate.
If you just have to code in what coordinates touch and which don't,
and the logic will roll through.
I have mine set up bit different. But this is the basic foundation of my random Tetris engine.
I also found that making it like that really helps to have a whiteboard and make a drawing of the grid and label with your coordinates.
since ur board is 8*8, i think u can use a int64 to represent the board. each bit of the int64 represents whether the specific grid is filled or not.
Implementing Tetris is a hobby of mine. First implemented it in Windows/C. Then in Perl/Tk! Last implementation I did in Obj-C/Cocoa (Mac). In all cases, the game logic is the same. Only the UI stuff changes. I treat every little box separately and have a two-dimensional array which contains the presence (and color) of every "set" box on the board. Standard board size I use is 10 boxes wide by 20 boxes high.
Separately I keep track of the "dropping" piece: it's location and what kind of piece it is. Based on a timer, try to make the piece drop. If any of the boxes where the "dropping" piece would drop is already set, then stop dropping the piece and add the piece boxes to the "set" part of the board. Create a new piece, and start over.
It may not be the best way to implement it, but it makes sense in my head. From a pure OO perspective, each shape of a dropping piece could be a subclass of a generic shape class. Override functions that check whether the shape can drop, the offsets of the individual boxes in the shape, etc.
I don't think anybody has taken a stab at your question #2 yet here, so I'm going to outline what I would do.
Setup:
You'll need to represent your grid as an array of some kind. At the very least, you'll want some kind of boolean values, to denote whether each coordinate in the grid is "occupied".
You'll need to keep track of the pieces on your grid. This could be another array, this time holding references to the four coordinates for each piece.
You'll need a variable or variables to keep track of a coordinate in your grid where you'll start filling in pieces, (I would probably populate these with a corner to start).
Set up a "pool" of all possible Tetris pieces and rotations. (You'll want to keep track of which ones you've already checked on every iteration outlined below.)
Iterate:
Get a random piece from your pool that will fit into your starting coordinate. (If you want to get fancy, you could be smart about which ones you choose, or you could just go totally random. As pieces don't fit, mark them checked, so you don't keep checking randomly forever. If you get to a point where you've checked all the pieces, you have a solution that doesn't work, either back up an iteration, or start over.)
Make sure the Tetris piece you selected didn't leave a "hole", or empty space with less than 4 squares. (I don't know your requirements for solving this problem, so I can't say whether you should focus on speed or ease of coding, but you may be able to skip this step if you want, and "brute force" the solution.)
"Place" the piece, by writing it to your piece array and marking the coordinates filled.
Check for "finished" condition, in which all your spaces are filled.
Pick a new coordinate in your grid and repeat #1. (I would pick an empty one next to the previous coordinate.)
If this actual yet, I wrote test tetris app on Objective-C few months ago https://github.com/SonnyBlack/Test-Demo-Tetris . I think my algorithm not very well, but it working. =)

Resources