我正在制作一个侧卷轴街机游戏,您可以控制火箭,并且必须避免从右侧到左侧的小行波。我遇到的问题是波浪只出现一次。我做另一波的循环不起作用。非常感谢帮助。我在下面添加了我的代码:
<public class AddNewDish extends Activity {
EditText name, quantity, calorie, fat, protein, sugar, vitamins;
Context context = this;
FoodDbHelper foodDbHelper;
SQLiteDatabase sqLiteDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_add_new_dish);
name = (EditText) findViewById(R.id.dish_name);
quantity = (EditText) findViewById(R.id.dish_quantity);
calorie = (EditText) findViewById(R.id.dish_calorie);
fat = (EditText) findViewById(R.id.dish_fat);
protein = (EditText) findViewById(R.id.dish_protein);
sugar = (EditText) findViewById(R.id.dish_sugar);
vitamins = (EditText) findViewById(R.id.dish_vitamins);
}
public void addDish(View view) {
String dish_name = name.getText().toString();
String dish_quantity = quantity.getText().toString();
Integer dish_calorie = Integer.valueOf(calorie.getText().toString());
String dish_fat = fat.getText().toString();
String dish_protein = protein.getText().toString();
String dish_sugar = sugar.getText().toString();
String dish_vitamins = vitamins.getText().toString();
foodDbHelper = new FoodDbHelper(context);
sqLiteDatabase = foodDbHelper.getWritableDatabase();
foodDbHelper.addInformations(dish_name, dish_quantity, dish_calorie, dish_fat,
dish_protein, dish_sugar, dish_vitamins, sqLiteDatabase);
Toast.makeText(getBaseContext(), "Data Saved", Toast.LENGTH_LONG).show();
foodDbHelper.close();
Intent intent = new Intent(this, AddNewDish.class);
startActivity(intent);
}
public void AllDish(View view) {
Intent intent = new Intent(this, DataListActivity.class);
startActivity(intent);
}
public void goback(View view)
{
Intent intent = new Intent(this,MainMenu.class);
startActivity(intent);
}
}>
答案 0 :(得分:0)
我设法使用以下代码解决了这个问题:
import pygame as pg
from random import *
import time
pg.init()
scr = pg.display.set_mode((1000,800))
img2 = pg.image.load("asteroid.gif")
img = pg.transform.scale(img2, (75,75))
imgrect = img.get_rect()
#list with asteroid postitions and speeds
xast = []
yast = []
vx = []
vy = []
t = 0.001*pg.time.get_ticks()
tast = t
t0 = t
dtast = 0.5
running = True
while running:
t = t = 0.001*pg.time.get_ticks()
dt = t - t0
if dt >0.:
t0 = t
for i in range(len(xast)):
xast[i] = xast[i] + vx[i] * dt
yast[i] = yast[i] + vy[i] * dt
#Create new asteroids every dtast seconds
if t - tast >= dtast:
xast.append(999.)
yast.append(float(randint(0,799)))
vx.append(-50)
vy.append(float(randint(-1,1)))
tast = t
#Draw frame
scr.fill((0,0,0))
for i in range(len(xast)):
imgrect.center = (xast[i],yast[i])
scr.blit(img,imgrect)
pg.display.flip()
pg.quit()