Java tutorial
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package com.gamemaker.GameObjects; import com.badlogic.gdx.math.Vector2; public class Monster { protected Vector2 position, velocity; protected int width, height; protected boolean angry = false; protected boolean happy = false; protected int monsterAppear = 0; protected int monsterGo = 0; public Monster(float x, float y, int width, int height) { this.width = width; this.height = height; position = new Vector2(x, y); velocity = new Vector2(0, 0); //boundingRect = new Rectangle(); } public void update(float delta, Player b) { position.add(velocity.cpy().scl(delta)); //boundingRect.set(position.x, position.y, width, height); if (position.y + height <= 400) { velocity.y = 0; } if (angry && b.getY() + b.getHeight() != position.y + height - 50) { position.y = b.getY() + b.getHeight() - height + 50; } } public float getX() { return position.x; } public float getY() { return position.y; } public int getWidth() { return width; } public int getHeight() { return height; } public void angry() { angry = true; } public void happy() { if (position.y + height > 400) velocity.y = -80; //happy = true; } public void stop() { velocity.x = 0; velocity.y = 0; } public void receive(int i) { if (i == 1) happy(); else angry(); } //public Rectangle getBoundingRect(){ // return boundingRect; //} public boolean collides(Player player) { if (position.x < player.getX() + player.getWidth()) { return true; } return false; } //collides item public boolean collidesItems(Scrollable item) { if (item.getX() + item.getWidth() > position.x) { return true; } return false; } public void setSpeed(float x) { velocity.x = x; } public int getMonsterAppear() { return monsterAppear; } public int getMonsterGo() { return monsterGo; } public void changeMonsterAppear(int a) { monsterAppear = a; } public void changeMonsterGo(int a) { monsterGo = a; } }