I am trying to develop a android runner game for school purpose..
I am still new to this and please I need your assistance..
You guys can view my CS5flash file at >>> http://www.filedropper.com/test_37
The obstacles and coins are on random. But the obstacles and coins are overlapping each other.. Which is very bad for a runner game because it looks very bad and the gameplay gets very very complicated.
How can i fix it??. Is there any way to fix it?.
And i am also thinking if I can set the obstacles and coins to a specific area (not on random). So the game will be more oganized and the gameplay won't be complicated. Which i still don't know -_-.
But i still prefer it on random. So guys please help me fix it..
You will need to change the way you are adding the coins and obstacles! I suggest using a timer for each. Atm you are adding a ton of them on every frame, calculating overlaps would use too much resources! and put them in an array or better a vector! i would reccomend using an object Pool aswell!
so limit the amout of coins and hurdles that can be present, like 5 or so. then remove them from the array/vector when they are offscreen or collected! then when you add new stuff you can check against the array/vector what the allowed values are!
when you got your Array you can pass it to the randomRange() function and exlcude those values!
would look somthing like this! not testet!!
function randomRange (min:Number, max:Number, exclude:Array = null):int
{
var val:int = (min + Math.random() * (max - min)) >> 0;
if (exclude)
{
for (var i:int = 0; i < exclude; i++)
{
while ((val < exclude[i].x + exclude[i].width) && (val > exclude[i].x))
{
val = (min + Math.random() * (max - min)) >> 0;
}
}
}
return val;
}
Its still quite exspensive performance wise. but with only a few object you should be fine
Related
I'm using Alamkanak's Week View Library. It's great but I'm having trouble with a specific feature I want to add to my app. It needs to look like this:
But this calendar starts showing time at 01:00 and goes all the way to 00:00 the following day. I'm looking to only show hours that are important to me: from 09:00 to 20:00.
I've also searched into this a lot, even found the same topic here, but still no solution.
Anyway, any help would be greatly appreciated. Also, if you can recommend another library to use for showing such events (I didn't quite like Google Calendar), it can also be of high value. Thanks in advance guys.
It turned out to be quite simple actually, (In my bellow explanation I've gone for the 07:00 - 19:00 hours)
Firstly copy the WeekView class and create a new WeekView class in your project.enter link description here
Secondly, assuming you've got the in your XML, you need to change that to
to reflect the newly created class and that fact that we want to use that instead of the default one.
Then in your new WeekView class you're going to need
import com.alamkanak.weekview.DateTimeInterpreter;
import com.alamkanak.weekview.MonthLoader;
import com.alamkanak.weekview.WeekViewEvent;
import com.alamkanak.weekview.WeekViewLoader;
After that, in the private void initTextTimeWidth() method, you'll need to update the for loop to
for (int i = 0; i < 12; i++) {
Then in the private void drawTimeColumnAndAxes(Canvas canvas) method you need to alter couple of things:
for (int i = 0; i < 12; i++) {
...
String time = getDateTimeInterpreter().interpretTime(i+7); //This will set the correct display hour digits
In the very next method drawHeaderRowAndEvents, update:
mEffectiveMinHourHeight= Math.max(mMinHourHeight, (int) ((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / 12));
There's another for loop that needs updating
for (int hourNumber = 0; hourNumber < 12; hourNumber++) {
And lastly
float top = mHourHeight * 12 * mEventRects.get(i).top / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 + mEventMarginVertical;
bottom = mHourHeight * 12 * bottom / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 - mEventMarginVertical;
Basically go trough all the 24s in the class and update those to whatever you like, in my case it's 12 as I'm going for a 12 hour time-span to show and add howevery many hours you want to, coresponding to your first starting hour in String time = getDateTimeInterpreter().interpretTime(i+7)
Here's a paste bin to visualise all the crap from above, Left is the original class, right mine
I'm using the same library, and I've tried to make something similar once. What I can suggest is set the goToHour(double); to your first event's start time, than scale the hour's height with something like this to match your last event's end time:
int height = weekView.getMeasuredHeight();
int textSize = weekView.getTextSize();
int padding = weekView.getHeaderRowPadding();
height = height - textSize - (2 * padding);
weekView.setHourHeight(height / 24);
Edit: I've used this code to see whole 0-24 on the weekview. I think tweaking this could get you what you want.
I am pretty new to all this Flash CS6 Action script 3.0 stuff and I was hoping to find out some different ways to apply a rare drop chance on an movie clip array for AS3. I have a random chance code that works pretty well for enemies, as they fall more often, however I'd like hearts to fall rarely for my player to catch and gain a life.
Here is the code I have so far, it drops far too many hearts. I've tried fiddling with the numbers but I only seem to make it worse. Any suggestions?
function makeHeart():void
{
var chance:Number = Math.floor(Math.random() * 60);
if (chance <= 1 + level)
{
var tempHeart:MovieClip;
tempHeart = new Heart();
tempHeart.speed = 3;
tempHeart.x = Math.round(Math.random() * 800);
tempHeart.cacheAsBitmapMatrix = tempHeart.transform.concatenatedMatrix;
tempHeart.cacheAsBitmap = true;
trace("tempHeart");
addChild(tempHeart);
hearts.push(tempHeart);
}
}
Well, this is either too simple of a question, or I just didn't understand it.
If I did however understand it correctly, here's the way out:
Let's say you want to have a 1% chance of a falling heart. Since you're using a Number class for your chance variable, and Math.random() returns a Number as well, you don't need any transformations.
Math.random() returns a Number (float) between 0 and 1, not including 1
so your code for 1% could look something like this:
var chance:Number = Math.random();
if (chance <= 0.01)
{
//enter code here
}
And yes, since you call less unneeded functions, it works faster.
Math.random() gives a very precise number, far beyond 1/100, so it's possible to make a much less number for chance possibility, here's one value returned from Math.random():
Math.random(); // 0.9044877095147967
i want to create an unfinished jump game. i use super jumper code. the main part for change height of world is :
while (y < WORLD_HEIGHT - WORLD_WIDTH / 2) {
...
y += (maxJumpHeight - 0.5f);
y -= rand.nextFloat() * (maxJumpHeight / 3);
}
if i change while condition to a big number(for example 100 or 1000), fps goes low(i get lag).
i try many things. but i couldn't reach to a correct answer.
if someone can, help me.
(sorry for my english...)
Changing
while (y < WORLD_HEIGHT - WORLD_WIDTH / 2) {
to
while (y < WORLD_HEIGHT * 100) {
in Super Jumper's World.generateLevel will generate a lot more content, but won't actually make the level longer (the display system will only display up to WORLD_HEIGHT, and the end-of-level Castle will still be in the same place.
If you want to make a very large level, change the definition of WORLD_HEIGHT itself. Its currently set to about 20 screens worth of platforms.
The reason the game slows down when you make the levels larger is probably because all the per-frame update and collision detection code uses a linear scan of all the elements. For small levels, this is fine, but if you have very large levels, this won't scale. However, I'm just guessing, and you should probably run the profiler to figure out where all the time is being spent.
I am developing an android game with box2d and use a fixed timestep system for advancing the physics.
However as I use this system it requires the box2d positions to be interpolates. I read this article
and have implemented an interpolation method very much like the one in the article.
The method seems to work nicely on the computer but on my phone the positions of objects are very jumpy. There is of course a big frame rate difference between PC and phone, but I think this algorithm should not mind that.
Here is the just of the code if you don't feel like looking at the article :
void PhysicsSystem::smoothStates_ ()
{
const float oneMinusRatio = 1.f - fixedTimestepAccumulatorRatio_;
for (b2Body * b = world_->GetBodyList (); b != NULL; b = b->GetNext ())
{
if (b->GetType () == b2_staticBody)
{
continue;
}
PhysicsComponent & c = PhysicsComponent::b2BodyToPhysicsComponent (* b);
c.smoothedPosition_ =
fixedTimestepAccumulatorRatio_ * b->GetPosition () +
oneMinusRatio * c.previousPosition_;
c.smoothedAngle_ =
fixedTimestepAccumulatorRatio_ * b->GetAngle () +
oneMinusRatio * c.previousAngle_;
}
}
Does anyone know why my game is acting like this?
Thanks for the help
That code in and of itself doesn't appear to have any issues as compared to the article. You might want to try posting this on https://gamedev.stackexchange.com/ and see if they have any recommendations.
Alternatively, here is a very well written article about having a semi-fixed time step, and decoupling physics and frame rate, which I imagine could be the problem. It isn't for Box2D, but reading over it might help you pinpoint the issue with your physics.
I'm trying to make an epub reader
I want to do the pagination like fbreader does
Now I have source code of fbreader, but I don't know where it implement pagination
I have my implementation on other features
All I need from fbreader is the pagination
Is there anyone who have done the similar thing?
Thanks for your time to read this question.
ps: the pagination is to spit html file to pages, depending on the size of screen and size of font, and language is also in consideration, when changed the font size, the page number also changed. And epub file content is html format
It is fascinating code. I would love to see a translation of the original student project (but I presume the original document is in Russian). As this is a port of a C++ project it has an interesting style of coding in places.
The app keeps track of where you are in the book by using paragraph cursors (ZLTextParagraphCursor). This situation is comparative with database cursors and record pagination. The class that is responsible for serving up the current page and calculating the number of pages is ZLTextView.
As epubs are reflowable documents and not page-oriented there isn't really a concrete definition of a page - it just depends on where in the document you happen to be looking (paragraph, word, character) and with what display settings.
As McLaren says, FBReader doesn't implement pagination: It uses the ZLibrary, which is available from the same website as FBReader.
The original code uses this to calculate the current page number:
size_t ZLTextView::pageNumber() const {
if (textArea().isEmpty()) {
return 0;
}
std::vector<size_t>::const_iterator i = nextBreakIterator();
const size_t startIndex = (i != myTextBreaks.begin()) ? *(i - 1) : 0;
const size_t endIndex = (i != myTextBreaks.end()) ? *i :
textArea().model()->paragraphsNumber();
return (myTextSize[endIndex] - myTextSize[startIndex]) / 2048 + 1;
}
The Java version uses this function to compute the page number:
private synchronized int computeTextPageNumber(int textSize) {
if (myModel == null || myModel.getParagraphsNumber() == 0) {
return 1;
}
final float factor = 1.0f / computeCharsPerPage();
final float pages = textSize * factor;
return Math.max((int)(pages + 1.0f - 0.5f * factor), 1);
}
This is located in org.geometerplus.zlibrary.text.view.TextView
It's so simplistic, though, that you might as well implement your own.
How I understood it is that it uses 3 bitmaps previous current and next. What they have done is written a text which gets stored and read over this 3 bitmaps. Over as what you see on the top they calculate paragraphs data of how long it is for the scroll you see on the others example. You can start reverse engineering at android.view package class bitmapManager. This should explain everything about how they do their paging.